blob: 8d7baf34aed6c77bd818a8a852618f3a61a09c9c [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 Wall3dad52d2019-03-22 14:03:19 -070072 const cached_buffer_t& uncacheBuffer,
73 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);
Marissa Wall78b72202019-03-15 14:58:34 -070091 data.writeStrongBinder(uncacheBuffer.token);
92 data.writeUint64(uncacheBuffer.cacheId);
Marissa Wall3dad52d2019-03-22 14:03:19 -070093
94 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
95 for (const auto& [listener, callbackIds] : listenerCallbacks) {
96 data.writeStrongBinder(IInterface::asBinder(listener));
97 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,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700112 const ui::Dataspace reqDataspace,
113 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);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700140
Ana Krulec2d41e422018-07-26 12:07:43 -0700141 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800142 }
143
Robert Carr866455f2019-04-02 16:28:26 -0700144 virtual status_t captureLayers(
145 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
146 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
147 const Rect& sourceCrop,
148 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
149 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700150 Parcel data, reply;
151 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
152 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700153 data.writeInt32(static_cast<int32_t>(reqDataspace));
154 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800155 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700156 data.writeInt32(excludeLayers.size());
157 for (auto el : excludeLayers) {
158 data.writeStrongBinder(el);
159 }
chaviw7206d492017-11-10 16:16:12 -0800160 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800161 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700162 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
163 if (result != NO_ERROR) {
164 ALOGE("captureLayers failed to transact: %d", result);
165 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000166 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700167 result = reply.readInt32();
168 if (result != NO_ERROR) {
169 ALOGE("captureLayers failed to readInt32: %d", result);
170 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000171 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700172
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000173 *outBuffer = new GraphicBuffer();
174 reply.read(**outBuffer);
175
Ana Krulec2d41e422018-07-26 12:07:43 -0700176 return result;
chaviwa76b2712017-09-20 12:02:26 -0700177 }
178
Jamie Gennis582270d2011-08-17 18:19:00 -0700179 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800180 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800181 {
182 Parcel data, reply;
183 int err = NO_ERROR;
184 err = data.writeInterfaceToken(
185 ISurfaceComposer::getInterfaceDescriptor());
186 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000187 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800188 "interface descriptor: %s (%d)", strerror(-err), -err);
189 return false;
190 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800191 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800192 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000193 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700194 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800195 return false;
196 }
197 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
198 &reply);
199 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000200 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700201 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800202 return false;
203 }
204 int32_t result = 0;
205 err = reply.readInt32(&result);
206 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000207 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700208 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800209 return false;
210 }
211 return result != 0;
212 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800213
Brian Anderson6b376712017-04-04 10:51:39 -0700214 virtual status_t getSupportedFrameTimestamps(
215 std::vector<FrameEvent>* outSupported) const {
216 if (!outSupported) {
217 return UNEXPECTED_NULL;
218 }
219 outSupported->clear();
220
221 Parcel data, reply;
222
223 status_t err = data.writeInterfaceToken(
224 ISurfaceComposer::getInterfaceDescriptor());
225 if (err != NO_ERROR) {
226 return err;
227 }
228
229 err = remote()->transact(
230 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
231 data, &reply);
232 if (err != NO_ERROR) {
233 return err;
234 }
235
236 int32_t result = 0;
237 err = reply.readInt32(&result);
238 if (err != NO_ERROR) {
239 return err;
240 }
241 if (result != NO_ERROR) {
242 return result;
243 }
244
245 std::vector<int32_t> supported;
246 err = reply.readInt32Vector(&supported);
247 if (err != NO_ERROR) {
248 return err;
249 }
250
251 outSupported->reserve(supported.size());
252 for (int32_t s : supported) {
253 outSupported->push_back(static_cast<FrameEvent>(s));
254 }
255 return NO_ERROR;
256 }
257
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700258 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800259 {
260 Parcel data, reply;
261 sp<IDisplayEventConnection> result;
262 int err = data.writeInterfaceToken(
263 ISurfaceComposer::getInterfaceDescriptor());
264 if (err != NO_ERROR) {
265 return result;
266 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700267 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800268 err = remote()->transact(
269 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
270 data, &reply);
271 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000272 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800273 "transaction: %s (%d)", strerror(-err), -err);
274 return result;
275 }
276 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
277 return result;
278 }
Colin Cross8e533062012-06-07 13:17:52 -0700279
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700280 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700284 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700285 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700286 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
287 return reply.readStrongBinder();
288 }
289
Jesse Hall6c913be2013-08-08 12:15:49 -0700290 virtual void destroyDisplay(const sp<IBinder>& display)
291 {
292 Parcel data, reply;
293 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
294 data.writeStrongBinder(display);
295 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
296 }
297
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800298 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700299 Parcel data, reply;
300 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800301 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
302 NO_ERROR) {
303 std::vector<PhysicalDisplayId> displayIds;
304 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
305 return displayIds;
306 }
307 }
308
309 return {};
310 }
311
312 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
313 Parcel data, reply;
314 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
315 data.writeUint64(displayId);
316 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700317 return reply.readStrongBinder();
318 }
319
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700320 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700324 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700325 data.writeInt32(mode);
326 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700327 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700328
Dan Stoza7f7da322014-05-02 15:26:25 -0700329 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
330 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700331 {
332 Parcel data, reply;
333 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700334 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700335 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
336 status_t result = reply.readInt32();
337 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800338 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700339 configs->clear();
340 configs->resize(numConfigs);
341 for (size_t c = 0; c < numConfigs; ++c) {
342 memcpy(&(configs->editItemAt(c)),
343 reply.readInplace(sizeof(DisplayInfo)),
344 sizeof(DisplayInfo));
345 }
346 }
347 return result;
348 }
349
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700350 virtual status_t getDisplayStats(const sp<IBinder>& display,
351 DisplayStatInfo* stats)
352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
355 data.writeStrongBinder(display);
356 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
357 status_t result = reply.readInt32();
358 if (result == NO_ERROR) {
359 memcpy(stats,
360 reply.readInplace(sizeof(DisplayStatInfo)),
361 sizeof(DisplayStatInfo));
362 }
363 return result;
364 }
365
Dan Stoza7f7da322014-05-02 15:26:25 -0700366 virtual int getActiveConfig(const sp<IBinder>& display)
367 {
368 Parcel data, reply;
369 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
370 data.writeStrongBinder(display);
371 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
372 return reply.readInt32();
373 }
374
375 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
376 {
377 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700378 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
379 if (result != NO_ERROR) {
380 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
381 return result;
382 }
383 result = data.writeStrongBinder(display);
384 if (result != NO_ERROR) {
385 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
386 return result;
387 }
388 result = data.writeInt32(id);
389 if (result != NO_ERROR) {
390 ALOGE("setActiveConfig failed to writeInt32: %d", result);
391 return result;
392 }
393 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
394 if (result != NO_ERROR) {
395 ALOGE("setActiveConfig failed to transact: %d", result);
396 return result;
397 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700398 return reply.readInt32();
399 }
Svetoslavd85084b2014-03-20 10:28:31 -0700400
Michael Wright28f24d02016-07-12 13:30:53 -0700401 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700402 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700403 Parcel data, reply;
404 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
405 if (result != NO_ERROR) {
406 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
407 return result;
408 }
409 result = data.writeStrongBinder(display);
410 if (result != NO_ERROR) {
411 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
412 return result;
413 }
414 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
415 if (result != NO_ERROR) {
416 ALOGE("getDisplayColorModes failed to transact: %d", result);
417 return result;
418 }
419 result = static_cast<status_t>(reply.readInt32());
420 if (result == NO_ERROR) {
421 size_t numModes = reply.readUint32();
422 outColorModes->clear();
423 outColorModes->resize(numModes);
424 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700425 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700426 }
427 }
428 return result;
429 }
430
Daniel Solomon42d04562019-01-20 21:03:19 -0800431 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
432 ui::DisplayPrimaries& primaries) {
433 Parcel data, reply;
434 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
435 if (result != NO_ERROR) {
436 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
437 return result;
438 }
439 result = data.writeStrongBinder(display);
440 if (result != NO_ERROR) {
441 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
442 return result;
443 }
444 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
445 if (result != NO_ERROR) {
446 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
447 return result;
448 }
449 result = reply.readInt32();
450 if (result == NO_ERROR) {
451 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
452 sizeof(ui::DisplayPrimaries));
453 }
454 return result;
455 }
456
Peiyong Lina52f0292018-03-14 17:26:31 -0700457 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700458 Parcel data, reply;
459 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
460 if (result != NO_ERROR) {
461 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700462 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700463 }
464 result = data.writeStrongBinder(display);
465 if (result != NO_ERROR) {
466 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700467 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700468 }
469 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
470 if (result != NO_ERROR) {
471 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700472 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700473 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700474 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700475 }
476
477 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700478 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700479 Parcel data, reply;
480 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
481 if (result != NO_ERROR) {
482 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
483 return result;
484 }
485 result = data.writeStrongBinder(display);
486 if (result != NO_ERROR) {
487 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
488 return result;
489 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700490 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700491 if (result != NO_ERROR) {
492 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
493 return result;
494 }
495 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
496 if (result != NO_ERROR) {
497 ALOGE("setActiveColorMode failed to transact: %d", result);
498 return result;
499 }
500 return static_cast<status_t>(reply.readInt32());
501 }
502
Svetoslavd85084b2014-03-20 10:28:31 -0700503 virtual status_t clearAnimationFrameStats() {
504 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700505 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
506 if (result != NO_ERROR) {
507 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
508 return result;
509 }
510 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
511 if (result != NO_ERROR) {
512 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
513 return result;
514 }
Svetoslavd85084b2014-03-20 10:28:31 -0700515 return reply.readInt32();
516 }
517
518 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
519 Parcel data, reply;
520 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
521 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
522 reply.read(*outStats);
523 return reply.readInt32();
524 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700525
526 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
527 HdrCapabilities* outCapabilities) const {
528 Parcel data, reply;
529 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
530 status_t result = data.writeStrongBinder(display);
531 if (result != NO_ERROR) {
532 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
533 return result;
534 }
535 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
536 data, &reply);
537 if (result != NO_ERROR) {
538 ALOGE("getHdrCapabilities failed to transact: %d", result);
539 return result;
540 }
541 result = reply.readInt32();
542 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800543 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700544 }
545 return result;
546 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700547
548 virtual status_t enableVSyncInjections(bool enable) {
549 Parcel data, reply;
550 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
551 if (result != NO_ERROR) {
552 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
553 return result;
554 }
555 result = data.writeBool(enable);
556 if (result != NO_ERROR) {
557 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
558 return result;
559 }
Steven Moreland366eb422019-04-01 19:22:32 -0700560 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
561 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700562 if (result != NO_ERROR) {
563 ALOGE("enableVSyncInjections failed to transact: %d", result);
564 return result;
565 }
566 return result;
567 }
568
569 virtual status_t injectVSync(nsecs_t when) {
570 Parcel data, reply;
571 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
572 if (result != NO_ERROR) {
573 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
574 return result;
575 }
576 result = data.writeInt64(when);
577 if (result != NO_ERROR) {
578 ALOGE("injectVSync failed to writeInt64: %d", result);
579 return result;
580 }
Steven Moreland366eb422019-04-01 19:22:32 -0700581 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
582 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700583 if (result != NO_ERROR) {
584 ALOGE("injectVSync failed to transact: %d", result);
585 return result;
586 }
587 return result;
588 }
589
Kalle Raitaa099a242017-01-11 11:17:29 -0800590 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
591 {
592 if (!outLayers) {
593 return UNEXPECTED_NULL;
594 }
595
596 Parcel data, reply;
597
598 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
599 if (err != NO_ERROR) {
600 return err;
601 }
602
603 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
604 if (err != NO_ERROR) {
605 return err;
606 }
607
608 int32_t result = 0;
609 err = reply.readInt32(&result);
610 if (err != NO_ERROR) {
611 return err;
612 }
613 if (result != NO_ERROR) {
614 return result;
615 }
616
617 outLayers->clear();
618 return reply.readParcelableVector(outLayers);
619 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700620
Peiyong Linc6780972018-10-28 15:24:08 -0700621 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
622 ui::PixelFormat* defaultPixelFormat,
623 ui::Dataspace* wideColorGamutDataspace,
624 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700625 Parcel data, reply;
626 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
627 if (error != NO_ERROR) {
628 return error;
629 }
630 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
631 if (error != NO_ERROR) {
632 return error;
633 }
634 error = static_cast<status_t>(reply.readInt32());
635 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700636 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
637 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
638 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
639 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700640 }
641 return error;
642 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700643
Ady Abraham37965d42018-11-01 13:43:32 -0700644 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700645 Parcel data, reply;
646 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700647 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
648 bool result;
649 status_t err = reply.readBool(&result);
650 if (err == NO_ERROR) {
651 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700652 }
Ady Abraham37965d42018-11-01 13:43:32 -0700653 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700654 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700655
656 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
657 ui::PixelFormat* outFormat,
658 ui::Dataspace* outDataspace,
659 uint8_t* outComponentMask) const {
660 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
661 Parcel data, reply;
662 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
663 data.writeStrongBinder(display);
664
665 status_t error =
666 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
667 data, &reply);
668 if (error != NO_ERROR) {
669 return error;
670 }
671
672 uint32_t value = 0;
673 error = reply.readUint32(&value);
674 if (error != NO_ERROR) {
675 return error;
676 }
677 *outFormat = static_cast<ui::PixelFormat>(value);
678
679 error = reply.readUint32(&value);
680 if (error != NO_ERROR) {
681 return error;
682 }
683 *outDataspace = static_cast<ui::Dataspace>(value);
684
685 error = reply.readUint32(&value);
686 if (error != NO_ERROR) {
687 return error;
688 }
689 *outComponentMask = static_cast<uint8_t>(value);
690 return error;
691 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800692
693 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
694 uint8_t componentMask,
695 uint64_t maxFrames) const {
696 Parcel data, reply;
697 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
698 data.writeStrongBinder(display);
699 data.writeBool(enable);
700 data.writeByte(static_cast<int8_t>(componentMask));
701 data.writeUint64(maxFrames);
702 status_t result =
703 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
704 &reply);
705 return result;
706 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700707
708 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
709 uint64_t timestamp,
710 DisplayedFrameStats* outStats) const {
711 if (!outStats) return BAD_VALUE;
712
713 Parcel data, reply;
714 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
715 data.writeStrongBinder(display);
716 data.writeUint64(maxFrames);
717 data.writeUint64(timestamp);
718
719 status_t result =
720 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
721
722 if (result != NO_ERROR) {
723 return result;
724 }
725
726 result = reply.readUint64(&outStats->numFrames);
727 if (result != NO_ERROR) {
728 return result;
729 }
730
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800731 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700732 if (result != NO_ERROR) {
733 return result;
734 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800735 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700736 if (result != NO_ERROR) {
737 return result;
738 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800739 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700740 if (result != NO_ERROR) {
741 return result;
742 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800743 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700744 return result;
745 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800746
747 virtual status_t getProtectedContentSupport(bool* outSupported) const {
748 Parcel data, reply;
749 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800750 status_t error =
751 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
752 if (error != NO_ERROR) {
753 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800754 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800755 error = reply.readBool(outSupported);
756 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800757 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800758
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800759 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
760 bool* outIsWideColorDisplay) const {
761 Parcel data, reply;
762 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
763 if (error != NO_ERROR) {
764 return error;
765 }
766 error = data.writeStrongBinder(token);
767 if (error != NO_ERROR) {
768 return error;
769 }
770
771 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
772 if (error != NO_ERROR) {
773 return error;
774 }
775 error = reply.readBool(outIsWideColorDisplay);
776 return error;
777 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800778
779 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
780 const sp<IBinder>& stopLayerHandle,
781 const sp<IRegionSamplingListener>& listener) {
782 Parcel data, reply;
783 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
784 if (error != NO_ERROR) {
785 ALOGE("addRegionSamplingListener: Failed to write interface token");
786 return error;
787 }
788 error = data.write(samplingArea);
789 if (error != NO_ERROR) {
790 ALOGE("addRegionSamplingListener: Failed to write sampling area");
791 return error;
792 }
793 error = data.writeStrongBinder(stopLayerHandle);
794 if (error != NO_ERROR) {
795 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
796 return error;
797 }
798 error = data.writeStrongBinder(IInterface::asBinder(listener));
799 if (error != NO_ERROR) {
800 ALOGE("addRegionSamplingListener: Failed to write listener");
801 return error;
802 }
803 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
804 if (error != NO_ERROR) {
805 ALOGE("addRegionSamplingListener: Failed to transact");
806 }
807 return error;
808 }
809
810 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
811 Parcel data, reply;
812 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
813 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800814 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800815 return error;
816 }
817 error = data.writeStrongBinder(IInterface::asBinder(listener));
818 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800819 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800820 return error;
821 }
822 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
823 &reply);
824 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800825 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800826 }
827 return error;
828 }
Ady Abraham838de062019-02-04 10:24:03 -0800829
830 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
831 const std::vector<int32_t>& allowedConfigs) {
832 Parcel data, reply;
833 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
834 if (result != NO_ERROR) {
835 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
836 return result;
837 }
838 result = data.writeStrongBinder(displayToken);
839 if (result != NO_ERROR) {
840 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
841 return result;
842 }
843 result = data.writeInt32Vector(allowedConfigs);
844 if (result != NO_ERROR) {
845 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
846 return result;
847 }
848 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
849 if (result != NO_ERROR) {
850 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
851 return result;
852 }
853 return reply.readInt32();
854 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800855
856 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
857 std::vector<int32_t>* outAllowedConfigs) {
858 if (!outAllowedConfigs) return BAD_VALUE;
859 Parcel data, reply;
860 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
861 if (result != NO_ERROR) {
862 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
863 return result;
864 }
865 result = data.writeStrongBinder(displayToken);
866 if (result != NO_ERROR) {
867 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
868 return result;
869 }
870 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
871 if (result != NO_ERROR) {
872 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
873 return result;
874 }
875 result = reply.readInt32Vector(outAllowedConfigs);
876 if (result != NO_ERROR) {
877 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
878 return result;
879 }
880 return reply.readInt32();
881 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000882
883 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
884 bool* outSupport) const {
885 Parcel data, reply;
886 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
887 if (error != NO_ERROR) {
888 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
889 return error;
890 }
891 error = data.writeStrongBinder(displayToken);
892 if (error != NO_ERROR) {
893 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
894 return error;
895 }
896 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
897 if (error != NO_ERROR) {
898 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
899 return error;
900 }
901 bool support;
902 error = reply.readBool(&support);
903 if (error != NO_ERROR) {
904 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
905 return error;
906 }
907 *outSupport = support;
908 return NO_ERROR;
909 }
910
911 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
912 Parcel data, reply;
913 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
914 if (error != NO_ERROR) {
915 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
916 return error;
917 }
918 error = data.writeStrongBinder(displayToken);
919 if (error != NO_ERROR) {
920 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
921 return error;
922 }
923 error = data.writeFloat(brightness);
924 if (error != NO_ERROR) {
925 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
926 return error;
927 }
928 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
929 if (error != NO_ERROR) {
930 ALOGE("setDisplayBrightness: failed to transact: %d", error);
931 return error;
932 }
933 return NO_ERROR;
934 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800935};
936
Dan Stozad723bd72014-11-18 10:24:03 -0800937// Out-of-line virtual method definition to trigger vtable emission in this
938// translation unit (see clang warning -Wweak-vtables)
939BpSurfaceComposer::~BpSurfaceComposer() {}
940
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800941IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
942
943// ----------------------------------------------------------------------
944
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800945status_t BnSurfaceComposer::onTransact(
946 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
947{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800948 switch(code) {
949 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700950 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800951 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800952 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700953 return NO_ERROR;
954 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700955 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700956 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800957
958 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700959 if (count > data.dataSize()) {
960 return BAD_VALUE;
961 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700962 Vector<ComposerState> state;
963 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800964 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700965 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700966 if (s.read(data) == BAD_VALUE) {
967 return BAD_VALUE;
968 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700969 state.add(s);
970 }
Dan Stozad723bd72014-11-18 10:24:03 -0800971
972 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700973 if (count > data.dataSize()) {
974 return BAD_VALUE;
975 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700976 DisplayState d;
977 Vector<DisplayState> displays;
978 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800979 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700980 if (d.read(data) == BAD_VALUE) {
981 return BAD_VALUE;
982 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700983 displays.add(d);
984 }
Dan Stozad723bd72014-11-18 10:24:03 -0800985
986 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700987 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800988 InputWindowCommands inputWindowCommands;
989 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800990
991 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -0700992
993 cached_buffer_t uncachedBuffer;
994 uncachedBuffer.token = data.readStrongBinder();
995 uncachedBuffer.cacheId = data.readUint64();
996
Marissa Wall3dad52d2019-03-22 14:03:19 -0700997 std::vector<ListenerCallbacks> listenerCallbacks;
998 int32_t listenersSize = data.readInt32();
999 for (int32_t i = 0; i < listenersSize; i++) {
1000 auto listener =
1001 interface_cast<ITransactionCompletedListener>(data.readStrongBinder());
1002 std::vector<CallbackId> callbackIds;
1003 data.readInt64Vector(&callbackIds);
1004 listenerCallbacks.emplace_back(listener, callbackIds);
1005 }
1006
Marissa Wall17b4e452018-12-26 16:32:34 -08001007 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001008 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001009 return NO_ERROR;
1010 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001011 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001012 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001013 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001014 return NO_ERROR;
1015 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001016 case CAPTURE_SCREEN: {
1017 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1018 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001019 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1020 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001021 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001022 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001023 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001024 uint32_t reqWidth = data.readUint32();
1025 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001026 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001027 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001028 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001029
Peiyong Lin0e003c92018-09-17 11:09:51 -07001030 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
1031 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -08001032 static_cast<ISurfaceComposer::Rotation>(rotation), captureSecureLayers);
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001033 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001034 if (res == NO_ERROR) {
1035 reply->write(*outBuffer);
1036 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001037 return NO_ERROR;
1038 }
chaviwa76b2712017-09-20 12:02:26 -07001039 case CAPTURE_LAYERS: {
1040 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1041 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001042 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1043 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001044 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001045 Rect sourceCrop(Rect::EMPTY_RECT);
1046 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001047
1048 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1049 int numExcludeHandles = data.readInt32();
1050 excludeHandles.reserve(numExcludeHandles);
1051 for (int i = 0; i < numExcludeHandles; i++) {
1052 excludeHandles.emplace(data.readStrongBinder());
1053 }
1054
chaviw7206d492017-11-10 16:16:12 -08001055 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001056 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001057
Robert Carr866455f2019-04-02 16:28:26 -07001058 status_t res =
1059 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1060 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001061 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001062 if (res == NO_ERROR) {
1063 reply->write(*outBuffer);
1064 }
chaviwa76b2712017-09-20 12:02:26 -07001065 return NO_ERROR;
1066 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001067 case AUTHENTICATE_SURFACE: {
1068 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001069 sp<IGraphicBufferProducer> bufferProducer =
1070 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1071 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001072 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001073 return NO_ERROR;
1074 }
Brian Anderson6b376712017-04-04 10:51:39 -07001075 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1076 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1077 std::vector<FrameEvent> supportedTimestamps;
1078 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1079 status_t err = reply->writeInt32(result);
1080 if (err != NO_ERROR) {
1081 return err;
1082 }
1083 if (result != NO_ERROR) {
1084 return result;
1085 }
1086
1087 std::vector<int32_t> supported;
1088 supported.reserve(supportedTimestamps.size());
1089 for (FrameEvent s : supportedTimestamps) {
1090 supported.push_back(static_cast<int32_t>(s));
1091 }
1092 return reply->writeInt32Vector(supported);
1093 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001094 case CREATE_DISPLAY_EVENT_CONNECTION: {
1095 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001096 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1097 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001098 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001099 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001100 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001101 case CREATE_DISPLAY: {
1102 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001103 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001104 bool secure = bool(data.readInt32());
1105 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001106 reply->writeStrongBinder(display);
1107 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001108 }
1109 case DESTROY_DISPLAY: {
1110 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1111 sp<IBinder> display = data.readStrongBinder();
1112 destroyDisplay(display);
1113 return NO_ERROR;
1114 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001115 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001116 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001117 PhysicalDisplayId displayId = data.readUint64();
1118 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001119 reply->writeStrongBinder(display);
1120 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001121 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001122 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001123 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001124 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001125 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001126 status_t result = getDisplayConfigs(display, &configs);
1127 reply->writeInt32(result);
1128 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001129 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001130 for (size_t c = 0; c < configs.size(); ++c) {
1131 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1132 &configs[c], sizeof(DisplayInfo));
1133 }
1134 }
1135 return NO_ERROR;
1136 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001137 case GET_DISPLAY_STATS: {
1138 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1139 DisplayStatInfo stats;
1140 sp<IBinder> display = data.readStrongBinder();
1141 status_t result = getDisplayStats(display, &stats);
1142 reply->writeInt32(result);
1143 if (result == NO_ERROR) {
1144 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1145 &stats, sizeof(DisplayStatInfo));
1146 }
1147 return NO_ERROR;
1148 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001149 case GET_ACTIVE_CONFIG: {
1150 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1151 sp<IBinder> display = data.readStrongBinder();
1152 int id = getActiveConfig(display);
1153 reply->writeInt32(id);
1154 return NO_ERROR;
1155 }
1156 case SET_ACTIVE_CONFIG: {
1157 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1158 sp<IBinder> display = data.readStrongBinder();
1159 int id = data.readInt32();
1160 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001161 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001162 return NO_ERROR;
1163 }
Michael Wright28f24d02016-07-12 13:30:53 -07001164 case GET_DISPLAY_COLOR_MODES: {
1165 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001166 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001167 sp<IBinder> display = nullptr;
1168 status_t result = data.readStrongBinder(&display);
1169 if (result != NO_ERROR) {
1170 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1171 return result;
1172 }
1173 result = getDisplayColorModes(display, &colorModes);
1174 reply->writeInt32(result);
1175 if (result == NO_ERROR) {
1176 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1177 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001178 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001179 }
1180 }
1181 return NO_ERROR;
1182 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001183 case GET_DISPLAY_NATIVE_PRIMARIES: {
1184 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1185 ui::DisplayPrimaries primaries;
1186 sp<IBinder> display = nullptr;
1187
1188 status_t result = data.readStrongBinder(&display);
1189 if (result != NO_ERROR) {
1190 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1191 return result;
1192 }
1193
1194 result = getDisplayNativePrimaries(display, primaries);
1195 reply->writeInt32(result);
1196 if (result == NO_ERROR) {
1197 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1198 sizeof(ui::DisplayPrimaries));
1199 }
1200
1201 return NO_ERROR;
1202 }
Michael Wright28f24d02016-07-12 13:30:53 -07001203 case GET_ACTIVE_COLOR_MODE: {
1204 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1205 sp<IBinder> display = nullptr;
1206 status_t result = data.readStrongBinder(&display);
1207 if (result != NO_ERROR) {
1208 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1209 return result;
1210 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001211 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001212 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1213 return result;
1214 }
1215 case SET_ACTIVE_COLOR_MODE: {
1216 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1217 sp<IBinder> display = nullptr;
1218 status_t result = data.readStrongBinder(&display);
1219 if (result != NO_ERROR) {
1220 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1221 return result;
1222 }
1223 int32_t colorModeInt = 0;
1224 result = data.readInt32(&colorModeInt);
1225 if (result != NO_ERROR) {
1226 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1227 return result;
1228 }
1229 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001230 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001231 result = reply->writeInt32(result);
1232 return result;
1233 }
Svetoslavd85084b2014-03-20 10:28:31 -07001234 case CLEAR_ANIMATION_FRAME_STATS: {
1235 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1236 status_t result = clearAnimationFrameStats();
1237 reply->writeInt32(result);
1238 return NO_ERROR;
1239 }
1240 case GET_ANIMATION_FRAME_STATS: {
1241 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1242 FrameStats stats;
1243 status_t result = getAnimationFrameStats(&stats);
1244 reply->write(stats);
1245 reply->writeInt32(result);
1246 return NO_ERROR;
1247 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001248 case SET_POWER_MODE: {
1249 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1250 sp<IBinder> display = data.readStrongBinder();
1251 int32_t mode = data.readInt32();
1252 setPowerMode(display, mode);
1253 return NO_ERROR;
1254 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001255 case GET_HDR_CAPABILITIES: {
1256 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1257 sp<IBinder> display = nullptr;
1258 status_t result = data.readStrongBinder(&display);
1259 if (result != NO_ERROR) {
1260 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1261 result);
1262 return result;
1263 }
1264 HdrCapabilities capabilities;
1265 result = getHdrCapabilities(display, &capabilities);
1266 reply->writeInt32(result);
1267 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001268 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001269 }
1270 return NO_ERROR;
1271 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001272 case ENABLE_VSYNC_INJECTIONS: {
1273 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1274 bool enable = false;
1275 status_t result = data.readBool(&enable);
1276 if (result != NO_ERROR) {
1277 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1278 return result;
1279 }
1280 return enableVSyncInjections(enable);
1281 }
1282 case INJECT_VSYNC: {
1283 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1284 int64_t when = 0;
1285 status_t result = data.readInt64(&when);
1286 if (result != NO_ERROR) {
1287 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1288 return result;
1289 }
1290 return injectVSync(when);
1291 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001292 case GET_LAYER_DEBUG_INFO: {
1293 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1294 std::vector<LayerDebugInfo> outLayers;
1295 status_t result = getLayerDebugInfo(&outLayers);
1296 reply->writeInt32(result);
1297 if (result == NO_ERROR)
1298 {
1299 result = reply->writeParcelableVector(outLayers);
1300 }
1301 return result;
1302 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001303 case GET_COMPOSITION_PREFERENCE: {
1304 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001305 ui::Dataspace defaultDataspace;
1306 ui::PixelFormat defaultPixelFormat;
1307 ui::Dataspace wideColorGamutDataspace;
1308 ui::PixelFormat wideColorGamutPixelFormat;
1309 status_t error =
1310 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1311 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001312 reply->writeInt32(error);
1313 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001314 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1315 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1316 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001317 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001318 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001319 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001320 }
Ady Abraham37965d42018-11-01 13:43:32 -07001321 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001322 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001323 bool result;
1324 status_t error = getColorManagement(&result);
1325 if (error == NO_ERROR) {
1326 reply->writeBool(result);
1327 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001328 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001329 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001330 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1331 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1332
1333 sp<IBinder> display = data.readStrongBinder();
1334 ui::PixelFormat format;
1335 ui::Dataspace dataspace;
1336 uint8_t component = 0;
1337 auto result =
1338 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1339 if (result == NO_ERROR) {
1340 reply->writeUint32(static_cast<uint32_t>(format));
1341 reply->writeUint32(static_cast<uint32_t>(dataspace));
1342 reply->writeUint32(static_cast<uint32_t>(component));
1343 }
1344 return result;
1345 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001346 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1347 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1348
1349 sp<IBinder> display = nullptr;
1350 bool enable = false;
1351 int8_t componentMask = 0;
1352 uint64_t maxFrames = 0;
1353 status_t result = data.readStrongBinder(&display);
1354 if (result != NO_ERROR) {
1355 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1356 result);
1357 return result;
1358 }
1359
1360 result = data.readBool(&enable);
1361 if (result != NO_ERROR) {
1362 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1363 return result;
1364 }
1365
1366 result = data.readByte(static_cast<int8_t*>(&componentMask));
1367 if (result != NO_ERROR) {
1368 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1369 result);
1370 return result;
1371 }
1372
1373 result = data.readUint64(&maxFrames);
1374 if (result != NO_ERROR) {
1375 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1376 return result;
1377 }
1378
1379 return setDisplayContentSamplingEnabled(display, enable,
1380 static_cast<uint8_t>(componentMask), maxFrames);
1381 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001382 case GET_DISPLAYED_CONTENT_SAMPLE: {
1383 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1384
1385 sp<IBinder> display = data.readStrongBinder();
1386 uint64_t maxFrames = 0;
1387 uint64_t timestamp = 0;
1388
1389 status_t result = data.readUint64(&maxFrames);
1390 if (result != NO_ERROR) {
1391 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1392 return result;
1393 }
1394
1395 result = data.readUint64(&timestamp);
1396 if (result != NO_ERROR) {
1397 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1398 return result;
1399 }
1400
1401 DisplayedFrameStats stats;
1402 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1403 if (result == NO_ERROR) {
1404 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001405 reply->writeUint64Vector(stats.component_0_sample);
1406 reply->writeUint64Vector(stats.component_1_sample);
1407 reply->writeUint64Vector(stats.component_2_sample);
1408 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001409 }
1410 return result;
1411 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001412 case GET_PROTECTED_CONTENT_SUPPORT: {
1413 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1414 bool result;
1415 status_t error = getProtectedContentSupport(&result);
1416 if (error == NO_ERROR) {
1417 reply->writeBool(result);
1418 }
1419 return error;
1420 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001421 case IS_WIDE_COLOR_DISPLAY: {
1422 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1423 sp<IBinder> display = nullptr;
1424 status_t error = data.readStrongBinder(&display);
1425 if (error != NO_ERROR) {
1426 return error;
1427 }
1428 bool result;
1429 error = isWideColorDisplay(display, &result);
1430 if (error == NO_ERROR) {
1431 reply->writeBool(result);
1432 }
1433 return error;
1434 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001435 case GET_PHYSICAL_DISPLAY_IDS: {
1436 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1437 return reply->writeUint64Vector(getPhysicalDisplayIds());
1438 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001439 case ADD_REGION_SAMPLING_LISTENER: {
1440 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1441 Rect samplingArea;
1442 status_t result = data.read(samplingArea);
1443 if (result != NO_ERROR) {
1444 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1445 return result;
1446 }
1447 sp<IBinder> stopLayerHandle;
1448 result = data.readNullableStrongBinder(&stopLayerHandle);
1449 if (result != NO_ERROR) {
1450 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1451 return result;
1452 }
1453 sp<IRegionSamplingListener> listener;
1454 result = data.readNullableStrongBinder(&listener);
1455 if (result != NO_ERROR) {
1456 ALOGE("addRegionSamplingListener: Failed to read listener");
1457 return result;
1458 }
1459 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1460 }
1461 case REMOVE_REGION_SAMPLING_LISTENER: {
1462 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1463 sp<IRegionSamplingListener> listener;
1464 status_t result = data.readNullableStrongBinder(&listener);
1465 if (result != NO_ERROR) {
1466 ALOGE("removeRegionSamplingListener: Failed to read listener");
1467 return result;
1468 }
1469 return removeRegionSamplingListener(listener);
1470 }
Ady Abraham838de062019-02-04 10:24:03 -08001471 case SET_ALLOWED_DISPLAY_CONFIGS: {
1472 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1473 sp<IBinder> displayToken = data.readStrongBinder();
1474 std::vector<int32_t> allowedConfigs;
1475 data.readInt32Vector(&allowedConfigs);
1476 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1477 reply->writeInt32(result);
1478 return result;
1479 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001480 case GET_ALLOWED_DISPLAY_CONFIGS: {
1481 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1482 sp<IBinder> displayToken = data.readStrongBinder();
1483 std::vector<int32_t> allowedConfigs;
1484 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1485 reply->writeInt32Vector(allowedConfigs);
1486 reply->writeInt32(result);
1487 return result;
1488 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001489 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1490 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1491 sp<IBinder> displayToken;
1492 status_t error = data.readNullableStrongBinder(&displayToken);
1493 if (error != NO_ERROR) {
1494 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1495 return error;
1496 }
1497 bool support = false;
1498 error = getDisplayBrightnessSupport(displayToken, &support);
1499 reply->writeBool(support);
1500 return error;
1501 }
1502 case SET_DISPLAY_BRIGHTNESS: {
1503 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1504 sp<IBinder> displayToken;
1505 status_t error = data.readNullableStrongBinder(&displayToken);
1506 if (error != NO_ERROR) {
1507 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1508 return error;
1509 }
1510 float brightness = -1.0f;
1511 error = data.readFloat(&brightness);
1512 if (error != NO_ERROR) {
1513 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1514 return error;
1515 }
1516 return setDisplayBrightness(displayToken, brightness);
1517 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001518 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001519 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001520 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001521 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001522}
1523
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001524} // namespace android