blob: bc63d315e06f3c8aac8088451550174b68421a54 [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>
Dan Stoza84ab9372018-12-17 15:27:57 -080029#include <gui/IRegionSamplingListener.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080030#include <gui/ISurfaceComposer.h>
31#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080032#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070033#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070038#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070039#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Jamie Gennis134f0422011-03-08 12:18:54 -080041#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Peiyong Lin9f034472018-03-28 15:29:00 -070047using ui::ColorMode;
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
50{
51public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070052 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 : BpInterface<ISurfaceComposer>(impl)
54 {
55 }
56
Dan Stozad723bd72014-11-18 10:24:03 -080057 virtual ~BpSurfaceComposer();
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 }
66
Marissa Wall713b63f2018-10-17 15:42:43 -070067 virtual void setTransactionState(const Vector<ComposerState>& state,
68 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080069 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080070 const InputWindowCommands& commands,
Marissa Wall78b72202019-03-15 14:58:34 -070071 int64_t desiredPresentTime,
72 const cached_buffer_t& uncacheBuffer) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 Parcel data, reply;
74 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080075
76 data.writeUint32(static_cast<uint32_t>(state.size()));
77 for (const auto& s : state) {
78 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070079 }
Dan Stozad723bd72014-11-18 10:24:03 -080080
81 data.writeUint32(static_cast<uint32_t>(displays.size()));
82 for (const auto& d : displays) {
83 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070084 }
Dan Stozad723bd72014-11-18 10:24:03 -080085
86 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070087 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080088 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080089 data.writeInt64(desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -070090 data.writeStrongBinder(uncacheBuffer.token);
91 data.writeUint64(uncacheBuffer.cacheId);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070092 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 }
94
95 virtual void bootFinished()
96 {
97 Parcel data, reply;
98 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
99 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
100 }
101
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000102 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700103 const ui::Dataspace reqDataspace,
104 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
105 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -0800106 ISurfaceComposer::Rotation rotation, bool captureSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800107 Parcel data, reply;
108 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
109 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700110 data.writeInt32(static_cast<int32_t>(reqDataspace));
111 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700112 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800113 data.writeUint32(reqWidth);
114 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800115 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700116 data.writeInt32(static_cast<int32_t>(rotation));
Robert Carrfa8855f2019-02-19 10:05:00 -0800117 data.writeInt32(static_cast<int32_t>(captureSecureLayers));
Ana Krulec2d41e422018-07-26 12:07:43 -0700118 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
119 if (result != NO_ERROR) {
120 ALOGE("captureScreen failed to transact: %d", result);
121 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000122 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700123 result = reply.readInt32();
124 if (result != NO_ERROR) {
125 ALOGE("captureScreen failed to readInt32: %d", result);
126 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000127 }
128
129 *outBuffer = new GraphicBuffer();
130 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700131
Ana Krulec2d41e422018-07-26 12:07:43 -0700132 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800133 }
134
chaviwa76b2712017-09-20 12:02:26 -0700135 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700136 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
137 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800138 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700139 Parcel data, reply;
140 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
141 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700142 data.writeInt32(static_cast<int32_t>(reqDataspace));
143 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800144 data.write(sourceCrop);
145 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800146 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700147 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
148 if (result != NO_ERROR) {
149 ALOGE("captureLayers failed to transact: %d", result);
150 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000151 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700152 result = reply.readInt32();
153 if (result != NO_ERROR) {
154 ALOGE("captureLayers failed to readInt32: %d", result);
155 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000156 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700157
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000158 *outBuffer = new GraphicBuffer();
159 reply.read(**outBuffer);
160
Ana Krulec2d41e422018-07-26 12:07:43 -0700161 return result;
chaviwa76b2712017-09-20 12:02:26 -0700162 }
163
Jamie Gennis582270d2011-08-17 18:19:00 -0700164 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800165 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800166 {
167 Parcel data, reply;
168 int err = NO_ERROR;
169 err = data.writeInterfaceToken(
170 ISurfaceComposer::getInterfaceDescriptor());
171 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000172 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800173 "interface descriptor: %s (%d)", strerror(-err), -err);
174 return false;
175 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800176 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800177 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000178 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700179 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800180 return false;
181 }
182 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
183 &reply);
184 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000185 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700186 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800187 return false;
188 }
189 int32_t result = 0;
190 err = reply.readInt32(&result);
191 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000192 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700193 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800194 return false;
195 }
196 return result != 0;
197 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800198
Brian Anderson6b376712017-04-04 10:51:39 -0700199 virtual status_t getSupportedFrameTimestamps(
200 std::vector<FrameEvent>* outSupported) const {
201 if (!outSupported) {
202 return UNEXPECTED_NULL;
203 }
204 outSupported->clear();
205
206 Parcel data, reply;
207
208 status_t err = data.writeInterfaceToken(
209 ISurfaceComposer::getInterfaceDescriptor());
210 if (err != NO_ERROR) {
211 return err;
212 }
213
214 err = remote()->transact(
215 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
216 data, &reply);
217 if (err != NO_ERROR) {
218 return err;
219 }
220
221 int32_t result = 0;
222 err = reply.readInt32(&result);
223 if (err != NO_ERROR) {
224 return err;
225 }
226 if (result != NO_ERROR) {
227 return result;
228 }
229
230 std::vector<int32_t> supported;
231 err = reply.readInt32Vector(&supported);
232 if (err != NO_ERROR) {
233 return err;
234 }
235
236 outSupported->reserve(supported.size());
237 for (int32_t s : supported) {
238 outSupported->push_back(static_cast<FrameEvent>(s));
239 }
240 return NO_ERROR;
241 }
242
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700243 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800244 {
245 Parcel data, reply;
246 sp<IDisplayEventConnection> result;
247 int err = data.writeInterfaceToken(
248 ISurfaceComposer::getInterfaceDescriptor());
249 if (err != NO_ERROR) {
250 return result;
251 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700252 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800253 err = remote()->transact(
254 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
255 data, &reply);
256 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000257 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800258 "transaction: %s (%d)", strerror(-err), -err);
259 return result;
260 }
261 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
262 return result;
263 }
Colin Cross8e533062012-06-07 13:17:52 -0700264
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700265 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700266 {
267 Parcel data, reply;
268 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700269 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700270 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700271 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
272 return reply.readStrongBinder();
273 }
274
Jesse Hall6c913be2013-08-08 12:15:49 -0700275 virtual void destroyDisplay(const sp<IBinder>& display)
276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
279 data.writeStrongBinder(display);
280 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
281 }
282
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800283 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700284 Parcel data, reply;
285 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800286 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
287 NO_ERROR) {
288 std::vector<PhysicalDisplayId> displayIds;
289 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
290 return displayIds;
291 }
292 }
293
294 return {};
295 }
296
297 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
298 Parcel data, reply;
299 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
300 data.writeUint64(displayId);
301 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700302 return reply.readStrongBinder();
303 }
304
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700305 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700309 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700310 data.writeInt32(mode);
311 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700312 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700313
Dan Stoza7f7da322014-05-02 15:26:25 -0700314 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
315 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700319 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700320 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
321 status_t result = reply.readInt32();
322 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800323 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700324 configs->clear();
325 configs->resize(numConfigs);
326 for (size_t c = 0; c < numConfigs; ++c) {
327 memcpy(&(configs->editItemAt(c)),
328 reply.readInplace(sizeof(DisplayInfo)),
329 sizeof(DisplayInfo));
330 }
331 }
332 return result;
333 }
334
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700335 virtual status_t getDisplayStats(const sp<IBinder>& display,
336 DisplayStatInfo* stats)
337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
340 data.writeStrongBinder(display);
341 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
342 status_t result = reply.readInt32();
343 if (result == NO_ERROR) {
344 memcpy(stats,
345 reply.readInplace(sizeof(DisplayStatInfo)),
346 sizeof(DisplayStatInfo));
347 }
348 return result;
349 }
350
Dan Stoza7f7da322014-05-02 15:26:25 -0700351 virtual int getActiveConfig(const sp<IBinder>& display)
352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
355 data.writeStrongBinder(display);
356 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
357 return reply.readInt32();
358 }
359
360 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
361 {
362 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700363 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
364 if (result != NO_ERROR) {
365 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
366 return result;
367 }
368 result = data.writeStrongBinder(display);
369 if (result != NO_ERROR) {
370 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
371 return result;
372 }
373 result = data.writeInt32(id);
374 if (result != NO_ERROR) {
375 ALOGE("setActiveConfig failed to writeInt32: %d", result);
376 return result;
377 }
378 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
379 if (result != NO_ERROR) {
380 ALOGE("setActiveConfig failed to transact: %d", result);
381 return result;
382 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700383 return reply.readInt32();
384 }
Svetoslavd85084b2014-03-20 10:28:31 -0700385
Michael Wright28f24d02016-07-12 13:30:53 -0700386 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700387 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700388 Parcel data, reply;
389 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
390 if (result != NO_ERROR) {
391 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
392 return result;
393 }
394 result = data.writeStrongBinder(display);
395 if (result != NO_ERROR) {
396 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
397 return result;
398 }
399 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
400 if (result != NO_ERROR) {
401 ALOGE("getDisplayColorModes failed to transact: %d", result);
402 return result;
403 }
404 result = static_cast<status_t>(reply.readInt32());
405 if (result == NO_ERROR) {
406 size_t numModes = reply.readUint32();
407 outColorModes->clear();
408 outColorModes->resize(numModes);
409 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700410 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700411 }
412 }
413 return result;
414 }
415
Daniel Solomon42d04562019-01-20 21:03:19 -0800416 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
417 ui::DisplayPrimaries& primaries) {
418 Parcel data, reply;
419 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
420 if (result != NO_ERROR) {
421 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
422 return result;
423 }
424 result = data.writeStrongBinder(display);
425 if (result != NO_ERROR) {
426 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
427 return result;
428 }
429 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
430 if (result != NO_ERROR) {
431 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
432 return result;
433 }
434 result = reply.readInt32();
435 if (result == NO_ERROR) {
436 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
437 sizeof(ui::DisplayPrimaries));
438 }
439 return result;
440 }
441
Peiyong Lina52f0292018-03-14 17:26:31 -0700442 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700443 Parcel data, reply;
444 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
445 if (result != NO_ERROR) {
446 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700447 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700448 }
449 result = data.writeStrongBinder(display);
450 if (result != NO_ERROR) {
451 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700452 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700453 }
454 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
455 if (result != NO_ERROR) {
456 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700457 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700458 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700459 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700460 }
461
462 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700463 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700464 Parcel data, reply;
465 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
466 if (result != NO_ERROR) {
467 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
468 return result;
469 }
470 result = data.writeStrongBinder(display);
471 if (result != NO_ERROR) {
472 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
473 return result;
474 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700475 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700476 if (result != NO_ERROR) {
477 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
478 return result;
479 }
480 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
481 if (result != NO_ERROR) {
482 ALOGE("setActiveColorMode failed to transact: %d", result);
483 return result;
484 }
485 return static_cast<status_t>(reply.readInt32());
486 }
487
Svetoslavd85084b2014-03-20 10:28:31 -0700488 virtual status_t clearAnimationFrameStats() {
489 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700490 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
491 if (result != NO_ERROR) {
492 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
493 return result;
494 }
495 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
496 if (result != NO_ERROR) {
497 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
498 return result;
499 }
Svetoslavd85084b2014-03-20 10:28:31 -0700500 return reply.readInt32();
501 }
502
503 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
504 Parcel data, reply;
505 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
506 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
507 reply.read(*outStats);
508 return reply.readInt32();
509 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700510
511 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
512 HdrCapabilities* outCapabilities) const {
513 Parcel data, reply;
514 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
515 status_t result = data.writeStrongBinder(display);
516 if (result != NO_ERROR) {
517 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
518 return result;
519 }
520 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
521 data, &reply);
522 if (result != NO_ERROR) {
523 ALOGE("getHdrCapabilities failed to transact: %d", result);
524 return result;
525 }
526 result = reply.readInt32();
527 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800528 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700529 }
530 return result;
531 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700532
533 virtual status_t enableVSyncInjections(bool enable) {
534 Parcel data, reply;
535 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
536 if (result != NO_ERROR) {
537 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
538 return result;
539 }
540 result = data.writeBool(enable);
541 if (result != NO_ERROR) {
542 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
543 return result;
544 }
545 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
546 data, &reply, TF_ONE_WAY);
547 if (result != NO_ERROR) {
548 ALOGE("enableVSyncInjections failed to transact: %d", result);
549 return result;
550 }
551 return result;
552 }
553
554 virtual status_t injectVSync(nsecs_t when) {
555 Parcel data, reply;
556 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
557 if (result != NO_ERROR) {
558 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
559 return result;
560 }
561 result = data.writeInt64(when);
562 if (result != NO_ERROR) {
563 ALOGE("injectVSync failed to writeInt64: %d", result);
564 return result;
565 }
566 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
567 if (result != NO_ERROR) {
568 ALOGE("injectVSync failed to transact: %d", result);
569 return result;
570 }
571 return result;
572 }
573
Kalle Raitaa099a242017-01-11 11:17:29 -0800574 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
575 {
576 if (!outLayers) {
577 return UNEXPECTED_NULL;
578 }
579
580 Parcel data, reply;
581
582 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
583 if (err != NO_ERROR) {
584 return err;
585 }
586
587 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
588 if (err != NO_ERROR) {
589 return err;
590 }
591
592 int32_t result = 0;
593 err = reply.readInt32(&result);
594 if (err != NO_ERROR) {
595 return err;
596 }
597 if (result != NO_ERROR) {
598 return result;
599 }
600
601 outLayers->clear();
602 return reply.readParcelableVector(outLayers);
603 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700604
Peiyong Linc6780972018-10-28 15:24:08 -0700605 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
606 ui::PixelFormat* defaultPixelFormat,
607 ui::Dataspace* wideColorGamutDataspace,
608 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700609 Parcel data, reply;
610 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
611 if (error != NO_ERROR) {
612 return error;
613 }
614 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
615 if (error != NO_ERROR) {
616 return error;
617 }
618 error = static_cast<status_t>(reply.readInt32());
619 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700620 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
621 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
622 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
623 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700624 }
625 return error;
626 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700627
Ady Abraham37965d42018-11-01 13:43:32 -0700628 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700629 Parcel data, reply;
630 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700631 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
632 bool result;
633 status_t err = reply.readBool(&result);
634 if (err == NO_ERROR) {
635 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700636 }
Ady Abraham37965d42018-11-01 13:43:32 -0700637 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700638 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700639
640 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
641 ui::PixelFormat* outFormat,
642 ui::Dataspace* outDataspace,
643 uint8_t* outComponentMask) const {
644 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
645 Parcel data, reply;
646 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
647 data.writeStrongBinder(display);
648
649 status_t error =
650 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
651 data, &reply);
652 if (error != NO_ERROR) {
653 return error;
654 }
655
656 uint32_t value = 0;
657 error = reply.readUint32(&value);
658 if (error != NO_ERROR) {
659 return error;
660 }
661 *outFormat = static_cast<ui::PixelFormat>(value);
662
663 error = reply.readUint32(&value);
664 if (error != NO_ERROR) {
665 return error;
666 }
667 *outDataspace = static_cast<ui::Dataspace>(value);
668
669 error = reply.readUint32(&value);
670 if (error != NO_ERROR) {
671 return error;
672 }
673 *outComponentMask = static_cast<uint8_t>(value);
674 return error;
675 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800676
677 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
678 uint8_t componentMask,
679 uint64_t maxFrames) const {
680 Parcel data, reply;
681 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
682 data.writeStrongBinder(display);
683 data.writeBool(enable);
684 data.writeByte(static_cast<int8_t>(componentMask));
685 data.writeUint64(maxFrames);
686 status_t result =
687 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
688 &reply);
689 return result;
690 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700691
692 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
693 uint64_t timestamp,
694 DisplayedFrameStats* outStats) const {
695 if (!outStats) return BAD_VALUE;
696
697 Parcel data, reply;
698 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
699 data.writeStrongBinder(display);
700 data.writeUint64(maxFrames);
701 data.writeUint64(timestamp);
702
703 status_t result =
704 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
705
706 if (result != NO_ERROR) {
707 return result;
708 }
709
710 result = reply.readUint64(&outStats->numFrames);
711 if (result != NO_ERROR) {
712 return result;
713 }
714
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800715 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700716 if (result != NO_ERROR) {
717 return result;
718 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800719 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700720 if (result != NO_ERROR) {
721 return result;
722 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800723 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700724 if (result != NO_ERROR) {
725 return result;
726 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800727 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700728 return result;
729 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800730
731 virtual status_t getProtectedContentSupport(bool* outSupported) const {
732 Parcel data, reply;
733 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800734 status_t error =
735 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
736 if (error != NO_ERROR) {
737 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800738 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800739 error = reply.readBool(outSupported);
740 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800741 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800742
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800743 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
744 bool* outIsWideColorDisplay) const {
745 Parcel data, reply;
746 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
747 if (error != NO_ERROR) {
748 return error;
749 }
750 error = data.writeStrongBinder(token);
751 if (error != NO_ERROR) {
752 return error;
753 }
754
755 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
756 if (error != NO_ERROR) {
757 return error;
758 }
759 error = reply.readBool(outIsWideColorDisplay);
760 return error;
761 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800762
763 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
764 const sp<IBinder>& stopLayerHandle,
765 const sp<IRegionSamplingListener>& listener) {
766 Parcel data, reply;
767 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
768 if (error != NO_ERROR) {
769 ALOGE("addRegionSamplingListener: Failed to write interface token");
770 return error;
771 }
772 error = data.write(samplingArea);
773 if (error != NO_ERROR) {
774 ALOGE("addRegionSamplingListener: Failed to write sampling area");
775 return error;
776 }
777 error = data.writeStrongBinder(stopLayerHandle);
778 if (error != NO_ERROR) {
779 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
780 return error;
781 }
782 error = data.writeStrongBinder(IInterface::asBinder(listener));
783 if (error != NO_ERROR) {
784 ALOGE("addRegionSamplingListener: Failed to write listener");
785 return error;
786 }
787 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
788 if (error != NO_ERROR) {
789 ALOGE("addRegionSamplingListener: Failed to transact");
790 }
791 return error;
792 }
793
794 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
795 Parcel data, reply;
796 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
797 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800798 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800799 return error;
800 }
801 error = data.writeStrongBinder(IInterface::asBinder(listener));
802 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800803 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800804 return error;
805 }
806 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
807 &reply);
808 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800809 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800810 }
811 return error;
812 }
Ady Abraham838de062019-02-04 10:24:03 -0800813
814 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
815 const std::vector<int32_t>& allowedConfigs) {
816 Parcel data, reply;
817 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
818 if (result != NO_ERROR) {
819 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
820 return result;
821 }
822 result = data.writeStrongBinder(displayToken);
823 if (result != NO_ERROR) {
824 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
825 return result;
826 }
827 result = data.writeInt32Vector(allowedConfigs);
828 if (result != NO_ERROR) {
829 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
830 return result;
831 }
832 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
833 if (result != NO_ERROR) {
834 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
835 return result;
836 }
837 return reply.readInt32();
838 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800839
840 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
841 std::vector<int32_t>* outAllowedConfigs) {
842 if (!outAllowedConfigs) return BAD_VALUE;
843 Parcel data, reply;
844 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
845 if (result != NO_ERROR) {
846 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
847 return result;
848 }
849 result = data.writeStrongBinder(displayToken);
850 if (result != NO_ERROR) {
851 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
852 return result;
853 }
854 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
855 if (result != NO_ERROR) {
856 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
857 return result;
858 }
859 result = reply.readInt32Vector(outAllowedConfigs);
860 if (result != NO_ERROR) {
861 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
862 return result;
863 }
864 return reply.readInt32();
865 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000866
867 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
868 bool* outSupport) const {
869 Parcel data, reply;
870 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
871 if (error != NO_ERROR) {
872 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
873 return error;
874 }
875 error = data.writeStrongBinder(displayToken);
876 if (error != NO_ERROR) {
877 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
878 return error;
879 }
880 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
881 if (error != NO_ERROR) {
882 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
883 return error;
884 }
885 bool support;
886 error = reply.readBool(&support);
887 if (error != NO_ERROR) {
888 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
889 return error;
890 }
891 *outSupport = support;
892 return NO_ERROR;
893 }
894
895 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
896 Parcel data, reply;
897 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
898 if (error != NO_ERROR) {
899 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
900 return error;
901 }
902 error = data.writeStrongBinder(displayToken);
903 if (error != NO_ERROR) {
904 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
905 return error;
906 }
907 error = data.writeFloat(brightness);
908 if (error != NO_ERROR) {
909 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
910 return error;
911 }
912 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
913 if (error != NO_ERROR) {
914 ALOGE("setDisplayBrightness: failed to transact: %d", error);
915 return error;
916 }
917 return NO_ERROR;
918 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800919};
920
Dan Stozad723bd72014-11-18 10:24:03 -0800921// Out-of-line virtual method definition to trigger vtable emission in this
922// translation unit (see clang warning -Wweak-vtables)
923BpSurfaceComposer::~BpSurfaceComposer() {}
924
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800925IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
926
927// ----------------------------------------------------------------------
928
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800929status_t BnSurfaceComposer::onTransact(
930 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
931{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800932 switch(code) {
933 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700934 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800935 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800936 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700937 return NO_ERROR;
938 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700939 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700940 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800941
942 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700943 if (count > data.dataSize()) {
944 return BAD_VALUE;
945 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700946 Vector<ComposerState> state;
947 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800948 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700949 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700950 if (s.read(data) == BAD_VALUE) {
951 return BAD_VALUE;
952 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700953 state.add(s);
954 }
Dan Stozad723bd72014-11-18 10:24:03 -0800955
956 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700957 if (count > data.dataSize()) {
958 return BAD_VALUE;
959 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700960 DisplayState d;
961 Vector<DisplayState> displays;
962 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800963 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700964 if (d.read(data) == BAD_VALUE) {
965 return BAD_VALUE;
966 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700967 displays.add(d);
968 }
Dan Stozad723bd72014-11-18 10:24:03 -0800969
970 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700971 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800972 InputWindowCommands inputWindowCommands;
973 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800974
975 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -0700976
977 cached_buffer_t uncachedBuffer;
978 uncachedBuffer.token = data.readStrongBinder();
979 uncachedBuffer.cacheId = data.readUint64();
980
Marissa Wall17b4e452018-12-26 16:32:34 -0800981 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall78b72202019-03-15 14:58:34 -0700982 desiredPresentTime, uncachedBuffer);
Jesse Hall6c913be2013-08-08 12:15:49 -0700983 return NO_ERROR;
984 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800985 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700986 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800987 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700988 return NO_ERROR;
989 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800990 case CAPTURE_SCREEN: {
991 CHECK_INTERFACE(ISurfaceComposer, data, reply);
992 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700993 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
994 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000995 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700996 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700997 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800998 uint32_t reqWidth = data.readUint32();
999 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001000 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001001 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001002 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001003
Peiyong Lin0e003c92018-09-17 11:09:51 -07001004 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
1005 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -08001006 static_cast<ISurfaceComposer::Rotation>(rotation), captureSecureLayers);
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001007 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001008 if (res == NO_ERROR) {
1009 reply->write(*outBuffer);
1010 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001011 return NO_ERROR;
1012 }
chaviwa76b2712017-09-20 12:02:26 -07001013 case CAPTURE_LAYERS: {
1014 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1015 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001016 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1017 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001018 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001019 Rect sourceCrop(Rect::EMPTY_RECT);
1020 data.read(sourceCrop);
1021 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001022 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001023
Peiyong Lin0e003c92018-09-17 11:09:51 -07001024 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
1025 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001026 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001027 if (res == NO_ERROR) {
1028 reply->write(*outBuffer);
1029 }
chaviwa76b2712017-09-20 12:02:26 -07001030 return NO_ERROR;
1031 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001032 case AUTHENTICATE_SURFACE: {
1033 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001034 sp<IGraphicBufferProducer> bufferProducer =
1035 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1036 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001037 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001038 return NO_ERROR;
1039 }
Brian Anderson6b376712017-04-04 10:51:39 -07001040 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1041 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1042 std::vector<FrameEvent> supportedTimestamps;
1043 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1044 status_t err = reply->writeInt32(result);
1045 if (err != NO_ERROR) {
1046 return err;
1047 }
1048 if (result != NO_ERROR) {
1049 return result;
1050 }
1051
1052 std::vector<int32_t> supported;
1053 supported.reserve(supportedTimestamps.size());
1054 for (FrameEvent s : supportedTimestamps) {
1055 supported.push_back(static_cast<int32_t>(s));
1056 }
1057 return reply->writeInt32Vector(supported);
1058 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001059 case CREATE_DISPLAY_EVENT_CONNECTION: {
1060 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001061 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1062 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001063 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001064 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001065 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001066 case CREATE_DISPLAY: {
1067 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001068 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001069 bool secure = bool(data.readInt32());
1070 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001071 reply->writeStrongBinder(display);
1072 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001073 }
1074 case DESTROY_DISPLAY: {
1075 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1076 sp<IBinder> display = data.readStrongBinder();
1077 destroyDisplay(display);
1078 return NO_ERROR;
1079 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001080 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001081 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001082 PhysicalDisplayId displayId = data.readUint64();
1083 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001084 reply->writeStrongBinder(display);
1085 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001086 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001087 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001088 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001089 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001090 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001091 status_t result = getDisplayConfigs(display, &configs);
1092 reply->writeInt32(result);
1093 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001094 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001095 for (size_t c = 0; c < configs.size(); ++c) {
1096 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1097 &configs[c], sizeof(DisplayInfo));
1098 }
1099 }
1100 return NO_ERROR;
1101 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001102 case GET_DISPLAY_STATS: {
1103 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1104 DisplayStatInfo stats;
1105 sp<IBinder> display = data.readStrongBinder();
1106 status_t result = getDisplayStats(display, &stats);
1107 reply->writeInt32(result);
1108 if (result == NO_ERROR) {
1109 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1110 &stats, sizeof(DisplayStatInfo));
1111 }
1112 return NO_ERROR;
1113 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001114 case GET_ACTIVE_CONFIG: {
1115 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1116 sp<IBinder> display = data.readStrongBinder();
1117 int id = getActiveConfig(display);
1118 reply->writeInt32(id);
1119 return NO_ERROR;
1120 }
1121 case SET_ACTIVE_CONFIG: {
1122 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1123 sp<IBinder> display = data.readStrongBinder();
1124 int id = data.readInt32();
1125 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001126 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001127 return NO_ERROR;
1128 }
Michael Wright28f24d02016-07-12 13:30:53 -07001129 case GET_DISPLAY_COLOR_MODES: {
1130 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001131 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001132 sp<IBinder> display = nullptr;
1133 status_t result = data.readStrongBinder(&display);
1134 if (result != NO_ERROR) {
1135 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1136 return result;
1137 }
1138 result = getDisplayColorModes(display, &colorModes);
1139 reply->writeInt32(result);
1140 if (result == NO_ERROR) {
1141 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1142 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001143 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001144 }
1145 }
1146 return NO_ERROR;
1147 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001148 case GET_DISPLAY_NATIVE_PRIMARIES: {
1149 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1150 ui::DisplayPrimaries primaries;
1151 sp<IBinder> display = nullptr;
1152
1153 status_t result = data.readStrongBinder(&display);
1154 if (result != NO_ERROR) {
1155 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1156 return result;
1157 }
1158
1159 result = getDisplayNativePrimaries(display, primaries);
1160 reply->writeInt32(result);
1161 if (result == NO_ERROR) {
1162 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1163 sizeof(ui::DisplayPrimaries));
1164 }
1165
1166 return NO_ERROR;
1167 }
Michael Wright28f24d02016-07-12 13:30:53 -07001168 case GET_ACTIVE_COLOR_MODE: {
1169 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1170 sp<IBinder> display = nullptr;
1171 status_t result = data.readStrongBinder(&display);
1172 if (result != NO_ERROR) {
1173 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1174 return result;
1175 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001176 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001177 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1178 return result;
1179 }
1180 case SET_ACTIVE_COLOR_MODE: {
1181 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1182 sp<IBinder> display = nullptr;
1183 status_t result = data.readStrongBinder(&display);
1184 if (result != NO_ERROR) {
1185 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1186 return result;
1187 }
1188 int32_t colorModeInt = 0;
1189 result = data.readInt32(&colorModeInt);
1190 if (result != NO_ERROR) {
1191 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1192 return result;
1193 }
1194 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001195 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001196 result = reply->writeInt32(result);
1197 return result;
1198 }
Svetoslavd85084b2014-03-20 10:28:31 -07001199 case CLEAR_ANIMATION_FRAME_STATS: {
1200 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1201 status_t result = clearAnimationFrameStats();
1202 reply->writeInt32(result);
1203 return NO_ERROR;
1204 }
1205 case GET_ANIMATION_FRAME_STATS: {
1206 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1207 FrameStats stats;
1208 status_t result = getAnimationFrameStats(&stats);
1209 reply->write(stats);
1210 reply->writeInt32(result);
1211 return NO_ERROR;
1212 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001213 case SET_POWER_MODE: {
1214 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1215 sp<IBinder> display = data.readStrongBinder();
1216 int32_t mode = data.readInt32();
1217 setPowerMode(display, mode);
1218 return NO_ERROR;
1219 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001220 case GET_HDR_CAPABILITIES: {
1221 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1222 sp<IBinder> display = nullptr;
1223 status_t result = data.readStrongBinder(&display);
1224 if (result != NO_ERROR) {
1225 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1226 result);
1227 return result;
1228 }
1229 HdrCapabilities capabilities;
1230 result = getHdrCapabilities(display, &capabilities);
1231 reply->writeInt32(result);
1232 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001233 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001234 }
1235 return NO_ERROR;
1236 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001237 case ENABLE_VSYNC_INJECTIONS: {
1238 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1239 bool enable = false;
1240 status_t result = data.readBool(&enable);
1241 if (result != NO_ERROR) {
1242 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1243 return result;
1244 }
1245 return enableVSyncInjections(enable);
1246 }
1247 case INJECT_VSYNC: {
1248 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1249 int64_t when = 0;
1250 status_t result = data.readInt64(&when);
1251 if (result != NO_ERROR) {
1252 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1253 return result;
1254 }
1255 return injectVSync(when);
1256 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001257 case GET_LAYER_DEBUG_INFO: {
1258 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1259 std::vector<LayerDebugInfo> outLayers;
1260 status_t result = getLayerDebugInfo(&outLayers);
1261 reply->writeInt32(result);
1262 if (result == NO_ERROR)
1263 {
1264 result = reply->writeParcelableVector(outLayers);
1265 }
1266 return result;
1267 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001268 case GET_COMPOSITION_PREFERENCE: {
1269 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001270 ui::Dataspace defaultDataspace;
1271 ui::PixelFormat defaultPixelFormat;
1272 ui::Dataspace wideColorGamutDataspace;
1273 ui::PixelFormat wideColorGamutPixelFormat;
1274 status_t error =
1275 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1276 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001277 reply->writeInt32(error);
1278 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001279 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1280 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1281 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001282 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001283 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001284 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001285 }
Ady Abraham37965d42018-11-01 13:43:32 -07001286 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001287 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001288 bool result;
1289 status_t error = getColorManagement(&result);
1290 if (error == NO_ERROR) {
1291 reply->writeBool(result);
1292 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001293 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001294 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001295 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1296 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1297
1298 sp<IBinder> display = data.readStrongBinder();
1299 ui::PixelFormat format;
1300 ui::Dataspace dataspace;
1301 uint8_t component = 0;
1302 auto result =
1303 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1304 if (result == NO_ERROR) {
1305 reply->writeUint32(static_cast<uint32_t>(format));
1306 reply->writeUint32(static_cast<uint32_t>(dataspace));
1307 reply->writeUint32(static_cast<uint32_t>(component));
1308 }
1309 return result;
1310 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001311 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1312 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1313
1314 sp<IBinder> display = nullptr;
1315 bool enable = false;
1316 int8_t componentMask = 0;
1317 uint64_t maxFrames = 0;
1318 status_t result = data.readStrongBinder(&display);
1319 if (result != NO_ERROR) {
1320 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1321 result);
1322 return result;
1323 }
1324
1325 result = data.readBool(&enable);
1326 if (result != NO_ERROR) {
1327 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1328 return result;
1329 }
1330
1331 result = data.readByte(static_cast<int8_t*>(&componentMask));
1332 if (result != NO_ERROR) {
1333 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1334 result);
1335 return result;
1336 }
1337
1338 result = data.readUint64(&maxFrames);
1339 if (result != NO_ERROR) {
1340 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1341 return result;
1342 }
1343
1344 return setDisplayContentSamplingEnabled(display, enable,
1345 static_cast<uint8_t>(componentMask), maxFrames);
1346 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001347 case GET_DISPLAYED_CONTENT_SAMPLE: {
1348 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1349
1350 sp<IBinder> display = data.readStrongBinder();
1351 uint64_t maxFrames = 0;
1352 uint64_t timestamp = 0;
1353
1354 status_t result = data.readUint64(&maxFrames);
1355 if (result != NO_ERROR) {
1356 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1357 return result;
1358 }
1359
1360 result = data.readUint64(&timestamp);
1361 if (result != NO_ERROR) {
1362 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1363 return result;
1364 }
1365
1366 DisplayedFrameStats stats;
1367 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1368 if (result == NO_ERROR) {
1369 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001370 reply->writeUint64Vector(stats.component_0_sample);
1371 reply->writeUint64Vector(stats.component_1_sample);
1372 reply->writeUint64Vector(stats.component_2_sample);
1373 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001374 }
1375 return result;
1376 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001377 case GET_PROTECTED_CONTENT_SUPPORT: {
1378 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1379 bool result;
1380 status_t error = getProtectedContentSupport(&result);
1381 if (error == NO_ERROR) {
1382 reply->writeBool(result);
1383 }
1384 return error;
1385 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001386 case IS_WIDE_COLOR_DISPLAY: {
1387 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1388 sp<IBinder> display = nullptr;
1389 status_t error = data.readStrongBinder(&display);
1390 if (error != NO_ERROR) {
1391 return error;
1392 }
1393 bool result;
1394 error = isWideColorDisplay(display, &result);
1395 if (error == NO_ERROR) {
1396 reply->writeBool(result);
1397 }
1398 return error;
1399 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001400 case GET_PHYSICAL_DISPLAY_IDS: {
1401 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1402 return reply->writeUint64Vector(getPhysicalDisplayIds());
1403 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001404 case ADD_REGION_SAMPLING_LISTENER: {
1405 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1406 Rect samplingArea;
1407 status_t result = data.read(samplingArea);
1408 if (result != NO_ERROR) {
1409 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1410 return result;
1411 }
1412 sp<IBinder> stopLayerHandle;
1413 result = data.readNullableStrongBinder(&stopLayerHandle);
1414 if (result != NO_ERROR) {
1415 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1416 return result;
1417 }
1418 sp<IRegionSamplingListener> listener;
1419 result = data.readNullableStrongBinder(&listener);
1420 if (result != NO_ERROR) {
1421 ALOGE("addRegionSamplingListener: Failed to read listener");
1422 return result;
1423 }
1424 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1425 }
1426 case REMOVE_REGION_SAMPLING_LISTENER: {
1427 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1428 sp<IRegionSamplingListener> listener;
1429 status_t result = data.readNullableStrongBinder(&listener);
1430 if (result != NO_ERROR) {
1431 ALOGE("removeRegionSamplingListener: Failed to read listener");
1432 return result;
1433 }
1434 return removeRegionSamplingListener(listener);
1435 }
Ady Abraham838de062019-02-04 10:24:03 -08001436 case SET_ALLOWED_DISPLAY_CONFIGS: {
1437 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1438 sp<IBinder> displayToken = data.readStrongBinder();
1439 std::vector<int32_t> allowedConfigs;
1440 data.readInt32Vector(&allowedConfigs);
1441 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1442 reply->writeInt32(result);
1443 return result;
1444 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001445 case GET_ALLOWED_DISPLAY_CONFIGS: {
1446 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1447 sp<IBinder> displayToken = data.readStrongBinder();
1448 std::vector<int32_t> allowedConfigs;
1449 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1450 reply->writeInt32Vector(allowedConfigs);
1451 reply->writeInt32(result);
1452 return result;
1453 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001454 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1455 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1456 sp<IBinder> displayToken;
1457 status_t error = data.readNullableStrongBinder(&displayToken);
1458 if (error != NO_ERROR) {
1459 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1460 return error;
1461 }
1462 bool support = false;
1463 error = getDisplayBrightnessSupport(displayToken, &support);
1464 reply->writeBool(support);
1465 return error;
1466 }
1467 case SET_DISPLAY_BRIGHTNESS: {
1468 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1469 sp<IBinder> displayToken;
1470 status_t error = data.readNullableStrongBinder(&displayToken);
1471 if (error != NO_ERROR) {
1472 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1473 return error;
1474 }
1475 float brightness = -1.0f;
1476 error = data.readFloat(&brightness);
1477 if (error != NO_ERROR) {
1478 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1479 return error;
1480 }
1481 return setDisplayBrightness(displayToken, brightness);
1482 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001483 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001484 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001485 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001486 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001487}
1488
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001489} // namespace android