blob: beda7783963a2adfabb9f2df0f56a961091ba4a2 [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,
Robert Carr578038f2018-03-09 12:25:24 -0800135 float frameScale, bool childrenOnly) {
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);
Robert Carr578038f2018-03-09 12:25:24 -0800141 data.writeBool(childrenOnly);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000142 status_t err = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
143
144 if (err != NO_ERROR) {
145 return err;
146 }
147
148 err = reply.readInt32();
149 if (err != NO_ERROR) {
150 return err;
151 }
152
153 *outBuffer = new GraphicBuffer();
154 reply.read(**outBuffer);
155
156 return err;
chaviwa76b2712017-09-20 12:02:26 -0700157 }
158
Jamie Gennis582270d2011-08-17 18:19:00 -0700159 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800160 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800161 {
162 Parcel data, reply;
163 int err = NO_ERROR;
164 err = data.writeInterfaceToken(
165 ISurfaceComposer::getInterfaceDescriptor());
166 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000167 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800168 "interface descriptor: %s (%d)", strerror(-err), -err);
169 return false;
170 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800171 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800172 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000173 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700174 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800175 return false;
176 }
177 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
178 &reply);
179 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000180 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700181 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800182 return false;
183 }
184 int32_t result = 0;
185 err = reply.readInt32(&result);
186 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000187 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700188 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800189 return false;
190 }
191 return result != 0;
192 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800193
Brian Anderson6b376712017-04-04 10:51:39 -0700194 virtual status_t getSupportedFrameTimestamps(
195 std::vector<FrameEvent>* outSupported) const {
196 if (!outSupported) {
197 return UNEXPECTED_NULL;
198 }
199 outSupported->clear();
200
201 Parcel data, reply;
202
203 status_t err = data.writeInterfaceToken(
204 ISurfaceComposer::getInterfaceDescriptor());
205 if (err != NO_ERROR) {
206 return err;
207 }
208
209 err = remote()->transact(
210 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
211 data, &reply);
212 if (err != NO_ERROR) {
213 return err;
214 }
215
216 int32_t result = 0;
217 err = reply.readInt32(&result);
218 if (err != NO_ERROR) {
219 return err;
220 }
221 if (result != NO_ERROR) {
222 return result;
223 }
224
225 std::vector<int32_t> supported;
226 err = reply.readInt32Vector(&supported);
227 if (err != NO_ERROR) {
228 return err;
229 }
230
231 outSupported->reserve(supported.size());
232 for (int32_t s : supported) {
233 outSupported->push_back(static_cast<FrameEvent>(s));
234 }
235 return NO_ERROR;
236 }
237
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700238 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800239 {
240 Parcel data, reply;
241 sp<IDisplayEventConnection> result;
242 int err = data.writeInterfaceToken(
243 ISurfaceComposer::getInterfaceDescriptor());
244 if (err != NO_ERROR) {
245 return result;
246 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700247 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800248 err = remote()->transact(
249 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
250 data, &reply);
251 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000252 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800253 "transaction: %s (%d)", strerror(-err), -err);
254 return result;
255 }
256 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
257 return result;
258 }
Colin Cross8e533062012-06-07 13:17:52 -0700259
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700260 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700261 {
262 Parcel data, reply;
263 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700264 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700265 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700266 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
267 return reply.readStrongBinder();
268 }
269
Jesse Hall6c913be2013-08-08 12:15:49 -0700270 virtual void destroyDisplay(const sp<IBinder>& display)
271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
274 data.writeStrongBinder(display);
275 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
276 }
277
Mathias Agopiane57f2922012-08-09 16:29:12 -0700278 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
279 {
280 Parcel data, reply;
281 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
282 data.writeInt32(id);
283 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
284 return reply.readStrongBinder();
285 }
286
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700287 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700288 {
289 Parcel data, reply;
290 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700291 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700292 data.writeInt32(mode);
293 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700294 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700295
Dan Stoza7f7da322014-05-02 15:26:25 -0700296 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
297 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700301 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700302 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
303 status_t result = reply.readInt32();
304 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800305 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700306 configs->clear();
307 configs->resize(numConfigs);
308 for (size_t c = 0; c < numConfigs; ++c) {
309 memcpy(&(configs->editItemAt(c)),
310 reply.readInplace(sizeof(DisplayInfo)),
311 sizeof(DisplayInfo));
312 }
313 }
314 return result;
315 }
316
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700317 virtual status_t getDisplayStats(const sp<IBinder>& display,
318 DisplayStatInfo* stats)
319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
322 data.writeStrongBinder(display);
323 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
324 status_t result = reply.readInt32();
325 if (result == NO_ERROR) {
326 memcpy(stats,
327 reply.readInplace(sizeof(DisplayStatInfo)),
328 sizeof(DisplayStatInfo));
329 }
330 return result;
331 }
332
Dan Stoza7f7da322014-05-02 15:26:25 -0700333 virtual int getActiveConfig(const sp<IBinder>& display)
334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
337 data.writeStrongBinder(display);
338 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
339 return reply.readInt32();
340 }
341
342 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
343 {
344 Parcel data, reply;
345 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
346 data.writeStrongBinder(display);
347 data.writeInt32(id);
348 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700349 return reply.readInt32();
350 }
Svetoslavd85084b2014-03-20 10:28:31 -0700351
Michael Wright28f24d02016-07-12 13:30:53 -0700352 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
353 Vector<android_color_mode_t>* outColorModes) {
354 Parcel data, reply;
355 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
356 if (result != NO_ERROR) {
357 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
358 return result;
359 }
360 result = data.writeStrongBinder(display);
361 if (result != NO_ERROR) {
362 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
363 return result;
364 }
365 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
366 if (result != NO_ERROR) {
367 ALOGE("getDisplayColorModes failed to transact: %d", result);
368 return result;
369 }
370 result = static_cast<status_t>(reply.readInt32());
371 if (result == NO_ERROR) {
372 size_t numModes = reply.readUint32();
373 outColorModes->clear();
374 outColorModes->resize(numModes);
375 for (size_t i = 0; i < numModes; ++i) {
376 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
377 }
378 }
379 return result;
380 }
381
382 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
383 Parcel data, reply;
384 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
385 if (result != NO_ERROR) {
386 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
387 return static_cast<android_color_mode_t>(result);
388 }
389 result = data.writeStrongBinder(display);
390 if (result != NO_ERROR) {
391 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
392 return static_cast<android_color_mode_t>(result);
393 }
394 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
395 if (result != NO_ERROR) {
396 ALOGE("getActiveColorMode failed to transact: %d", result);
397 return static_cast<android_color_mode_t>(result);
398 }
399 return static_cast<android_color_mode_t>(reply.readInt32());
400 }
401
402 virtual status_t setActiveColorMode(const sp<IBinder>& display,
403 android_color_mode_t colorMode) {
404 Parcel data, reply;
405 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
406 if (result != NO_ERROR) {
407 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
408 return result;
409 }
410 result = data.writeStrongBinder(display);
411 if (result != NO_ERROR) {
412 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
413 return result;
414 }
415 result = data.writeInt32(colorMode);
416 if (result != NO_ERROR) {
417 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
418 return result;
419 }
420 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
421 if (result != NO_ERROR) {
422 ALOGE("setActiveColorMode failed to transact: %d", result);
423 return result;
424 }
425 return static_cast<status_t>(reply.readInt32());
426 }
427
Svetoslavd85084b2014-03-20 10:28:31 -0700428 virtual status_t clearAnimationFrameStats() {
429 Parcel data, reply;
430 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
431 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
432 return reply.readInt32();
433 }
434
435 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
436 Parcel data, reply;
437 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
438 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
439 reply.read(*outStats);
440 return reply.readInt32();
441 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700442
443 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
444 HdrCapabilities* outCapabilities) const {
445 Parcel data, reply;
446 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
447 status_t result = data.writeStrongBinder(display);
448 if (result != NO_ERROR) {
449 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
450 return result;
451 }
452 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
453 data, &reply);
454 if (result != NO_ERROR) {
455 ALOGE("getHdrCapabilities failed to transact: %d", result);
456 return result;
457 }
458 result = reply.readInt32();
459 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800460 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700461 }
462 return result;
463 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700464
465 virtual status_t enableVSyncInjections(bool enable) {
466 Parcel data, reply;
467 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
468 if (result != NO_ERROR) {
469 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
470 return result;
471 }
472 result = data.writeBool(enable);
473 if (result != NO_ERROR) {
474 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
475 return result;
476 }
477 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
478 data, &reply, TF_ONE_WAY);
479 if (result != NO_ERROR) {
480 ALOGE("enableVSyncInjections failed to transact: %d", result);
481 return result;
482 }
483 return result;
484 }
485
486 virtual status_t injectVSync(nsecs_t when) {
487 Parcel data, reply;
488 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
489 if (result != NO_ERROR) {
490 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
491 return result;
492 }
493 result = data.writeInt64(when);
494 if (result != NO_ERROR) {
495 ALOGE("injectVSync failed to writeInt64: %d", result);
496 return result;
497 }
498 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
499 if (result != NO_ERROR) {
500 ALOGE("injectVSync failed to transact: %d", result);
501 return result;
502 }
503 return result;
504 }
505
Kalle Raitaa099a242017-01-11 11:17:29 -0800506 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
507 {
508 if (!outLayers) {
509 return UNEXPECTED_NULL;
510 }
511
512 Parcel data, reply;
513
514 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
515 if (err != NO_ERROR) {
516 return err;
517 }
518
519 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
520 if (err != NO_ERROR) {
521 return err;
522 }
523
524 int32_t result = 0;
525 err = reply.readInt32(&result);
526 if (err != NO_ERROR) {
527 return err;
528 }
529 if (result != NO_ERROR) {
530 return result;
531 }
532
533 outLayers->clear();
534 return reply.readParcelableVector(outLayers);
535 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800536};
537
Dan Stozad723bd72014-11-18 10:24:03 -0800538// Out-of-line virtual method definition to trigger vtable emission in this
539// translation unit (see clang warning -Wweak-vtables)
540BpSurfaceComposer::~BpSurfaceComposer() {}
541
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800542IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
543
544// ----------------------------------------------------------------------
545
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800546status_t BnSurfaceComposer::onTransact(
547 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
548{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549 switch(code) {
550 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700551 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800552 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800553 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700554 return NO_ERROR;
555 }
Robert Carr1db73f62016-12-21 12:58:51 -0800556 case CREATE_SCOPED_CONNECTION: {
557 CHECK_INTERFACE(ISurfaceComposer, data, reply);
558 sp<IGraphicBufferProducer> bufferProducer =
559 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
560 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
561 reply->writeStrongBinder(b);
562 return NO_ERROR;
563 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700564 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700565 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800566
567 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700568 if (count > data.dataSize()) {
569 return BAD_VALUE;
570 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700571 ComposerState s;
572 Vector<ComposerState> state;
573 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800574 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700575 if (s.read(data) == BAD_VALUE) {
576 return BAD_VALUE;
577 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700578 state.add(s);
579 }
Dan Stozad723bd72014-11-18 10:24:03 -0800580
581 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700582 if (count > data.dataSize()) {
583 return BAD_VALUE;
584 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700585 DisplayState d;
586 Vector<DisplayState> displays;
587 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800588 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700589 if (d.read(data) == BAD_VALUE) {
590 return BAD_VALUE;
591 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700592 displays.add(d);
593 }
Dan Stozad723bd72014-11-18 10:24:03 -0800594
595 uint32_t stateFlags = data.readUint32();
596 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700597 return NO_ERROR;
598 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700600 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800601 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700602 return NO_ERROR;
603 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800604 case CAPTURE_SCREEN: {
605 CHECK_INTERFACE(ISurfaceComposer, data, reply);
606 sp<IBinder> display = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000607 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700608 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700609 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800610 uint32_t reqWidth = data.readUint32();
611 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800612 int32_t minLayerZ = data.readInt32();
613 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800614 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800615 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800616
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000617 status_t res = captureScreen(display, &outBuffer, sourceCrop, reqWidth, reqHeight,
618 minLayerZ, maxLayerZ, useIdentityTransform,
619 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800620 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000621 if (res == NO_ERROR) {
622 reply->write(*outBuffer);
623 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700624 return NO_ERROR;
625 }
chaviwa76b2712017-09-20 12:02:26 -0700626 case CAPTURE_LAYERS: {
627 CHECK_INTERFACE(ISurfaceComposer, data, reply);
628 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000629 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800630 Rect sourceCrop(Rect::EMPTY_RECT);
631 data.read(sourceCrop);
632 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800633 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700634
Robert Carr578038f2018-03-09 12:25:24 -0800635 status_t res = captureLayers(layerHandleBinder, &outBuffer, sourceCrop, frameScale,
636 childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700637 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000638 if (res == NO_ERROR) {
639 reply->write(*outBuffer);
640 }
chaviwa76b2712017-09-20 12:02:26 -0700641 return NO_ERROR;
642 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800643 case AUTHENTICATE_SURFACE: {
644 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800645 sp<IGraphicBufferProducer> bufferProducer =
646 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
647 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800648 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700649 return NO_ERROR;
650 }
Brian Anderson6b376712017-04-04 10:51:39 -0700651 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
652 CHECK_INTERFACE(ISurfaceComposer, data, reply);
653 std::vector<FrameEvent> supportedTimestamps;
654 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
655 status_t err = reply->writeInt32(result);
656 if (err != NO_ERROR) {
657 return err;
658 }
659 if (result != NO_ERROR) {
660 return result;
661 }
662
663 std::vector<int32_t> supported;
664 supported.reserve(supportedTimestamps.size());
665 for (FrameEvent s : supportedTimestamps) {
666 supported.push_back(static_cast<int32_t>(s));
667 }
668 return reply->writeInt32Vector(supported);
669 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800670 case CREATE_DISPLAY_EVENT_CONNECTION: {
671 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700672 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
673 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800674 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800675 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700676 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700677 case CREATE_DISPLAY: {
678 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700679 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700680 bool secure = bool(data.readInt32());
681 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700682 reply->writeStrongBinder(display);
683 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700684 }
685 case DESTROY_DISPLAY: {
686 CHECK_INTERFACE(ISurfaceComposer, data, reply);
687 sp<IBinder> display = data.readStrongBinder();
688 destroyDisplay(display);
689 return NO_ERROR;
690 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700691 case GET_BUILT_IN_DISPLAY: {
692 CHECK_INTERFACE(ISurfaceComposer, data, reply);
693 int32_t id = data.readInt32();
694 sp<IBinder> display(getBuiltInDisplay(id));
695 reply->writeStrongBinder(display);
696 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700697 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700698 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700699 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700700 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700701 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700702 status_t result = getDisplayConfigs(display, &configs);
703 reply->writeInt32(result);
704 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800705 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700706 for (size_t c = 0; c < configs.size(); ++c) {
707 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
708 &configs[c], sizeof(DisplayInfo));
709 }
710 }
711 return NO_ERROR;
712 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700713 case GET_DISPLAY_STATS: {
714 CHECK_INTERFACE(ISurfaceComposer, data, reply);
715 DisplayStatInfo stats;
716 sp<IBinder> display = data.readStrongBinder();
717 status_t result = getDisplayStats(display, &stats);
718 reply->writeInt32(result);
719 if (result == NO_ERROR) {
720 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
721 &stats, sizeof(DisplayStatInfo));
722 }
723 return NO_ERROR;
724 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700725 case GET_ACTIVE_CONFIG: {
726 CHECK_INTERFACE(ISurfaceComposer, data, reply);
727 sp<IBinder> display = data.readStrongBinder();
728 int id = getActiveConfig(display);
729 reply->writeInt32(id);
730 return NO_ERROR;
731 }
732 case SET_ACTIVE_CONFIG: {
733 CHECK_INTERFACE(ISurfaceComposer, data, reply);
734 sp<IBinder> display = data.readStrongBinder();
735 int id = data.readInt32();
736 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700737 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700738 return NO_ERROR;
739 }
Michael Wright28f24d02016-07-12 13:30:53 -0700740 case GET_DISPLAY_COLOR_MODES: {
741 CHECK_INTERFACE(ISurfaceComposer, data, reply);
742 Vector<android_color_mode_t> colorModes;
743 sp<IBinder> display = nullptr;
744 status_t result = data.readStrongBinder(&display);
745 if (result != NO_ERROR) {
746 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
747 return result;
748 }
749 result = getDisplayColorModes(display, &colorModes);
750 reply->writeInt32(result);
751 if (result == NO_ERROR) {
752 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
753 for (size_t i = 0; i < colorModes.size(); ++i) {
754 reply->writeInt32(colorModes[i]);
755 }
756 }
757 return NO_ERROR;
758 }
759 case GET_ACTIVE_COLOR_MODE: {
760 CHECK_INTERFACE(ISurfaceComposer, data, reply);
761 sp<IBinder> display = nullptr;
762 status_t result = data.readStrongBinder(&display);
763 if (result != NO_ERROR) {
764 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
765 return result;
766 }
767 android_color_mode_t colorMode = getActiveColorMode(display);
768 result = reply->writeInt32(static_cast<int32_t>(colorMode));
769 return result;
770 }
771 case SET_ACTIVE_COLOR_MODE: {
772 CHECK_INTERFACE(ISurfaceComposer, data, reply);
773 sp<IBinder> display = nullptr;
774 status_t result = data.readStrongBinder(&display);
775 if (result != NO_ERROR) {
776 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
777 return result;
778 }
779 int32_t colorModeInt = 0;
780 result = data.readInt32(&colorModeInt);
781 if (result != NO_ERROR) {
782 ALOGE("setActiveColorMode failed to readInt32: %d", result);
783 return result;
784 }
785 result = setActiveColorMode(display,
786 static_cast<android_color_mode_t>(colorModeInt));
787 result = reply->writeInt32(result);
788 return result;
789 }
Svetoslavd85084b2014-03-20 10:28:31 -0700790 case CLEAR_ANIMATION_FRAME_STATS: {
791 CHECK_INTERFACE(ISurfaceComposer, data, reply);
792 status_t result = clearAnimationFrameStats();
793 reply->writeInt32(result);
794 return NO_ERROR;
795 }
796 case GET_ANIMATION_FRAME_STATS: {
797 CHECK_INTERFACE(ISurfaceComposer, data, reply);
798 FrameStats stats;
799 status_t result = getAnimationFrameStats(&stats);
800 reply->write(stats);
801 reply->writeInt32(result);
802 return NO_ERROR;
803 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700804 case SET_POWER_MODE: {
805 CHECK_INTERFACE(ISurfaceComposer, data, reply);
806 sp<IBinder> display = data.readStrongBinder();
807 int32_t mode = data.readInt32();
808 setPowerMode(display, mode);
809 return NO_ERROR;
810 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700811 case GET_HDR_CAPABILITIES: {
812 CHECK_INTERFACE(ISurfaceComposer, data, reply);
813 sp<IBinder> display = nullptr;
814 status_t result = data.readStrongBinder(&display);
815 if (result != NO_ERROR) {
816 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
817 result);
818 return result;
819 }
820 HdrCapabilities capabilities;
821 result = getHdrCapabilities(display, &capabilities);
822 reply->writeInt32(result);
823 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800824 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700825 }
826 return NO_ERROR;
827 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700828 case ENABLE_VSYNC_INJECTIONS: {
829 CHECK_INTERFACE(ISurfaceComposer, data, reply);
830 bool enable = false;
831 status_t result = data.readBool(&enable);
832 if (result != NO_ERROR) {
833 ALOGE("enableVSyncInjections failed to readBool: %d", result);
834 return result;
835 }
836 return enableVSyncInjections(enable);
837 }
838 case INJECT_VSYNC: {
839 CHECK_INTERFACE(ISurfaceComposer, data, reply);
840 int64_t when = 0;
841 status_t result = data.readInt64(&when);
842 if (result != NO_ERROR) {
843 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
844 return result;
845 }
846 return injectVSync(when);
847 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800848 case GET_LAYER_DEBUG_INFO: {
849 CHECK_INTERFACE(ISurfaceComposer, data, reply);
850 std::vector<LayerDebugInfo> outLayers;
851 status_t result = getLayerDebugInfo(&outLayers);
852 reply->writeInt32(result);
853 if (result == NO_ERROR)
854 {
855 result = reply->writeParcelableVector(outLayers);
856 }
857 return result;
858 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700859 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700860 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700861 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800862 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800863}
864
865// ----------------------------------------------------------------------------
866
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800867};