blob: b586bf3989e9d6f94b581a3630d03b893949fd4f [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
chaviwa76b2712017-09-20 12:02:26 -0700144 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700145 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
146 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800147 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700148 Parcel data, reply;
149 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
150 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700151 data.writeInt32(static_cast<int32_t>(reqDataspace));
152 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800153 data.write(sourceCrop);
154 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800155 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700156 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
157 if (result != NO_ERROR) {
158 ALOGE("captureLayers failed to transact: %d", result);
159 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000160 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700161 result = reply.readInt32();
162 if (result != NO_ERROR) {
163 ALOGE("captureLayers failed to readInt32: %d", result);
164 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000165 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700166
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000167 *outBuffer = new GraphicBuffer();
168 reply.read(**outBuffer);
169
Ana Krulec2d41e422018-07-26 12:07:43 -0700170 return result;
chaviwa76b2712017-09-20 12:02:26 -0700171 }
172
Jamie Gennis582270d2011-08-17 18:19:00 -0700173 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800174 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800175 {
176 Parcel data, reply;
177 int err = NO_ERROR;
178 err = data.writeInterfaceToken(
179 ISurfaceComposer::getInterfaceDescriptor());
180 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000181 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800182 "interface descriptor: %s (%d)", strerror(-err), -err);
183 return false;
184 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800185 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800186 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000187 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700188 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800189 return false;
190 }
191 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
192 &reply);
193 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000194 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700195 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800196 return false;
197 }
198 int32_t result = 0;
199 err = reply.readInt32(&result);
200 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000201 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700202 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800203 return false;
204 }
205 return result != 0;
206 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800207
Brian Anderson6b376712017-04-04 10:51:39 -0700208 virtual status_t getSupportedFrameTimestamps(
209 std::vector<FrameEvent>* outSupported) const {
210 if (!outSupported) {
211 return UNEXPECTED_NULL;
212 }
213 outSupported->clear();
214
215 Parcel data, reply;
216
217 status_t err = data.writeInterfaceToken(
218 ISurfaceComposer::getInterfaceDescriptor());
219 if (err != NO_ERROR) {
220 return err;
221 }
222
223 err = remote()->transact(
224 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
225 data, &reply);
226 if (err != NO_ERROR) {
227 return err;
228 }
229
230 int32_t result = 0;
231 err = reply.readInt32(&result);
232 if (err != NO_ERROR) {
233 return err;
234 }
235 if (result != NO_ERROR) {
236 return result;
237 }
238
239 std::vector<int32_t> supported;
240 err = reply.readInt32Vector(&supported);
241 if (err != NO_ERROR) {
242 return err;
243 }
244
245 outSupported->reserve(supported.size());
246 for (int32_t s : supported) {
247 outSupported->push_back(static_cast<FrameEvent>(s));
248 }
249 return NO_ERROR;
250 }
251
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700252 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800253 {
254 Parcel data, reply;
255 sp<IDisplayEventConnection> result;
256 int err = data.writeInterfaceToken(
257 ISurfaceComposer::getInterfaceDescriptor());
258 if (err != NO_ERROR) {
259 return result;
260 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700261 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800262 err = remote()->transact(
263 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
264 data, &reply);
265 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000266 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800267 "transaction: %s (%d)", strerror(-err), -err);
268 return result;
269 }
270 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
271 return result;
272 }
Colin Cross8e533062012-06-07 13:17:52 -0700273
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700274 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700278 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700279 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700280 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
281 return reply.readStrongBinder();
282 }
283
Jesse Hall6c913be2013-08-08 12:15:49 -0700284 virtual void destroyDisplay(const sp<IBinder>& display)
285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
288 data.writeStrongBinder(display);
289 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
290 }
291
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800292 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700293 Parcel data, reply;
294 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800295 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
296 NO_ERROR) {
297 std::vector<PhysicalDisplayId> displayIds;
298 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
299 return displayIds;
300 }
301 }
302
303 return {};
304 }
305
306 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
307 Parcel data, reply;
308 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
309 data.writeUint64(displayId);
310 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700311 return reply.readStrongBinder();
312 }
313
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700314 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700318 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700319 data.writeInt32(mode);
320 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700321 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700322
Dan Stoza7f7da322014-05-02 15:26:25 -0700323 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
324 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700325 {
326 Parcel data, reply;
327 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700328 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700329 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
330 status_t result = reply.readInt32();
331 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800332 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700333 configs->clear();
334 configs->resize(numConfigs);
335 for (size_t c = 0; c < numConfigs; ++c) {
336 memcpy(&(configs->editItemAt(c)),
337 reply.readInplace(sizeof(DisplayInfo)),
338 sizeof(DisplayInfo));
339 }
340 }
341 return result;
342 }
343
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700344 virtual status_t getDisplayStats(const sp<IBinder>& display,
345 DisplayStatInfo* stats)
346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
349 data.writeStrongBinder(display);
350 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
351 status_t result = reply.readInt32();
352 if (result == NO_ERROR) {
353 memcpy(stats,
354 reply.readInplace(sizeof(DisplayStatInfo)),
355 sizeof(DisplayStatInfo));
356 }
357 return result;
358 }
359
Dan Stoza7f7da322014-05-02 15:26:25 -0700360 virtual int getActiveConfig(const sp<IBinder>& display)
361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
364 data.writeStrongBinder(display);
365 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
366 return reply.readInt32();
367 }
368
369 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
370 {
371 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700372 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
373 if (result != NO_ERROR) {
374 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
375 return result;
376 }
377 result = data.writeStrongBinder(display);
378 if (result != NO_ERROR) {
379 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
380 return result;
381 }
382 result = data.writeInt32(id);
383 if (result != NO_ERROR) {
384 ALOGE("setActiveConfig failed to writeInt32: %d", result);
385 return result;
386 }
387 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
388 if (result != NO_ERROR) {
389 ALOGE("setActiveConfig failed to transact: %d", result);
390 return result;
391 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700392 return reply.readInt32();
393 }
Svetoslavd85084b2014-03-20 10:28:31 -0700394
Michael Wright28f24d02016-07-12 13:30:53 -0700395 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700396 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700397 Parcel data, reply;
398 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
399 if (result != NO_ERROR) {
400 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
401 return result;
402 }
403 result = data.writeStrongBinder(display);
404 if (result != NO_ERROR) {
405 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
406 return result;
407 }
408 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
409 if (result != NO_ERROR) {
410 ALOGE("getDisplayColorModes failed to transact: %d", result);
411 return result;
412 }
413 result = static_cast<status_t>(reply.readInt32());
414 if (result == NO_ERROR) {
415 size_t numModes = reply.readUint32();
416 outColorModes->clear();
417 outColorModes->resize(numModes);
418 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700419 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700420 }
421 }
422 return result;
423 }
424
Daniel Solomon42d04562019-01-20 21:03:19 -0800425 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
426 ui::DisplayPrimaries& primaries) {
427 Parcel data, reply;
428 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
429 if (result != NO_ERROR) {
430 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
431 return result;
432 }
433 result = data.writeStrongBinder(display);
434 if (result != NO_ERROR) {
435 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
436 return result;
437 }
438 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
439 if (result != NO_ERROR) {
440 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
441 return result;
442 }
443 result = reply.readInt32();
444 if (result == NO_ERROR) {
445 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
446 sizeof(ui::DisplayPrimaries));
447 }
448 return result;
449 }
450
Peiyong Lina52f0292018-03-14 17:26:31 -0700451 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700452 Parcel data, reply;
453 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
454 if (result != NO_ERROR) {
455 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700456 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700457 }
458 result = data.writeStrongBinder(display);
459 if (result != NO_ERROR) {
460 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700461 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700462 }
463 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
464 if (result != NO_ERROR) {
465 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700466 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700467 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700468 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700469 }
470
471 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700472 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700473 Parcel data, reply;
474 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
475 if (result != NO_ERROR) {
476 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
477 return result;
478 }
479 result = data.writeStrongBinder(display);
480 if (result != NO_ERROR) {
481 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
482 return result;
483 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700484 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700485 if (result != NO_ERROR) {
486 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
487 return result;
488 }
489 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
490 if (result != NO_ERROR) {
491 ALOGE("setActiveColorMode failed to transact: %d", result);
492 return result;
493 }
494 return static_cast<status_t>(reply.readInt32());
495 }
496
Svetoslavd85084b2014-03-20 10:28:31 -0700497 virtual status_t clearAnimationFrameStats() {
498 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700499 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
500 if (result != NO_ERROR) {
501 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
502 return result;
503 }
504 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
505 if (result != NO_ERROR) {
506 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
507 return result;
508 }
Svetoslavd85084b2014-03-20 10:28:31 -0700509 return reply.readInt32();
510 }
511
512 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
513 Parcel data, reply;
514 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
515 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
516 reply.read(*outStats);
517 return reply.readInt32();
518 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700519
520 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
521 HdrCapabilities* outCapabilities) const {
522 Parcel data, reply;
523 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
524 status_t result = data.writeStrongBinder(display);
525 if (result != NO_ERROR) {
526 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
527 return result;
528 }
529 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
530 data, &reply);
531 if (result != NO_ERROR) {
532 ALOGE("getHdrCapabilities failed to transact: %d", result);
533 return result;
534 }
535 result = reply.readInt32();
536 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800537 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700538 }
539 return result;
540 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700541
542 virtual status_t enableVSyncInjections(bool enable) {
543 Parcel data, reply;
544 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
545 if (result != NO_ERROR) {
546 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
547 return result;
548 }
549 result = data.writeBool(enable);
550 if (result != NO_ERROR) {
551 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
552 return result;
553 }
Steven Moreland366eb422019-04-01 19:22:32 -0700554 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
555 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700556 if (result != NO_ERROR) {
557 ALOGE("enableVSyncInjections failed to transact: %d", result);
558 return result;
559 }
560 return result;
561 }
562
563 virtual status_t injectVSync(nsecs_t when) {
564 Parcel data, reply;
565 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
566 if (result != NO_ERROR) {
567 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
568 return result;
569 }
570 result = data.writeInt64(when);
571 if (result != NO_ERROR) {
572 ALOGE("injectVSync failed to writeInt64: %d", result);
573 return result;
574 }
Steven Moreland366eb422019-04-01 19:22:32 -0700575 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
576 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700577 if (result != NO_ERROR) {
578 ALOGE("injectVSync failed to transact: %d", result);
579 return result;
580 }
581 return result;
582 }
583
Kalle Raitaa099a242017-01-11 11:17:29 -0800584 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
585 {
586 if (!outLayers) {
587 return UNEXPECTED_NULL;
588 }
589
590 Parcel data, reply;
591
592 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
593 if (err != NO_ERROR) {
594 return err;
595 }
596
597 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
598 if (err != NO_ERROR) {
599 return err;
600 }
601
602 int32_t result = 0;
603 err = reply.readInt32(&result);
604 if (err != NO_ERROR) {
605 return err;
606 }
607 if (result != NO_ERROR) {
608 return result;
609 }
610
611 outLayers->clear();
612 return reply.readParcelableVector(outLayers);
613 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700614
Peiyong Linc6780972018-10-28 15:24:08 -0700615 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
616 ui::PixelFormat* defaultPixelFormat,
617 ui::Dataspace* wideColorGamutDataspace,
618 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700619 Parcel data, reply;
620 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
621 if (error != NO_ERROR) {
622 return error;
623 }
624 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
625 if (error != NO_ERROR) {
626 return error;
627 }
628 error = static_cast<status_t>(reply.readInt32());
629 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700630 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
631 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
632 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
633 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700634 }
635 return error;
636 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700637
Ady Abraham37965d42018-11-01 13:43:32 -0700638 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700639 Parcel data, reply;
640 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700641 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
642 bool result;
643 status_t err = reply.readBool(&result);
644 if (err == NO_ERROR) {
645 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700646 }
Ady Abraham37965d42018-11-01 13:43:32 -0700647 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700648 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700649
650 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
651 ui::PixelFormat* outFormat,
652 ui::Dataspace* outDataspace,
653 uint8_t* outComponentMask) const {
654 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
655 Parcel data, reply;
656 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
657 data.writeStrongBinder(display);
658
659 status_t error =
660 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
661 data, &reply);
662 if (error != NO_ERROR) {
663 return error;
664 }
665
666 uint32_t value = 0;
667 error = reply.readUint32(&value);
668 if (error != NO_ERROR) {
669 return error;
670 }
671 *outFormat = static_cast<ui::PixelFormat>(value);
672
673 error = reply.readUint32(&value);
674 if (error != NO_ERROR) {
675 return error;
676 }
677 *outDataspace = static_cast<ui::Dataspace>(value);
678
679 error = reply.readUint32(&value);
680 if (error != NO_ERROR) {
681 return error;
682 }
683 *outComponentMask = static_cast<uint8_t>(value);
684 return error;
685 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800686
687 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
688 uint8_t componentMask,
689 uint64_t maxFrames) const {
690 Parcel data, reply;
691 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
692 data.writeStrongBinder(display);
693 data.writeBool(enable);
694 data.writeByte(static_cast<int8_t>(componentMask));
695 data.writeUint64(maxFrames);
696 status_t result =
697 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
698 &reply);
699 return result;
700 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700701
702 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
703 uint64_t timestamp,
704 DisplayedFrameStats* outStats) const {
705 if (!outStats) return BAD_VALUE;
706
707 Parcel data, reply;
708 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
709 data.writeStrongBinder(display);
710 data.writeUint64(maxFrames);
711 data.writeUint64(timestamp);
712
713 status_t result =
714 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
715
716 if (result != NO_ERROR) {
717 return result;
718 }
719
720 result = reply.readUint64(&outStats->numFrames);
721 if (result != NO_ERROR) {
722 return result;
723 }
724
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800725 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700726 if (result != NO_ERROR) {
727 return result;
728 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800729 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700730 if (result != NO_ERROR) {
731 return result;
732 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800733 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700734 if (result != NO_ERROR) {
735 return result;
736 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800737 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700738 return result;
739 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800740
741 virtual status_t getProtectedContentSupport(bool* outSupported) const {
742 Parcel data, reply;
743 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800744 status_t error =
745 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
746 if (error != NO_ERROR) {
747 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800748 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800749 error = reply.readBool(outSupported);
750 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800751 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800752
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800753 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
754 bool* outIsWideColorDisplay) const {
755 Parcel data, reply;
756 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
757 if (error != NO_ERROR) {
758 return error;
759 }
760 error = data.writeStrongBinder(token);
761 if (error != NO_ERROR) {
762 return error;
763 }
764
765 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
766 if (error != NO_ERROR) {
767 return error;
768 }
769 error = reply.readBool(outIsWideColorDisplay);
770 return error;
771 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800772
773 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
774 const sp<IBinder>& stopLayerHandle,
775 const sp<IRegionSamplingListener>& listener) {
776 Parcel data, reply;
777 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
778 if (error != NO_ERROR) {
779 ALOGE("addRegionSamplingListener: Failed to write interface token");
780 return error;
781 }
782 error = data.write(samplingArea);
783 if (error != NO_ERROR) {
784 ALOGE("addRegionSamplingListener: Failed to write sampling area");
785 return error;
786 }
787 error = data.writeStrongBinder(stopLayerHandle);
788 if (error != NO_ERROR) {
789 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
790 return error;
791 }
792 error = data.writeStrongBinder(IInterface::asBinder(listener));
793 if (error != NO_ERROR) {
794 ALOGE("addRegionSamplingListener: Failed to write listener");
795 return error;
796 }
797 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
798 if (error != NO_ERROR) {
799 ALOGE("addRegionSamplingListener: Failed to transact");
800 }
801 return error;
802 }
803
804 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
805 Parcel data, reply;
806 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
807 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800808 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800809 return error;
810 }
811 error = data.writeStrongBinder(IInterface::asBinder(listener));
812 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800813 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800814 return error;
815 }
816 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
817 &reply);
818 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800819 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800820 }
821 return error;
822 }
Ady Abraham838de062019-02-04 10:24:03 -0800823
824 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
825 const std::vector<int32_t>& allowedConfigs) {
826 Parcel data, reply;
827 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
828 if (result != NO_ERROR) {
829 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
830 return result;
831 }
832 result = data.writeStrongBinder(displayToken);
833 if (result != NO_ERROR) {
834 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
835 return result;
836 }
837 result = data.writeInt32Vector(allowedConfigs);
838 if (result != NO_ERROR) {
839 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
840 return result;
841 }
842 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
843 if (result != NO_ERROR) {
844 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
845 return result;
846 }
847 return reply.readInt32();
848 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800849
850 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
851 std::vector<int32_t>* outAllowedConfigs) {
852 if (!outAllowedConfigs) return BAD_VALUE;
853 Parcel data, reply;
854 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
855 if (result != NO_ERROR) {
856 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
857 return result;
858 }
859 result = data.writeStrongBinder(displayToken);
860 if (result != NO_ERROR) {
861 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
862 return result;
863 }
864 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
865 if (result != NO_ERROR) {
866 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
867 return result;
868 }
869 result = reply.readInt32Vector(outAllowedConfigs);
870 if (result != NO_ERROR) {
871 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
872 return result;
873 }
874 return reply.readInt32();
875 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000876
877 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
878 bool* outSupport) const {
879 Parcel data, reply;
880 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
881 if (error != NO_ERROR) {
882 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
883 return error;
884 }
885 error = data.writeStrongBinder(displayToken);
886 if (error != NO_ERROR) {
887 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
888 return error;
889 }
890 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
891 if (error != NO_ERROR) {
892 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
893 return error;
894 }
895 bool support;
896 error = reply.readBool(&support);
897 if (error != NO_ERROR) {
898 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
899 return error;
900 }
901 *outSupport = support;
902 return NO_ERROR;
903 }
904
905 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
906 Parcel data, reply;
907 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
908 if (error != NO_ERROR) {
909 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
910 return error;
911 }
912 error = data.writeStrongBinder(displayToken);
913 if (error != NO_ERROR) {
914 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
915 return error;
916 }
917 error = data.writeFloat(brightness);
918 if (error != NO_ERROR) {
919 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
920 return error;
921 }
922 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
923 if (error != NO_ERROR) {
924 ALOGE("setDisplayBrightness: failed to transact: %d", error);
925 return error;
926 }
927 return NO_ERROR;
928 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800929};
930
Dan Stozad723bd72014-11-18 10:24:03 -0800931// Out-of-line virtual method definition to trigger vtable emission in this
932// translation unit (see clang warning -Wweak-vtables)
933BpSurfaceComposer::~BpSurfaceComposer() {}
934
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800935IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
936
937// ----------------------------------------------------------------------
938
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800939status_t BnSurfaceComposer::onTransact(
940 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
941{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800942 switch(code) {
943 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700944 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800945 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800946 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700947 return NO_ERROR;
948 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700949 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700950 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800951
952 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700953 if (count > data.dataSize()) {
954 return BAD_VALUE;
955 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700956 Vector<ComposerState> state;
957 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800958 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700959 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700960 if (s.read(data) == BAD_VALUE) {
961 return BAD_VALUE;
962 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700963 state.add(s);
964 }
Dan Stozad723bd72014-11-18 10:24:03 -0800965
966 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700967 if (count > data.dataSize()) {
968 return BAD_VALUE;
969 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700970 DisplayState d;
971 Vector<DisplayState> displays;
972 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800973 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700974 if (d.read(data) == BAD_VALUE) {
975 return BAD_VALUE;
976 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700977 displays.add(d);
978 }
Dan Stozad723bd72014-11-18 10:24:03 -0800979
980 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700981 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800982 InputWindowCommands inputWindowCommands;
983 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800984
985 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -0700986
987 cached_buffer_t uncachedBuffer;
988 uncachedBuffer.token = data.readStrongBinder();
989 uncachedBuffer.cacheId = data.readUint64();
990
Marissa Wall3dad52d2019-03-22 14:03:19 -0700991 std::vector<ListenerCallbacks> listenerCallbacks;
992 int32_t listenersSize = data.readInt32();
993 for (int32_t i = 0; i < listenersSize; i++) {
994 auto listener =
995 interface_cast<ITransactionCompletedListener>(data.readStrongBinder());
996 std::vector<CallbackId> callbackIds;
997 data.readInt64Vector(&callbackIds);
998 listenerCallbacks.emplace_back(listener, callbackIds);
999 }
1000
Marissa Wall17b4e452018-12-26 16:32:34 -08001001 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001002 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001003 return NO_ERROR;
1004 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001005 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001006 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001007 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001008 return NO_ERROR;
1009 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001010 case CAPTURE_SCREEN: {
1011 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1012 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001013 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1014 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001015 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001016 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001017 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001018 uint32_t reqWidth = data.readUint32();
1019 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001020 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001021 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001022 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001023
Peiyong Lin0e003c92018-09-17 11:09:51 -07001024 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
1025 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -08001026 static_cast<ISurfaceComposer::Rotation>(rotation), captureSecureLayers);
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001027 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001028 if (res == NO_ERROR) {
1029 reply->write(*outBuffer);
1030 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001031 return NO_ERROR;
1032 }
chaviwa76b2712017-09-20 12:02:26 -07001033 case CAPTURE_LAYERS: {
1034 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1035 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001036 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1037 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001038 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001039 Rect sourceCrop(Rect::EMPTY_RECT);
1040 data.read(sourceCrop);
1041 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001042 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001043
Peiyong Lin0e003c92018-09-17 11:09:51 -07001044 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
1045 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001046 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001047 if (res == NO_ERROR) {
1048 reply->write(*outBuffer);
1049 }
chaviwa76b2712017-09-20 12:02:26 -07001050 return NO_ERROR;
1051 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001052 case AUTHENTICATE_SURFACE: {
1053 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001054 sp<IGraphicBufferProducer> bufferProducer =
1055 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1056 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001057 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001058 return NO_ERROR;
1059 }
Brian Anderson6b376712017-04-04 10:51:39 -07001060 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1061 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1062 std::vector<FrameEvent> supportedTimestamps;
1063 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1064 status_t err = reply->writeInt32(result);
1065 if (err != NO_ERROR) {
1066 return err;
1067 }
1068 if (result != NO_ERROR) {
1069 return result;
1070 }
1071
1072 std::vector<int32_t> supported;
1073 supported.reserve(supportedTimestamps.size());
1074 for (FrameEvent s : supportedTimestamps) {
1075 supported.push_back(static_cast<int32_t>(s));
1076 }
1077 return reply->writeInt32Vector(supported);
1078 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001079 case CREATE_DISPLAY_EVENT_CONNECTION: {
1080 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001081 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1082 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001083 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001084 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001085 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001086 case CREATE_DISPLAY: {
1087 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001088 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001089 bool secure = bool(data.readInt32());
1090 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001091 reply->writeStrongBinder(display);
1092 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001093 }
1094 case DESTROY_DISPLAY: {
1095 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1096 sp<IBinder> display = data.readStrongBinder();
1097 destroyDisplay(display);
1098 return NO_ERROR;
1099 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001100 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001101 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001102 PhysicalDisplayId displayId = data.readUint64();
1103 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001104 reply->writeStrongBinder(display);
1105 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001106 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001107 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001108 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001109 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001110 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001111 status_t result = getDisplayConfigs(display, &configs);
1112 reply->writeInt32(result);
1113 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001114 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001115 for (size_t c = 0; c < configs.size(); ++c) {
1116 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1117 &configs[c], sizeof(DisplayInfo));
1118 }
1119 }
1120 return NO_ERROR;
1121 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001122 case GET_DISPLAY_STATS: {
1123 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1124 DisplayStatInfo stats;
1125 sp<IBinder> display = data.readStrongBinder();
1126 status_t result = getDisplayStats(display, &stats);
1127 reply->writeInt32(result);
1128 if (result == NO_ERROR) {
1129 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1130 &stats, sizeof(DisplayStatInfo));
1131 }
1132 return NO_ERROR;
1133 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001134 case GET_ACTIVE_CONFIG: {
1135 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1136 sp<IBinder> display = data.readStrongBinder();
1137 int id = getActiveConfig(display);
1138 reply->writeInt32(id);
1139 return NO_ERROR;
1140 }
1141 case SET_ACTIVE_CONFIG: {
1142 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1143 sp<IBinder> display = data.readStrongBinder();
1144 int id = data.readInt32();
1145 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001146 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001147 return NO_ERROR;
1148 }
Michael Wright28f24d02016-07-12 13:30:53 -07001149 case GET_DISPLAY_COLOR_MODES: {
1150 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001151 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001152 sp<IBinder> display = nullptr;
1153 status_t result = data.readStrongBinder(&display);
1154 if (result != NO_ERROR) {
1155 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1156 return result;
1157 }
1158 result = getDisplayColorModes(display, &colorModes);
1159 reply->writeInt32(result);
1160 if (result == NO_ERROR) {
1161 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1162 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001163 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001164 }
1165 }
1166 return NO_ERROR;
1167 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001168 case GET_DISPLAY_NATIVE_PRIMARIES: {
1169 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1170 ui::DisplayPrimaries primaries;
1171 sp<IBinder> display = nullptr;
1172
1173 status_t result = data.readStrongBinder(&display);
1174 if (result != NO_ERROR) {
1175 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1176 return result;
1177 }
1178
1179 result = getDisplayNativePrimaries(display, primaries);
1180 reply->writeInt32(result);
1181 if (result == NO_ERROR) {
1182 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1183 sizeof(ui::DisplayPrimaries));
1184 }
1185
1186 return NO_ERROR;
1187 }
Michael Wright28f24d02016-07-12 13:30:53 -07001188 case GET_ACTIVE_COLOR_MODE: {
1189 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1190 sp<IBinder> display = nullptr;
1191 status_t result = data.readStrongBinder(&display);
1192 if (result != NO_ERROR) {
1193 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1194 return result;
1195 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001196 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001197 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1198 return result;
1199 }
1200 case SET_ACTIVE_COLOR_MODE: {
1201 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1202 sp<IBinder> display = nullptr;
1203 status_t result = data.readStrongBinder(&display);
1204 if (result != NO_ERROR) {
1205 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1206 return result;
1207 }
1208 int32_t colorModeInt = 0;
1209 result = data.readInt32(&colorModeInt);
1210 if (result != NO_ERROR) {
1211 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1212 return result;
1213 }
1214 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001215 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001216 result = reply->writeInt32(result);
1217 return result;
1218 }
Svetoslavd85084b2014-03-20 10:28:31 -07001219 case CLEAR_ANIMATION_FRAME_STATS: {
1220 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1221 status_t result = clearAnimationFrameStats();
1222 reply->writeInt32(result);
1223 return NO_ERROR;
1224 }
1225 case GET_ANIMATION_FRAME_STATS: {
1226 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1227 FrameStats stats;
1228 status_t result = getAnimationFrameStats(&stats);
1229 reply->write(stats);
1230 reply->writeInt32(result);
1231 return NO_ERROR;
1232 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001233 case SET_POWER_MODE: {
1234 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1235 sp<IBinder> display = data.readStrongBinder();
1236 int32_t mode = data.readInt32();
1237 setPowerMode(display, mode);
1238 return NO_ERROR;
1239 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001240 case GET_HDR_CAPABILITIES: {
1241 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1242 sp<IBinder> display = nullptr;
1243 status_t result = data.readStrongBinder(&display);
1244 if (result != NO_ERROR) {
1245 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1246 result);
1247 return result;
1248 }
1249 HdrCapabilities capabilities;
1250 result = getHdrCapabilities(display, &capabilities);
1251 reply->writeInt32(result);
1252 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001253 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001254 }
1255 return NO_ERROR;
1256 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001257 case ENABLE_VSYNC_INJECTIONS: {
1258 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1259 bool enable = false;
1260 status_t result = data.readBool(&enable);
1261 if (result != NO_ERROR) {
1262 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1263 return result;
1264 }
1265 return enableVSyncInjections(enable);
1266 }
1267 case INJECT_VSYNC: {
1268 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1269 int64_t when = 0;
1270 status_t result = data.readInt64(&when);
1271 if (result != NO_ERROR) {
1272 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1273 return result;
1274 }
1275 return injectVSync(when);
1276 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001277 case GET_LAYER_DEBUG_INFO: {
1278 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1279 std::vector<LayerDebugInfo> outLayers;
1280 status_t result = getLayerDebugInfo(&outLayers);
1281 reply->writeInt32(result);
1282 if (result == NO_ERROR)
1283 {
1284 result = reply->writeParcelableVector(outLayers);
1285 }
1286 return result;
1287 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001288 case GET_COMPOSITION_PREFERENCE: {
1289 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001290 ui::Dataspace defaultDataspace;
1291 ui::PixelFormat defaultPixelFormat;
1292 ui::Dataspace wideColorGamutDataspace;
1293 ui::PixelFormat wideColorGamutPixelFormat;
1294 status_t error =
1295 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1296 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001297 reply->writeInt32(error);
1298 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001299 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1300 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1301 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001302 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001303 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001304 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001305 }
Ady Abraham37965d42018-11-01 13:43:32 -07001306 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001307 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001308 bool result;
1309 status_t error = getColorManagement(&result);
1310 if (error == NO_ERROR) {
1311 reply->writeBool(result);
1312 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001313 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001314 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001315 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1316 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1317
1318 sp<IBinder> display = data.readStrongBinder();
1319 ui::PixelFormat format;
1320 ui::Dataspace dataspace;
1321 uint8_t component = 0;
1322 auto result =
1323 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1324 if (result == NO_ERROR) {
1325 reply->writeUint32(static_cast<uint32_t>(format));
1326 reply->writeUint32(static_cast<uint32_t>(dataspace));
1327 reply->writeUint32(static_cast<uint32_t>(component));
1328 }
1329 return result;
1330 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001331 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1332 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1333
1334 sp<IBinder> display = nullptr;
1335 bool enable = false;
1336 int8_t componentMask = 0;
1337 uint64_t maxFrames = 0;
1338 status_t result = data.readStrongBinder(&display);
1339 if (result != NO_ERROR) {
1340 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1341 result);
1342 return result;
1343 }
1344
1345 result = data.readBool(&enable);
1346 if (result != NO_ERROR) {
1347 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1348 return result;
1349 }
1350
1351 result = data.readByte(static_cast<int8_t*>(&componentMask));
1352 if (result != NO_ERROR) {
1353 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1354 result);
1355 return result;
1356 }
1357
1358 result = data.readUint64(&maxFrames);
1359 if (result != NO_ERROR) {
1360 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1361 return result;
1362 }
1363
1364 return setDisplayContentSamplingEnabled(display, enable,
1365 static_cast<uint8_t>(componentMask), maxFrames);
1366 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001367 case GET_DISPLAYED_CONTENT_SAMPLE: {
1368 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1369
1370 sp<IBinder> display = data.readStrongBinder();
1371 uint64_t maxFrames = 0;
1372 uint64_t timestamp = 0;
1373
1374 status_t result = data.readUint64(&maxFrames);
1375 if (result != NO_ERROR) {
1376 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1377 return result;
1378 }
1379
1380 result = data.readUint64(&timestamp);
1381 if (result != NO_ERROR) {
1382 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1383 return result;
1384 }
1385
1386 DisplayedFrameStats stats;
1387 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1388 if (result == NO_ERROR) {
1389 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001390 reply->writeUint64Vector(stats.component_0_sample);
1391 reply->writeUint64Vector(stats.component_1_sample);
1392 reply->writeUint64Vector(stats.component_2_sample);
1393 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001394 }
1395 return result;
1396 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001397 case GET_PROTECTED_CONTENT_SUPPORT: {
1398 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1399 bool result;
1400 status_t error = getProtectedContentSupport(&result);
1401 if (error == NO_ERROR) {
1402 reply->writeBool(result);
1403 }
1404 return error;
1405 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001406 case IS_WIDE_COLOR_DISPLAY: {
1407 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1408 sp<IBinder> display = nullptr;
1409 status_t error = data.readStrongBinder(&display);
1410 if (error != NO_ERROR) {
1411 return error;
1412 }
1413 bool result;
1414 error = isWideColorDisplay(display, &result);
1415 if (error == NO_ERROR) {
1416 reply->writeBool(result);
1417 }
1418 return error;
1419 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001420 case GET_PHYSICAL_DISPLAY_IDS: {
1421 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1422 return reply->writeUint64Vector(getPhysicalDisplayIds());
1423 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001424 case ADD_REGION_SAMPLING_LISTENER: {
1425 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1426 Rect samplingArea;
1427 status_t result = data.read(samplingArea);
1428 if (result != NO_ERROR) {
1429 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1430 return result;
1431 }
1432 sp<IBinder> stopLayerHandle;
1433 result = data.readNullableStrongBinder(&stopLayerHandle);
1434 if (result != NO_ERROR) {
1435 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1436 return result;
1437 }
1438 sp<IRegionSamplingListener> listener;
1439 result = data.readNullableStrongBinder(&listener);
1440 if (result != NO_ERROR) {
1441 ALOGE("addRegionSamplingListener: Failed to read listener");
1442 return result;
1443 }
1444 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1445 }
1446 case REMOVE_REGION_SAMPLING_LISTENER: {
1447 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1448 sp<IRegionSamplingListener> listener;
1449 status_t result = data.readNullableStrongBinder(&listener);
1450 if (result != NO_ERROR) {
1451 ALOGE("removeRegionSamplingListener: Failed to read listener");
1452 return result;
1453 }
1454 return removeRegionSamplingListener(listener);
1455 }
Ady Abraham838de062019-02-04 10:24:03 -08001456 case SET_ALLOWED_DISPLAY_CONFIGS: {
1457 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1458 sp<IBinder> displayToken = data.readStrongBinder();
1459 std::vector<int32_t> allowedConfigs;
1460 data.readInt32Vector(&allowedConfigs);
1461 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1462 reply->writeInt32(result);
1463 return result;
1464 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001465 case GET_ALLOWED_DISPLAY_CONFIGS: {
1466 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1467 sp<IBinder> displayToken = data.readStrongBinder();
1468 std::vector<int32_t> allowedConfigs;
1469 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1470 reply->writeInt32Vector(allowedConfigs);
1471 reply->writeInt32(result);
1472 return result;
1473 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001474 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1475 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1476 sp<IBinder> displayToken;
1477 status_t error = data.readNullableStrongBinder(&displayToken);
1478 if (error != NO_ERROR) {
1479 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1480 return error;
1481 }
1482 bool support = false;
1483 error = getDisplayBrightnessSupport(displayToken, &support);
1484 reply->writeBool(support);
1485 return error;
1486 }
1487 case SET_DISPLAY_BRIGHTNESS: {
1488 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1489 sp<IBinder> displayToken;
1490 status_t error = data.readNullableStrongBinder(&displayToken);
1491 if (error != NO_ERROR) {
1492 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1493 return error;
1494 }
1495 float brightness = -1.0f;
1496 error = data.readFloat(&brightness);
1497 if (error != NO_ERROR) {
1498 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1499 return error;
1500 }
1501 return setDisplayBrightness(displayToken, brightness);
1502 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001503 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001504 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001505 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001506 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001507}
1508
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001509} // namespace android