blob: b74d675e4d80d3f7de8b52d8f8100c207a053b0c [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 }
554 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
555 data, &reply, TF_ONE_WAY);
556 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 }
575 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
576 if (result != NO_ERROR) {
577 ALOGE("injectVSync failed to transact: %d", result);
578 return result;
579 }
580 return result;
581 }
582
Kalle Raitaa099a242017-01-11 11:17:29 -0800583 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
584 {
585 if (!outLayers) {
586 return UNEXPECTED_NULL;
587 }
588
589 Parcel data, reply;
590
591 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
592 if (err != NO_ERROR) {
593 return err;
594 }
595
596 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
597 if (err != NO_ERROR) {
598 return err;
599 }
600
601 int32_t result = 0;
602 err = reply.readInt32(&result);
603 if (err != NO_ERROR) {
604 return err;
605 }
606 if (result != NO_ERROR) {
607 return result;
608 }
609
610 outLayers->clear();
611 return reply.readParcelableVector(outLayers);
612 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700613
Peiyong Linc6780972018-10-28 15:24:08 -0700614 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
615 ui::PixelFormat* defaultPixelFormat,
616 ui::Dataspace* wideColorGamutDataspace,
617 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700618 Parcel data, reply;
619 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
620 if (error != NO_ERROR) {
621 return error;
622 }
623 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
624 if (error != NO_ERROR) {
625 return error;
626 }
627 error = static_cast<status_t>(reply.readInt32());
628 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700629 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
630 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
631 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
632 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700633 }
634 return error;
635 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700636
Ady Abraham37965d42018-11-01 13:43:32 -0700637 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700638 Parcel data, reply;
639 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700640 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
641 bool result;
642 status_t err = reply.readBool(&result);
643 if (err == NO_ERROR) {
644 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700645 }
Ady Abraham37965d42018-11-01 13:43:32 -0700646 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700647 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700648
649 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
650 ui::PixelFormat* outFormat,
651 ui::Dataspace* outDataspace,
652 uint8_t* outComponentMask) const {
653 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
654 Parcel data, reply;
655 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
656 data.writeStrongBinder(display);
657
658 status_t error =
659 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
660 data, &reply);
661 if (error != NO_ERROR) {
662 return error;
663 }
664
665 uint32_t value = 0;
666 error = reply.readUint32(&value);
667 if (error != NO_ERROR) {
668 return error;
669 }
670 *outFormat = static_cast<ui::PixelFormat>(value);
671
672 error = reply.readUint32(&value);
673 if (error != NO_ERROR) {
674 return error;
675 }
676 *outDataspace = static_cast<ui::Dataspace>(value);
677
678 error = reply.readUint32(&value);
679 if (error != NO_ERROR) {
680 return error;
681 }
682 *outComponentMask = static_cast<uint8_t>(value);
683 return error;
684 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800685
686 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
687 uint8_t componentMask,
688 uint64_t maxFrames) const {
689 Parcel data, reply;
690 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
691 data.writeStrongBinder(display);
692 data.writeBool(enable);
693 data.writeByte(static_cast<int8_t>(componentMask));
694 data.writeUint64(maxFrames);
695 status_t result =
696 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
697 &reply);
698 return result;
699 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700700
701 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
702 uint64_t timestamp,
703 DisplayedFrameStats* outStats) const {
704 if (!outStats) return BAD_VALUE;
705
706 Parcel data, reply;
707 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
708 data.writeStrongBinder(display);
709 data.writeUint64(maxFrames);
710 data.writeUint64(timestamp);
711
712 status_t result =
713 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
714
715 if (result != NO_ERROR) {
716 return result;
717 }
718
719 result = reply.readUint64(&outStats->numFrames);
720 if (result != NO_ERROR) {
721 return result;
722 }
723
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800724 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700725 if (result != NO_ERROR) {
726 return result;
727 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800728 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700729 if (result != NO_ERROR) {
730 return result;
731 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800732 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700733 if (result != NO_ERROR) {
734 return result;
735 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800736 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700737 return result;
738 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800739
740 virtual status_t getProtectedContentSupport(bool* outSupported) const {
741 Parcel data, reply;
742 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800743 status_t error =
744 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
745 if (error != NO_ERROR) {
746 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800747 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800748 error = reply.readBool(outSupported);
749 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800750 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800751
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800752 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
753 bool* outIsWideColorDisplay) const {
754 Parcel data, reply;
755 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
756 if (error != NO_ERROR) {
757 return error;
758 }
759 error = data.writeStrongBinder(token);
760 if (error != NO_ERROR) {
761 return error;
762 }
763
764 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
765 if (error != NO_ERROR) {
766 return error;
767 }
768 error = reply.readBool(outIsWideColorDisplay);
769 return error;
770 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800771
772 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
773 const sp<IBinder>& stopLayerHandle,
774 const sp<IRegionSamplingListener>& listener) {
775 Parcel data, reply;
776 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
777 if (error != NO_ERROR) {
778 ALOGE("addRegionSamplingListener: Failed to write interface token");
779 return error;
780 }
781 error = data.write(samplingArea);
782 if (error != NO_ERROR) {
783 ALOGE("addRegionSamplingListener: Failed to write sampling area");
784 return error;
785 }
786 error = data.writeStrongBinder(stopLayerHandle);
787 if (error != NO_ERROR) {
788 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
789 return error;
790 }
791 error = data.writeStrongBinder(IInterface::asBinder(listener));
792 if (error != NO_ERROR) {
793 ALOGE("addRegionSamplingListener: Failed to write listener");
794 return error;
795 }
796 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
797 if (error != NO_ERROR) {
798 ALOGE("addRegionSamplingListener: Failed to transact");
799 }
800 return error;
801 }
802
803 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
804 Parcel data, reply;
805 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
806 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800807 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800808 return error;
809 }
810 error = data.writeStrongBinder(IInterface::asBinder(listener));
811 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800812 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800813 return error;
814 }
815 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
816 &reply);
817 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800818 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800819 }
820 return error;
821 }
Ady Abraham838de062019-02-04 10:24:03 -0800822
823 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
824 const std::vector<int32_t>& allowedConfigs) {
825 Parcel data, reply;
826 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
827 if (result != NO_ERROR) {
828 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
829 return result;
830 }
831 result = data.writeStrongBinder(displayToken);
832 if (result != NO_ERROR) {
833 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
834 return result;
835 }
836 result = data.writeInt32Vector(allowedConfigs);
837 if (result != NO_ERROR) {
838 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
839 return result;
840 }
841 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
842 if (result != NO_ERROR) {
843 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
844 return result;
845 }
846 return reply.readInt32();
847 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800848
849 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
850 std::vector<int32_t>* outAllowedConfigs) {
851 if (!outAllowedConfigs) return BAD_VALUE;
852 Parcel data, reply;
853 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
854 if (result != NO_ERROR) {
855 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
856 return result;
857 }
858 result = data.writeStrongBinder(displayToken);
859 if (result != NO_ERROR) {
860 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
861 return result;
862 }
863 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
864 if (result != NO_ERROR) {
865 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
866 return result;
867 }
868 result = reply.readInt32Vector(outAllowedConfigs);
869 if (result != NO_ERROR) {
870 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
871 return result;
872 }
873 return reply.readInt32();
874 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000875
876 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
877 bool* outSupport) const {
878 Parcel data, reply;
879 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
880 if (error != NO_ERROR) {
881 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
882 return error;
883 }
884 error = data.writeStrongBinder(displayToken);
885 if (error != NO_ERROR) {
886 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
887 return error;
888 }
889 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
890 if (error != NO_ERROR) {
891 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
892 return error;
893 }
894 bool support;
895 error = reply.readBool(&support);
896 if (error != NO_ERROR) {
897 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
898 return error;
899 }
900 *outSupport = support;
901 return NO_ERROR;
902 }
903
904 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
905 Parcel data, reply;
906 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
907 if (error != NO_ERROR) {
908 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
909 return error;
910 }
911 error = data.writeStrongBinder(displayToken);
912 if (error != NO_ERROR) {
913 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
914 return error;
915 }
916 error = data.writeFloat(brightness);
917 if (error != NO_ERROR) {
918 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
919 return error;
920 }
921 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
922 if (error != NO_ERROR) {
923 ALOGE("setDisplayBrightness: failed to transact: %d", error);
924 return error;
925 }
926 return NO_ERROR;
927 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800928};
929
Dan Stozad723bd72014-11-18 10:24:03 -0800930// Out-of-line virtual method definition to trigger vtable emission in this
931// translation unit (see clang warning -Wweak-vtables)
932BpSurfaceComposer::~BpSurfaceComposer() {}
933
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800934IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
935
936// ----------------------------------------------------------------------
937
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800938status_t BnSurfaceComposer::onTransact(
939 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
940{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800941 switch(code) {
942 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700943 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800944 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800945 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700946 return NO_ERROR;
947 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700948 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700949 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800950
951 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700952 if (count > data.dataSize()) {
953 return BAD_VALUE;
954 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700955 Vector<ComposerState> state;
956 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800957 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700958 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700959 if (s.read(data) == BAD_VALUE) {
960 return BAD_VALUE;
961 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700962 state.add(s);
963 }
Dan Stozad723bd72014-11-18 10:24:03 -0800964
965 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700966 if (count > data.dataSize()) {
967 return BAD_VALUE;
968 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700969 DisplayState d;
970 Vector<DisplayState> displays;
971 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800972 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700973 if (d.read(data) == BAD_VALUE) {
974 return BAD_VALUE;
975 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700976 displays.add(d);
977 }
Dan Stozad723bd72014-11-18 10:24:03 -0800978
979 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700980 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800981 InputWindowCommands inputWindowCommands;
982 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800983
984 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -0700985
986 cached_buffer_t uncachedBuffer;
987 uncachedBuffer.token = data.readStrongBinder();
988 uncachedBuffer.cacheId = data.readUint64();
989
Marissa Wall3dad52d2019-03-22 14:03:19 -0700990 std::vector<ListenerCallbacks> listenerCallbacks;
991 int32_t listenersSize = data.readInt32();
992 for (int32_t i = 0; i < listenersSize; i++) {
993 auto listener =
994 interface_cast<ITransactionCompletedListener>(data.readStrongBinder());
995 std::vector<CallbackId> callbackIds;
996 data.readInt64Vector(&callbackIds);
997 listenerCallbacks.emplace_back(listener, callbackIds);
998 }
999
Marissa Wall17b4e452018-12-26 16:32:34 -08001000 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001001 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001002 return NO_ERROR;
1003 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001004 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001005 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001006 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001007 return NO_ERROR;
1008 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001009 case CAPTURE_SCREEN: {
1010 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1011 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001012 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1013 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001014 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001015 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001016 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001017 uint32_t reqWidth = data.readUint32();
1018 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001019 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001020 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001021 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001022
Peiyong Lin0e003c92018-09-17 11:09:51 -07001023 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
1024 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -08001025 static_cast<ISurfaceComposer::Rotation>(rotation), captureSecureLayers);
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001026 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001027 if (res == NO_ERROR) {
1028 reply->write(*outBuffer);
1029 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001030 return NO_ERROR;
1031 }
chaviwa76b2712017-09-20 12:02:26 -07001032 case CAPTURE_LAYERS: {
1033 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1034 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001035 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1036 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001037 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001038 Rect sourceCrop(Rect::EMPTY_RECT);
1039 data.read(sourceCrop);
1040 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001041 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001042
Peiyong Lin0e003c92018-09-17 11:09:51 -07001043 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
1044 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001045 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001046 if (res == NO_ERROR) {
1047 reply->write(*outBuffer);
1048 }
chaviwa76b2712017-09-20 12:02:26 -07001049 return NO_ERROR;
1050 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001051 case AUTHENTICATE_SURFACE: {
1052 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001053 sp<IGraphicBufferProducer> bufferProducer =
1054 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1055 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001056 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001057 return NO_ERROR;
1058 }
Brian Anderson6b376712017-04-04 10:51:39 -07001059 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1060 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1061 std::vector<FrameEvent> supportedTimestamps;
1062 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1063 status_t err = reply->writeInt32(result);
1064 if (err != NO_ERROR) {
1065 return err;
1066 }
1067 if (result != NO_ERROR) {
1068 return result;
1069 }
1070
1071 std::vector<int32_t> supported;
1072 supported.reserve(supportedTimestamps.size());
1073 for (FrameEvent s : supportedTimestamps) {
1074 supported.push_back(static_cast<int32_t>(s));
1075 }
1076 return reply->writeInt32Vector(supported);
1077 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001078 case CREATE_DISPLAY_EVENT_CONNECTION: {
1079 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001080 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1081 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001082 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001083 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001084 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001085 case CREATE_DISPLAY: {
1086 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001087 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001088 bool secure = bool(data.readInt32());
1089 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001090 reply->writeStrongBinder(display);
1091 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001092 }
1093 case DESTROY_DISPLAY: {
1094 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1095 sp<IBinder> display = data.readStrongBinder();
1096 destroyDisplay(display);
1097 return NO_ERROR;
1098 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001099 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001100 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001101 PhysicalDisplayId displayId = data.readUint64();
1102 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001103 reply->writeStrongBinder(display);
1104 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001105 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001106 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001107 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001108 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001109 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001110 status_t result = getDisplayConfigs(display, &configs);
1111 reply->writeInt32(result);
1112 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001113 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001114 for (size_t c = 0; c < configs.size(); ++c) {
1115 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1116 &configs[c], sizeof(DisplayInfo));
1117 }
1118 }
1119 return NO_ERROR;
1120 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001121 case GET_DISPLAY_STATS: {
1122 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1123 DisplayStatInfo stats;
1124 sp<IBinder> display = data.readStrongBinder();
1125 status_t result = getDisplayStats(display, &stats);
1126 reply->writeInt32(result);
1127 if (result == NO_ERROR) {
1128 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1129 &stats, sizeof(DisplayStatInfo));
1130 }
1131 return NO_ERROR;
1132 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001133 case GET_ACTIVE_CONFIG: {
1134 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1135 sp<IBinder> display = data.readStrongBinder();
1136 int id = getActiveConfig(display);
1137 reply->writeInt32(id);
1138 return NO_ERROR;
1139 }
1140 case SET_ACTIVE_CONFIG: {
1141 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1142 sp<IBinder> display = data.readStrongBinder();
1143 int id = data.readInt32();
1144 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001145 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001146 return NO_ERROR;
1147 }
Michael Wright28f24d02016-07-12 13:30:53 -07001148 case GET_DISPLAY_COLOR_MODES: {
1149 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001150 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001151 sp<IBinder> display = nullptr;
1152 status_t result = data.readStrongBinder(&display);
1153 if (result != NO_ERROR) {
1154 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1155 return result;
1156 }
1157 result = getDisplayColorModes(display, &colorModes);
1158 reply->writeInt32(result);
1159 if (result == NO_ERROR) {
1160 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1161 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001162 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001163 }
1164 }
1165 return NO_ERROR;
1166 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001167 case GET_DISPLAY_NATIVE_PRIMARIES: {
1168 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1169 ui::DisplayPrimaries primaries;
1170 sp<IBinder> display = nullptr;
1171
1172 status_t result = data.readStrongBinder(&display);
1173 if (result != NO_ERROR) {
1174 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1175 return result;
1176 }
1177
1178 result = getDisplayNativePrimaries(display, primaries);
1179 reply->writeInt32(result);
1180 if (result == NO_ERROR) {
1181 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1182 sizeof(ui::DisplayPrimaries));
1183 }
1184
1185 return NO_ERROR;
1186 }
Michael Wright28f24d02016-07-12 13:30:53 -07001187 case GET_ACTIVE_COLOR_MODE: {
1188 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1189 sp<IBinder> display = nullptr;
1190 status_t result = data.readStrongBinder(&display);
1191 if (result != NO_ERROR) {
1192 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1193 return result;
1194 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001195 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001196 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1197 return result;
1198 }
1199 case SET_ACTIVE_COLOR_MODE: {
1200 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1201 sp<IBinder> display = nullptr;
1202 status_t result = data.readStrongBinder(&display);
1203 if (result != NO_ERROR) {
1204 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1205 return result;
1206 }
1207 int32_t colorModeInt = 0;
1208 result = data.readInt32(&colorModeInt);
1209 if (result != NO_ERROR) {
1210 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1211 return result;
1212 }
1213 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001214 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001215 result = reply->writeInt32(result);
1216 return result;
1217 }
Svetoslavd85084b2014-03-20 10:28:31 -07001218 case CLEAR_ANIMATION_FRAME_STATS: {
1219 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1220 status_t result = clearAnimationFrameStats();
1221 reply->writeInt32(result);
1222 return NO_ERROR;
1223 }
1224 case GET_ANIMATION_FRAME_STATS: {
1225 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1226 FrameStats stats;
1227 status_t result = getAnimationFrameStats(&stats);
1228 reply->write(stats);
1229 reply->writeInt32(result);
1230 return NO_ERROR;
1231 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001232 case SET_POWER_MODE: {
1233 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1234 sp<IBinder> display = data.readStrongBinder();
1235 int32_t mode = data.readInt32();
1236 setPowerMode(display, mode);
1237 return NO_ERROR;
1238 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001239 case GET_HDR_CAPABILITIES: {
1240 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1241 sp<IBinder> display = nullptr;
1242 status_t result = data.readStrongBinder(&display);
1243 if (result != NO_ERROR) {
1244 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1245 result);
1246 return result;
1247 }
1248 HdrCapabilities capabilities;
1249 result = getHdrCapabilities(display, &capabilities);
1250 reply->writeInt32(result);
1251 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001252 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001253 }
1254 return NO_ERROR;
1255 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001256 case ENABLE_VSYNC_INJECTIONS: {
1257 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1258 bool enable = false;
1259 status_t result = data.readBool(&enable);
1260 if (result != NO_ERROR) {
1261 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1262 return result;
1263 }
1264 return enableVSyncInjections(enable);
1265 }
1266 case INJECT_VSYNC: {
1267 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1268 int64_t when = 0;
1269 status_t result = data.readInt64(&when);
1270 if (result != NO_ERROR) {
1271 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1272 return result;
1273 }
1274 return injectVSync(when);
1275 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001276 case GET_LAYER_DEBUG_INFO: {
1277 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1278 std::vector<LayerDebugInfo> outLayers;
1279 status_t result = getLayerDebugInfo(&outLayers);
1280 reply->writeInt32(result);
1281 if (result == NO_ERROR)
1282 {
1283 result = reply->writeParcelableVector(outLayers);
1284 }
1285 return result;
1286 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001287 case GET_COMPOSITION_PREFERENCE: {
1288 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001289 ui::Dataspace defaultDataspace;
1290 ui::PixelFormat defaultPixelFormat;
1291 ui::Dataspace wideColorGamutDataspace;
1292 ui::PixelFormat wideColorGamutPixelFormat;
1293 status_t error =
1294 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1295 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001296 reply->writeInt32(error);
1297 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001298 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1299 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1300 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001301 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001302 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001303 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001304 }
Ady Abraham37965d42018-11-01 13:43:32 -07001305 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001306 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001307 bool result;
1308 status_t error = getColorManagement(&result);
1309 if (error == NO_ERROR) {
1310 reply->writeBool(result);
1311 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001312 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001313 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001314 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1315 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1316
1317 sp<IBinder> display = data.readStrongBinder();
1318 ui::PixelFormat format;
1319 ui::Dataspace dataspace;
1320 uint8_t component = 0;
1321 auto result =
1322 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1323 if (result == NO_ERROR) {
1324 reply->writeUint32(static_cast<uint32_t>(format));
1325 reply->writeUint32(static_cast<uint32_t>(dataspace));
1326 reply->writeUint32(static_cast<uint32_t>(component));
1327 }
1328 return result;
1329 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001330 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1331 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1332
1333 sp<IBinder> display = nullptr;
1334 bool enable = false;
1335 int8_t componentMask = 0;
1336 uint64_t maxFrames = 0;
1337 status_t result = data.readStrongBinder(&display);
1338 if (result != NO_ERROR) {
1339 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1340 result);
1341 return result;
1342 }
1343
1344 result = data.readBool(&enable);
1345 if (result != NO_ERROR) {
1346 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1347 return result;
1348 }
1349
1350 result = data.readByte(static_cast<int8_t*>(&componentMask));
1351 if (result != NO_ERROR) {
1352 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1353 result);
1354 return result;
1355 }
1356
1357 result = data.readUint64(&maxFrames);
1358 if (result != NO_ERROR) {
1359 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1360 return result;
1361 }
1362
1363 return setDisplayContentSamplingEnabled(display, enable,
1364 static_cast<uint8_t>(componentMask), maxFrames);
1365 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001366 case GET_DISPLAYED_CONTENT_SAMPLE: {
1367 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1368
1369 sp<IBinder> display = data.readStrongBinder();
1370 uint64_t maxFrames = 0;
1371 uint64_t timestamp = 0;
1372
1373 status_t result = data.readUint64(&maxFrames);
1374 if (result != NO_ERROR) {
1375 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1376 return result;
1377 }
1378
1379 result = data.readUint64(&timestamp);
1380 if (result != NO_ERROR) {
1381 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1382 return result;
1383 }
1384
1385 DisplayedFrameStats stats;
1386 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1387 if (result == NO_ERROR) {
1388 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001389 reply->writeUint64Vector(stats.component_0_sample);
1390 reply->writeUint64Vector(stats.component_1_sample);
1391 reply->writeUint64Vector(stats.component_2_sample);
1392 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001393 }
1394 return result;
1395 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001396 case GET_PROTECTED_CONTENT_SUPPORT: {
1397 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1398 bool result;
1399 status_t error = getProtectedContentSupport(&result);
1400 if (error == NO_ERROR) {
1401 reply->writeBool(result);
1402 }
1403 return error;
1404 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001405 case IS_WIDE_COLOR_DISPLAY: {
1406 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1407 sp<IBinder> display = nullptr;
1408 status_t error = data.readStrongBinder(&display);
1409 if (error != NO_ERROR) {
1410 return error;
1411 }
1412 bool result;
1413 error = isWideColorDisplay(display, &result);
1414 if (error == NO_ERROR) {
1415 reply->writeBool(result);
1416 }
1417 return error;
1418 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001419 case GET_PHYSICAL_DISPLAY_IDS: {
1420 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1421 return reply->writeUint64Vector(getPhysicalDisplayIds());
1422 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001423 case ADD_REGION_SAMPLING_LISTENER: {
1424 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1425 Rect samplingArea;
1426 status_t result = data.read(samplingArea);
1427 if (result != NO_ERROR) {
1428 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1429 return result;
1430 }
1431 sp<IBinder> stopLayerHandle;
1432 result = data.readNullableStrongBinder(&stopLayerHandle);
1433 if (result != NO_ERROR) {
1434 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1435 return result;
1436 }
1437 sp<IRegionSamplingListener> listener;
1438 result = data.readNullableStrongBinder(&listener);
1439 if (result != NO_ERROR) {
1440 ALOGE("addRegionSamplingListener: Failed to read listener");
1441 return result;
1442 }
1443 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1444 }
1445 case REMOVE_REGION_SAMPLING_LISTENER: {
1446 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1447 sp<IRegionSamplingListener> listener;
1448 status_t result = data.readNullableStrongBinder(&listener);
1449 if (result != NO_ERROR) {
1450 ALOGE("removeRegionSamplingListener: Failed to read listener");
1451 return result;
1452 }
1453 return removeRegionSamplingListener(listener);
1454 }
Ady Abraham838de062019-02-04 10:24:03 -08001455 case SET_ALLOWED_DISPLAY_CONFIGS: {
1456 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1457 sp<IBinder> displayToken = data.readStrongBinder();
1458 std::vector<int32_t> allowedConfigs;
1459 data.readInt32Vector(&allowedConfigs);
1460 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1461 reply->writeInt32(result);
1462 return result;
1463 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001464 case GET_ALLOWED_DISPLAY_CONFIGS: {
1465 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1466 sp<IBinder> displayToken = data.readStrongBinder();
1467 std::vector<int32_t> allowedConfigs;
1468 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1469 reply->writeInt32Vector(allowedConfigs);
1470 reply->writeInt32(result);
1471 return result;
1472 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001473 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1474 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1475 sp<IBinder> displayToken;
1476 status_t error = data.readNullableStrongBinder(&displayToken);
1477 if (error != NO_ERROR) {
1478 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1479 return error;
1480 }
1481 bool support = false;
1482 error = getDisplayBrightnessSupport(displayToken, &support);
1483 reply->writeBool(support);
1484 return error;
1485 }
1486 case SET_DISPLAY_BRIGHTNESS: {
1487 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1488 sp<IBinder> displayToken;
1489 status_t error = data.readNullableStrongBinder(&displayToken);
1490 if (error != NO_ERROR) {
1491 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1492 return error;
1493 }
1494 float brightness = -1.0f;
1495 error = data.readFloat(&brightness);
1496 if (error != NO_ERROR) {
1497 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1498 return error;
1499 }
1500 return setDisplayBrightness(displayToken, brightness);
1501 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001502 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001503 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001504 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001505 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001506}
1507
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001508} // namespace android