blob: 5a3fa04379d0c68cf46eb7795255095767015779 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// tag as surfaceflinger
18#define LOG_TAG "SurfaceFlinger"
19
20#include <stdio.h>
21#include <stdint.h>
22#include <sys/types.h>
23
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
25#include <binder/IMemory.h>
26#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <ui/Point.h>
30#include <ui/Rect.h>
31
Mathias Agopian4d9b8222013-03-12 17:11:48 -070032#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080033#include <gui/ISurfaceComposerClient.h>
34#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40enum {
Mathias Agopiana67932f2011-04-20 14:20:59 -070041 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Svetoslavd85084b2014-03-20 10:28:31 -070042 DESTROY_SURFACE,
43 CLEAR_LAYER_FRAME_STATS,
Robert Carr367c5682016-06-20 11:55:28 -070044 GET_LAYER_FRAME_STATS,
45 GET_TRANSFORM_TO_DISPLAY_INVERSE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046};
47
Mathias Agopian7e27f052010-05-28 14:22:23 -070048class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049{
50public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070051 explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
Mathias Agopian4d9b8222013-03-12 17:11:48 -070052 : BpInterface<ISurfaceComposerClient>(impl) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 }
54
Dan Stozad723bd72014-11-18 10:24:03 -080055 virtual ~BpSurfaceComposerClient();
56
57 virtual status_t createSurface(const String8& name, uint32_t width,
58 uint32_t height, PixelFormat format, uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -050059 const sp<IBinder>& parent, uint32_t windowType, uint32_t ownerUid,
60 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070062 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080063 data.writeString8(name);
Dan Stozad723bd72014-11-18 10:24:03 -080064 data.writeUint32(width);
65 data.writeUint32(height);
66 data.writeInt32(static_cast<int32_t>(format));
67 data.writeUint32(flags);
Albert Chaulk479c60c2017-01-27 14:21:34 -050068 data.writeUint32(windowType);
69 data.writeUint32(ownerUid);
Robert Carr1f0a16a2016-10-24 16:27:39 -070070 if (parent != nullptr) {
71 data.writeStrongBinder(parent);
72 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070074 *handle = reply.readStrongBinder();
75 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
76 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070078
Mathias Agopian4d9b8222013-03-12 17:11:48 -070079 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070081 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080082 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 remote()->transact(DESTROY_SURFACE, data, &reply);
84 return reply.readInt32();
85 }
Svetoslavd85084b2014-03-20 10:28:31 -070086
87 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
88 Parcel data, reply;
89 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
90 data.writeStrongBinder(handle);
91 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
92 return reply.readInt32();
93 }
94
95 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
96 Parcel data, reply;
97 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
98 data.writeStrongBinder(handle);
99 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
100 reply.read(*outStats);
101 return reply.readInt32();
102 }
Robert Carr367c5682016-06-20 11:55:28 -0700103
104 virtual status_t getTransformToDisplayInverse(const sp<IBinder>& handle,
105 bool* outTransformToDisplayInverse) const {
106 Parcel data, reply;
107 status_t result =
108 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
109 if (result != NO_ERROR) {
110 return result;
111 }
112 result = data.writeStrongBinder(handle);
113 if (result != NO_ERROR) {
114 return result;
115 }
116 result = remote()->transact(GET_TRANSFORM_TO_DISPLAY_INVERSE, data, &reply);
117 if (result != NO_ERROR) {
118 return result;
119 }
120 int transformInverse;
121 result = reply.readInt32(&transformInverse);
122 if (result != NO_ERROR) {
123 return result;
124 }
125 *outTransformToDisplayInverse = transformInverse != 0 ? true : false;
126 status_t result2 = reply.readInt32(&result);
127 if (result2 != NO_ERROR) {
128 return result2;
129 }
130 return result;
131 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132};
133
Dan Stozad723bd72014-11-18 10:24:03 -0800134// Out-of-line virtual method definition to trigger vtable emission in this
135// translation unit (see clang warning -Wweak-vtables)
136BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
137
Mathias Agopian7e27f052010-05-28 14:22:23 -0700138IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139
140// ----------------------------------------------------------------------
141
Mathias Agopian7e27f052010-05-28 14:22:23 -0700142status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
144{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 switch(code) {
146 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700147 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800148 String8 name = data.readString8();
Dan Stozad723bd72014-11-18 10:24:03 -0800149 uint32_t width = data.readUint32();
150 uint32_t height = data.readUint32();
151 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
152 uint32_t createFlags = data.readUint32();
Albert Chaulk479c60c2017-01-27 14:21:34 -0500153 uint32_t windowType = data.readUint32();
154 uint32_t ownerUid = data.readUint32();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700155 sp<IBinder> parent = nullptr;
156 if (data.dataAvail() > 0) {
157 parent = data.readStrongBinder();
158 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700159 sp<IBinder> handle;
160 sp<IGraphicBufferProducer> gbp;
Dan Stozad723bd72014-11-18 10:24:03 -0800161 status_t result = createSurface(name, width, height, format,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500162 createFlags, parent, windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700163 reply->writeStrongBinder(handle);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800164 reply->writeStrongBinder(IInterface::asBinder(gbp));
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700165 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800167 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700169 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Svetoslavd85084b2014-03-20 10:28:31 -0700170 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
171 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800172 }
Svetoslavd85084b2014-03-20 10:28:31 -0700173 case CLEAR_LAYER_FRAME_STATS: {
174 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
175 sp<IBinder> handle = data.readStrongBinder();
176 status_t result = clearLayerFrameStats(handle);
177 reply->writeInt32(result);
178 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800179 }
Svetoslavd85084b2014-03-20 10:28:31 -0700180 case GET_LAYER_FRAME_STATS: {
181 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
182 sp<IBinder> handle = data.readStrongBinder();
183 FrameStats stats;
184 status_t result = getLayerFrameStats(handle, &stats);
185 reply->write(stats);
186 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800188 }
Robert Carr367c5682016-06-20 11:55:28 -0700189 case GET_TRANSFORM_TO_DISPLAY_INVERSE: {
190 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
191 sp<IBinder> handle;
192 status_t result = data.readStrongBinder(&handle);
193 if (result != NO_ERROR) {
194 return result;
195 }
196 bool transformInverse = false;
197 result = getTransformToDisplayInverse(handle, &transformInverse);
198 if (result != NO_ERROR) {
199 return result;
200 }
201 result = reply->writeInt32(transformInverse ? 1 : 0);
202 if (result != NO_ERROR) {
203 return result;
204 }
205 result = reply->writeInt32(NO_ERROR);
206 return result;
207 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208 default:
209 return BBinder::onTransact(code, data, reply, flags);
210 }
211}
212
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213}; // namespace android