blob: da7369db1b40527a30890cad258f00d4c36f4a78 [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,
Valerie Hau9dab9732019-08-20 09:29:25 -070072 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
Marissa Wall3dad52d2019-03-22 14:03:19 -070073 const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080076
77 data.writeUint32(static_cast<uint32_t>(state.size()));
78 for (const auto& s : state) {
79 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070080 }
Dan Stozad723bd72014-11-18 10:24:03 -080081
82 data.writeUint32(static_cast<uint32_t>(displays.size()));
83 for (const auto& d : displays) {
84 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
87 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070088 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080089 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080090 data.writeInt64(desiredPresentTime);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070091 data.writeStrongBinder(uncacheBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070092 data.writeUint64(uncacheBuffer.id);
Valerie Hau9dab9732019-08-20 09:29:25 -070093 data.writeBool(hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070094
95 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
96 for (const auto& [listener, callbackIds] : listenerCallbacks) {
Valerie Hau5de3ad22019-08-20 07:47:43 -070097 data.writeStrongBinder(listener);
Marissa Wall3dad52d2019-03-22 14:03:19 -070098 data.writeInt64Vector(callbackIds);
99 }
100 }
101
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700102 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 }
104
105 virtual void bootFinished()
106 {
107 Parcel data, reply;
108 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
109 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
110 }
111
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000112 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Robert Carr108b2c72019-04-02 16:32:58 -0700113 bool& outCapturedSecureLayers, const ui::Dataspace reqDataspace,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700114 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
115 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -0800116 ISurfaceComposer::Rotation rotation, bool captureSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800117 Parcel data, reply;
118 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
119 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700120 data.writeInt32(static_cast<int32_t>(reqDataspace));
121 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700122 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800123 data.writeUint32(reqWidth);
124 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800125 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700126 data.writeInt32(static_cast<int32_t>(rotation));
Robert Carrfa8855f2019-02-19 10:05:00 -0800127 data.writeInt32(static_cast<int32_t>(captureSecureLayers));
Ana Krulec2d41e422018-07-26 12:07:43 -0700128 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
129 if (result != NO_ERROR) {
130 ALOGE("captureScreen failed to transact: %d", result);
131 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000132 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700133 result = reply.readInt32();
134 if (result != NO_ERROR) {
135 ALOGE("captureScreen failed to readInt32: %d", result);
136 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000137 }
138
139 *outBuffer = new GraphicBuffer();
140 reply.read(**outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -0700141 outCapturedSecureLayers = reply.readBool();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700142
Ana Krulec2d41e422018-07-26 12:07:43 -0700143 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800144 }
145
chaviw93df2ea2019-04-30 16:45:12 -0700146 virtual status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
147 sp<GraphicBuffer>* outBuffer) {
148 Parcel data, reply;
149 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
150 data.writeUint64(displayOrLayerStack);
151 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN_BY_ID, data, &reply);
152 if (result != NO_ERROR) {
153 ALOGE("captureScreen failed to transact: %d", result);
154 return result;
155 }
156 result = reply.readInt32();
157 if (result != NO_ERROR) {
158 ALOGE("captureScreen failed to readInt32: %d", result);
159 return result;
160 }
161
162 *outDataspace = static_cast<ui::Dataspace>(reply.readInt32());
163 *outBuffer = new GraphicBuffer();
164 reply.read(**outBuffer);
165 return result;
166 }
167
Robert Carr866455f2019-04-02 16:28:26 -0700168 virtual status_t captureLayers(
169 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
170 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
171 const Rect& sourceCrop,
172 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
173 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700174 Parcel data, reply;
175 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
176 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700177 data.writeInt32(static_cast<int32_t>(reqDataspace));
178 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800179 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700180 data.writeInt32(excludeLayers.size());
181 for (auto el : excludeLayers) {
182 data.writeStrongBinder(el);
183 }
chaviw7206d492017-11-10 16:16:12 -0800184 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800185 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700186 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
187 if (result != NO_ERROR) {
188 ALOGE("captureLayers failed to transact: %d", result);
189 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000190 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700191 result = reply.readInt32();
192 if (result != NO_ERROR) {
193 ALOGE("captureLayers failed to readInt32: %d", result);
194 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000195 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700196
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000197 *outBuffer = new GraphicBuffer();
198 reply.read(**outBuffer);
199
Ana Krulec2d41e422018-07-26 12:07:43 -0700200 return result;
chaviwa76b2712017-09-20 12:02:26 -0700201 }
202
Jamie Gennis582270d2011-08-17 18:19:00 -0700203 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800204 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800205 {
206 Parcel data, reply;
207 int err = NO_ERROR;
208 err = data.writeInterfaceToken(
209 ISurfaceComposer::getInterfaceDescriptor());
210 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000211 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800212 "interface descriptor: %s (%d)", strerror(-err), -err);
213 return false;
214 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800215 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800216 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000217 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700218 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800219 return false;
220 }
221 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
222 &reply);
223 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000224 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700225 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800226 return false;
227 }
228 int32_t result = 0;
229 err = reply.readInt32(&result);
230 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000231 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700232 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800233 return false;
234 }
235 return result != 0;
236 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800237
Brian Anderson6b376712017-04-04 10:51:39 -0700238 virtual status_t getSupportedFrameTimestamps(
239 std::vector<FrameEvent>* outSupported) const {
240 if (!outSupported) {
241 return UNEXPECTED_NULL;
242 }
243 outSupported->clear();
244
245 Parcel data, reply;
246
247 status_t err = data.writeInterfaceToken(
248 ISurfaceComposer::getInterfaceDescriptor());
249 if (err != NO_ERROR) {
250 return err;
251 }
252
253 err = remote()->transact(
254 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
255 data, &reply);
256 if (err != NO_ERROR) {
257 return err;
258 }
259
260 int32_t result = 0;
261 err = reply.readInt32(&result);
262 if (err != NO_ERROR) {
263 return err;
264 }
265 if (result != NO_ERROR) {
266 return result;
267 }
268
269 std::vector<int32_t> supported;
270 err = reply.readInt32Vector(&supported);
271 if (err != NO_ERROR) {
272 return err;
273 }
274
275 outSupported->reserve(supported.size());
276 for (int32_t s : supported) {
277 outSupported->push_back(static_cast<FrameEvent>(s));
278 }
279 return NO_ERROR;
280 }
281
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700282 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
283 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800284 Parcel data, reply;
285 sp<IDisplayEventConnection> result;
286 int err = data.writeInterfaceToken(
287 ISurfaceComposer::getInterfaceDescriptor());
288 if (err != NO_ERROR) {
289 return result;
290 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700291 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700292 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800293 err = remote()->transact(
294 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
295 data, &reply);
296 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000297 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800298 "transaction: %s (%d)", strerror(-err), -err);
299 return result;
300 }
301 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
302 return result;
303 }
Colin Cross8e533062012-06-07 13:17:52 -0700304
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700305 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700309 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700310 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700311 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
312 return reply.readStrongBinder();
313 }
314
Jesse Hall6c913be2013-08-08 12:15:49 -0700315 virtual void destroyDisplay(const sp<IBinder>& display)
316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
319 data.writeStrongBinder(display);
320 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
321 }
322
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800323 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700324 Parcel data, reply;
325 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800326 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
327 NO_ERROR) {
328 std::vector<PhysicalDisplayId> displayIds;
329 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
330 return displayIds;
331 }
332 }
333
334 return {};
335 }
336
337 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
338 Parcel data, reply;
339 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
340 data.writeUint64(displayId);
341 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700342 return reply.readStrongBinder();
343 }
344
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700345 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700349 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700350 data.writeInt32(mode);
351 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700352 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700353
Dan Stoza7f7da322014-05-02 15:26:25 -0700354 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
355 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700359 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700360 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
361 status_t result = reply.readInt32();
362 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800363 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700364 configs->clear();
365 configs->resize(numConfigs);
366 for (size_t c = 0; c < numConfigs; ++c) {
367 memcpy(&(configs->editItemAt(c)),
368 reply.readInplace(sizeof(DisplayInfo)),
369 sizeof(DisplayInfo));
370 }
371 }
372 return result;
373 }
374
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700375 virtual status_t getDisplayStats(const sp<IBinder>& display,
376 DisplayStatInfo* stats)
377 {
378 Parcel data, reply;
379 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
380 data.writeStrongBinder(display);
381 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
382 status_t result = reply.readInt32();
383 if (result == NO_ERROR) {
384 memcpy(stats,
385 reply.readInplace(sizeof(DisplayStatInfo)),
386 sizeof(DisplayStatInfo));
387 }
388 return result;
389 }
390
Dan Stoza7f7da322014-05-02 15:26:25 -0700391 virtual int getActiveConfig(const sp<IBinder>& display)
392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
395 data.writeStrongBinder(display);
396 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
397 return reply.readInt32();
398 }
399
400 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
401 {
402 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700403 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
404 if (result != NO_ERROR) {
405 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
406 return result;
407 }
408 result = data.writeStrongBinder(display);
409 if (result != NO_ERROR) {
410 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
411 return result;
412 }
413 result = data.writeInt32(id);
414 if (result != NO_ERROR) {
415 ALOGE("setActiveConfig failed to writeInt32: %d", result);
416 return result;
417 }
418 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
419 if (result != NO_ERROR) {
420 ALOGE("setActiveConfig failed to transact: %d", result);
421 return result;
422 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700423 return reply.readInt32();
424 }
Svetoslavd85084b2014-03-20 10:28:31 -0700425
Michael Wright28f24d02016-07-12 13:30:53 -0700426 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700427 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700428 Parcel data, reply;
429 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
430 if (result != NO_ERROR) {
431 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
432 return result;
433 }
434 result = data.writeStrongBinder(display);
435 if (result != NO_ERROR) {
436 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
437 return result;
438 }
439 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
440 if (result != NO_ERROR) {
441 ALOGE("getDisplayColorModes failed to transact: %d", result);
442 return result;
443 }
444 result = static_cast<status_t>(reply.readInt32());
445 if (result == NO_ERROR) {
446 size_t numModes = reply.readUint32();
447 outColorModes->clear();
448 outColorModes->resize(numModes);
449 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700450 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700451 }
452 }
453 return result;
454 }
455
Daniel Solomon42d04562019-01-20 21:03:19 -0800456 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
457 ui::DisplayPrimaries& primaries) {
458 Parcel data, reply;
459 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
460 if (result != NO_ERROR) {
461 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
462 return result;
463 }
464 result = data.writeStrongBinder(display);
465 if (result != NO_ERROR) {
466 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
467 return result;
468 }
469 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
470 if (result != NO_ERROR) {
471 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
472 return result;
473 }
474 result = reply.readInt32();
475 if (result == NO_ERROR) {
476 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
477 sizeof(ui::DisplayPrimaries));
478 }
479 return result;
480 }
481
Peiyong Lina52f0292018-03-14 17:26:31 -0700482 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700483 Parcel data, reply;
484 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
485 if (result != NO_ERROR) {
486 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700487 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700488 }
489 result = data.writeStrongBinder(display);
490 if (result != NO_ERROR) {
491 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700492 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700493 }
494 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
495 if (result != NO_ERROR) {
496 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700497 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700498 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700499 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700500 }
501
502 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700503 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700504 Parcel data, reply;
505 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
506 if (result != NO_ERROR) {
507 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
508 return result;
509 }
510 result = data.writeStrongBinder(display);
511 if (result != NO_ERROR) {
512 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
513 return result;
514 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700515 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700516 if (result != NO_ERROR) {
517 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
518 return result;
519 }
520 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
521 if (result != NO_ERROR) {
522 ALOGE("setActiveColorMode failed to transact: %d", result);
523 return result;
524 }
525 return static_cast<status_t>(reply.readInt32());
526 }
527
Svetoslavd85084b2014-03-20 10:28:31 -0700528 virtual status_t clearAnimationFrameStats() {
529 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700530 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
531 if (result != NO_ERROR) {
532 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
533 return result;
534 }
535 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
536 if (result != NO_ERROR) {
537 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
538 return result;
539 }
Svetoslavd85084b2014-03-20 10:28:31 -0700540 return reply.readInt32();
541 }
542
543 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
544 Parcel data, reply;
545 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
546 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
547 reply.read(*outStats);
548 return reply.readInt32();
549 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700550
551 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
552 HdrCapabilities* outCapabilities) const {
553 Parcel data, reply;
554 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
555 status_t result = data.writeStrongBinder(display);
556 if (result != NO_ERROR) {
557 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
558 return result;
559 }
560 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
561 data, &reply);
562 if (result != NO_ERROR) {
563 ALOGE("getHdrCapabilities failed to transact: %d", result);
564 return result;
565 }
566 result = reply.readInt32();
567 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800568 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700569 }
570 return result;
571 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700572
573 virtual status_t enableVSyncInjections(bool enable) {
574 Parcel data, reply;
575 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
576 if (result != NO_ERROR) {
577 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
578 return result;
579 }
580 result = data.writeBool(enable);
581 if (result != NO_ERROR) {
582 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
583 return result;
584 }
Steven Moreland366eb422019-04-01 19:22:32 -0700585 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
586 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700587 if (result != NO_ERROR) {
588 ALOGE("enableVSyncInjections failed to transact: %d", result);
589 return result;
590 }
591 return result;
592 }
593
594 virtual status_t injectVSync(nsecs_t when) {
595 Parcel data, reply;
596 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
597 if (result != NO_ERROR) {
598 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
599 return result;
600 }
601 result = data.writeInt64(when);
602 if (result != NO_ERROR) {
603 ALOGE("injectVSync failed to writeInt64: %d", result);
604 return result;
605 }
Steven Moreland366eb422019-04-01 19:22:32 -0700606 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
607 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700608 if (result != NO_ERROR) {
609 ALOGE("injectVSync failed to transact: %d", result);
610 return result;
611 }
612 return result;
613 }
614
Kalle Raitaa099a242017-01-11 11:17:29 -0800615 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
616 {
617 if (!outLayers) {
618 return UNEXPECTED_NULL;
619 }
620
621 Parcel data, reply;
622
623 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
624 if (err != NO_ERROR) {
625 return err;
626 }
627
628 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
629 if (err != NO_ERROR) {
630 return err;
631 }
632
633 int32_t result = 0;
634 err = reply.readInt32(&result);
635 if (err != NO_ERROR) {
636 return err;
637 }
638 if (result != NO_ERROR) {
639 return result;
640 }
641
642 outLayers->clear();
643 return reply.readParcelableVector(outLayers);
644 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700645
Peiyong Linc6780972018-10-28 15:24:08 -0700646 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
647 ui::PixelFormat* defaultPixelFormat,
648 ui::Dataspace* wideColorGamutDataspace,
649 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700650 Parcel data, reply;
651 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
652 if (error != NO_ERROR) {
653 return error;
654 }
655 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
656 if (error != NO_ERROR) {
657 return error;
658 }
659 error = static_cast<status_t>(reply.readInt32());
660 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700661 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
662 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
663 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
664 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700665 }
666 return error;
667 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700668
Ady Abraham37965d42018-11-01 13:43:32 -0700669 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700670 Parcel data, reply;
671 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700672 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
673 bool result;
674 status_t err = reply.readBool(&result);
675 if (err == NO_ERROR) {
676 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700677 }
Ady Abraham37965d42018-11-01 13:43:32 -0700678 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700679 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700680
681 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
682 ui::PixelFormat* outFormat,
683 ui::Dataspace* outDataspace,
684 uint8_t* outComponentMask) const {
685 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
686 Parcel data, reply;
687 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
688 data.writeStrongBinder(display);
689
690 status_t error =
691 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
692 data, &reply);
693 if (error != NO_ERROR) {
694 return error;
695 }
696
697 uint32_t value = 0;
698 error = reply.readUint32(&value);
699 if (error != NO_ERROR) {
700 return error;
701 }
702 *outFormat = static_cast<ui::PixelFormat>(value);
703
704 error = reply.readUint32(&value);
705 if (error != NO_ERROR) {
706 return error;
707 }
708 *outDataspace = static_cast<ui::Dataspace>(value);
709
710 error = reply.readUint32(&value);
711 if (error != NO_ERROR) {
712 return error;
713 }
714 *outComponentMask = static_cast<uint8_t>(value);
715 return error;
716 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800717
718 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
719 uint8_t componentMask,
720 uint64_t maxFrames) const {
721 Parcel data, reply;
722 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
723 data.writeStrongBinder(display);
724 data.writeBool(enable);
725 data.writeByte(static_cast<int8_t>(componentMask));
726 data.writeUint64(maxFrames);
727 status_t result =
728 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
729 &reply);
730 return result;
731 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700732
733 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
734 uint64_t timestamp,
735 DisplayedFrameStats* outStats) const {
736 if (!outStats) return BAD_VALUE;
737
738 Parcel data, reply;
739 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
740 data.writeStrongBinder(display);
741 data.writeUint64(maxFrames);
742 data.writeUint64(timestamp);
743
744 status_t result =
745 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
746
747 if (result != NO_ERROR) {
748 return result;
749 }
750
751 result = reply.readUint64(&outStats->numFrames);
752 if (result != NO_ERROR) {
753 return result;
754 }
755
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800756 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700757 if (result != NO_ERROR) {
758 return result;
759 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800760 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700761 if (result != NO_ERROR) {
762 return result;
763 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800764 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700765 if (result != NO_ERROR) {
766 return result;
767 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800768 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700769 return result;
770 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800771
772 virtual status_t getProtectedContentSupport(bool* outSupported) const {
773 Parcel data, reply;
774 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800775 status_t error =
776 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
777 if (error != NO_ERROR) {
778 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800779 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800780 error = reply.readBool(outSupported);
781 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800782 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800783
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800784 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
785 bool* outIsWideColorDisplay) const {
786 Parcel data, reply;
787 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
788 if (error != NO_ERROR) {
789 return error;
790 }
791 error = data.writeStrongBinder(token);
792 if (error != NO_ERROR) {
793 return error;
794 }
795
796 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
797 if (error != NO_ERROR) {
798 return error;
799 }
800 error = reply.readBool(outIsWideColorDisplay);
801 return error;
802 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800803
804 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
805 const sp<IBinder>& stopLayerHandle,
806 const sp<IRegionSamplingListener>& listener) {
807 Parcel data, reply;
808 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
809 if (error != NO_ERROR) {
810 ALOGE("addRegionSamplingListener: Failed to write interface token");
811 return error;
812 }
813 error = data.write(samplingArea);
814 if (error != NO_ERROR) {
815 ALOGE("addRegionSamplingListener: Failed to write sampling area");
816 return error;
817 }
818 error = data.writeStrongBinder(stopLayerHandle);
819 if (error != NO_ERROR) {
820 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
821 return error;
822 }
823 error = data.writeStrongBinder(IInterface::asBinder(listener));
824 if (error != NO_ERROR) {
825 ALOGE("addRegionSamplingListener: Failed to write listener");
826 return error;
827 }
828 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
829 if (error != NO_ERROR) {
830 ALOGE("addRegionSamplingListener: Failed to transact");
831 }
832 return error;
833 }
834
835 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
836 Parcel data, reply;
837 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
838 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800839 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800840 return error;
841 }
842 error = data.writeStrongBinder(IInterface::asBinder(listener));
843 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800844 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800845 return error;
846 }
847 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
848 &reply);
849 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800850 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800851 }
852 return error;
853 }
Ady Abraham838de062019-02-04 10:24:03 -0800854
855 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
856 const std::vector<int32_t>& allowedConfigs) {
857 Parcel data, reply;
858 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
859 if (result != NO_ERROR) {
860 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
861 return result;
862 }
863 result = data.writeStrongBinder(displayToken);
864 if (result != NO_ERROR) {
865 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
866 return result;
867 }
868 result = data.writeInt32Vector(allowedConfigs);
869 if (result != NO_ERROR) {
870 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
871 return result;
872 }
873 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
874 if (result != NO_ERROR) {
875 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
876 return result;
877 }
878 return reply.readInt32();
879 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800880
Ana Krulec0782b882019-10-15 17:34:54 -0700881 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
882 int32_t defaultModeId, float minRefreshRate,
883 float maxRefreshRate) {
884 Parcel data, reply;
885 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
886 if (result != NO_ERROR) {
887 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
888 return result;
889 }
890 result = data.writeStrongBinder(displayToken);
891 if (result != NO_ERROR) {
892 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
893 return result;
894 }
895 result = data.writeInt32(defaultModeId);
896 if (result != NO_ERROR) {
897 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultModeId: %d", result);
898 return result;
899 }
900 result = data.writeFloat(minRefreshRate);
901 if (result != NO_ERROR) {
902 ALOGE("setDesiredDisplayConfigSpecs failed to write minRefreshRate: %d", result);
903 return result;
904 }
905 result = data.writeFloat(maxRefreshRate);
906 if (result != NO_ERROR) {
907 ALOGE("setDesiredDisplayConfigSpecs failed to write maxRefreshRate: %d", result);
908 return result;
909 }
910
911 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
912 &reply);
913 if (result != NO_ERROR) {
914 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
915 return result;
916 }
917 return reply.readInt32();
918 }
919
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800920 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
921 std::vector<int32_t>* outAllowedConfigs) {
922 if (!outAllowedConfigs) return BAD_VALUE;
923 Parcel data, reply;
924 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
925 if (result != NO_ERROR) {
926 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
927 return result;
928 }
929 result = data.writeStrongBinder(displayToken);
930 if (result != NO_ERROR) {
931 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
932 return result;
933 }
934 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
935 if (result != NO_ERROR) {
936 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
937 return result;
938 }
939 result = reply.readInt32Vector(outAllowedConfigs);
940 if (result != NO_ERROR) {
941 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
942 return result;
943 }
944 return reply.readInt32();
945 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000946
947 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
948 bool* outSupport) const {
949 Parcel data, reply;
950 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
951 if (error != NO_ERROR) {
952 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
953 return error;
954 }
955 error = data.writeStrongBinder(displayToken);
956 if (error != NO_ERROR) {
957 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
958 return error;
959 }
960 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
961 if (error != NO_ERROR) {
962 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
963 return error;
964 }
965 bool support;
966 error = reply.readBool(&support);
967 if (error != NO_ERROR) {
968 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
969 return error;
970 }
971 *outSupport = support;
972 return NO_ERROR;
973 }
974
975 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
976 Parcel data, reply;
977 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
978 if (error != NO_ERROR) {
979 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
980 return error;
981 }
982 error = data.writeStrongBinder(displayToken);
983 if (error != NO_ERROR) {
984 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
985 return error;
986 }
987 error = data.writeFloat(brightness);
988 if (error != NO_ERROR) {
989 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
990 return error;
991 }
992 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
993 if (error != NO_ERROR) {
994 ALOGE("setDisplayBrightness: failed to transact: %d", error);
995 return error;
996 }
997 return NO_ERROR;
998 }
Ady Abraham8532d012019-05-08 14:50:56 -0700999
1000 virtual status_t notifyPowerHint(int32_t hintId) {
1001 Parcel data, reply;
1002 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1003 if (error != NO_ERROR) {
1004 ALOGE("notifyPowerHint: failed to write interface token: %d", error);
1005 return error;
1006 }
1007 error = data.writeInt32(hintId);
1008 if (error != NO_ERROR) {
1009 ALOGE("notifyPowerHint: failed to write hintId: %d", error);
1010 return error;
1011 }
1012 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_HINT, data, &reply,
1013 IBinder::FLAG_ONEWAY);
1014 if (error != NO_ERROR) {
1015 ALOGE("notifyPowerHint: failed to transact: %d", error);
1016 return error;
1017 }
1018 return NO_ERROR;
1019 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001020};
1021
Dan Stozad723bd72014-11-18 10:24:03 -08001022// Out-of-line virtual method definition to trigger vtable emission in this
1023// translation unit (see clang warning -Wweak-vtables)
1024BpSurfaceComposer::~BpSurfaceComposer() {}
1025
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001026IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1027
1028// ----------------------------------------------------------------------
1029
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001030status_t BnSurfaceComposer::onTransact(
1031 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1032{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001033 switch(code) {
1034 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001035 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001036 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001037 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001038 return NO_ERROR;
1039 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001040 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001041 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001042
1043 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001044 if (count > data.dataSize()) {
1045 return BAD_VALUE;
1046 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001047 Vector<ComposerState> state;
1048 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001049 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001050 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001051 if (s.read(data) == BAD_VALUE) {
1052 return BAD_VALUE;
1053 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001054 state.add(s);
1055 }
Dan Stozad723bd72014-11-18 10:24:03 -08001056
1057 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001058 if (count > data.dataSize()) {
1059 return BAD_VALUE;
1060 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001061 DisplayState d;
1062 Vector<DisplayState> displays;
1063 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001064 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001065 if (d.read(data) == BAD_VALUE) {
1066 return BAD_VALUE;
1067 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001068 displays.add(d);
1069 }
Dan Stozad723bd72014-11-18 10:24:03 -08001070
1071 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001072 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001073 InputWindowCommands inputWindowCommands;
1074 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001075
1076 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001077
Marissa Wall947d34e2019-03-29 14:03:53 -07001078 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001079 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001080 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001081
Valerie Hau9dab9732019-08-20 09:29:25 -07001082 bool hasListenerCallbacks = data.readBool();
1083
Marissa Wall3dad52d2019-03-22 14:03:19 -07001084 std::vector<ListenerCallbacks> listenerCallbacks;
1085 int32_t listenersSize = data.readInt32();
1086 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001087 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001088 std::vector<CallbackId> callbackIds;
1089 data.readInt64Vector(&callbackIds);
1090 listenerCallbacks.emplace_back(listener, callbackIds);
1091 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001092 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001093 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1094 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001095 return NO_ERROR;
1096 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001097 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001098 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001099 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001100 return NO_ERROR;
1101 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001102 case CAPTURE_SCREEN: {
1103 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1104 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001105 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1106 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001107 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001108 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001109 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001110 uint32_t reqWidth = data.readUint32();
1111 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001112 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001113 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001114 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001115
Robert Carr108b2c72019-04-02 16:32:58 -07001116 bool capturedSecureLayers = false;
1117 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1118 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1119 useIdentityTransform,
1120 static_cast<ISurfaceComposer::Rotation>(rotation),
1121 captureSecureLayers);
1122
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001123 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001124 if (res == NO_ERROR) {
1125 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001126 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001127 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001128 return NO_ERROR;
1129 }
chaviw93df2ea2019-04-30 16:45:12 -07001130 case CAPTURE_SCREEN_BY_ID: {
1131 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1132 uint64_t displayOrLayerStack = data.readUint64();
1133 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1134 sp<GraphicBuffer> outBuffer;
1135 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1136 reply->writeInt32(res);
1137 if (res == NO_ERROR) {
1138 reply->writeInt32(static_cast<int32_t>(outDataspace));
1139 reply->write(*outBuffer);
1140 }
1141 return NO_ERROR;
1142 }
chaviwa76b2712017-09-20 12:02:26 -07001143 case CAPTURE_LAYERS: {
1144 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1145 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001146 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1147 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001148 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001149 Rect sourceCrop(Rect::EMPTY_RECT);
1150 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001151
1152 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1153 int numExcludeHandles = data.readInt32();
1154 excludeHandles.reserve(numExcludeHandles);
1155 for (int i = 0; i < numExcludeHandles; i++) {
1156 excludeHandles.emplace(data.readStrongBinder());
1157 }
1158
chaviw7206d492017-11-10 16:16:12 -08001159 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001160 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001161
Robert Carr866455f2019-04-02 16:28:26 -07001162 status_t res =
1163 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1164 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001165 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001166 if (res == NO_ERROR) {
1167 reply->write(*outBuffer);
1168 }
chaviwa76b2712017-09-20 12:02:26 -07001169 return NO_ERROR;
1170 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001171 case AUTHENTICATE_SURFACE: {
1172 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001173 sp<IGraphicBufferProducer> bufferProducer =
1174 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1175 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001176 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001177 return NO_ERROR;
1178 }
Brian Anderson6b376712017-04-04 10:51:39 -07001179 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1180 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1181 std::vector<FrameEvent> supportedTimestamps;
1182 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1183 status_t err = reply->writeInt32(result);
1184 if (err != NO_ERROR) {
1185 return err;
1186 }
1187 if (result != NO_ERROR) {
1188 return result;
1189 }
1190
1191 std::vector<int32_t> supported;
1192 supported.reserve(supportedTimestamps.size());
1193 for (FrameEvent s : supportedTimestamps) {
1194 supported.push_back(static_cast<int32_t>(s));
1195 }
1196 return reply->writeInt32Vector(supported);
1197 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001198 case CREATE_DISPLAY_EVENT_CONNECTION: {
1199 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001200 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1201 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1202
1203 sp<IDisplayEventConnection> connection(
1204 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001205 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001206 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001207 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001208 case CREATE_DISPLAY: {
1209 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001210 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001211 bool secure = bool(data.readInt32());
1212 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001213 reply->writeStrongBinder(display);
1214 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001215 }
1216 case DESTROY_DISPLAY: {
1217 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1218 sp<IBinder> display = data.readStrongBinder();
1219 destroyDisplay(display);
1220 return NO_ERROR;
1221 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001222 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001223 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001224 PhysicalDisplayId displayId = data.readUint64();
1225 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001226 reply->writeStrongBinder(display);
1227 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001228 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001229 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001230 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001231 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001232 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001233 status_t result = getDisplayConfigs(display, &configs);
1234 reply->writeInt32(result);
1235 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001236 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001237 for (size_t c = 0; c < configs.size(); ++c) {
1238 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1239 &configs[c], sizeof(DisplayInfo));
1240 }
1241 }
1242 return NO_ERROR;
1243 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001244 case GET_DISPLAY_STATS: {
1245 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1246 DisplayStatInfo stats;
1247 sp<IBinder> display = data.readStrongBinder();
1248 status_t result = getDisplayStats(display, &stats);
1249 reply->writeInt32(result);
1250 if (result == NO_ERROR) {
1251 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1252 &stats, sizeof(DisplayStatInfo));
1253 }
1254 return NO_ERROR;
1255 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001256 case GET_ACTIVE_CONFIG: {
1257 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1258 sp<IBinder> display = data.readStrongBinder();
1259 int id = getActiveConfig(display);
1260 reply->writeInt32(id);
1261 return NO_ERROR;
1262 }
1263 case SET_ACTIVE_CONFIG: {
1264 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1265 sp<IBinder> display = data.readStrongBinder();
1266 int id = data.readInt32();
1267 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001268 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001269 return NO_ERROR;
1270 }
Michael Wright28f24d02016-07-12 13:30:53 -07001271 case GET_DISPLAY_COLOR_MODES: {
1272 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001273 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001274 sp<IBinder> display = nullptr;
1275 status_t result = data.readStrongBinder(&display);
1276 if (result != NO_ERROR) {
1277 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1278 return result;
1279 }
1280 result = getDisplayColorModes(display, &colorModes);
1281 reply->writeInt32(result);
1282 if (result == NO_ERROR) {
1283 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1284 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001285 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001286 }
1287 }
1288 return NO_ERROR;
1289 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001290 case GET_DISPLAY_NATIVE_PRIMARIES: {
1291 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1292 ui::DisplayPrimaries primaries;
1293 sp<IBinder> display = nullptr;
1294
1295 status_t result = data.readStrongBinder(&display);
1296 if (result != NO_ERROR) {
1297 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1298 return result;
1299 }
1300
1301 result = getDisplayNativePrimaries(display, primaries);
1302 reply->writeInt32(result);
1303 if (result == NO_ERROR) {
1304 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1305 sizeof(ui::DisplayPrimaries));
1306 }
1307
1308 return NO_ERROR;
1309 }
Michael Wright28f24d02016-07-12 13:30:53 -07001310 case GET_ACTIVE_COLOR_MODE: {
1311 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1312 sp<IBinder> display = nullptr;
1313 status_t result = data.readStrongBinder(&display);
1314 if (result != NO_ERROR) {
1315 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1316 return result;
1317 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001318 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001319 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1320 return result;
1321 }
1322 case SET_ACTIVE_COLOR_MODE: {
1323 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1324 sp<IBinder> display = nullptr;
1325 status_t result = data.readStrongBinder(&display);
1326 if (result != NO_ERROR) {
1327 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1328 return result;
1329 }
1330 int32_t colorModeInt = 0;
1331 result = data.readInt32(&colorModeInt);
1332 if (result != NO_ERROR) {
1333 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1334 return result;
1335 }
1336 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001337 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001338 result = reply->writeInt32(result);
1339 return result;
1340 }
Svetoslavd85084b2014-03-20 10:28:31 -07001341 case CLEAR_ANIMATION_FRAME_STATS: {
1342 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1343 status_t result = clearAnimationFrameStats();
1344 reply->writeInt32(result);
1345 return NO_ERROR;
1346 }
1347 case GET_ANIMATION_FRAME_STATS: {
1348 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1349 FrameStats stats;
1350 status_t result = getAnimationFrameStats(&stats);
1351 reply->write(stats);
1352 reply->writeInt32(result);
1353 return NO_ERROR;
1354 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001355 case SET_POWER_MODE: {
1356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1357 sp<IBinder> display = data.readStrongBinder();
1358 int32_t mode = data.readInt32();
1359 setPowerMode(display, mode);
1360 return NO_ERROR;
1361 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001362 case GET_HDR_CAPABILITIES: {
1363 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1364 sp<IBinder> display = nullptr;
1365 status_t result = data.readStrongBinder(&display);
1366 if (result != NO_ERROR) {
1367 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1368 result);
1369 return result;
1370 }
1371 HdrCapabilities capabilities;
1372 result = getHdrCapabilities(display, &capabilities);
1373 reply->writeInt32(result);
1374 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001375 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001376 }
1377 return NO_ERROR;
1378 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001379 case ENABLE_VSYNC_INJECTIONS: {
1380 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1381 bool enable = false;
1382 status_t result = data.readBool(&enable);
1383 if (result != NO_ERROR) {
1384 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1385 return result;
1386 }
1387 return enableVSyncInjections(enable);
1388 }
1389 case INJECT_VSYNC: {
1390 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1391 int64_t when = 0;
1392 status_t result = data.readInt64(&when);
1393 if (result != NO_ERROR) {
1394 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1395 return result;
1396 }
1397 return injectVSync(when);
1398 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001399 case GET_LAYER_DEBUG_INFO: {
1400 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1401 std::vector<LayerDebugInfo> outLayers;
1402 status_t result = getLayerDebugInfo(&outLayers);
1403 reply->writeInt32(result);
1404 if (result == NO_ERROR)
1405 {
1406 result = reply->writeParcelableVector(outLayers);
1407 }
1408 return result;
1409 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001410 case GET_COMPOSITION_PREFERENCE: {
1411 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001412 ui::Dataspace defaultDataspace;
1413 ui::PixelFormat defaultPixelFormat;
1414 ui::Dataspace wideColorGamutDataspace;
1415 ui::PixelFormat wideColorGamutPixelFormat;
1416 status_t error =
1417 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1418 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001419 reply->writeInt32(error);
1420 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001421 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1422 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1423 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001424 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001425 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001426 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001427 }
Ady Abraham37965d42018-11-01 13:43:32 -07001428 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001429 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001430 bool result;
1431 status_t error = getColorManagement(&result);
1432 if (error == NO_ERROR) {
1433 reply->writeBool(result);
1434 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001435 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001436 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001437 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1438 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1439
1440 sp<IBinder> display = data.readStrongBinder();
1441 ui::PixelFormat format;
1442 ui::Dataspace dataspace;
1443 uint8_t component = 0;
1444 auto result =
1445 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1446 if (result == NO_ERROR) {
1447 reply->writeUint32(static_cast<uint32_t>(format));
1448 reply->writeUint32(static_cast<uint32_t>(dataspace));
1449 reply->writeUint32(static_cast<uint32_t>(component));
1450 }
1451 return result;
1452 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001453 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1454 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1455
1456 sp<IBinder> display = nullptr;
1457 bool enable = false;
1458 int8_t componentMask = 0;
1459 uint64_t maxFrames = 0;
1460 status_t result = data.readStrongBinder(&display);
1461 if (result != NO_ERROR) {
1462 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1463 result);
1464 return result;
1465 }
1466
1467 result = data.readBool(&enable);
1468 if (result != NO_ERROR) {
1469 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1470 return result;
1471 }
1472
1473 result = data.readByte(static_cast<int8_t*>(&componentMask));
1474 if (result != NO_ERROR) {
1475 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1476 result);
1477 return result;
1478 }
1479
1480 result = data.readUint64(&maxFrames);
1481 if (result != NO_ERROR) {
1482 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1483 return result;
1484 }
1485
1486 return setDisplayContentSamplingEnabled(display, enable,
1487 static_cast<uint8_t>(componentMask), maxFrames);
1488 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001489 case GET_DISPLAYED_CONTENT_SAMPLE: {
1490 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1491
1492 sp<IBinder> display = data.readStrongBinder();
1493 uint64_t maxFrames = 0;
1494 uint64_t timestamp = 0;
1495
1496 status_t result = data.readUint64(&maxFrames);
1497 if (result != NO_ERROR) {
1498 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1499 return result;
1500 }
1501
1502 result = data.readUint64(&timestamp);
1503 if (result != NO_ERROR) {
1504 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1505 return result;
1506 }
1507
1508 DisplayedFrameStats stats;
1509 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1510 if (result == NO_ERROR) {
1511 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001512 reply->writeUint64Vector(stats.component_0_sample);
1513 reply->writeUint64Vector(stats.component_1_sample);
1514 reply->writeUint64Vector(stats.component_2_sample);
1515 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001516 }
1517 return result;
1518 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001519 case GET_PROTECTED_CONTENT_SUPPORT: {
1520 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1521 bool result;
1522 status_t error = getProtectedContentSupport(&result);
1523 if (error == NO_ERROR) {
1524 reply->writeBool(result);
1525 }
1526 return error;
1527 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001528 case IS_WIDE_COLOR_DISPLAY: {
1529 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1530 sp<IBinder> display = nullptr;
1531 status_t error = data.readStrongBinder(&display);
1532 if (error != NO_ERROR) {
1533 return error;
1534 }
1535 bool result;
1536 error = isWideColorDisplay(display, &result);
1537 if (error == NO_ERROR) {
1538 reply->writeBool(result);
1539 }
1540 return error;
1541 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001542 case GET_PHYSICAL_DISPLAY_IDS: {
1543 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1544 return reply->writeUint64Vector(getPhysicalDisplayIds());
1545 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001546 case ADD_REGION_SAMPLING_LISTENER: {
1547 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1548 Rect samplingArea;
1549 status_t result = data.read(samplingArea);
1550 if (result != NO_ERROR) {
1551 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1552 return result;
1553 }
1554 sp<IBinder> stopLayerHandle;
1555 result = data.readNullableStrongBinder(&stopLayerHandle);
1556 if (result != NO_ERROR) {
1557 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1558 return result;
1559 }
1560 sp<IRegionSamplingListener> listener;
1561 result = data.readNullableStrongBinder(&listener);
1562 if (result != NO_ERROR) {
1563 ALOGE("addRegionSamplingListener: Failed to read listener");
1564 return result;
1565 }
1566 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1567 }
1568 case REMOVE_REGION_SAMPLING_LISTENER: {
1569 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1570 sp<IRegionSamplingListener> listener;
1571 status_t result = data.readNullableStrongBinder(&listener);
1572 if (result != NO_ERROR) {
1573 ALOGE("removeRegionSamplingListener: Failed to read listener");
1574 return result;
1575 }
1576 return removeRegionSamplingListener(listener);
1577 }
Ady Abraham838de062019-02-04 10:24:03 -08001578 case SET_ALLOWED_DISPLAY_CONFIGS: {
1579 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1580 sp<IBinder> displayToken = data.readStrongBinder();
1581 std::vector<int32_t> allowedConfigs;
1582 data.readInt32Vector(&allowedConfigs);
1583 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1584 reply->writeInt32(result);
1585 return result;
1586 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001587 case GET_ALLOWED_DISPLAY_CONFIGS: {
1588 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1589 sp<IBinder> displayToken = data.readStrongBinder();
1590 std::vector<int32_t> allowedConfigs;
1591 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1592 reply->writeInt32Vector(allowedConfigs);
1593 reply->writeInt32(result);
1594 return result;
1595 }
Ana Krulec0782b882019-10-15 17:34:54 -07001596 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1597 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1598 sp<IBinder> displayToken = data.readStrongBinder();
1599 int32_t defaultModeId;
1600 status_t result = data.readInt32(&defaultModeId);
1601 if (result != NO_ERROR) {
1602 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultModeId: %d", result);
1603 return result;
1604 }
1605 float minRefreshRate;
1606 result = data.readFloat(&minRefreshRate);
1607 if (result != NO_ERROR) {
1608 ALOGE("setDesiredDisplayConfigSpecs: failed to read minRefreshRate: %d", result);
1609 return result;
1610 }
1611 float maxRefreshRate;
1612 result = data.readFloat(&maxRefreshRate);
1613 if (result != NO_ERROR) {
1614 ALOGE("setDesiredDisplayConfigSpecs: failed to read maxRefreshRate: %d", result);
1615 return result;
1616 }
1617 result = setDesiredDisplayConfigSpecs(displayToken, defaultModeId, minRefreshRate,
1618 maxRefreshRate);
1619 if (result != NO_ERROR) {
1620 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1621 "%d",
1622 result);
1623 return result;
1624 }
1625 reply->writeInt32(result);
1626 return result;
1627 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001628 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1629 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1630 sp<IBinder> displayToken;
1631 status_t error = data.readNullableStrongBinder(&displayToken);
1632 if (error != NO_ERROR) {
1633 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1634 return error;
1635 }
1636 bool support = false;
1637 error = getDisplayBrightnessSupport(displayToken, &support);
1638 reply->writeBool(support);
1639 return error;
1640 }
1641 case SET_DISPLAY_BRIGHTNESS: {
1642 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1643 sp<IBinder> displayToken;
1644 status_t error = data.readNullableStrongBinder(&displayToken);
1645 if (error != NO_ERROR) {
1646 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1647 return error;
1648 }
1649 float brightness = -1.0f;
1650 error = data.readFloat(&brightness);
1651 if (error != NO_ERROR) {
1652 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1653 return error;
1654 }
1655 return setDisplayBrightness(displayToken, brightness);
1656 }
Ady Abraham8532d012019-05-08 14:50:56 -07001657 case NOTIFY_POWER_HINT: {
1658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1659 int32_t hintId;
1660 status_t error = data.readInt32(&hintId);
1661 if (error != NO_ERROR) {
1662 ALOGE("notifyPowerHint: failed to read hintId: %d", error);
1663 return error;
1664 }
1665 return notifyPowerHint(hintId);
1666 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001667 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001668 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001669 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001670 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001671}
1672
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001673} // namespace android