blob: dc161b722259312ac474ae0c9fbb92c86368b294 [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,
Marissa Wall947d34e2019-03-29 14:03:53 -070072 const client_cache_t& uncacheBuffer,
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);
Marissa Wall3dad52d2019-03-22 14:03:19 -070093
94 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
95 for (const auto& [listener, callbackIds] : listenerCallbacks) {
Valerie Hau5de3ad22019-08-20 07:47:43 -070096 data.writeStrongBinder(listener);
Marissa Wall3dad52d2019-03-22 14:03:19 -070097 data.writeInt64Vector(callbackIds);
98 }
99 }
100
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700101 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 }
103
104 virtual void bootFinished()
105 {
106 Parcel data, reply;
107 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
108 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
109 }
110
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000111 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Robert Carr108b2c72019-04-02 16:32:58 -0700112 bool& outCapturedSecureLayers, const ui::Dataspace reqDataspace,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700113 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
114 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -0800115 ISurfaceComposer::Rotation rotation, bool captureSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800116 Parcel data, reply;
117 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
118 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700119 data.writeInt32(static_cast<int32_t>(reqDataspace));
120 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700121 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800122 data.writeUint32(reqWidth);
123 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800124 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700125 data.writeInt32(static_cast<int32_t>(rotation));
Robert Carrfa8855f2019-02-19 10:05:00 -0800126 data.writeInt32(static_cast<int32_t>(captureSecureLayers));
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
128 if (result != NO_ERROR) {
129 ALOGE("captureScreen failed to transact: %d", result);
130 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000131 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700132 result = reply.readInt32();
133 if (result != NO_ERROR) {
134 ALOGE("captureScreen failed to readInt32: %d", result);
135 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000136 }
137
138 *outBuffer = new GraphicBuffer();
139 reply.read(**outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -0700140 outCapturedSecureLayers = reply.readBool();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700141
Ana Krulec2d41e422018-07-26 12:07:43 -0700142 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800143 }
144
chaviw93df2ea2019-04-30 16:45:12 -0700145 virtual status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
146 sp<GraphicBuffer>* outBuffer) {
147 Parcel data, reply;
148 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
149 data.writeUint64(displayOrLayerStack);
150 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN_BY_ID, data, &reply);
151 if (result != NO_ERROR) {
152 ALOGE("captureScreen failed to transact: %d", result);
153 return result;
154 }
155 result = reply.readInt32();
156 if (result != NO_ERROR) {
157 ALOGE("captureScreen failed to readInt32: %d", result);
158 return result;
159 }
160
161 *outDataspace = static_cast<ui::Dataspace>(reply.readInt32());
162 *outBuffer = new GraphicBuffer();
163 reply.read(**outBuffer);
164 return result;
165 }
166
Robert Carr866455f2019-04-02 16:28:26 -0700167 virtual status_t captureLayers(
168 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
169 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
170 const Rect& sourceCrop,
171 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
172 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700173 Parcel data, reply;
174 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
175 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700176 data.writeInt32(static_cast<int32_t>(reqDataspace));
177 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800178 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700179 data.writeInt32(excludeLayers.size());
180 for (auto el : excludeLayers) {
181 data.writeStrongBinder(el);
182 }
chaviw7206d492017-11-10 16:16:12 -0800183 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800184 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700185 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
186 if (result != NO_ERROR) {
187 ALOGE("captureLayers failed to transact: %d", result);
188 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000189 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700190 result = reply.readInt32();
191 if (result != NO_ERROR) {
192 ALOGE("captureLayers failed to readInt32: %d", result);
193 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000194 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700195
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000196 *outBuffer = new GraphicBuffer();
197 reply.read(**outBuffer);
198
Ana Krulec2d41e422018-07-26 12:07:43 -0700199 return result;
chaviwa76b2712017-09-20 12:02:26 -0700200 }
201
Jamie Gennis582270d2011-08-17 18:19:00 -0700202 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800203 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800204 {
205 Parcel data, reply;
206 int err = NO_ERROR;
207 err = data.writeInterfaceToken(
208 ISurfaceComposer::getInterfaceDescriptor());
209 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000210 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800211 "interface descriptor: %s (%d)", strerror(-err), -err);
212 return false;
213 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800214 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800215 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000216 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700217 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800218 return false;
219 }
220 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
221 &reply);
222 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000223 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700224 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800225 return false;
226 }
227 int32_t result = 0;
228 err = reply.readInt32(&result);
229 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000230 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700231 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800232 return false;
233 }
234 return result != 0;
235 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800236
Brian Anderson6b376712017-04-04 10:51:39 -0700237 virtual status_t getSupportedFrameTimestamps(
238 std::vector<FrameEvent>* outSupported) const {
239 if (!outSupported) {
240 return UNEXPECTED_NULL;
241 }
242 outSupported->clear();
243
244 Parcel data, reply;
245
246 status_t err = data.writeInterfaceToken(
247 ISurfaceComposer::getInterfaceDescriptor());
248 if (err != NO_ERROR) {
249 return err;
250 }
251
252 err = remote()->transact(
253 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
254 data, &reply);
255 if (err != NO_ERROR) {
256 return err;
257 }
258
259 int32_t result = 0;
260 err = reply.readInt32(&result);
261 if (err != NO_ERROR) {
262 return err;
263 }
264 if (result != NO_ERROR) {
265 return result;
266 }
267
268 std::vector<int32_t> supported;
269 err = reply.readInt32Vector(&supported);
270 if (err != NO_ERROR) {
271 return err;
272 }
273
274 outSupported->reserve(supported.size());
275 for (int32_t s : supported) {
276 outSupported->push_back(static_cast<FrameEvent>(s));
277 }
278 return NO_ERROR;
279 }
280
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700281 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
282 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800283 Parcel data, reply;
284 sp<IDisplayEventConnection> result;
285 int err = data.writeInterfaceToken(
286 ISurfaceComposer::getInterfaceDescriptor());
287 if (err != NO_ERROR) {
288 return result;
289 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700290 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700291 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800292 err = remote()->transact(
293 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
294 data, &reply);
295 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000296 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800297 "transaction: %s (%d)", strerror(-err), -err);
298 return result;
299 }
300 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
301 return result;
302 }
Colin Cross8e533062012-06-07 13:17:52 -0700303
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700304 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700305 {
306 Parcel data, reply;
307 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700308 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700309 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700310 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
311 return reply.readStrongBinder();
312 }
313
Jesse Hall6c913be2013-08-08 12:15:49 -0700314 virtual void destroyDisplay(const sp<IBinder>& display)
315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
318 data.writeStrongBinder(display);
319 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
320 }
321
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800322 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700323 Parcel data, reply;
324 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800325 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
326 NO_ERROR) {
327 std::vector<PhysicalDisplayId> displayIds;
328 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
329 return displayIds;
330 }
331 }
332
333 return {};
334 }
335
336 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
337 Parcel data, reply;
338 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
339 data.writeUint64(displayId);
340 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700341 return reply.readStrongBinder();
342 }
343
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700344 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700345 {
346 Parcel data, reply;
347 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700348 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700349 data.writeInt32(mode);
350 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700351 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700352
Dan Stoza7f7da322014-05-02 15:26:25 -0700353 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
354 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700355 {
356 Parcel data, reply;
357 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700358 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700359 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
360 status_t result = reply.readInt32();
361 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800362 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700363 configs->clear();
364 configs->resize(numConfigs);
365 for (size_t c = 0; c < numConfigs; ++c) {
366 memcpy(&(configs->editItemAt(c)),
367 reply.readInplace(sizeof(DisplayInfo)),
368 sizeof(DisplayInfo));
369 }
370 }
371 return result;
372 }
373
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700374 virtual status_t getDisplayStats(const sp<IBinder>& display,
375 DisplayStatInfo* stats)
376 {
377 Parcel data, reply;
378 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
379 data.writeStrongBinder(display);
380 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
381 status_t result = reply.readInt32();
382 if (result == NO_ERROR) {
383 memcpy(stats,
384 reply.readInplace(sizeof(DisplayStatInfo)),
385 sizeof(DisplayStatInfo));
386 }
387 return result;
388 }
389
Dan Stoza7f7da322014-05-02 15:26:25 -0700390 virtual int getActiveConfig(const sp<IBinder>& display)
391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
394 data.writeStrongBinder(display);
395 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
396 return reply.readInt32();
397 }
398
399 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
400 {
401 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700402 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
403 if (result != NO_ERROR) {
404 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
405 return result;
406 }
407 result = data.writeStrongBinder(display);
408 if (result != NO_ERROR) {
409 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
410 return result;
411 }
412 result = data.writeInt32(id);
413 if (result != NO_ERROR) {
414 ALOGE("setActiveConfig failed to writeInt32: %d", result);
415 return result;
416 }
417 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
418 if (result != NO_ERROR) {
419 ALOGE("setActiveConfig failed to transact: %d", result);
420 return result;
421 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700422 return reply.readInt32();
423 }
Svetoslavd85084b2014-03-20 10:28:31 -0700424
Michael Wright28f24d02016-07-12 13:30:53 -0700425 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700426 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700427 Parcel data, reply;
428 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
429 if (result != NO_ERROR) {
430 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
431 return result;
432 }
433 result = data.writeStrongBinder(display);
434 if (result != NO_ERROR) {
435 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
436 return result;
437 }
438 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
439 if (result != NO_ERROR) {
440 ALOGE("getDisplayColorModes failed to transact: %d", result);
441 return result;
442 }
443 result = static_cast<status_t>(reply.readInt32());
444 if (result == NO_ERROR) {
445 size_t numModes = reply.readUint32();
446 outColorModes->clear();
447 outColorModes->resize(numModes);
448 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700449 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700450 }
451 }
452 return result;
453 }
454
Daniel Solomon42d04562019-01-20 21:03:19 -0800455 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
456 ui::DisplayPrimaries& primaries) {
457 Parcel data, reply;
458 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
459 if (result != NO_ERROR) {
460 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
461 return result;
462 }
463 result = data.writeStrongBinder(display);
464 if (result != NO_ERROR) {
465 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
466 return result;
467 }
468 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
469 if (result != NO_ERROR) {
470 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
471 return result;
472 }
473 result = reply.readInt32();
474 if (result == NO_ERROR) {
475 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
476 sizeof(ui::DisplayPrimaries));
477 }
478 return result;
479 }
480
Peiyong Lina52f0292018-03-14 17:26:31 -0700481 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700482 Parcel data, reply;
483 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
484 if (result != NO_ERROR) {
485 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700486 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700487 }
488 result = data.writeStrongBinder(display);
489 if (result != NO_ERROR) {
490 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700491 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700492 }
493 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
494 if (result != NO_ERROR) {
495 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700496 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700497 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700498 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700499 }
500
501 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700502 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700503 Parcel data, reply;
504 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
505 if (result != NO_ERROR) {
506 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
507 return result;
508 }
509 result = data.writeStrongBinder(display);
510 if (result != NO_ERROR) {
511 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
512 return result;
513 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700514 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700515 if (result != NO_ERROR) {
516 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
517 return result;
518 }
519 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
520 if (result != NO_ERROR) {
521 ALOGE("setActiveColorMode failed to transact: %d", result);
522 return result;
523 }
524 return static_cast<status_t>(reply.readInt32());
525 }
526
Svetoslavd85084b2014-03-20 10:28:31 -0700527 virtual status_t clearAnimationFrameStats() {
528 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700529 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
530 if (result != NO_ERROR) {
531 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
532 return result;
533 }
534 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
535 if (result != NO_ERROR) {
536 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
537 return result;
538 }
Svetoslavd85084b2014-03-20 10:28:31 -0700539 return reply.readInt32();
540 }
541
542 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
543 Parcel data, reply;
544 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
545 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
546 reply.read(*outStats);
547 return reply.readInt32();
548 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700549
550 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
551 HdrCapabilities* outCapabilities) const {
552 Parcel data, reply;
553 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
554 status_t result = data.writeStrongBinder(display);
555 if (result != NO_ERROR) {
556 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
557 return result;
558 }
559 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
560 data, &reply);
561 if (result != NO_ERROR) {
562 ALOGE("getHdrCapabilities failed to transact: %d", result);
563 return result;
564 }
565 result = reply.readInt32();
566 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800567 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700568 }
569 return result;
570 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700571
572 virtual status_t enableVSyncInjections(bool enable) {
573 Parcel data, reply;
574 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
575 if (result != NO_ERROR) {
576 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
577 return result;
578 }
579 result = data.writeBool(enable);
580 if (result != NO_ERROR) {
581 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
582 return result;
583 }
Steven Moreland366eb422019-04-01 19:22:32 -0700584 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
585 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700586 if (result != NO_ERROR) {
587 ALOGE("enableVSyncInjections failed to transact: %d", result);
588 return result;
589 }
590 return result;
591 }
592
593 virtual status_t injectVSync(nsecs_t when) {
594 Parcel data, reply;
595 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
596 if (result != NO_ERROR) {
597 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
598 return result;
599 }
600 result = data.writeInt64(when);
601 if (result != NO_ERROR) {
602 ALOGE("injectVSync failed to writeInt64: %d", result);
603 return result;
604 }
Steven Moreland366eb422019-04-01 19:22:32 -0700605 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
606 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700607 if (result != NO_ERROR) {
608 ALOGE("injectVSync failed to transact: %d", result);
609 return result;
610 }
611 return result;
612 }
613
Kalle Raitaa099a242017-01-11 11:17:29 -0800614 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
615 {
616 if (!outLayers) {
617 return UNEXPECTED_NULL;
618 }
619
620 Parcel data, reply;
621
622 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
623 if (err != NO_ERROR) {
624 return err;
625 }
626
627 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
628 if (err != NO_ERROR) {
629 return err;
630 }
631
632 int32_t result = 0;
633 err = reply.readInt32(&result);
634 if (err != NO_ERROR) {
635 return err;
636 }
637 if (result != NO_ERROR) {
638 return result;
639 }
640
641 outLayers->clear();
642 return reply.readParcelableVector(outLayers);
643 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700644
Peiyong Linc6780972018-10-28 15:24:08 -0700645 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
646 ui::PixelFormat* defaultPixelFormat,
647 ui::Dataspace* wideColorGamutDataspace,
648 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700649 Parcel data, reply;
650 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
651 if (error != NO_ERROR) {
652 return error;
653 }
654 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
655 if (error != NO_ERROR) {
656 return error;
657 }
658 error = static_cast<status_t>(reply.readInt32());
659 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700660 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
661 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
662 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
663 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700664 }
665 return error;
666 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700667
Ady Abraham37965d42018-11-01 13:43:32 -0700668 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700669 Parcel data, reply;
670 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700671 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
672 bool result;
673 status_t err = reply.readBool(&result);
674 if (err == NO_ERROR) {
675 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700676 }
Ady Abraham37965d42018-11-01 13:43:32 -0700677 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700678 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700679
680 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
681 ui::PixelFormat* outFormat,
682 ui::Dataspace* outDataspace,
683 uint8_t* outComponentMask) const {
684 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
685 Parcel data, reply;
686 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
687 data.writeStrongBinder(display);
688
689 status_t error =
690 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
691 data, &reply);
692 if (error != NO_ERROR) {
693 return error;
694 }
695
696 uint32_t value = 0;
697 error = reply.readUint32(&value);
698 if (error != NO_ERROR) {
699 return error;
700 }
701 *outFormat = static_cast<ui::PixelFormat>(value);
702
703 error = reply.readUint32(&value);
704 if (error != NO_ERROR) {
705 return error;
706 }
707 *outDataspace = static_cast<ui::Dataspace>(value);
708
709 error = reply.readUint32(&value);
710 if (error != NO_ERROR) {
711 return error;
712 }
713 *outComponentMask = static_cast<uint8_t>(value);
714 return error;
715 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800716
717 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
718 uint8_t componentMask,
719 uint64_t maxFrames) const {
720 Parcel data, reply;
721 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
722 data.writeStrongBinder(display);
723 data.writeBool(enable);
724 data.writeByte(static_cast<int8_t>(componentMask));
725 data.writeUint64(maxFrames);
726 status_t result =
727 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
728 &reply);
729 return result;
730 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700731
732 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
733 uint64_t timestamp,
734 DisplayedFrameStats* outStats) const {
735 if (!outStats) return BAD_VALUE;
736
737 Parcel data, reply;
738 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
739 data.writeStrongBinder(display);
740 data.writeUint64(maxFrames);
741 data.writeUint64(timestamp);
742
743 status_t result =
744 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
745
746 if (result != NO_ERROR) {
747 return result;
748 }
749
750 result = reply.readUint64(&outStats->numFrames);
751 if (result != NO_ERROR) {
752 return result;
753 }
754
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800755 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700756 if (result != NO_ERROR) {
757 return result;
758 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800759 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700760 if (result != NO_ERROR) {
761 return result;
762 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800763 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700764 if (result != NO_ERROR) {
765 return result;
766 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800767 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700768 return result;
769 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800770
771 virtual status_t getProtectedContentSupport(bool* outSupported) const {
772 Parcel data, reply;
773 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800774 status_t error =
775 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
776 if (error != NO_ERROR) {
777 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800778 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800779 error = reply.readBool(outSupported);
780 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800781 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800782
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800783 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
784 bool* outIsWideColorDisplay) const {
785 Parcel data, reply;
786 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
787 if (error != NO_ERROR) {
788 return error;
789 }
790 error = data.writeStrongBinder(token);
791 if (error != NO_ERROR) {
792 return error;
793 }
794
795 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
796 if (error != NO_ERROR) {
797 return error;
798 }
799 error = reply.readBool(outIsWideColorDisplay);
800 return error;
801 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800802
803 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
804 const sp<IBinder>& stopLayerHandle,
805 const sp<IRegionSamplingListener>& listener) {
806 Parcel data, reply;
807 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
808 if (error != NO_ERROR) {
809 ALOGE("addRegionSamplingListener: Failed to write interface token");
810 return error;
811 }
812 error = data.write(samplingArea);
813 if (error != NO_ERROR) {
814 ALOGE("addRegionSamplingListener: Failed to write sampling area");
815 return error;
816 }
817 error = data.writeStrongBinder(stopLayerHandle);
818 if (error != NO_ERROR) {
819 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
820 return error;
821 }
822 error = data.writeStrongBinder(IInterface::asBinder(listener));
823 if (error != NO_ERROR) {
824 ALOGE("addRegionSamplingListener: Failed to write listener");
825 return error;
826 }
827 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
828 if (error != NO_ERROR) {
829 ALOGE("addRegionSamplingListener: Failed to transact");
830 }
831 return error;
832 }
833
834 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
835 Parcel data, reply;
836 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
837 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800838 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800839 return error;
840 }
841 error = data.writeStrongBinder(IInterface::asBinder(listener));
842 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800843 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800844 return error;
845 }
846 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
847 &reply);
848 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800849 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800850 }
851 return error;
852 }
Ady Abraham838de062019-02-04 10:24:03 -0800853
854 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
855 const std::vector<int32_t>& allowedConfigs) {
856 Parcel data, reply;
857 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
858 if (result != NO_ERROR) {
859 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
860 return result;
861 }
862 result = data.writeStrongBinder(displayToken);
863 if (result != NO_ERROR) {
864 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
865 return result;
866 }
867 result = data.writeInt32Vector(allowedConfigs);
868 if (result != NO_ERROR) {
869 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
870 return result;
871 }
872 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
873 if (result != NO_ERROR) {
874 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
875 return result;
876 }
877 return reply.readInt32();
878 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800879
880 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
881 std::vector<int32_t>* outAllowedConfigs) {
882 if (!outAllowedConfigs) return BAD_VALUE;
883 Parcel data, reply;
884 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
885 if (result != NO_ERROR) {
886 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
887 return result;
888 }
889 result = data.writeStrongBinder(displayToken);
890 if (result != NO_ERROR) {
891 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
892 return result;
893 }
894 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
895 if (result != NO_ERROR) {
896 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
897 return result;
898 }
899 result = reply.readInt32Vector(outAllowedConfigs);
900 if (result != NO_ERROR) {
901 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
902 return result;
903 }
904 return reply.readInt32();
905 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000906
907 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
908 bool* outSupport) const {
909 Parcel data, reply;
910 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
911 if (error != NO_ERROR) {
912 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
913 return error;
914 }
915 error = data.writeStrongBinder(displayToken);
916 if (error != NO_ERROR) {
917 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
918 return error;
919 }
920 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
921 if (error != NO_ERROR) {
922 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
923 return error;
924 }
925 bool support;
926 error = reply.readBool(&support);
927 if (error != NO_ERROR) {
928 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
929 return error;
930 }
931 *outSupport = support;
932 return NO_ERROR;
933 }
934
935 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
936 Parcel data, reply;
937 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
938 if (error != NO_ERROR) {
939 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
940 return error;
941 }
942 error = data.writeStrongBinder(displayToken);
943 if (error != NO_ERROR) {
944 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
945 return error;
946 }
947 error = data.writeFloat(brightness);
948 if (error != NO_ERROR) {
949 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
950 return error;
951 }
952 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
953 if (error != NO_ERROR) {
954 ALOGE("setDisplayBrightness: failed to transact: %d", error);
955 return error;
956 }
957 return NO_ERROR;
958 }
Ady Abraham8532d012019-05-08 14:50:56 -0700959
960 virtual status_t notifyPowerHint(int32_t hintId) {
961 Parcel data, reply;
962 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
963 if (error != NO_ERROR) {
964 ALOGE("notifyPowerHint: failed to write interface token: %d", error);
965 return error;
966 }
967 error = data.writeInt32(hintId);
968 if (error != NO_ERROR) {
969 ALOGE("notifyPowerHint: failed to write hintId: %d", error);
970 return error;
971 }
972 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_HINT, data, &reply,
973 IBinder::FLAG_ONEWAY);
974 if (error != NO_ERROR) {
975 ALOGE("notifyPowerHint: failed to transact: %d", error);
976 return error;
977 }
978 return NO_ERROR;
979 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800980};
981
Dan Stozad723bd72014-11-18 10:24:03 -0800982// Out-of-line virtual method definition to trigger vtable emission in this
983// translation unit (see clang warning -Wweak-vtables)
984BpSurfaceComposer::~BpSurfaceComposer() {}
985
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800986IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
987
988// ----------------------------------------------------------------------
989
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800990status_t BnSurfaceComposer::onTransact(
991 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
992{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800993 switch(code) {
994 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700995 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800996 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800997 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700998 return NO_ERROR;
999 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001000 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001001 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001002
1003 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001004 if (count > data.dataSize()) {
1005 return BAD_VALUE;
1006 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001007 Vector<ComposerState> state;
1008 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001009 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001010 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001011 if (s.read(data) == BAD_VALUE) {
1012 return BAD_VALUE;
1013 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001014 state.add(s);
1015 }
Dan Stozad723bd72014-11-18 10:24:03 -08001016
1017 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001018 if (count > data.dataSize()) {
1019 return BAD_VALUE;
1020 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001021 DisplayState d;
1022 Vector<DisplayState> displays;
1023 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001024 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001025 if (d.read(data) == BAD_VALUE) {
1026 return BAD_VALUE;
1027 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001028 displays.add(d);
1029 }
Dan Stozad723bd72014-11-18 10:24:03 -08001030
1031 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001032 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001033 InputWindowCommands inputWindowCommands;
1034 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001035
1036 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001037
Marissa Wall947d34e2019-03-29 14:03:53 -07001038 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001039 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001040 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001041
Marissa Wall3dad52d2019-03-22 14:03:19 -07001042 std::vector<ListenerCallbacks> listenerCallbacks;
1043 int32_t listenersSize = data.readInt32();
1044 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001045 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001046 std::vector<CallbackId> callbackIds;
1047 data.readInt64Vector(&callbackIds);
1048 listenerCallbacks.emplace_back(listener, callbackIds);
1049 }
1050
Marissa Wall17b4e452018-12-26 16:32:34 -08001051 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001052 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001053 return NO_ERROR;
1054 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001055 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001056 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001057 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001058 return NO_ERROR;
1059 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001060 case CAPTURE_SCREEN: {
1061 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1062 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001063 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1064 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001065 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001066 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001067 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001068 uint32_t reqWidth = data.readUint32();
1069 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001070 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001071 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001072 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001073
Robert Carr108b2c72019-04-02 16:32:58 -07001074 bool capturedSecureLayers = false;
1075 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1076 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1077 useIdentityTransform,
1078 static_cast<ISurfaceComposer::Rotation>(rotation),
1079 captureSecureLayers);
1080
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001081 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001082 if (res == NO_ERROR) {
1083 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001084 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001085 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001086 return NO_ERROR;
1087 }
chaviw93df2ea2019-04-30 16:45:12 -07001088 case CAPTURE_SCREEN_BY_ID: {
1089 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1090 uint64_t displayOrLayerStack = data.readUint64();
1091 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1092 sp<GraphicBuffer> outBuffer;
1093 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1094 reply->writeInt32(res);
1095 if (res == NO_ERROR) {
1096 reply->writeInt32(static_cast<int32_t>(outDataspace));
1097 reply->write(*outBuffer);
1098 }
1099 return NO_ERROR;
1100 }
chaviwa76b2712017-09-20 12:02:26 -07001101 case CAPTURE_LAYERS: {
1102 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1103 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001104 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1105 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001106 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001107 Rect sourceCrop(Rect::EMPTY_RECT);
1108 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001109
1110 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1111 int numExcludeHandles = data.readInt32();
1112 excludeHandles.reserve(numExcludeHandles);
1113 for (int i = 0; i < numExcludeHandles; i++) {
1114 excludeHandles.emplace(data.readStrongBinder());
1115 }
1116
chaviw7206d492017-11-10 16:16:12 -08001117 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001118 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001119
Robert Carr866455f2019-04-02 16:28:26 -07001120 status_t res =
1121 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1122 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001123 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001124 if (res == NO_ERROR) {
1125 reply->write(*outBuffer);
1126 }
chaviwa76b2712017-09-20 12:02:26 -07001127 return NO_ERROR;
1128 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001129 case AUTHENTICATE_SURFACE: {
1130 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001131 sp<IGraphicBufferProducer> bufferProducer =
1132 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1133 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001134 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001135 return NO_ERROR;
1136 }
Brian Anderson6b376712017-04-04 10:51:39 -07001137 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1138 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1139 std::vector<FrameEvent> supportedTimestamps;
1140 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1141 status_t err = reply->writeInt32(result);
1142 if (err != NO_ERROR) {
1143 return err;
1144 }
1145 if (result != NO_ERROR) {
1146 return result;
1147 }
1148
1149 std::vector<int32_t> supported;
1150 supported.reserve(supportedTimestamps.size());
1151 for (FrameEvent s : supportedTimestamps) {
1152 supported.push_back(static_cast<int32_t>(s));
1153 }
1154 return reply->writeInt32Vector(supported);
1155 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001156 case CREATE_DISPLAY_EVENT_CONNECTION: {
1157 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001158 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1159 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1160
1161 sp<IDisplayEventConnection> connection(
1162 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001163 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001164 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001165 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001166 case CREATE_DISPLAY: {
1167 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001168 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001169 bool secure = bool(data.readInt32());
1170 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001171 reply->writeStrongBinder(display);
1172 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001173 }
1174 case DESTROY_DISPLAY: {
1175 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1176 sp<IBinder> display = data.readStrongBinder();
1177 destroyDisplay(display);
1178 return NO_ERROR;
1179 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001180 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001181 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001182 PhysicalDisplayId displayId = data.readUint64();
1183 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001184 reply->writeStrongBinder(display);
1185 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001186 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001187 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001188 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001189 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001190 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001191 status_t result = getDisplayConfigs(display, &configs);
1192 reply->writeInt32(result);
1193 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001194 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001195 for (size_t c = 0; c < configs.size(); ++c) {
1196 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1197 &configs[c], sizeof(DisplayInfo));
1198 }
1199 }
1200 return NO_ERROR;
1201 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001202 case GET_DISPLAY_STATS: {
1203 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1204 DisplayStatInfo stats;
1205 sp<IBinder> display = data.readStrongBinder();
1206 status_t result = getDisplayStats(display, &stats);
1207 reply->writeInt32(result);
1208 if (result == NO_ERROR) {
1209 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1210 &stats, sizeof(DisplayStatInfo));
1211 }
1212 return NO_ERROR;
1213 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001214 case GET_ACTIVE_CONFIG: {
1215 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1216 sp<IBinder> display = data.readStrongBinder();
1217 int id = getActiveConfig(display);
1218 reply->writeInt32(id);
1219 return NO_ERROR;
1220 }
1221 case SET_ACTIVE_CONFIG: {
1222 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1223 sp<IBinder> display = data.readStrongBinder();
1224 int id = data.readInt32();
1225 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001226 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001227 return NO_ERROR;
1228 }
Michael Wright28f24d02016-07-12 13:30:53 -07001229 case GET_DISPLAY_COLOR_MODES: {
1230 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001231 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001232 sp<IBinder> display = nullptr;
1233 status_t result = data.readStrongBinder(&display);
1234 if (result != NO_ERROR) {
1235 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1236 return result;
1237 }
1238 result = getDisplayColorModes(display, &colorModes);
1239 reply->writeInt32(result);
1240 if (result == NO_ERROR) {
1241 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1242 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001243 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001244 }
1245 }
1246 return NO_ERROR;
1247 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001248 case GET_DISPLAY_NATIVE_PRIMARIES: {
1249 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1250 ui::DisplayPrimaries primaries;
1251 sp<IBinder> display = nullptr;
1252
1253 status_t result = data.readStrongBinder(&display);
1254 if (result != NO_ERROR) {
1255 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1256 return result;
1257 }
1258
1259 result = getDisplayNativePrimaries(display, primaries);
1260 reply->writeInt32(result);
1261 if (result == NO_ERROR) {
1262 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1263 sizeof(ui::DisplayPrimaries));
1264 }
1265
1266 return NO_ERROR;
1267 }
Michael Wright28f24d02016-07-12 13:30:53 -07001268 case GET_ACTIVE_COLOR_MODE: {
1269 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1270 sp<IBinder> display = nullptr;
1271 status_t result = data.readStrongBinder(&display);
1272 if (result != NO_ERROR) {
1273 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1274 return result;
1275 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001276 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001277 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1278 return result;
1279 }
1280 case SET_ACTIVE_COLOR_MODE: {
1281 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1282 sp<IBinder> display = nullptr;
1283 status_t result = data.readStrongBinder(&display);
1284 if (result != NO_ERROR) {
1285 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1286 return result;
1287 }
1288 int32_t colorModeInt = 0;
1289 result = data.readInt32(&colorModeInt);
1290 if (result != NO_ERROR) {
1291 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1292 return result;
1293 }
1294 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001295 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001296 result = reply->writeInt32(result);
1297 return result;
1298 }
Svetoslavd85084b2014-03-20 10:28:31 -07001299 case CLEAR_ANIMATION_FRAME_STATS: {
1300 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1301 status_t result = clearAnimationFrameStats();
1302 reply->writeInt32(result);
1303 return NO_ERROR;
1304 }
1305 case GET_ANIMATION_FRAME_STATS: {
1306 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1307 FrameStats stats;
1308 status_t result = getAnimationFrameStats(&stats);
1309 reply->write(stats);
1310 reply->writeInt32(result);
1311 return NO_ERROR;
1312 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001313 case SET_POWER_MODE: {
1314 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1315 sp<IBinder> display = data.readStrongBinder();
1316 int32_t mode = data.readInt32();
1317 setPowerMode(display, mode);
1318 return NO_ERROR;
1319 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001320 case GET_HDR_CAPABILITIES: {
1321 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1322 sp<IBinder> display = nullptr;
1323 status_t result = data.readStrongBinder(&display);
1324 if (result != NO_ERROR) {
1325 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1326 result);
1327 return result;
1328 }
1329 HdrCapabilities capabilities;
1330 result = getHdrCapabilities(display, &capabilities);
1331 reply->writeInt32(result);
1332 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001333 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001334 }
1335 return NO_ERROR;
1336 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001337 case ENABLE_VSYNC_INJECTIONS: {
1338 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1339 bool enable = false;
1340 status_t result = data.readBool(&enable);
1341 if (result != NO_ERROR) {
1342 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1343 return result;
1344 }
1345 return enableVSyncInjections(enable);
1346 }
1347 case INJECT_VSYNC: {
1348 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1349 int64_t when = 0;
1350 status_t result = data.readInt64(&when);
1351 if (result != NO_ERROR) {
1352 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1353 return result;
1354 }
1355 return injectVSync(when);
1356 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001357 case GET_LAYER_DEBUG_INFO: {
1358 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1359 std::vector<LayerDebugInfo> outLayers;
1360 status_t result = getLayerDebugInfo(&outLayers);
1361 reply->writeInt32(result);
1362 if (result == NO_ERROR)
1363 {
1364 result = reply->writeParcelableVector(outLayers);
1365 }
1366 return result;
1367 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001368 case GET_COMPOSITION_PREFERENCE: {
1369 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001370 ui::Dataspace defaultDataspace;
1371 ui::PixelFormat defaultPixelFormat;
1372 ui::Dataspace wideColorGamutDataspace;
1373 ui::PixelFormat wideColorGamutPixelFormat;
1374 status_t error =
1375 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1376 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001377 reply->writeInt32(error);
1378 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001379 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1380 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1381 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001382 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001383 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001384 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001385 }
Ady Abraham37965d42018-11-01 13:43:32 -07001386 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001387 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001388 bool result;
1389 status_t error = getColorManagement(&result);
1390 if (error == NO_ERROR) {
1391 reply->writeBool(result);
1392 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001393 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001394 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001395 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1396 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1397
1398 sp<IBinder> display = data.readStrongBinder();
1399 ui::PixelFormat format;
1400 ui::Dataspace dataspace;
1401 uint8_t component = 0;
1402 auto result =
1403 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1404 if (result == NO_ERROR) {
1405 reply->writeUint32(static_cast<uint32_t>(format));
1406 reply->writeUint32(static_cast<uint32_t>(dataspace));
1407 reply->writeUint32(static_cast<uint32_t>(component));
1408 }
1409 return result;
1410 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001411 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1412 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1413
1414 sp<IBinder> display = nullptr;
1415 bool enable = false;
1416 int8_t componentMask = 0;
1417 uint64_t maxFrames = 0;
1418 status_t result = data.readStrongBinder(&display);
1419 if (result != NO_ERROR) {
1420 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1421 result);
1422 return result;
1423 }
1424
1425 result = data.readBool(&enable);
1426 if (result != NO_ERROR) {
1427 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1428 return result;
1429 }
1430
1431 result = data.readByte(static_cast<int8_t*>(&componentMask));
1432 if (result != NO_ERROR) {
1433 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1434 result);
1435 return result;
1436 }
1437
1438 result = data.readUint64(&maxFrames);
1439 if (result != NO_ERROR) {
1440 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1441 return result;
1442 }
1443
1444 return setDisplayContentSamplingEnabled(display, enable,
1445 static_cast<uint8_t>(componentMask), maxFrames);
1446 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001447 case GET_DISPLAYED_CONTENT_SAMPLE: {
1448 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1449
1450 sp<IBinder> display = data.readStrongBinder();
1451 uint64_t maxFrames = 0;
1452 uint64_t timestamp = 0;
1453
1454 status_t result = data.readUint64(&maxFrames);
1455 if (result != NO_ERROR) {
1456 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1457 return result;
1458 }
1459
1460 result = data.readUint64(&timestamp);
1461 if (result != NO_ERROR) {
1462 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1463 return result;
1464 }
1465
1466 DisplayedFrameStats stats;
1467 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1468 if (result == NO_ERROR) {
1469 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001470 reply->writeUint64Vector(stats.component_0_sample);
1471 reply->writeUint64Vector(stats.component_1_sample);
1472 reply->writeUint64Vector(stats.component_2_sample);
1473 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001474 }
1475 return result;
1476 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001477 case GET_PROTECTED_CONTENT_SUPPORT: {
1478 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1479 bool result;
1480 status_t error = getProtectedContentSupport(&result);
1481 if (error == NO_ERROR) {
1482 reply->writeBool(result);
1483 }
1484 return error;
1485 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001486 case IS_WIDE_COLOR_DISPLAY: {
1487 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1488 sp<IBinder> display = nullptr;
1489 status_t error = data.readStrongBinder(&display);
1490 if (error != NO_ERROR) {
1491 return error;
1492 }
1493 bool result;
1494 error = isWideColorDisplay(display, &result);
1495 if (error == NO_ERROR) {
1496 reply->writeBool(result);
1497 }
1498 return error;
1499 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001500 case GET_PHYSICAL_DISPLAY_IDS: {
1501 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1502 return reply->writeUint64Vector(getPhysicalDisplayIds());
1503 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001504 case ADD_REGION_SAMPLING_LISTENER: {
1505 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1506 Rect samplingArea;
1507 status_t result = data.read(samplingArea);
1508 if (result != NO_ERROR) {
1509 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1510 return result;
1511 }
1512 sp<IBinder> stopLayerHandle;
1513 result = data.readNullableStrongBinder(&stopLayerHandle);
1514 if (result != NO_ERROR) {
1515 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1516 return result;
1517 }
1518 sp<IRegionSamplingListener> listener;
1519 result = data.readNullableStrongBinder(&listener);
1520 if (result != NO_ERROR) {
1521 ALOGE("addRegionSamplingListener: Failed to read listener");
1522 return result;
1523 }
1524 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1525 }
1526 case REMOVE_REGION_SAMPLING_LISTENER: {
1527 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1528 sp<IRegionSamplingListener> listener;
1529 status_t result = data.readNullableStrongBinder(&listener);
1530 if (result != NO_ERROR) {
1531 ALOGE("removeRegionSamplingListener: Failed to read listener");
1532 return result;
1533 }
1534 return removeRegionSamplingListener(listener);
1535 }
Ady Abraham838de062019-02-04 10:24:03 -08001536 case SET_ALLOWED_DISPLAY_CONFIGS: {
1537 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1538 sp<IBinder> displayToken = data.readStrongBinder();
1539 std::vector<int32_t> allowedConfigs;
1540 data.readInt32Vector(&allowedConfigs);
1541 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1542 reply->writeInt32(result);
1543 return result;
1544 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001545 case GET_ALLOWED_DISPLAY_CONFIGS: {
1546 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1547 sp<IBinder> displayToken = data.readStrongBinder();
1548 std::vector<int32_t> allowedConfigs;
1549 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1550 reply->writeInt32Vector(allowedConfigs);
1551 reply->writeInt32(result);
1552 return result;
1553 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001554 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1555 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1556 sp<IBinder> displayToken;
1557 status_t error = data.readNullableStrongBinder(&displayToken);
1558 if (error != NO_ERROR) {
1559 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1560 return error;
1561 }
1562 bool support = false;
1563 error = getDisplayBrightnessSupport(displayToken, &support);
1564 reply->writeBool(support);
1565 return error;
1566 }
1567 case SET_DISPLAY_BRIGHTNESS: {
1568 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1569 sp<IBinder> displayToken;
1570 status_t error = data.readNullableStrongBinder(&displayToken);
1571 if (error != NO_ERROR) {
1572 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1573 return error;
1574 }
1575 float brightness = -1.0f;
1576 error = data.readFloat(&brightness);
1577 if (error != NO_ERROR) {
1578 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1579 return error;
1580 }
1581 return setDisplayBrightness(displayToken, brightness);
1582 }
Ady Abraham8532d012019-05-08 14:50:56 -07001583 case NOTIFY_POWER_HINT: {
1584 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1585 int32_t hintId;
1586 status_t error = data.readInt32(&hintId);
1587 if (error != NO_ERROR) {
1588 ALOGE("notifyPowerHint: failed to read hintId: %d", error);
1589 return error;
1590 }
1591 return notifyPowerHint(hintId);
1592 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001593 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001594 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001595 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001596 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001597}
1598
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001599} // namespace android