blob: 5de84ecbabd0b513db857d837b81c913fb245386 [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 <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/IPCThreadState.h>
25#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiand0566bc2011-11-17 17:49:17 -080027#include <gui/IDisplayEventConnection.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080028#include <gui/IGraphicBufferProducer.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080029#include <gui/ISurfaceComposer.h>
30#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080031#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070032#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080033
Michael Wright28f24d02016-07-12 13:30:53 -070034#include <system/graphics.h>
35
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070037#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070038#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Jamie Gennis134f0422011-03-08 12:18:54 -080040#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080041
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042// ---------------------------------------------------------------------------
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044namespace android {
45
46class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
47{
48public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070049 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 : BpInterface<ISurfaceComposer>(impl)
51 {
52 }
53
Dan Stozad723bd72014-11-18 10:24:03 -080054 virtual ~BpSurfaceComposer();
55
Mathias Agopian7e27f052010-05-28 14:22:23 -070056 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 Parcel data, reply;
59 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
60 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 }
63
Robert Carr1db73f62016-12-21 12:58:51 -080064 virtual sp<ISurfaceComposerClient> createScopedConnection(
65 const sp<IGraphicBufferProducer>& parent)
66 {
67 Parcel data, reply;
68 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
69 data.writeStrongBinder(IInterface::asBinder(parent));
70 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
71 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
72 }
73
Mathias Agopian8b33f032012-07-24 20:43:54 -070074 virtual void setTransactionState(
75 const Vector<ComposerState>& state,
76 const Vector<DisplayState>& displays,
77 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 {
79 Parcel data, reply;
80 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080081
82 data.writeUint32(static_cast<uint32_t>(state.size()));
83 for (const auto& s : state) {
84 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
87 data.writeUint32(static_cast<uint32_t>(displays.size()));
88 for (const auto& d : displays) {
89 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070090 }
Dan Stozad723bd72014-11-18 10:24:03 -080091
92 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070093 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 }
95
96 virtual void bootFinished()
97 {
98 Parcel data, reply;
99 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
100 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
101 }
102
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000103 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
104 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
105 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
106 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800107 Parcel data, reply;
108 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
109 data.writeStrongBinder(display);
Dan Stozac1879002014-05-22 15:59:05 -0700110 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800111 data.writeUint32(reqWidth);
112 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800113 data.writeInt32(minLayerZ);
114 data.writeInt32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800115 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700116 data.writeInt32(static_cast<int32_t>(rotation));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000117 status_t err = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
118
119 if (err != NO_ERROR) {
120 return err;
121 }
122
123 err = reply.readInt32();
124 if (err != NO_ERROR) {
125 return err;
126 }
127
128 *outBuffer = new GraphicBuffer();
129 reply.read(**outBuffer);
130 return err;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800131 }
132
chaviwa76b2712017-09-20 12:02:26 -0700133 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000134 sp<GraphicBuffer>* outBuffer, const Rect& sourceCrop,
135 float frameScale) {
chaviwa76b2712017-09-20 12:02:26 -0700136 Parcel data, reply;
137 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
138 data.writeStrongBinder(layerHandleBinder);
chaviw7206d492017-11-10 16:16:12 -0800139 data.write(sourceCrop);
140 data.writeFloat(frameScale);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000141 status_t err = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
142
143 if (err != NO_ERROR) {
144 return err;
145 }
146
147 err = reply.readInt32();
148 if (err != NO_ERROR) {
149 return err;
150 }
151
152 *outBuffer = new GraphicBuffer();
153 reply.read(**outBuffer);
154
155 return err;
chaviwa76b2712017-09-20 12:02:26 -0700156 }
157
Jamie Gennis582270d2011-08-17 18:19:00 -0700158 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800159 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800160 {
161 Parcel data, reply;
162 int err = NO_ERROR;
163 err = data.writeInterfaceToken(
164 ISurfaceComposer::getInterfaceDescriptor());
165 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000166 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800167 "interface descriptor: %s (%d)", strerror(-err), -err);
168 return false;
169 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800170 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800171 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000172 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700173 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800174 return false;
175 }
176 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
177 &reply);
178 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000179 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700180 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800181 return false;
182 }
183 int32_t result = 0;
184 err = reply.readInt32(&result);
185 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000186 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700187 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800188 return false;
189 }
190 return result != 0;
191 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800192
Brian Anderson6b376712017-04-04 10:51:39 -0700193 virtual status_t getSupportedFrameTimestamps(
194 std::vector<FrameEvent>* outSupported) const {
195 if (!outSupported) {
196 return UNEXPECTED_NULL;
197 }
198 outSupported->clear();
199
200 Parcel data, reply;
201
202 status_t err = data.writeInterfaceToken(
203 ISurfaceComposer::getInterfaceDescriptor());
204 if (err != NO_ERROR) {
205 return err;
206 }
207
208 err = remote()->transact(
209 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
210 data, &reply);
211 if (err != NO_ERROR) {
212 return err;
213 }
214
215 int32_t result = 0;
216 err = reply.readInt32(&result);
217 if (err != NO_ERROR) {
218 return err;
219 }
220 if (result != NO_ERROR) {
221 return result;
222 }
223
224 std::vector<int32_t> supported;
225 err = reply.readInt32Vector(&supported);
226 if (err != NO_ERROR) {
227 return err;
228 }
229
230 outSupported->reserve(supported.size());
231 for (int32_t s : supported) {
232 outSupported->push_back(static_cast<FrameEvent>(s));
233 }
234 return NO_ERROR;
235 }
236
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700237 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800238 {
239 Parcel data, reply;
240 sp<IDisplayEventConnection> result;
241 int err = data.writeInterfaceToken(
242 ISurfaceComposer::getInterfaceDescriptor());
243 if (err != NO_ERROR) {
244 return result;
245 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700246 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800247 err = remote()->transact(
248 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
249 data, &reply);
250 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000251 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800252 "transaction: %s (%d)", strerror(-err), -err);
253 return result;
254 }
255 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
256 return result;
257 }
Colin Cross8e533062012-06-07 13:17:52 -0700258
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700259 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700260 {
261 Parcel data, reply;
262 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700263 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700264 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700265 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
266 return reply.readStrongBinder();
267 }
268
Jesse Hall6c913be2013-08-08 12:15:49 -0700269 virtual void destroyDisplay(const sp<IBinder>& display)
270 {
271 Parcel data, reply;
272 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
273 data.writeStrongBinder(display);
274 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
275 }
276
Mathias Agopiane57f2922012-08-09 16:29:12 -0700277 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
281 data.writeInt32(id);
282 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
283 return reply.readStrongBinder();
284 }
285
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700286 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700287 {
288 Parcel data, reply;
289 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700290 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700291 data.writeInt32(mode);
292 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700293 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700294
Dan Stoza7f7da322014-05-02 15:26:25 -0700295 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
296 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700297 {
298 Parcel data, reply;
299 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700300 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700301 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
302 status_t result = reply.readInt32();
303 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800304 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700305 configs->clear();
306 configs->resize(numConfigs);
307 for (size_t c = 0; c < numConfigs; ++c) {
308 memcpy(&(configs->editItemAt(c)),
309 reply.readInplace(sizeof(DisplayInfo)),
310 sizeof(DisplayInfo));
311 }
312 }
313 return result;
314 }
315
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700316 virtual status_t getDisplayStats(const sp<IBinder>& display,
317 DisplayStatInfo* stats)
318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
321 data.writeStrongBinder(display);
322 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
323 status_t result = reply.readInt32();
324 if (result == NO_ERROR) {
325 memcpy(stats,
326 reply.readInplace(sizeof(DisplayStatInfo)),
327 sizeof(DisplayStatInfo));
328 }
329 return result;
330 }
331
Dan Stoza7f7da322014-05-02 15:26:25 -0700332 virtual int getActiveConfig(const sp<IBinder>& display)
333 {
334 Parcel data, reply;
335 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
336 data.writeStrongBinder(display);
337 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
338 return reply.readInt32();
339 }
340
341 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
345 data.writeStrongBinder(display);
346 data.writeInt32(id);
347 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700348 return reply.readInt32();
349 }
Svetoslavd85084b2014-03-20 10:28:31 -0700350
Michael Wright28f24d02016-07-12 13:30:53 -0700351 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
352 Vector<android_color_mode_t>* outColorModes) {
353 Parcel data, reply;
354 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
355 if (result != NO_ERROR) {
356 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
357 return result;
358 }
359 result = data.writeStrongBinder(display);
360 if (result != NO_ERROR) {
361 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
362 return result;
363 }
364 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
365 if (result != NO_ERROR) {
366 ALOGE("getDisplayColorModes failed to transact: %d", result);
367 return result;
368 }
369 result = static_cast<status_t>(reply.readInt32());
370 if (result == NO_ERROR) {
371 size_t numModes = reply.readUint32();
372 outColorModes->clear();
373 outColorModes->resize(numModes);
374 for (size_t i = 0; i < numModes; ++i) {
375 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
376 }
377 }
378 return result;
379 }
380
381 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
382 Parcel data, reply;
383 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
384 if (result != NO_ERROR) {
385 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
386 return static_cast<android_color_mode_t>(result);
387 }
388 result = data.writeStrongBinder(display);
389 if (result != NO_ERROR) {
390 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
391 return static_cast<android_color_mode_t>(result);
392 }
393 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
394 if (result != NO_ERROR) {
395 ALOGE("getActiveColorMode failed to transact: %d", result);
396 return static_cast<android_color_mode_t>(result);
397 }
398 return static_cast<android_color_mode_t>(reply.readInt32());
399 }
400
401 virtual status_t setActiveColorMode(const sp<IBinder>& display,
402 android_color_mode_t colorMode) {
403 Parcel data, reply;
404 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
405 if (result != NO_ERROR) {
406 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
407 return result;
408 }
409 result = data.writeStrongBinder(display);
410 if (result != NO_ERROR) {
411 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
412 return result;
413 }
414 result = data.writeInt32(colorMode);
415 if (result != NO_ERROR) {
416 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
417 return result;
418 }
419 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
420 if (result != NO_ERROR) {
421 ALOGE("setActiveColorMode failed to transact: %d", result);
422 return result;
423 }
424 return static_cast<status_t>(reply.readInt32());
425 }
426
Svetoslavd85084b2014-03-20 10:28:31 -0700427 virtual status_t clearAnimationFrameStats() {
428 Parcel data, reply;
429 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
430 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
431 return reply.readInt32();
432 }
433
434 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
435 Parcel data, reply;
436 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
437 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
438 reply.read(*outStats);
439 return reply.readInt32();
440 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700441
442 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
443 HdrCapabilities* outCapabilities) const {
444 Parcel data, reply;
445 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
446 status_t result = data.writeStrongBinder(display);
447 if (result != NO_ERROR) {
448 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
449 return result;
450 }
451 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
452 data, &reply);
453 if (result != NO_ERROR) {
454 ALOGE("getHdrCapabilities failed to transact: %d", result);
455 return result;
456 }
457 result = reply.readInt32();
458 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800459 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700460 }
461 return result;
462 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700463
464 virtual status_t enableVSyncInjections(bool enable) {
465 Parcel data, reply;
466 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
467 if (result != NO_ERROR) {
468 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
469 return result;
470 }
471 result = data.writeBool(enable);
472 if (result != NO_ERROR) {
473 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
474 return result;
475 }
476 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
477 data, &reply, TF_ONE_WAY);
478 if (result != NO_ERROR) {
479 ALOGE("enableVSyncInjections failed to transact: %d", result);
480 return result;
481 }
482 return result;
483 }
484
485 virtual status_t injectVSync(nsecs_t when) {
486 Parcel data, reply;
487 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
488 if (result != NO_ERROR) {
489 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
490 return result;
491 }
492 result = data.writeInt64(when);
493 if (result != NO_ERROR) {
494 ALOGE("injectVSync failed to writeInt64: %d", result);
495 return result;
496 }
497 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
498 if (result != NO_ERROR) {
499 ALOGE("injectVSync failed to transact: %d", result);
500 return result;
501 }
502 return result;
503 }
504
Kalle Raitaa099a242017-01-11 11:17:29 -0800505 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
506 {
507 if (!outLayers) {
508 return UNEXPECTED_NULL;
509 }
510
511 Parcel data, reply;
512
513 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
514 if (err != NO_ERROR) {
515 return err;
516 }
517
518 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
519 if (err != NO_ERROR) {
520 return err;
521 }
522
523 int32_t result = 0;
524 err = reply.readInt32(&result);
525 if (err != NO_ERROR) {
526 return err;
527 }
528 if (result != NO_ERROR) {
529 return result;
530 }
531
532 outLayers->clear();
533 return reply.readParcelableVector(outLayers);
534 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535};
536
Dan Stozad723bd72014-11-18 10:24:03 -0800537// Out-of-line virtual method definition to trigger vtable emission in this
538// translation unit (see clang warning -Wweak-vtables)
539BpSurfaceComposer::~BpSurfaceComposer() {}
540
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
542
543// ----------------------------------------------------------------------
544
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800545status_t BnSurfaceComposer::onTransact(
546 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
547{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800548 switch(code) {
549 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700550 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800551 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800552 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700553 return NO_ERROR;
554 }
Robert Carr1db73f62016-12-21 12:58:51 -0800555 case CREATE_SCOPED_CONNECTION: {
556 CHECK_INTERFACE(ISurfaceComposer, data, reply);
557 sp<IGraphicBufferProducer> bufferProducer =
558 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
559 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
560 reply->writeStrongBinder(b);
561 return NO_ERROR;
562 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700563 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700564 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800565
566 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700567 if (count > data.dataSize()) {
568 return BAD_VALUE;
569 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700570 ComposerState s;
571 Vector<ComposerState> state;
572 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800573 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700574 if (s.read(data) == BAD_VALUE) {
575 return BAD_VALUE;
576 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700577 state.add(s);
578 }
Dan Stozad723bd72014-11-18 10:24:03 -0800579
580 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700581 if (count > data.dataSize()) {
582 return BAD_VALUE;
583 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700584 DisplayState d;
585 Vector<DisplayState> displays;
586 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800587 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700588 if (d.read(data) == BAD_VALUE) {
589 return BAD_VALUE;
590 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700591 displays.add(d);
592 }
Dan Stozad723bd72014-11-18 10:24:03 -0800593
594 uint32_t stateFlags = data.readUint32();
595 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700596 return NO_ERROR;
597 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800598 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700599 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800600 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700601 return NO_ERROR;
602 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800603 case CAPTURE_SCREEN: {
604 CHECK_INTERFACE(ISurfaceComposer, data, reply);
605 sp<IBinder> display = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000606 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700607 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700608 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800609 uint32_t reqWidth = data.readUint32();
610 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800611 int32_t minLayerZ = data.readInt32();
612 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800613 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800614 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800615
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000616 status_t res = captureScreen(display, &outBuffer, sourceCrop, reqWidth, reqHeight,
617 minLayerZ, maxLayerZ, useIdentityTransform,
618 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800619 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000620 if (res == NO_ERROR) {
621 reply->write(*outBuffer);
622 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700623 return NO_ERROR;
624 }
chaviwa76b2712017-09-20 12:02:26 -0700625 case CAPTURE_LAYERS: {
626 CHECK_INTERFACE(ISurfaceComposer, data, reply);
627 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000628 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800629 Rect sourceCrop(Rect::EMPTY_RECT);
630 data.read(sourceCrop);
631 float frameScale = data.readFloat();
chaviwa76b2712017-09-20 12:02:26 -0700632
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000633 status_t res = captureLayers(layerHandleBinder, &outBuffer, sourceCrop, frameScale);
chaviwa76b2712017-09-20 12:02:26 -0700634 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000635 if (res == NO_ERROR) {
636 reply->write(*outBuffer);
637 }
chaviwa76b2712017-09-20 12:02:26 -0700638 return NO_ERROR;
639 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800640 case AUTHENTICATE_SURFACE: {
641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800642 sp<IGraphicBufferProducer> bufferProducer =
643 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
644 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800645 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700646 return NO_ERROR;
647 }
Brian Anderson6b376712017-04-04 10:51:39 -0700648 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
649 CHECK_INTERFACE(ISurfaceComposer, data, reply);
650 std::vector<FrameEvent> supportedTimestamps;
651 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
652 status_t err = reply->writeInt32(result);
653 if (err != NO_ERROR) {
654 return err;
655 }
656 if (result != NO_ERROR) {
657 return result;
658 }
659
660 std::vector<int32_t> supported;
661 supported.reserve(supportedTimestamps.size());
662 for (FrameEvent s : supportedTimestamps) {
663 supported.push_back(static_cast<int32_t>(s));
664 }
665 return reply->writeInt32Vector(supported);
666 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800667 case CREATE_DISPLAY_EVENT_CONNECTION: {
668 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700669 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
670 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800671 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800672 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700673 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700674 case CREATE_DISPLAY: {
675 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700676 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700677 bool secure = bool(data.readInt32());
678 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700679 reply->writeStrongBinder(display);
680 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700681 }
682 case DESTROY_DISPLAY: {
683 CHECK_INTERFACE(ISurfaceComposer, data, reply);
684 sp<IBinder> display = data.readStrongBinder();
685 destroyDisplay(display);
686 return NO_ERROR;
687 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700688 case GET_BUILT_IN_DISPLAY: {
689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
690 int32_t id = data.readInt32();
691 sp<IBinder> display(getBuiltInDisplay(id));
692 reply->writeStrongBinder(display);
693 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700694 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700695 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700696 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700697 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700698 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700699 status_t result = getDisplayConfigs(display, &configs);
700 reply->writeInt32(result);
701 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800702 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700703 for (size_t c = 0; c < configs.size(); ++c) {
704 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
705 &configs[c], sizeof(DisplayInfo));
706 }
707 }
708 return NO_ERROR;
709 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700710 case GET_DISPLAY_STATS: {
711 CHECK_INTERFACE(ISurfaceComposer, data, reply);
712 DisplayStatInfo stats;
713 sp<IBinder> display = data.readStrongBinder();
714 status_t result = getDisplayStats(display, &stats);
715 reply->writeInt32(result);
716 if (result == NO_ERROR) {
717 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
718 &stats, sizeof(DisplayStatInfo));
719 }
720 return NO_ERROR;
721 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700722 case GET_ACTIVE_CONFIG: {
723 CHECK_INTERFACE(ISurfaceComposer, data, reply);
724 sp<IBinder> display = data.readStrongBinder();
725 int id = getActiveConfig(display);
726 reply->writeInt32(id);
727 return NO_ERROR;
728 }
729 case SET_ACTIVE_CONFIG: {
730 CHECK_INTERFACE(ISurfaceComposer, data, reply);
731 sp<IBinder> display = data.readStrongBinder();
732 int id = data.readInt32();
733 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700734 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700735 return NO_ERROR;
736 }
Michael Wright28f24d02016-07-12 13:30:53 -0700737 case GET_DISPLAY_COLOR_MODES: {
738 CHECK_INTERFACE(ISurfaceComposer, data, reply);
739 Vector<android_color_mode_t> colorModes;
740 sp<IBinder> display = nullptr;
741 status_t result = data.readStrongBinder(&display);
742 if (result != NO_ERROR) {
743 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
744 return result;
745 }
746 result = getDisplayColorModes(display, &colorModes);
747 reply->writeInt32(result);
748 if (result == NO_ERROR) {
749 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
750 for (size_t i = 0; i < colorModes.size(); ++i) {
751 reply->writeInt32(colorModes[i]);
752 }
753 }
754 return NO_ERROR;
755 }
756 case GET_ACTIVE_COLOR_MODE: {
757 CHECK_INTERFACE(ISurfaceComposer, data, reply);
758 sp<IBinder> display = nullptr;
759 status_t result = data.readStrongBinder(&display);
760 if (result != NO_ERROR) {
761 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
762 return result;
763 }
764 android_color_mode_t colorMode = getActiveColorMode(display);
765 result = reply->writeInt32(static_cast<int32_t>(colorMode));
766 return result;
767 }
768 case SET_ACTIVE_COLOR_MODE: {
769 CHECK_INTERFACE(ISurfaceComposer, data, reply);
770 sp<IBinder> display = nullptr;
771 status_t result = data.readStrongBinder(&display);
772 if (result != NO_ERROR) {
773 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
774 return result;
775 }
776 int32_t colorModeInt = 0;
777 result = data.readInt32(&colorModeInt);
778 if (result != NO_ERROR) {
779 ALOGE("setActiveColorMode failed to readInt32: %d", result);
780 return result;
781 }
782 result = setActiveColorMode(display,
783 static_cast<android_color_mode_t>(colorModeInt));
784 result = reply->writeInt32(result);
785 return result;
786 }
Svetoslavd85084b2014-03-20 10:28:31 -0700787 case CLEAR_ANIMATION_FRAME_STATS: {
788 CHECK_INTERFACE(ISurfaceComposer, data, reply);
789 status_t result = clearAnimationFrameStats();
790 reply->writeInt32(result);
791 return NO_ERROR;
792 }
793 case GET_ANIMATION_FRAME_STATS: {
794 CHECK_INTERFACE(ISurfaceComposer, data, reply);
795 FrameStats stats;
796 status_t result = getAnimationFrameStats(&stats);
797 reply->write(stats);
798 reply->writeInt32(result);
799 return NO_ERROR;
800 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700801 case SET_POWER_MODE: {
802 CHECK_INTERFACE(ISurfaceComposer, data, reply);
803 sp<IBinder> display = data.readStrongBinder();
804 int32_t mode = data.readInt32();
805 setPowerMode(display, mode);
806 return NO_ERROR;
807 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700808 case GET_HDR_CAPABILITIES: {
809 CHECK_INTERFACE(ISurfaceComposer, data, reply);
810 sp<IBinder> display = nullptr;
811 status_t result = data.readStrongBinder(&display);
812 if (result != NO_ERROR) {
813 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
814 result);
815 return result;
816 }
817 HdrCapabilities capabilities;
818 result = getHdrCapabilities(display, &capabilities);
819 reply->writeInt32(result);
820 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800821 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700822 }
823 return NO_ERROR;
824 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700825 case ENABLE_VSYNC_INJECTIONS: {
826 CHECK_INTERFACE(ISurfaceComposer, data, reply);
827 bool enable = false;
828 status_t result = data.readBool(&enable);
829 if (result != NO_ERROR) {
830 ALOGE("enableVSyncInjections failed to readBool: %d", result);
831 return result;
832 }
833 return enableVSyncInjections(enable);
834 }
835 case INJECT_VSYNC: {
836 CHECK_INTERFACE(ISurfaceComposer, data, reply);
837 int64_t when = 0;
838 status_t result = data.readInt64(&when);
839 if (result != NO_ERROR) {
840 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
841 return result;
842 }
843 return injectVSync(when);
844 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800845 case GET_LAYER_DEBUG_INFO: {
846 CHECK_INTERFACE(ISurfaceComposer, data, reply);
847 std::vector<LayerDebugInfo> outLayers;
848 status_t result = getLayerDebugInfo(&outLayers);
849 reply->writeInt32(result);
850 if (result == NO_ERROR)
851 {
852 result = reply->writeParcelableVector(outLayers);
853 }
854 return result;
855 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700856 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700857 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700858 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800859 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800860}
861
862// ----------------------------------------------------------------------------
863
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800864};