blob: ad2dc1485859d2e054b213b24369d18c2adc9642 [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
Marissa Wall713b63f2018-10-17 15:42:43 -070066 virtual void setTransactionState(const Vector<ComposerState>& state,
67 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080068 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080069 const InputWindowCommands& commands,
70 int64_t desiredPresentTime) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 Parcel data, reply;
72 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080073
74 data.writeUint32(static_cast<uint32_t>(state.size()));
75 for (const auto& s : state) {
76 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070077 }
Dan Stozad723bd72014-11-18 10:24:03 -080078
79 data.writeUint32(static_cast<uint32_t>(displays.size()));
80 for (const auto& d : displays) {
81 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070085 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080086 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080087 data.writeInt64(desiredPresentTime);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070088 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 }
90
91 virtual void bootFinished()
92 {
93 Parcel data, reply;
94 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
95 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
96 }
97
Chavi Weingarten40482ff2017-11-30 01:51:40 +000098 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -070099 const ui::Dataspace reqDataspace,
100 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
101 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
102 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800103 Parcel data, reply;
104 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
105 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700106 data.writeInt32(static_cast<int32_t>(reqDataspace));
107 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700108 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800109 data.writeUint32(reqWidth);
110 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800111 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700112 data.writeInt32(static_cast<int32_t>(rotation));
Ana Krulec2d41e422018-07-26 12:07:43 -0700113 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
114 if (result != NO_ERROR) {
115 ALOGE("captureScreen failed to transact: %d", result);
116 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000117 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700118 result = reply.readInt32();
119 if (result != NO_ERROR) {
120 ALOGE("captureScreen failed to readInt32: %d", result);
121 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000122 }
123
124 *outBuffer = new GraphicBuffer();
125 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700126
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800128 }
129
chaviwa76b2712017-09-20 12:02:26 -0700130 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700131 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
132 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800133 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700134 Parcel data, reply;
135 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
136 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700137 data.writeInt32(static_cast<int32_t>(reqDataspace));
138 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
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);
Ana Krulec2d41e422018-07-26 12:07:43 -0700142 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
143 if (result != NO_ERROR) {
144 ALOGE("captureLayers failed to transact: %d", result);
145 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000146 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700147 result = reply.readInt32();
148 if (result != NO_ERROR) {
149 ALOGE("captureLayers failed to readInt32: %d", result);
150 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000151 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700152
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000153 *outBuffer = new GraphicBuffer();
154 reply.read(**outBuffer);
155
Ana Krulec2d41e422018-07-26 12:07:43 -0700156 return result;
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;
Ana Krulec2d41e422018-07-26 12:07:43 -0700345 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
346 if (result != NO_ERROR) {
347 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
348 return result;
349 }
350 result = data.writeStrongBinder(display);
351 if (result != NO_ERROR) {
352 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
353 return result;
354 }
355 result = data.writeInt32(id);
356 if (result != NO_ERROR) {
357 ALOGE("setActiveConfig failed to writeInt32: %d", result);
358 return result;
359 }
360 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
361 if (result != NO_ERROR) {
362 ALOGE("setActiveConfig failed to transact: %d", result);
363 return result;
364 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700365 return reply.readInt32();
366 }
Svetoslavd85084b2014-03-20 10:28:31 -0700367
Michael Wright28f24d02016-07-12 13:30:53 -0700368 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700369 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700370 Parcel data, reply;
371 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
372 if (result != NO_ERROR) {
373 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
374 return result;
375 }
376 result = data.writeStrongBinder(display);
377 if (result != NO_ERROR) {
378 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
379 return result;
380 }
381 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
382 if (result != NO_ERROR) {
383 ALOGE("getDisplayColorModes failed to transact: %d", result);
384 return result;
385 }
386 result = static_cast<status_t>(reply.readInt32());
387 if (result == NO_ERROR) {
388 size_t numModes = reply.readUint32();
389 outColorModes->clear();
390 outColorModes->resize(numModes);
391 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700392 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700393 }
394 }
395 return result;
396 }
397
Peiyong Lina52f0292018-03-14 17:26:31 -0700398 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700399 Parcel data, reply;
400 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
401 if (result != NO_ERROR) {
402 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700403 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700404 }
405 result = data.writeStrongBinder(display);
406 if (result != NO_ERROR) {
407 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700408 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700409 }
410 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
411 if (result != NO_ERROR) {
412 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700413 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700414 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700415 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700416 }
417
418 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700419 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700420 Parcel data, reply;
421 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
422 if (result != NO_ERROR) {
423 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
424 return result;
425 }
426 result = data.writeStrongBinder(display);
427 if (result != NO_ERROR) {
428 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
429 return result;
430 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700431 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700432 if (result != NO_ERROR) {
433 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
434 return result;
435 }
436 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
437 if (result != NO_ERROR) {
438 ALOGE("setActiveColorMode failed to transact: %d", result);
439 return result;
440 }
441 return static_cast<status_t>(reply.readInt32());
442 }
443
Svetoslavd85084b2014-03-20 10:28:31 -0700444 virtual status_t clearAnimationFrameStats() {
445 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700446 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
447 if (result != NO_ERROR) {
448 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
449 return result;
450 }
451 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
452 if (result != NO_ERROR) {
453 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
454 return result;
455 }
Svetoslavd85084b2014-03-20 10:28:31 -0700456 return reply.readInt32();
457 }
458
459 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
460 Parcel data, reply;
461 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
462 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
463 reply.read(*outStats);
464 return reply.readInt32();
465 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700466
467 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
468 HdrCapabilities* outCapabilities) const {
469 Parcel data, reply;
470 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
471 status_t result = data.writeStrongBinder(display);
472 if (result != NO_ERROR) {
473 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
474 return result;
475 }
476 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
477 data, &reply);
478 if (result != NO_ERROR) {
479 ALOGE("getHdrCapabilities failed to transact: %d", result);
480 return result;
481 }
482 result = reply.readInt32();
483 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800484 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700485 }
486 return result;
487 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700488
489 virtual status_t enableVSyncInjections(bool enable) {
490 Parcel data, reply;
491 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
492 if (result != NO_ERROR) {
493 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
494 return result;
495 }
496 result = data.writeBool(enable);
497 if (result != NO_ERROR) {
498 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
499 return result;
500 }
501 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
502 data, &reply, TF_ONE_WAY);
503 if (result != NO_ERROR) {
504 ALOGE("enableVSyncInjections failed to transact: %d", result);
505 return result;
506 }
507 return result;
508 }
509
510 virtual status_t injectVSync(nsecs_t when) {
511 Parcel data, reply;
512 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
513 if (result != NO_ERROR) {
514 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
515 return result;
516 }
517 result = data.writeInt64(when);
518 if (result != NO_ERROR) {
519 ALOGE("injectVSync failed to writeInt64: %d", result);
520 return result;
521 }
522 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
523 if (result != NO_ERROR) {
524 ALOGE("injectVSync failed to transact: %d", result);
525 return result;
526 }
527 return result;
528 }
529
Kalle Raitaa099a242017-01-11 11:17:29 -0800530 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
531 {
532 if (!outLayers) {
533 return UNEXPECTED_NULL;
534 }
535
536 Parcel data, reply;
537
538 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
539 if (err != NO_ERROR) {
540 return err;
541 }
542
543 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
544 if (err != NO_ERROR) {
545 return err;
546 }
547
548 int32_t result = 0;
549 err = reply.readInt32(&result);
550 if (err != NO_ERROR) {
551 return err;
552 }
553 if (result != NO_ERROR) {
554 return result;
555 }
556
557 outLayers->clear();
558 return reply.readParcelableVector(outLayers);
559 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700560
Peiyong Linc6780972018-10-28 15:24:08 -0700561 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
562 ui::PixelFormat* defaultPixelFormat,
563 ui::Dataspace* wideColorGamutDataspace,
564 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700565 Parcel data, reply;
566 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
567 if (error != NO_ERROR) {
568 return error;
569 }
570 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
571 if (error != NO_ERROR) {
572 return error;
573 }
574 error = static_cast<status_t>(reply.readInt32());
575 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700576 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
577 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
578 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
579 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700580 }
581 return error;
582 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700583
Ady Abraham37965d42018-11-01 13:43:32 -0700584 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700585 Parcel data, reply;
586 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700587 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
588 bool result;
589 status_t err = reply.readBool(&result);
590 if (err == NO_ERROR) {
591 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700592 }
Ady Abraham37965d42018-11-01 13:43:32 -0700593 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700594 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700595
596 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
597 ui::PixelFormat* outFormat,
598 ui::Dataspace* outDataspace,
599 uint8_t* outComponentMask) const {
600 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
601 Parcel data, reply;
602 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
603 data.writeStrongBinder(display);
604
605 status_t error =
606 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
607 data, &reply);
608 if (error != NO_ERROR) {
609 return error;
610 }
611
612 uint32_t value = 0;
613 error = reply.readUint32(&value);
614 if (error != NO_ERROR) {
615 return error;
616 }
617 *outFormat = static_cast<ui::PixelFormat>(value);
618
619 error = reply.readUint32(&value);
620 if (error != NO_ERROR) {
621 return error;
622 }
623 *outDataspace = static_cast<ui::Dataspace>(value);
624
625 error = reply.readUint32(&value);
626 if (error != NO_ERROR) {
627 return error;
628 }
629 *outComponentMask = static_cast<uint8_t>(value);
630 return error;
631 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800632
633 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
634 uint8_t componentMask,
635 uint64_t maxFrames) const {
636 Parcel data, reply;
637 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
638 data.writeStrongBinder(display);
639 data.writeBool(enable);
640 data.writeByte(static_cast<int8_t>(componentMask));
641 data.writeUint64(maxFrames);
642 status_t result =
643 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
644 &reply);
645 return result;
646 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700647
648 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
649 uint64_t timestamp,
650 DisplayedFrameStats* outStats) const {
651 if (!outStats) return BAD_VALUE;
652
653 Parcel data, reply;
654 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
655 data.writeStrongBinder(display);
656 data.writeUint64(maxFrames);
657 data.writeUint64(timestamp);
658
659 status_t result =
660 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
661
662 if (result != NO_ERROR) {
663 return result;
664 }
665
666 result = reply.readUint64(&outStats->numFrames);
667 if (result != NO_ERROR) {
668 return result;
669 }
670
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800671 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700672 if (result != NO_ERROR) {
673 return result;
674 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800675 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700676 if (result != NO_ERROR) {
677 return result;
678 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800679 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700680 if (result != NO_ERROR) {
681 return result;
682 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800683 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700684 return result;
685 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800686
687 virtual status_t getProtectedContentSupport(bool* outSupported) const {
688 Parcel data, reply;
689 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
690 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
691 bool result;
692 status_t err = reply.readBool(&result);
693 if (err == NO_ERROR) {
694 *outSupported = result;
695 }
696 return err;
697 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800698
699 virtual status_t cacheBuffer(const sp<IBinder>& token, const sp<GraphicBuffer>& buffer,
700 int32_t* outBufferId) {
701 Parcel data, reply;
702 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
703
704 data.writeStrongBinder(token);
705 if (buffer) {
706 data.writeBool(true);
707 data.write(*buffer);
708 } else {
709 data.writeBool(false);
710 }
711
712 status_t result = remote()->transact(BnSurfaceComposer::CACHE_BUFFER, data, &reply);
713 if (result != NO_ERROR) {
714 return result;
715 }
716
717 int32_t id = -1;
718 result = reply.readInt32(&id);
719 if (result == NO_ERROR) {
720 *outBufferId = id;
721 }
722 return result;
723 }
724
725 virtual status_t uncacheBuffer(const sp<IBinder>& token, int32_t bufferId) {
726 Parcel data, reply;
727 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
728
729 data.writeStrongBinder(token);
730 data.writeInt32(bufferId);
731
732 return remote()->transact(BnSurfaceComposer::UNCACHE_BUFFER, data, &reply);
733 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800734};
735
Dan Stozad723bd72014-11-18 10:24:03 -0800736// Out-of-line virtual method definition to trigger vtable emission in this
737// translation unit (see clang warning -Wweak-vtables)
738BpSurfaceComposer::~BpSurfaceComposer() {}
739
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800740IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
741
742// ----------------------------------------------------------------------
743
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800744status_t BnSurfaceComposer::onTransact(
745 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
746{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800747 switch(code) {
748 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700749 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800750 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800751 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700752 return NO_ERROR;
753 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700754 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700755 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800756
757 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700758 if (count > data.dataSize()) {
759 return BAD_VALUE;
760 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700761 Vector<ComposerState> state;
762 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800763 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700764 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700765 if (s.read(data) == BAD_VALUE) {
766 return BAD_VALUE;
767 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700768 state.add(s);
769 }
Dan Stozad723bd72014-11-18 10:24:03 -0800770
771 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700772 if (count > data.dataSize()) {
773 return BAD_VALUE;
774 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700775 DisplayState d;
776 Vector<DisplayState> displays;
777 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800778 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700779 if (d.read(data) == BAD_VALUE) {
780 return BAD_VALUE;
781 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700782 displays.add(d);
783 }
Dan Stozad723bd72014-11-18 10:24:03 -0800784
785 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700786 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800787 InputWindowCommands inputWindowCommands;
788 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800789
790 int64_t desiredPresentTime = data.readInt64();
791 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
792 desiredPresentTime);
Jesse Hall6c913be2013-08-08 12:15:49 -0700793 return NO_ERROR;
794 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800795 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700796 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800797 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700798 return NO_ERROR;
799 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800800 case CAPTURE_SCREEN: {
801 CHECK_INTERFACE(ISurfaceComposer, data, reply);
802 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700803 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
804 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000805 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700806 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700807 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800808 uint32_t reqWidth = data.readUint32();
809 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800810 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800811 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800812
Peiyong Lin0e003c92018-09-17 11:09:51 -0700813 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
814 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000815 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800816 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000817 if (res == NO_ERROR) {
818 reply->write(*outBuffer);
819 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700820 return NO_ERROR;
821 }
chaviwa76b2712017-09-20 12:02:26 -0700822 case CAPTURE_LAYERS: {
823 CHECK_INTERFACE(ISurfaceComposer, data, reply);
824 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700825 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
826 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000827 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800828 Rect sourceCrop(Rect::EMPTY_RECT);
829 data.read(sourceCrop);
830 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800831 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700832
Peiyong Lin0e003c92018-09-17 11:09:51 -0700833 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
834 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700835 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000836 if (res == NO_ERROR) {
837 reply->write(*outBuffer);
838 }
chaviwa76b2712017-09-20 12:02:26 -0700839 return NO_ERROR;
840 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800841 case AUTHENTICATE_SURFACE: {
842 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800843 sp<IGraphicBufferProducer> bufferProducer =
844 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
845 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800846 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700847 return NO_ERROR;
848 }
Brian Anderson6b376712017-04-04 10:51:39 -0700849 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
850 CHECK_INTERFACE(ISurfaceComposer, data, reply);
851 std::vector<FrameEvent> supportedTimestamps;
852 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
853 status_t err = reply->writeInt32(result);
854 if (err != NO_ERROR) {
855 return err;
856 }
857 if (result != NO_ERROR) {
858 return result;
859 }
860
861 std::vector<int32_t> supported;
862 supported.reserve(supportedTimestamps.size());
863 for (FrameEvent s : supportedTimestamps) {
864 supported.push_back(static_cast<int32_t>(s));
865 }
866 return reply->writeInt32Vector(supported);
867 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800868 case CREATE_DISPLAY_EVENT_CONNECTION: {
869 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700870 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
871 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800872 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800873 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700874 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700875 case CREATE_DISPLAY: {
876 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700877 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700878 bool secure = bool(data.readInt32());
879 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700880 reply->writeStrongBinder(display);
881 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700882 }
883 case DESTROY_DISPLAY: {
884 CHECK_INTERFACE(ISurfaceComposer, data, reply);
885 sp<IBinder> display = data.readStrongBinder();
886 destroyDisplay(display);
887 return NO_ERROR;
888 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700889 case GET_BUILT_IN_DISPLAY: {
890 CHECK_INTERFACE(ISurfaceComposer, data, reply);
891 int32_t id = data.readInt32();
892 sp<IBinder> display(getBuiltInDisplay(id));
893 reply->writeStrongBinder(display);
894 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700895 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700896 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700897 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700898 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700899 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700900 status_t result = getDisplayConfigs(display, &configs);
901 reply->writeInt32(result);
902 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800903 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700904 for (size_t c = 0; c < configs.size(); ++c) {
905 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
906 &configs[c], sizeof(DisplayInfo));
907 }
908 }
909 return NO_ERROR;
910 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700911 case GET_DISPLAY_STATS: {
912 CHECK_INTERFACE(ISurfaceComposer, data, reply);
913 DisplayStatInfo stats;
914 sp<IBinder> display = data.readStrongBinder();
915 status_t result = getDisplayStats(display, &stats);
916 reply->writeInt32(result);
917 if (result == NO_ERROR) {
918 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
919 &stats, sizeof(DisplayStatInfo));
920 }
921 return NO_ERROR;
922 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700923 case GET_ACTIVE_CONFIG: {
924 CHECK_INTERFACE(ISurfaceComposer, data, reply);
925 sp<IBinder> display = data.readStrongBinder();
926 int id = getActiveConfig(display);
927 reply->writeInt32(id);
928 return NO_ERROR;
929 }
930 case SET_ACTIVE_CONFIG: {
931 CHECK_INTERFACE(ISurfaceComposer, data, reply);
932 sp<IBinder> display = data.readStrongBinder();
933 int id = data.readInt32();
934 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700935 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700936 return NO_ERROR;
937 }
Michael Wright28f24d02016-07-12 13:30:53 -0700938 case GET_DISPLAY_COLOR_MODES: {
939 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700940 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -0700941 sp<IBinder> display = nullptr;
942 status_t result = data.readStrongBinder(&display);
943 if (result != NO_ERROR) {
944 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
945 return result;
946 }
947 result = getDisplayColorModes(display, &colorModes);
948 reply->writeInt32(result);
949 if (result == NO_ERROR) {
950 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
951 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700952 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -0700953 }
954 }
955 return NO_ERROR;
956 }
957 case GET_ACTIVE_COLOR_MODE: {
958 CHECK_INTERFACE(ISurfaceComposer, data, reply);
959 sp<IBinder> display = nullptr;
960 status_t result = data.readStrongBinder(&display);
961 if (result != NO_ERROR) {
962 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
963 return result;
964 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700965 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -0700966 result = reply->writeInt32(static_cast<int32_t>(colorMode));
967 return result;
968 }
969 case SET_ACTIVE_COLOR_MODE: {
970 CHECK_INTERFACE(ISurfaceComposer, data, reply);
971 sp<IBinder> display = nullptr;
972 status_t result = data.readStrongBinder(&display);
973 if (result != NO_ERROR) {
974 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
975 return result;
976 }
977 int32_t colorModeInt = 0;
978 result = data.readInt32(&colorModeInt);
979 if (result != NO_ERROR) {
980 ALOGE("setActiveColorMode failed to readInt32: %d", result);
981 return result;
982 }
983 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700984 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -0700985 result = reply->writeInt32(result);
986 return result;
987 }
Svetoslavd85084b2014-03-20 10:28:31 -0700988 case CLEAR_ANIMATION_FRAME_STATS: {
989 CHECK_INTERFACE(ISurfaceComposer, data, reply);
990 status_t result = clearAnimationFrameStats();
991 reply->writeInt32(result);
992 return NO_ERROR;
993 }
994 case GET_ANIMATION_FRAME_STATS: {
995 CHECK_INTERFACE(ISurfaceComposer, data, reply);
996 FrameStats stats;
997 status_t result = getAnimationFrameStats(&stats);
998 reply->write(stats);
999 reply->writeInt32(result);
1000 return NO_ERROR;
1001 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001002 case SET_POWER_MODE: {
1003 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1004 sp<IBinder> display = data.readStrongBinder();
1005 int32_t mode = data.readInt32();
1006 setPowerMode(display, mode);
1007 return NO_ERROR;
1008 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001009 case GET_HDR_CAPABILITIES: {
1010 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1011 sp<IBinder> display = nullptr;
1012 status_t result = data.readStrongBinder(&display);
1013 if (result != NO_ERROR) {
1014 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1015 result);
1016 return result;
1017 }
1018 HdrCapabilities capabilities;
1019 result = getHdrCapabilities(display, &capabilities);
1020 reply->writeInt32(result);
1021 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001022 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001023 }
1024 return NO_ERROR;
1025 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001026 case ENABLE_VSYNC_INJECTIONS: {
1027 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1028 bool enable = false;
1029 status_t result = data.readBool(&enable);
1030 if (result != NO_ERROR) {
1031 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1032 return result;
1033 }
1034 return enableVSyncInjections(enable);
1035 }
1036 case INJECT_VSYNC: {
1037 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1038 int64_t when = 0;
1039 status_t result = data.readInt64(&when);
1040 if (result != NO_ERROR) {
1041 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1042 return result;
1043 }
1044 return injectVSync(when);
1045 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001046 case GET_LAYER_DEBUG_INFO: {
1047 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1048 std::vector<LayerDebugInfo> outLayers;
1049 status_t result = getLayerDebugInfo(&outLayers);
1050 reply->writeInt32(result);
1051 if (result == NO_ERROR)
1052 {
1053 result = reply->writeParcelableVector(outLayers);
1054 }
1055 return result;
1056 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001057 case GET_COMPOSITION_PREFERENCE: {
1058 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001059 ui::Dataspace defaultDataspace;
1060 ui::PixelFormat defaultPixelFormat;
1061 ui::Dataspace wideColorGamutDataspace;
1062 ui::PixelFormat wideColorGamutPixelFormat;
1063 status_t error =
1064 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1065 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001066 reply->writeInt32(error);
1067 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001068 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1069 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1070 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001071 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001072 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001073 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001074 }
Ady Abraham37965d42018-11-01 13:43:32 -07001075 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001076 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001077 bool result;
1078 status_t error = getColorManagement(&result);
1079 if (error == NO_ERROR) {
1080 reply->writeBool(result);
1081 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001082 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001083 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001084 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1085 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1086
1087 sp<IBinder> display = data.readStrongBinder();
1088 ui::PixelFormat format;
1089 ui::Dataspace dataspace;
1090 uint8_t component = 0;
1091 auto result =
1092 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1093 if (result == NO_ERROR) {
1094 reply->writeUint32(static_cast<uint32_t>(format));
1095 reply->writeUint32(static_cast<uint32_t>(dataspace));
1096 reply->writeUint32(static_cast<uint32_t>(component));
1097 }
1098 return result;
1099 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001100 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1101 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1102
1103 sp<IBinder> display = nullptr;
1104 bool enable = false;
1105 int8_t componentMask = 0;
1106 uint64_t maxFrames = 0;
1107 status_t result = data.readStrongBinder(&display);
1108 if (result != NO_ERROR) {
1109 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1110 result);
1111 return result;
1112 }
1113
1114 result = data.readBool(&enable);
1115 if (result != NO_ERROR) {
1116 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1117 return result;
1118 }
1119
1120 result = data.readByte(static_cast<int8_t*>(&componentMask));
1121 if (result != NO_ERROR) {
1122 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1123 result);
1124 return result;
1125 }
1126
1127 result = data.readUint64(&maxFrames);
1128 if (result != NO_ERROR) {
1129 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1130 return result;
1131 }
1132
1133 return setDisplayContentSamplingEnabled(display, enable,
1134 static_cast<uint8_t>(componentMask), maxFrames);
1135 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001136 case GET_DISPLAYED_CONTENT_SAMPLE: {
1137 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1138
1139 sp<IBinder> display = data.readStrongBinder();
1140 uint64_t maxFrames = 0;
1141 uint64_t timestamp = 0;
1142
1143 status_t result = data.readUint64(&maxFrames);
1144 if (result != NO_ERROR) {
1145 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1146 return result;
1147 }
1148
1149 result = data.readUint64(&timestamp);
1150 if (result != NO_ERROR) {
1151 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1152 return result;
1153 }
1154
1155 DisplayedFrameStats stats;
1156 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1157 if (result == NO_ERROR) {
1158 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001159 reply->writeUint64Vector(stats.component_0_sample);
1160 reply->writeUint64Vector(stats.component_1_sample);
1161 reply->writeUint64Vector(stats.component_2_sample);
1162 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001163 }
1164 return result;
1165 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001166 case GET_PROTECTED_CONTENT_SUPPORT: {
1167 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1168 bool result;
1169 status_t error = getProtectedContentSupport(&result);
1170 if (error == NO_ERROR) {
1171 reply->writeBool(result);
1172 }
1173 return error;
1174 }
Marissa Wallebc2c052019-01-16 19:16:55 -08001175 case CACHE_BUFFER: {
1176 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1177 sp<IBinder> token;
1178 status_t result = data.readStrongBinder(&token);
1179 if (result != NO_ERROR) {
1180 ALOGE("cache buffer failure in reading token: %d", result);
1181 return result;
1182 }
1183
1184 sp<GraphicBuffer> buffer = new GraphicBuffer();
1185 if (data.readBool()) {
1186 result = data.read(*buffer);
1187 if (result != NO_ERROR) {
1188 ALOGE("cache buffer failure in reading buffer: %d", result);
1189 return result;
1190 }
1191 }
1192 int32_t bufferId = -1;
1193 status_t error = cacheBuffer(token, buffer, &bufferId);
1194 if (error == NO_ERROR) {
1195 reply->writeInt32(bufferId);
1196 }
1197 return error;
1198 }
1199 case UNCACHE_BUFFER: {
1200 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1201 sp<IBinder> token;
1202 status_t result = data.readStrongBinder(&token);
1203 if (result != NO_ERROR) {
1204 ALOGE("uncache buffer failure in reading token: %d", result);
1205 return result;
1206 }
1207
1208 int32_t bufferId = -1;
1209 result = data.readInt32(&bufferId);
1210 if (result != NO_ERROR) {
1211 ALOGE("uncache buffer failure in reading buffer id: %d", result);
1212 return result;
1213 }
1214
1215 return uncacheBuffer(token, bufferId);
1216 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001217 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001218 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001219 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001220 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001221}
1222
1223// ----------------------------------------------------------------------------
1224
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001225};