blob: 7d2615166f9539744140fbe38103110c62c9b8b3 [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
Peiyong Lin9f034472018-03-28 15:29:00 -070046using ui::ColorMode;
47
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
49{
50public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070051 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 : BpInterface<ISurfaceComposer>(impl)
53 {
54 }
55
Dan Stozad723bd72014-11-18 10:24:03 -080056 virtual ~BpSurfaceComposer();
57
Mathias Agopian7e27f052010-05-28 14:22:23 -070058 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 Parcel data, reply;
61 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
62 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070063 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 }
65
Robert Carr1db73f62016-12-21 12:58:51 -080066 virtual sp<ISurfaceComposerClient> createScopedConnection(
67 const sp<IGraphicBufferProducer>& parent)
68 {
69 Parcel data, reply;
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 data.writeStrongBinder(IInterface::asBinder(parent));
72 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
73 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
74 }
75
Mathias Agopian8b33f032012-07-24 20:43:54 -070076 virtual void setTransactionState(
77 const Vector<ComposerState>& state,
78 const Vector<DisplayState>& displays,
79 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 {
81 Parcel data, reply;
82 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(static_cast<uint32_t>(state.size()));
85 for (const auto& s : state) {
86 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070087 }
Dan Stozad723bd72014-11-18 10:24:03 -080088
89 data.writeUint32(static_cast<uint32_t>(displays.size()));
90 for (const auto& d : displays) {
91 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070092 }
Dan Stozad723bd72014-11-18 10:24:03 -080093
94 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070095 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 }
97
98 virtual void bootFinished()
99 {
100 Parcel data, reply;
101 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
102 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
103 }
104
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000105 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700106 const ui::Dataspace reqDataspace,
107 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
108 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
109 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800110 Parcel data, reply;
111 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
112 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700113 data.writeInt32(static_cast<int32_t>(reqDataspace));
114 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700115 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800116 data.writeUint32(reqWidth);
117 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800118 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700119 data.writeInt32(static_cast<int32_t>(rotation));
Ana Krulec2d41e422018-07-26 12:07:43 -0700120 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
121 if (result != NO_ERROR) {
122 ALOGE("captureScreen failed to transact: %d", result);
123 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000124 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700125 result = reply.readInt32();
126 if (result != NO_ERROR) {
127 ALOGE("captureScreen failed to readInt32: %d", result);
128 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000129 }
130
131 *outBuffer = new GraphicBuffer();
132 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700133
Ana Krulec2d41e422018-07-26 12:07:43 -0700134 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800135 }
136
chaviwa76b2712017-09-20 12:02:26 -0700137 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700138 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
139 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800140 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700141 Parcel data, reply;
142 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
143 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700144 data.writeInt32(static_cast<int32_t>(reqDataspace));
145 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800146 data.write(sourceCrop);
147 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800148 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700149 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
150 if (result != NO_ERROR) {
151 ALOGE("captureLayers failed to transact: %d", result);
152 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000153 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700154 result = reply.readInt32();
155 if (result != NO_ERROR) {
156 ALOGE("captureLayers failed to readInt32: %d", result);
157 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000158 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700159
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000160 *outBuffer = new GraphicBuffer();
161 reply.read(**outBuffer);
162
Ana Krulec2d41e422018-07-26 12:07:43 -0700163 return result;
chaviwa76b2712017-09-20 12:02:26 -0700164 }
165
Jamie Gennis582270d2011-08-17 18:19:00 -0700166 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800167 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800168 {
169 Parcel data, reply;
170 int err = NO_ERROR;
171 err = data.writeInterfaceToken(
172 ISurfaceComposer::getInterfaceDescriptor());
173 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000174 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800175 "interface descriptor: %s (%d)", strerror(-err), -err);
176 return false;
177 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800178 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800179 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000180 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700181 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800182 return false;
183 }
184 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
185 &reply);
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 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800189 return false;
190 }
191 int32_t result = 0;
192 err = reply.readInt32(&result);
193 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000194 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700195 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800196 return false;
197 }
198 return result != 0;
199 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800200
Brian Anderson6b376712017-04-04 10:51:39 -0700201 virtual status_t getSupportedFrameTimestamps(
202 std::vector<FrameEvent>* outSupported) const {
203 if (!outSupported) {
204 return UNEXPECTED_NULL;
205 }
206 outSupported->clear();
207
208 Parcel data, reply;
209
210 status_t err = data.writeInterfaceToken(
211 ISurfaceComposer::getInterfaceDescriptor());
212 if (err != NO_ERROR) {
213 return err;
214 }
215
216 err = remote()->transact(
217 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
218 data, &reply);
219 if (err != NO_ERROR) {
220 return err;
221 }
222
223 int32_t result = 0;
224 err = reply.readInt32(&result);
225 if (err != NO_ERROR) {
226 return err;
227 }
228 if (result != NO_ERROR) {
229 return result;
230 }
231
232 std::vector<int32_t> supported;
233 err = reply.readInt32Vector(&supported);
234 if (err != NO_ERROR) {
235 return err;
236 }
237
238 outSupported->reserve(supported.size());
239 for (int32_t s : supported) {
240 outSupported->push_back(static_cast<FrameEvent>(s));
241 }
242 return NO_ERROR;
243 }
244
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700245 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800246 {
247 Parcel data, reply;
248 sp<IDisplayEventConnection> result;
249 int err = data.writeInterfaceToken(
250 ISurfaceComposer::getInterfaceDescriptor());
251 if (err != NO_ERROR) {
252 return result;
253 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700254 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800255 err = remote()->transact(
256 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
257 data, &reply);
258 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000259 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800260 "transaction: %s (%d)", strerror(-err), -err);
261 return result;
262 }
263 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
264 return result;
265 }
Colin Cross8e533062012-06-07 13:17:52 -0700266
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700267 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700268 {
269 Parcel data, reply;
270 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700271 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700272 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700273 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
274 return reply.readStrongBinder();
275 }
276
Jesse Hall6c913be2013-08-08 12:15:49 -0700277 virtual void destroyDisplay(const sp<IBinder>& display)
278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
281 data.writeStrongBinder(display);
282 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
283 }
284
Mathias Agopiane57f2922012-08-09 16:29:12 -0700285 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
286 {
287 Parcel data, reply;
288 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
289 data.writeInt32(id);
290 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
291 return reply.readStrongBinder();
292 }
293
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700294 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700295 {
296 Parcel data, reply;
297 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700298 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700299 data.writeInt32(mode);
300 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700301 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700302
Dan Stoza7f7da322014-05-02 15:26:25 -0700303 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
304 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700305 {
306 Parcel data, reply;
307 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700308 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700309 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
310 status_t result = reply.readInt32();
311 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800312 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700313 configs->clear();
314 configs->resize(numConfigs);
315 for (size_t c = 0; c < numConfigs; ++c) {
316 memcpy(&(configs->editItemAt(c)),
317 reply.readInplace(sizeof(DisplayInfo)),
318 sizeof(DisplayInfo));
319 }
320 }
321 return result;
322 }
323
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700324 virtual status_t getDisplayStats(const sp<IBinder>& display,
325 DisplayStatInfo* stats)
326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
329 data.writeStrongBinder(display);
330 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
331 status_t result = reply.readInt32();
332 if (result == NO_ERROR) {
333 memcpy(stats,
334 reply.readInplace(sizeof(DisplayStatInfo)),
335 sizeof(DisplayStatInfo));
336 }
337 return result;
338 }
339
Dan Stoza7f7da322014-05-02 15:26:25 -0700340 virtual int getActiveConfig(const sp<IBinder>& display)
341 {
342 Parcel data, reply;
343 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
344 data.writeStrongBinder(display);
345 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
346 return reply.readInt32();
347 }
348
349 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
350 {
351 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700352 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
353 if (result != NO_ERROR) {
354 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
355 return result;
356 }
357 result = data.writeStrongBinder(display);
358 if (result != NO_ERROR) {
359 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
360 return result;
361 }
362 result = data.writeInt32(id);
363 if (result != NO_ERROR) {
364 ALOGE("setActiveConfig failed to writeInt32: %d", result);
365 return result;
366 }
367 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
368 if (result != NO_ERROR) {
369 ALOGE("setActiveConfig failed to transact: %d", result);
370 return result;
371 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700372 return reply.readInt32();
373 }
Svetoslavd85084b2014-03-20 10:28:31 -0700374
Michael Wright28f24d02016-07-12 13:30:53 -0700375 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700376 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700377 Parcel data, reply;
378 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
379 if (result != NO_ERROR) {
380 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
381 return result;
382 }
383 result = data.writeStrongBinder(display);
384 if (result != NO_ERROR) {
385 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
386 return result;
387 }
388 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
389 if (result != NO_ERROR) {
390 ALOGE("getDisplayColorModes failed to transact: %d", result);
391 return result;
392 }
393 result = static_cast<status_t>(reply.readInt32());
394 if (result == NO_ERROR) {
395 size_t numModes = reply.readUint32();
396 outColorModes->clear();
397 outColorModes->resize(numModes);
398 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700399 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700400 }
401 }
402 return result;
403 }
404
Peiyong Lina52f0292018-03-14 17:26:31 -0700405 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700406 Parcel data, reply;
407 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
408 if (result != NO_ERROR) {
409 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700410 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700411 }
412 result = data.writeStrongBinder(display);
413 if (result != NO_ERROR) {
414 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700415 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700416 }
417 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
418 if (result != NO_ERROR) {
419 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700420 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700421 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700422 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700423 }
424
425 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700426 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700427 Parcel data, reply;
428 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
429 if (result != NO_ERROR) {
430 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
431 return result;
432 }
433 result = data.writeStrongBinder(display);
434 if (result != NO_ERROR) {
435 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
436 return result;
437 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700438 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700439 if (result != NO_ERROR) {
440 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
441 return result;
442 }
443 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
444 if (result != NO_ERROR) {
445 ALOGE("setActiveColorMode failed to transact: %d", result);
446 return result;
447 }
448 return static_cast<status_t>(reply.readInt32());
449 }
450
Svetoslavd85084b2014-03-20 10:28:31 -0700451 virtual status_t clearAnimationFrameStats() {
452 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700453 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
454 if (result != NO_ERROR) {
455 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
456 return result;
457 }
458 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
459 if (result != NO_ERROR) {
460 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
461 return result;
462 }
Svetoslavd85084b2014-03-20 10:28:31 -0700463 return reply.readInt32();
464 }
465
466 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
467 Parcel data, reply;
468 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
469 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
470 reply.read(*outStats);
471 return reply.readInt32();
472 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700473
474 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
475 HdrCapabilities* outCapabilities) const {
476 Parcel data, reply;
477 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
478 status_t result = data.writeStrongBinder(display);
479 if (result != NO_ERROR) {
480 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
481 return result;
482 }
483 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
484 data, &reply);
485 if (result != NO_ERROR) {
486 ALOGE("getHdrCapabilities failed to transact: %d", result);
487 return result;
488 }
489 result = reply.readInt32();
490 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800491 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700492 }
493 return result;
494 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700495
496 virtual status_t enableVSyncInjections(bool enable) {
497 Parcel data, reply;
498 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
499 if (result != NO_ERROR) {
500 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
501 return result;
502 }
503 result = data.writeBool(enable);
504 if (result != NO_ERROR) {
505 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
506 return result;
507 }
508 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
509 data, &reply, TF_ONE_WAY);
510 if (result != NO_ERROR) {
511 ALOGE("enableVSyncInjections failed to transact: %d", result);
512 return result;
513 }
514 return result;
515 }
516
517 virtual status_t injectVSync(nsecs_t when) {
518 Parcel data, reply;
519 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
520 if (result != NO_ERROR) {
521 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
522 return result;
523 }
524 result = data.writeInt64(when);
525 if (result != NO_ERROR) {
526 ALOGE("injectVSync failed to writeInt64: %d", result);
527 return result;
528 }
529 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
530 if (result != NO_ERROR) {
531 ALOGE("injectVSync failed to transact: %d", result);
532 return result;
533 }
534 return result;
535 }
536
Kalle Raitaa099a242017-01-11 11:17:29 -0800537 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
538 {
539 if (!outLayers) {
540 return UNEXPECTED_NULL;
541 }
542
543 Parcel data, reply;
544
545 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
546 if (err != NO_ERROR) {
547 return err;
548 }
549
550 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
551 if (err != NO_ERROR) {
552 return err;
553 }
554
555 int32_t result = 0;
556 err = reply.readInt32(&result);
557 if (err != NO_ERROR) {
558 return err;
559 }
560 if (result != NO_ERROR) {
561 return result;
562 }
563
564 outLayers->clear();
565 return reply.readParcelableVector(outLayers);
566 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700567
Peiyong Linc6780972018-10-28 15:24:08 -0700568 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
569 ui::PixelFormat* defaultPixelFormat,
570 ui::Dataspace* wideColorGamutDataspace,
571 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700572 Parcel data, reply;
573 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
574 if (error != NO_ERROR) {
575 return error;
576 }
577 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
578 if (error != NO_ERROR) {
579 return error;
580 }
581 error = static_cast<status_t>(reply.readInt32());
582 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700583 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
584 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
585 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
586 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700587 }
588 return error;
589 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700590
Ady Abraham37965d42018-11-01 13:43:32 -0700591 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700592 Parcel data, reply;
593 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700594 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
595 bool result;
596 status_t err = reply.readBool(&result);
597 if (err == NO_ERROR) {
598 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700599 }
Ady Abraham37965d42018-11-01 13:43:32 -0700600 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700601 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700602
603 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
604 ui::PixelFormat* outFormat,
605 ui::Dataspace* outDataspace,
606 uint8_t* outComponentMask) const {
607 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
608 Parcel data, reply;
609 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
610 data.writeStrongBinder(display);
611
612 status_t error =
613 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
614 data, &reply);
615 if (error != NO_ERROR) {
616 return error;
617 }
618
619 uint32_t value = 0;
620 error = reply.readUint32(&value);
621 if (error != NO_ERROR) {
622 return error;
623 }
624 *outFormat = static_cast<ui::PixelFormat>(value);
625
626 error = reply.readUint32(&value);
627 if (error != NO_ERROR) {
628 return error;
629 }
630 *outDataspace = static_cast<ui::Dataspace>(value);
631
632 error = reply.readUint32(&value);
633 if (error != NO_ERROR) {
634 return error;
635 }
636 *outComponentMask = static_cast<uint8_t>(value);
637 return error;
638 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800639
640 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
641 uint8_t componentMask,
642 uint64_t maxFrames) const {
643 Parcel data, reply;
644 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
645 data.writeStrongBinder(display);
646 data.writeBool(enable);
647 data.writeByte(static_cast<int8_t>(componentMask));
648 data.writeUint64(maxFrames);
649 status_t result =
650 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
651 &reply);
652 return result;
653 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800654};
655
Dan Stozad723bd72014-11-18 10:24:03 -0800656// Out-of-line virtual method definition to trigger vtable emission in this
657// translation unit (see clang warning -Wweak-vtables)
658BpSurfaceComposer::~BpSurfaceComposer() {}
659
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800660IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
661
662// ----------------------------------------------------------------------
663
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800664status_t BnSurfaceComposer::onTransact(
665 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
666{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800667 switch(code) {
668 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700669 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800670 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800671 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700672 return NO_ERROR;
673 }
Robert Carr1db73f62016-12-21 12:58:51 -0800674 case CREATE_SCOPED_CONNECTION: {
675 CHECK_INTERFACE(ISurfaceComposer, data, reply);
676 sp<IGraphicBufferProducer> bufferProducer =
677 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
678 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
679 reply->writeStrongBinder(b);
680 return NO_ERROR;
681 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700682 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700683 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800684
685 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700686 if (count > data.dataSize()) {
687 return BAD_VALUE;
688 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700689 Vector<ComposerState> state;
690 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800691 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700692 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700693 if (s.read(data) == BAD_VALUE) {
694 return BAD_VALUE;
695 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700696 state.add(s);
697 }
Dan Stozad723bd72014-11-18 10:24:03 -0800698
699 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700700 if (count > data.dataSize()) {
701 return BAD_VALUE;
702 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700703 DisplayState d;
704 Vector<DisplayState> displays;
705 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800706 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700707 if (d.read(data) == BAD_VALUE) {
708 return BAD_VALUE;
709 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700710 displays.add(d);
711 }
Dan Stozad723bd72014-11-18 10:24:03 -0800712
713 uint32_t stateFlags = data.readUint32();
714 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700715 return NO_ERROR;
716 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800717 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700718 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800719 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700720 return NO_ERROR;
721 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800722 case CAPTURE_SCREEN: {
723 CHECK_INTERFACE(ISurfaceComposer, data, reply);
724 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700725 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
726 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000727 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700728 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700729 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800730 uint32_t reqWidth = data.readUint32();
731 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800732 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800733 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800734
Peiyong Lin0e003c92018-09-17 11:09:51 -0700735 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
736 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000737 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800738 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000739 if (res == NO_ERROR) {
740 reply->write(*outBuffer);
741 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700742 return NO_ERROR;
743 }
chaviwa76b2712017-09-20 12:02:26 -0700744 case CAPTURE_LAYERS: {
745 CHECK_INTERFACE(ISurfaceComposer, data, reply);
746 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700747 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
748 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000749 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800750 Rect sourceCrop(Rect::EMPTY_RECT);
751 data.read(sourceCrop);
752 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800753 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700754
Peiyong Lin0e003c92018-09-17 11:09:51 -0700755 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
756 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700757 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000758 if (res == NO_ERROR) {
759 reply->write(*outBuffer);
760 }
chaviwa76b2712017-09-20 12:02:26 -0700761 return NO_ERROR;
762 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800763 case AUTHENTICATE_SURFACE: {
764 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800765 sp<IGraphicBufferProducer> bufferProducer =
766 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
767 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800768 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700769 return NO_ERROR;
770 }
Brian Anderson6b376712017-04-04 10:51:39 -0700771 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
772 CHECK_INTERFACE(ISurfaceComposer, data, reply);
773 std::vector<FrameEvent> supportedTimestamps;
774 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
775 status_t err = reply->writeInt32(result);
776 if (err != NO_ERROR) {
777 return err;
778 }
779 if (result != NO_ERROR) {
780 return result;
781 }
782
783 std::vector<int32_t> supported;
784 supported.reserve(supportedTimestamps.size());
785 for (FrameEvent s : supportedTimestamps) {
786 supported.push_back(static_cast<int32_t>(s));
787 }
788 return reply->writeInt32Vector(supported);
789 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800790 case CREATE_DISPLAY_EVENT_CONNECTION: {
791 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700792 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
793 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800794 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800795 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700796 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700797 case CREATE_DISPLAY: {
798 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700799 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700800 bool secure = bool(data.readInt32());
801 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700802 reply->writeStrongBinder(display);
803 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700804 }
805 case DESTROY_DISPLAY: {
806 CHECK_INTERFACE(ISurfaceComposer, data, reply);
807 sp<IBinder> display = data.readStrongBinder();
808 destroyDisplay(display);
809 return NO_ERROR;
810 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700811 case GET_BUILT_IN_DISPLAY: {
812 CHECK_INTERFACE(ISurfaceComposer, data, reply);
813 int32_t id = data.readInt32();
814 sp<IBinder> display(getBuiltInDisplay(id));
815 reply->writeStrongBinder(display);
816 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700817 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700818 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700819 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700820 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700821 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700822 status_t result = getDisplayConfigs(display, &configs);
823 reply->writeInt32(result);
824 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800825 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700826 for (size_t c = 0; c < configs.size(); ++c) {
827 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
828 &configs[c], sizeof(DisplayInfo));
829 }
830 }
831 return NO_ERROR;
832 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700833 case GET_DISPLAY_STATS: {
834 CHECK_INTERFACE(ISurfaceComposer, data, reply);
835 DisplayStatInfo stats;
836 sp<IBinder> display = data.readStrongBinder();
837 status_t result = getDisplayStats(display, &stats);
838 reply->writeInt32(result);
839 if (result == NO_ERROR) {
840 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
841 &stats, sizeof(DisplayStatInfo));
842 }
843 return NO_ERROR;
844 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700845 case GET_ACTIVE_CONFIG: {
846 CHECK_INTERFACE(ISurfaceComposer, data, reply);
847 sp<IBinder> display = data.readStrongBinder();
848 int id = getActiveConfig(display);
849 reply->writeInt32(id);
850 return NO_ERROR;
851 }
852 case SET_ACTIVE_CONFIG: {
853 CHECK_INTERFACE(ISurfaceComposer, data, reply);
854 sp<IBinder> display = data.readStrongBinder();
855 int id = data.readInt32();
856 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700857 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700858 return NO_ERROR;
859 }
Michael Wright28f24d02016-07-12 13:30:53 -0700860 case GET_DISPLAY_COLOR_MODES: {
861 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700862 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -0700863 sp<IBinder> display = nullptr;
864 status_t result = data.readStrongBinder(&display);
865 if (result != NO_ERROR) {
866 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
867 return result;
868 }
869 result = getDisplayColorModes(display, &colorModes);
870 reply->writeInt32(result);
871 if (result == NO_ERROR) {
872 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
873 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700874 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -0700875 }
876 }
877 return NO_ERROR;
878 }
879 case GET_ACTIVE_COLOR_MODE: {
880 CHECK_INTERFACE(ISurfaceComposer, data, reply);
881 sp<IBinder> display = nullptr;
882 status_t result = data.readStrongBinder(&display);
883 if (result != NO_ERROR) {
884 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
885 return result;
886 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700887 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -0700888 result = reply->writeInt32(static_cast<int32_t>(colorMode));
889 return result;
890 }
891 case SET_ACTIVE_COLOR_MODE: {
892 CHECK_INTERFACE(ISurfaceComposer, data, reply);
893 sp<IBinder> display = nullptr;
894 status_t result = data.readStrongBinder(&display);
895 if (result != NO_ERROR) {
896 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
897 return result;
898 }
899 int32_t colorModeInt = 0;
900 result = data.readInt32(&colorModeInt);
901 if (result != NO_ERROR) {
902 ALOGE("setActiveColorMode failed to readInt32: %d", result);
903 return result;
904 }
905 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700906 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -0700907 result = reply->writeInt32(result);
908 return result;
909 }
Svetoslavd85084b2014-03-20 10:28:31 -0700910 case CLEAR_ANIMATION_FRAME_STATS: {
911 CHECK_INTERFACE(ISurfaceComposer, data, reply);
912 status_t result = clearAnimationFrameStats();
913 reply->writeInt32(result);
914 return NO_ERROR;
915 }
916 case GET_ANIMATION_FRAME_STATS: {
917 CHECK_INTERFACE(ISurfaceComposer, data, reply);
918 FrameStats stats;
919 status_t result = getAnimationFrameStats(&stats);
920 reply->write(stats);
921 reply->writeInt32(result);
922 return NO_ERROR;
923 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700924 case SET_POWER_MODE: {
925 CHECK_INTERFACE(ISurfaceComposer, data, reply);
926 sp<IBinder> display = data.readStrongBinder();
927 int32_t mode = data.readInt32();
928 setPowerMode(display, mode);
929 return NO_ERROR;
930 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700931 case GET_HDR_CAPABILITIES: {
932 CHECK_INTERFACE(ISurfaceComposer, data, reply);
933 sp<IBinder> display = nullptr;
934 status_t result = data.readStrongBinder(&display);
935 if (result != NO_ERROR) {
936 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
937 result);
938 return result;
939 }
940 HdrCapabilities capabilities;
941 result = getHdrCapabilities(display, &capabilities);
942 reply->writeInt32(result);
943 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800944 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700945 }
946 return NO_ERROR;
947 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700948 case ENABLE_VSYNC_INJECTIONS: {
949 CHECK_INTERFACE(ISurfaceComposer, data, reply);
950 bool enable = false;
951 status_t result = data.readBool(&enable);
952 if (result != NO_ERROR) {
953 ALOGE("enableVSyncInjections failed to readBool: %d", result);
954 return result;
955 }
956 return enableVSyncInjections(enable);
957 }
958 case INJECT_VSYNC: {
959 CHECK_INTERFACE(ISurfaceComposer, data, reply);
960 int64_t when = 0;
961 status_t result = data.readInt64(&when);
962 if (result != NO_ERROR) {
963 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
964 return result;
965 }
966 return injectVSync(when);
967 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800968 case GET_LAYER_DEBUG_INFO: {
969 CHECK_INTERFACE(ISurfaceComposer, data, reply);
970 std::vector<LayerDebugInfo> outLayers;
971 status_t result = getLayerDebugInfo(&outLayers);
972 reply->writeInt32(result);
973 if (result == NO_ERROR)
974 {
975 result = reply->writeParcelableVector(outLayers);
976 }
977 return result;
978 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700979 case GET_COMPOSITION_PREFERENCE: {
980 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -0700981 ui::Dataspace defaultDataspace;
982 ui::PixelFormat defaultPixelFormat;
983 ui::Dataspace wideColorGamutDataspace;
984 ui::PixelFormat wideColorGamutPixelFormat;
985 status_t error =
986 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
987 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -0700988 reply->writeInt32(error);
989 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700990 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
991 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
992 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
993 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Lin0256f722018-08-31 15:45:10 -0700994 }
995 return NO_ERROR;
996 }
Ady Abraham37965d42018-11-01 13:43:32 -0700997 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700998 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -0700999 bool result;
1000 status_t error = getColorManagement(&result);
1001 if (error == NO_ERROR) {
1002 reply->writeBool(result);
1003 }
1004 return result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001005 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001006 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1007 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1008
1009 sp<IBinder> display = data.readStrongBinder();
1010 ui::PixelFormat format;
1011 ui::Dataspace dataspace;
1012 uint8_t component = 0;
1013 auto result =
1014 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1015 if (result == NO_ERROR) {
1016 reply->writeUint32(static_cast<uint32_t>(format));
1017 reply->writeUint32(static_cast<uint32_t>(dataspace));
1018 reply->writeUint32(static_cast<uint32_t>(component));
1019 }
1020 return result;
1021 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001022 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1023 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1024
1025 sp<IBinder> display = nullptr;
1026 bool enable = false;
1027 int8_t componentMask = 0;
1028 uint64_t maxFrames = 0;
1029 status_t result = data.readStrongBinder(&display);
1030 if (result != NO_ERROR) {
1031 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1032 result);
1033 return result;
1034 }
1035
1036 result = data.readBool(&enable);
1037 if (result != NO_ERROR) {
1038 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1039 return result;
1040 }
1041
1042 result = data.readByte(static_cast<int8_t*>(&componentMask));
1043 if (result != NO_ERROR) {
1044 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1045 result);
1046 return result;
1047 }
1048
1049 result = data.readUint64(&maxFrames);
1050 if (result != NO_ERROR) {
1051 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1052 return result;
1053 }
1054
1055 return setDisplayContentSamplingEnabled(display, enable,
1056 static_cast<uint8_t>(componentMask), maxFrames);
1057 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001058 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001059 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001060 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001061 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001062}
1063
1064// ----------------------------------------------------------------------------
1065
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001066};