blob: 4372e16a1fe7671ef8475bce58be1c0c2ce8059b [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// tag as surfaceflinger
18#define LOG_TAG "SurfaceFlinger"
19
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/IPCThreadState.h>
25#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiand0566bc2011-11-17 17:49:17 -080027#include <gui/IDisplayEventConnection.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080028#include <gui/IGraphicBufferProducer.h>
Dan Stoza84ab9372018-12-17 15:27:57 -080029#include <gui/IRegionSamplingListener.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080030#include <gui/ISurfaceComposer.h>
31#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080032#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070033#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070038#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070039#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Jamie Gennis134f0422011-03-08 12:18:54 -080041#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Peiyong Lin9f034472018-03-28 15:29:00 -070047using ui::ColorMode;
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
50{
51public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070052 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 : BpInterface<ISurfaceComposer>(impl)
54 {
55 }
56
Dan Stozad723bd72014-11-18 10:24:03 -080057 virtual ~BpSurfaceComposer();
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 }
66
Marissa Wall713b63f2018-10-17 15:42:43 -070067 virtual void setTransactionState(const Vector<ComposerState>& state,
68 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080069 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080070 const InputWindowCommands& commands,
Marissa Wall78b72202019-03-15 14:58:34 -070071 int64_t desiredPresentTime,
Marissa Wall947d34e2019-03-29 14:03:53 -070072 const client_cache_t& uncacheBuffer,
Marissa Wall3dad52d2019-03-22 14:03:19 -070073 const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080076
77 data.writeUint32(static_cast<uint32_t>(state.size()));
78 for (const auto& s : state) {
79 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070080 }
Dan Stozad723bd72014-11-18 10:24:03 -080081
82 data.writeUint32(static_cast<uint32_t>(displays.size()));
83 for (const auto& d : displays) {
84 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
87 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070088 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080089 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080090 data.writeInt64(desiredPresentTime);
Marissa Wall947d34e2019-03-29 14:03:53 -070091 data.writeWeakBinder(uncacheBuffer.token);
92 data.writeUint64(uncacheBuffer.id);
Marissa Wall3dad52d2019-03-22 14:03:19 -070093
94 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
95 for (const auto& [listener, callbackIds] : listenerCallbacks) {
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,
Robert Carr108b2c72019-04-02 16:32:58 -0700112 bool& outCapturedSecureLayers, const ui::Dataspace reqDataspace,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700113 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
114 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carrfa8855f2019-02-19 10:05:00 -0800115 ISurfaceComposer::Rotation rotation, bool captureSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800116 Parcel data, reply;
117 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
118 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700119 data.writeInt32(static_cast<int32_t>(reqDataspace));
120 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700121 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800122 data.writeUint32(reqWidth);
123 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800124 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700125 data.writeInt32(static_cast<int32_t>(rotation));
Robert Carrfa8855f2019-02-19 10:05:00 -0800126 data.writeInt32(static_cast<int32_t>(captureSecureLayers));
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
128 if (result != NO_ERROR) {
129 ALOGE("captureScreen failed to transact: %d", result);
130 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000131 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700132 result = reply.readInt32();
133 if (result != NO_ERROR) {
134 ALOGE("captureScreen failed to readInt32: %d", result);
135 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000136 }
137
138 *outBuffer = new GraphicBuffer();
139 reply.read(**outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -0700140 outCapturedSecureLayers = reply.readBool();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700141
Ana Krulec2d41e422018-07-26 12:07:43 -0700142 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800143 }
144
chaviw93df2ea2019-04-30 16:45:12 -0700145 virtual status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
146 sp<GraphicBuffer>* outBuffer) {
147 Parcel data, reply;
148 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
149 data.writeUint64(displayOrLayerStack);
150 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN_BY_ID, data, &reply);
151 if (result != NO_ERROR) {
152 ALOGE("captureScreen failed to transact: %d", result);
153 return result;
154 }
155 result = reply.readInt32();
156 if (result != NO_ERROR) {
157 ALOGE("captureScreen failed to readInt32: %d", result);
158 return result;
159 }
160
161 *outDataspace = static_cast<ui::Dataspace>(reply.readInt32());
162 *outBuffer = new GraphicBuffer();
163 reply.read(**outBuffer);
164 return result;
165 }
166
Robert Carr866455f2019-04-02 16:28:26 -0700167 virtual status_t captureLayers(
168 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
169 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
170 const Rect& sourceCrop,
171 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
172 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700173 Parcel data, reply;
174 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
175 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700176 data.writeInt32(static_cast<int32_t>(reqDataspace));
177 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800178 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700179 data.writeInt32(excludeLayers.size());
180 for (auto el : excludeLayers) {
181 data.writeStrongBinder(el);
182 }
chaviw7206d492017-11-10 16:16:12 -0800183 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800184 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700185 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
186 if (result != NO_ERROR) {
187 ALOGE("captureLayers failed to transact: %d", result);
188 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000189 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700190 result = reply.readInt32();
191 if (result != NO_ERROR) {
192 ALOGE("captureLayers failed to readInt32: %d", result);
193 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000194 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700195
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000196 *outBuffer = new GraphicBuffer();
197 reply.read(**outBuffer);
198
Ana Krulec2d41e422018-07-26 12:07:43 -0700199 return result;
chaviwa76b2712017-09-20 12:02:26 -0700200 }
201
Jamie Gennis582270d2011-08-17 18:19:00 -0700202 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800203 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800204 {
205 Parcel data, reply;
206 int err = NO_ERROR;
207 err = data.writeInterfaceToken(
208 ISurfaceComposer::getInterfaceDescriptor());
209 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000210 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800211 "interface descriptor: %s (%d)", strerror(-err), -err);
212 return false;
213 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800214 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800215 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000216 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700217 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800218 return false;
219 }
220 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
221 &reply);
222 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000223 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700224 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800225 return false;
226 }
227 int32_t result = 0;
228 err = reply.readInt32(&result);
229 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000230 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700231 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800232 return false;
233 }
234 return result != 0;
235 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800236
Brian Anderson6b376712017-04-04 10:51:39 -0700237 virtual status_t getSupportedFrameTimestamps(
238 std::vector<FrameEvent>* outSupported) const {
239 if (!outSupported) {
240 return UNEXPECTED_NULL;
241 }
242 outSupported->clear();
243
244 Parcel data, reply;
245
246 status_t err = data.writeInterfaceToken(
247 ISurfaceComposer::getInterfaceDescriptor());
248 if (err != NO_ERROR) {
249 return err;
250 }
251
252 err = remote()->transact(
253 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
254 data, &reply);
255 if (err != NO_ERROR) {
256 return err;
257 }
258
259 int32_t result = 0;
260 err = reply.readInt32(&result);
261 if (err != NO_ERROR) {
262 return err;
263 }
264 if (result != NO_ERROR) {
265 return result;
266 }
267
268 std::vector<int32_t> supported;
269 err = reply.readInt32Vector(&supported);
270 if (err != NO_ERROR) {
271 return err;
272 }
273
274 outSupported->reserve(supported.size());
275 for (int32_t s : supported) {
276 outSupported->push_back(static_cast<FrameEvent>(s));
277 }
278 return NO_ERROR;
279 }
280
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700281 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800282 {
283 Parcel data, reply;
284 sp<IDisplayEventConnection> result;
285 int err = data.writeInterfaceToken(
286 ISurfaceComposer::getInterfaceDescriptor());
287 if (err != NO_ERROR) {
288 return result;
289 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700290 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800291 err = remote()->transact(
292 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
293 data, &reply);
294 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000295 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800296 "transaction: %s (%d)", strerror(-err), -err);
297 return result;
298 }
299 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
300 return result;
301 }
Colin Cross8e533062012-06-07 13:17:52 -0700302
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700303 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700304 {
305 Parcel data, reply;
306 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700307 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700308 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700309 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
310 return reply.readStrongBinder();
311 }
312
Jesse Hall6c913be2013-08-08 12:15:49 -0700313 virtual void destroyDisplay(const sp<IBinder>& display)
314 {
315 Parcel data, reply;
316 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
317 data.writeStrongBinder(display);
318 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
319 }
320
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800321 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700322 Parcel data, reply;
323 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800324 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
325 NO_ERROR) {
326 std::vector<PhysicalDisplayId> displayIds;
327 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
328 return displayIds;
329 }
330 }
331
332 return {};
333 }
334
335 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
336 Parcel data, reply;
337 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
338 data.writeUint64(displayId);
339 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700340 return reply.readStrongBinder();
341 }
342
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700343 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700344 {
345 Parcel data, reply;
346 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700347 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700348 data.writeInt32(mode);
349 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700350 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700351
Dan Stoza7f7da322014-05-02 15:26:25 -0700352 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
353 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700357 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700358 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
359 status_t result = reply.readInt32();
360 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800361 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700362 configs->clear();
363 configs->resize(numConfigs);
364 for (size_t c = 0; c < numConfigs; ++c) {
365 memcpy(&(configs->editItemAt(c)),
366 reply.readInplace(sizeof(DisplayInfo)),
367 sizeof(DisplayInfo));
368 }
369 }
370 return result;
371 }
372
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700373 virtual status_t getDisplayStats(const sp<IBinder>& display,
374 DisplayStatInfo* stats)
375 {
376 Parcel data, reply;
377 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
378 data.writeStrongBinder(display);
379 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
380 status_t result = reply.readInt32();
381 if (result == NO_ERROR) {
382 memcpy(stats,
383 reply.readInplace(sizeof(DisplayStatInfo)),
384 sizeof(DisplayStatInfo));
385 }
386 return result;
387 }
388
Dan Stoza7f7da322014-05-02 15:26:25 -0700389 virtual int getActiveConfig(const sp<IBinder>& display)
390 {
391 Parcel data, reply;
392 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
393 data.writeStrongBinder(display);
394 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
395 return reply.readInt32();
396 }
397
398 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
399 {
400 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700401 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
402 if (result != NO_ERROR) {
403 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
404 return result;
405 }
406 result = data.writeStrongBinder(display);
407 if (result != NO_ERROR) {
408 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
409 return result;
410 }
411 result = data.writeInt32(id);
412 if (result != NO_ERROR) {
413 ALOGE("setActiveConfig failed to writeInt32: %d", result);
414 return result;
415 }
416 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
417 if (result != NO_ERROR) {
418 ALOGE("setActiveConfig failed to transact: %d", result);
419 return result;
420 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700421 return reply.readInt32();
422 }
Svetoslavd85084b2014-03-20 10:28:31 -0700423
Michael Wright28f24d02016-07-12 13:30:53 -0700424 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700425 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700426 Parcel data, reply;
427 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
428 if (result != NO_ERROR) {
429 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
430 return result;
431 }
432 result = data.writeStrongBinder(display);
433 if (result != NO_ERROR) {
434 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
435 return result;
436 }
437 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
438 if (result != NO_ERROR) {
439 ALOGE("getDisplayColorModes failed to transact: %d", result);
440 return result;
441 }
442 result = static_cast<status_t>(reply.readInt32());
443 if (result == NO_ERROR) {
444 size_t numModes = reply.readUint32();
445 outColorModes->clear();
446 outColorModes->resize(numModes);
447 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700448 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700449 }
450 }
451 return result;
452 }
453
Daniel Solomon42d04562019-01-20 21:03:19 -0800454 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
455 ui::DisplayPrimaries& primaries) {
456 Parcel data, reply;
457 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
458 if (result != NO_ERROR) {
459 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
460 return result;
461 }
462 result = data.writeStrongBinder(display);
463 if (result != NO_ERROR) {
464 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
465 return result;
466 }
467 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
468 if (result != NO_ERROR) {
469 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
470 return result;
471 }
472 result = reply.readInt32();
473 if (result == NO_ERROR) {
474 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
475 sizeof(ui::DisplayPrimaries));
476 }
477 return result;
478 }
479
Peiyong Lina52f0292018-03-14 17:26:31 -0700480 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700481 Parcel data, reply;
482 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
483 if (result != NO_ERROR) {
484 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700485 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700486 }
487 result = data.writeStrongBinder(display);
488 if (result != NO_ERROR) {
489 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700490 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700491 }
492 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
493 if (result != NO_ERROR) {
494 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700495 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700496 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700497 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700498 }
499
500 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700501 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700502 Parcel data, reply;
503 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
504 if (result != NO_ERROR) {
505 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
506 return result;
507 }
508 result = data.writeStrongBinder(display);
509 if (result != NO_ERROR) {
510 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
511 return result;
512 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700513 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700514 if (result != NO_ERROR) {
515 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
516 return result;
517 }
518 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
519 if (result != NO_ERROR) {
520 ALOGE("setActiveColorMode failed to transact: %d", result);
521 return result;
522 }
523 return static_cast<status_t>(reply.readInt32());
524 }
525
Svetoslavd85084b2014-03-20 10:28:31 -0700526 virtual status_t clearAnimationFrameStats() {
527 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700528 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
529 if (result != NO_ERROR) {
530 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
531 return result;
532 }
533 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
534 if (result != NO_ERROR) {
535 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
536 return result;
537 }
Svetoslavd85084b2014-03-20 10:28:31 -0700538 return reply.readInt32();
539 }
540
541 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
542 Parcel data, reply;
543 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
544 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
545 reply.read(*outStats);
546 return reply.readInt32();
547 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700548
549 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
550 HdrCapabilities* outCapabilities) const {
551 Parcel data, reply;
552 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
553 status_t result = data.writeStrongBinder(display);
554 if (result != NO_ERROR) {
555 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
556 return result;
557 }
558 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
559 data, &reply);
560 if (result != NO_ERROR) {
561 ALOGE("getHdrCapabilities failed to transact: %d", result);
562 return result;
563 }
564 result = reply.readInt32();
565 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800566 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700567 }
568 return result;
569 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700570
571 virtual status_t enableVSyncInjections(bool enable) {
572 Parcel data, reply;
573 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
574 if (result != NO_ERROR) {
575 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
576 return result;
577 }
578 result = data.writeBool(enable);
579 if (result != NO_ERROR) {
580 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
581 return result;
582 }
Steven Moreland366eb422019-04-01 19:22:32 -0700583 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
584 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700585 if (result != NO_ERROR) {
586 ALOGE("enableVSyncInjections failed to transact: %d", result);
587 return result;
588 }
589 return result;
590 }
591
592 virtual status_t injectVSync(nsecs_t when) {
593 Parcel data, reply;
594 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
595 if (result != NO_ERROR) {
596 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
597 return result;
598 }
599 result = data.writeInt64(when);
600 if (result != NO_ERROR) {
601 ALOGE("injectVSync failed to writeInt64: %d", result);
602 return result;
603 }
Steven Moreland366eb422019-04-01 19:22:32 -0700604 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
605 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700606 if (result != NO_ERROR) {
607 ALOGE("injectVSync failed to transact: %d", result);
608 return result;
609 }
610 return result;
611 }
612
Kalle Raitaa099a242017-01-11 11:17:29 -0800613 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
614 {
615 if (!outLayers) {
616 return UNEXPECTED_NULL;
617 }
618
619 Parcel data, reply;
620
621 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
622 if (err != NO_ERROR) {
623 return err;
624 }
625
626 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
627 if (err != NO_ERROR) {
628 return err;
629 }
630
631 int32_t result = 0;
632 err = reply.readInt32(&result);
633 if (err != NO_ERROR) {
634 return err;
635 }
636 if (result != NO_ERROR) {
637 return result;
638 }
639
640 outLayers->clear();
641 return reply.readParcelableVector(outLayers);
642 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700643
Peiyong Linc6780972018-10-28 15:24:08 -0700644 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
645 ui::PixelFormat* defaultPixelFormat,
646 ui::Dataspace* wideColorGamutDataspace,
647 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700648 Parcel data, reply;
649 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
650 if (error != NO_ERROR) {
651 return error;
652 }
653 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
654 if (error != NO_ERROR) {
655 return error;
656 }
657 error = static_cast<status_t>(reply.readInt32());
658 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700659 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
660 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
661 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
662 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700663 }
664 return error;
665 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700666
Ady Abraham37965d42018-11-01 13:43:32 -0700667 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700668 Parcel data, reply;
669 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700670 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
671 bool result;
672 status_t err = reply.readBool(&result);
673 if (err == NO_ERROR) {
674 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700675 }
Ady Abraham37965d42018-11-01 13:43:32 -0700676 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700677 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700678
679 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
680 ui::PixelFormat* outFormat,
681 ui::Dataspace* outDataspace,
682 uint8_t* outComponentMask) const {
683 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
684 Parcel data, reply;
685 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
686 data.writeStrongBinder(display);
687
688 status_t error =
689 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
690 data, &reply);
691 if (error != NO_ERROR) {
692 return error;
693 }
694
695 uint32_t value = 0;
696 error = reply.readUint32(&value);
697 if (error != NO_ERROR) {
698 return error;
699 }
700 *outFormat = static_cast<ui::PixelFormat>(value);
701
702 error = reply.readUint32(&value);
703 if (error != NO_ERROR) {
704 return error;
705 }
706 *outDataspace = static_cast<ui::Dataspace>(value);
707
708 error = reply.readUint32(&value);
709 if (error != NO_ERROR) {
710 return error;
711 }
712 *outComponentMask = static_cast<uint8_t>(value);
713 return error;
714 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800715
716 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
717 uint8_t componentMask,
718 uint64_t maxFrames) const {
719 Parcel data, reply;
720 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
721 data.writeStrongBinder(display);
722 data.writeBool(enable);
723 data.writeByte(static_cast<int8_t>(componentMask));
724 data.writeUint64(maxFrames);
725 status_t result =
726 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
727 &reply);
728 return result;
729 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700730
731 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
732 uint64_t timestamp,
733 DisplayedFrameStats* outStats) const {
734 if (!outStats) return BAD_VALUE;
735
736 Parcel data, reply;
737 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
738 data.writeStrongBinder(display);
739 data.writeUint64(maxFrames);
740 data.writeUint64(timestamp);
741
742 status_t result =
743 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
744
745 if (result != NO_ERROR) {
746 return result;
747 }
748
749 result = reply.readUint64(&outStats->numFrames);
750 if (result != NO_ERROR) {
751 return result;
752 }
753
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800754 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700755 if (result != NO_ERROR) {
756 return result;
757 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800758 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700759 if (result != NO_ERROR) {
760 return result;
761 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800762 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700763 if (result != NO_ERROR) {
764 return result;
765 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800766 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700767 return result;
768 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800769
770 virtual status_t getProtectedContentSupport(bool* outSupported) const {
771 Parcel data, reply;
772 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800773 status_t error =
774 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
775 if (error != NO_ERROR) {
776 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800777 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800778 error = reply.readBool(outSupported);
779 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800780 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800781
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800782 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
783 bool* outIsWideColorDisplay) const {
784 Parcel data, reply;
785 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
786 if (error != NO_ERROR) {
787 return error;
788 }
789 error = data.writeStrongBinder(token);
790 if (error != NO_ERROR) {
791 return error;
792 }
793
794 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
795 if (error != NO_ERROR) {
796 return error;
797 }
798 error = reply.readBool(outIsWideColorDisplay);
799 return error;
800 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800801
802 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
803 const sp<IBinder>& stopLayerHandle,
804 const sp<IRegionSamplingListener>& listener) {
805 Parcel data, reply;
806 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
807 if (error != NO_ERROR) {
808 ALOGE("addRegionSamplingListener: Failed to write interface token");
809 return error;
810 }
811 error = data.write(samplingArea);
812 if (error != NO_ERROR) {
813 ALOGE("addRegionSamplingListener: Failed to write sampling area");
814 return error;
815 }
816 error = data.writeStrongBinder(stopLayerHandle);
817 if (error != NO_ERROR) {
818 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
819 return error;
820 }
821 error = data.writeStrongBinder(IInterface::asBinder(listener));
822 if (error != NO_ERROR) {
823 ALOGE("addRegionSamplingListener: Failed to write listener");
824 return error;
825 }
826 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
827 if (error != NO_ERROR) {
828 ALOGE("addRegionSamplingListener: Failed to transact");
829 }
830 return error;
831 }
832
833 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
834 Parcel data, reply;
835 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
836 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800837 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800838 return error;
839 }
840 error = data.writeStrongBinder(IInterface::asBinder(listener));
841 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800842 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800843 return error;
844 }
845 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
846 &reply);
847 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800848 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800849 }
850 return error;
851 }
Ady Abraham838de062019-02-04 10:24:03 -0800852
853 virtual status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
854 const std::vector<int32_t>& allowedConfigs) {
855 Parcel data, reply;
856 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
857 if (result != NO_ERROR) {
858 ALOGE("setAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
859 return result;
860 }
861 result = data.writeStrongBinder(displayToken);
862 if (result != NO_ERROR) {
863 ALOGE("setAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
864 return result;
865 }
866 result = data.writeInt32Vector(allowedConfigs);
867 if (result != NO_ERROR) {
868 ALOGE("setAllowedDisplayConfigs failed to writeInt32Vector: %d", result);
869 return result;
870 }
871 result = remote()->transact(BnSurfaceComposer::SET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
872 if (result != NO_ERROR) {
873 ALOGE("setAllowedDisplayConfigs failed to transact: %d", result);
874 return result;
875 }
876 return reply.readInt32();
877 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800878
879 virtual status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
880 std::vector<int32_t>* outAllowedConfigs) {
881 if (!outAllowedConfigs) return BAD_VALUE;
882 Parcel data, reply;
883 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
884 if (result != NO_ERROR) {
885 ALOGE("getAllowedDisplayConfigs failed to writeInterfaceToken: %d", result);
886 return result;
887 }
888 result = data.writeStrongBinder(displayToken);
889 if (result != NO_ERROR) {
890 ALOGE("getAllowedDisplayConfigs failed to writeStrongBinder: %d", result);
891 return result;
892 }
893 result = remote()->transact(BnSurfaceComposer::GET_ALLOWED_DISPLAY_CONFIGS, data, &reply);
894 if (result != NO_ERROR) {
895 ALOGE("getAllowedDisplayConfigs failed to transact: %d", result);
896 return result;
897 }
898 result = reply.readInt32Vector(outAllowedConfigs);
899 if (result != NO_ERROR) {
900 ALOGE("getAllowedDisplayConfigs failed to readInt32Vector: %d", result);
901 return result;
902 }
903 return reply.readInt32();
904 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000905
906 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
907 bool* outSupport) const {
908 Parcel data, reply;
909 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
910 if (error != NO_ERROR) {
911 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
912 return error;
913 }
914 error = data.writeStrongBinder(displayToken);
915 if (error != NO_ERROR) {
916 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
917 return error;
918 }
919 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
920 if (error != NO_ERROR) {
921 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
922 return error;
923 }
924 bool support;
925 error = reply.readBool(&support);
926 if (error != NO_ERROR) {
927 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
928 return error;
929 }
930 *outSupport = support;
931 return NO_ERROR;
932 }
933
934 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
935 Parcel data, reply;
936 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
937 if (error != NO_ERROR) {
938 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
939 return error;
940 }
941 error = data.writeStrongBinder(displayToken);
942 if (error != NO_ERROR) {
943 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
944 return error;
945 }
946 error = data.writeFloat(brightness);
947 if (error != NO_ERROR) {
948 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
949 return error;
950 }
951 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
952 if (error != NO_ERROR) {
953 ALOGE("setDisplayBrightness: failed to transact: %d", error);
954 return error;
955 }
956 return NO_ERROR;
957 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800958};
959
Dan Stozad723bd72014-11-18 10:24:03 -0800960// Out-of-line virtual method definition to trigger vtable emission in this
961// translation unit (see clang warning -Wweak-vtables)
962BpSurfaceComposer::~BpSurfaceComposer() {}
963
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800964IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
965
966// ----------------------------------------------------------------------
967
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800968status_t BnSurfaceComposer::onTransact(
969 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
970{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800971 switch(code) {
972 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700973 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800974 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800975 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700976 return NO_ERROR;
977 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700978 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700979 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800980
981 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700982 if (count > data.dataSize()) {
983 return BAD_VALUE;
984 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700985 Vector<ComposerState> state;
986 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800987 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700988 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700989 if (s.read(data) == BAD_VALUE) {
990 return BAD_VALUE;
991 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700992 state.add(s);
993 }
Dan Stozad723bd72014-11-18 10:24:03 -0800994
995 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700996 if (count > data.dataSize()) {
997 return BAD_VALUE;
998 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700999 DisplayState d;
1000 Vector<DisplayState> displays;
1001 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001002 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001003 if (d.read(data) == BAD_VALUE) {
1004 return BAD_VALUE;
1005 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001006 displays.add(d);
1007 }
Dan Stozad723bd72014-11-18 10:24:03 -08001008
1009 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001010 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001011 InputWindowCommands inputWindowCommands;
1012 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001013
1014 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001015
Marissa Wall947d34e2019-03-29 14:03:53 -07001016 client_cache_t uncachedBuffer;
1017 uncachedBuffer.token = data.readWeakBinder();
1018 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001019
Marissa Wall3dad52d2019-03-22 14:03:19 -07001020 std::vector<ListenerCallbacks> listenerCallbacks;
1021 int32_t listenersSize = data.readInt32();
1022 for (int32_t i = 0; i < listenersSize; i++) {
1023 auto listener =
1024 interface_cast<ITransactionCompletedListener>(data.readStrongBinder());
1025 std::vector<CallbackId> callbackIds;
1026 data.readInt64Vector(&callbackIds);
1027 listenerCallbacks.emplace_back(listener, callbackIds);
1028 }
1029
Marissa Wall17b4e452018-12-26 16:32:34 -08001030 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001031 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001032 return NO_ERROR;
1033 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001034 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001035 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001036 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001037 return NO_ERROR;
1038 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001039 case CAPTURE_SCREEN: {
1040 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1041 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001042 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1043 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001044 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001045 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001046 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001047 uint32_t reqWidth = data.readUint32();
1048 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001049 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001050 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001051 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001052
Robert Carr108b2c72019-04-02 16:32:58 -07001053 bool capturedSecureLayers = false;
1054 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1055 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1056 useIdentityTransform,
1057 static_cast<ISurfaceComposer::Rotation>(rotation),
1058 captureSecureLayers);
1059
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001060 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001061 if (res == NO_ERROR) {
1062 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001063 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001064 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001065 return NO_ERROR;
1066 }
chaviw93df2ea2019-04-30 16:45:12 -07001067 case CAPTURE_SCREEN_BY_ID: {
1068 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1069 uint64_t displayOrLayerStack = data.readUint64();
1070 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1071 sp<GraphicBuffer> outBuffer;
1072 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1073 reply->writeInt32(res);
1074 if (res == NO_ERROR) {
1075 reply->writeInt32(static_cast<int32_t>(outDataspace));
1076 reply->write(*outBuffer);
1077 }
1078 return NO_ERROR;
1079 }
chaviwa76b2712017-09-20 12:02:26 -07001080 case CAPTURE_LAYERS: {
1081 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1082 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001083 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1084 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001085 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001086 Rect sourceCrop(Rect::EMPTY_RECT);
1087 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001088
1089 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1090 int numExcludeHandles = data.readInt32();
1091 excludeHandles.reserve(numExcludeHandles);
1092 for (int i = 0; i < numExcludeHandles; i++) {
1093 excludeHandles.emplace(data.readStrongBinder());
1094 }
1095
chaviw7206d492017-11-10 16:16:12 -08001096 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001097 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001098
Robert Carr866455f2019-04-02 16:28:26 -07001099 status_t res =
1100 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1101 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001102 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001103 if (res == NO_ERROR) {
1104 reply->write(*outBuffer);
1105 }
chaviwa76b2712017-09-20 12:02:26 -07001106 return NO_ERROR;
1107 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001108 case AUTHENTICATE_SURFACE: {
1109 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001110 sp<IGraphicBufferProducer> bufferProducer =
1111 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1112 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001113 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001114 return NO_ERROR;
1115 }
Brian Anderson6b376712017-04-04 10:51:39 -07001116 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1117 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1118 std::vector<FrameEvent> supportedTimestamps;
1119 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1120 status_t err = reply->writeInt32(result);
1121 if (err != NO_ERROR) {
1122 return err;
1123 }
1124 if (result != NO_ERROR) {
1125 return result;
1126 }
1127
1128 std::vector<int32_t> supported;
1129 supported.reserve(supportedTimestamps.size());
1130 for (FrameEvent s : supportedTimestamps) {
1131 supported.push_back(static_cast<int32_t>(s));
1132 }
1133 return reply->writeInt32Vector(supported);
1134 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001135 case CREATE_DISPLAY_EVENT_CONNECTION: {
1136 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001137 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1138 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001139 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001140 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001141 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001142 case CREATE_DISPLAY: {
1143 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001144 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001145 bool secure = bool(data.readInt32());
1146 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001147 reply->writeStrongBinder(display);
1148 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001149 }
1150 case DESTROY_DISPLAY: {
1151 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1152 sp<IBinder> display = data.readStrongBinder();
1153 destroyDisplay(display);
1154 return NO_ERROR;
1155 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001156 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001157 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001158 PhysicalDisplayId displayId = data.readUint64();
1159 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001160 reply->writeStrongBinder(display);
1161 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001162 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001163 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001164 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001165 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001166 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001167 status_t result = getDisplayConfigs(display, &configs);
1168 reply->writeInt32(result);
1169 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001170 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001171 for (size_t c = 0; c < configs.size(); ++c) {
1172 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1173 &configs[c], sizeof(DisplayInfo));
1174 }
1175 }
1176 return NO_ERROR;
1177 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001178 case GET_DISPLAY_STATS: {
1179 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1180 DisplayStatInfo stats;
1181 sp<IBinder> display = data.readStrongBinder();
1182 status_t result = getDisplayStats(display, &stats);
1183 reply->writeInt32(result);
1184 if (result == NO_ERROR) {
1185 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1186 &stats, sizeof(DisplayStatInfo));
1187 }
1188 return NO_ERROR;
1189 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001190 case GET_ACTIVE_CONFIG: {
1191 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1192 sp<IBinder> display = data.readStrongBinder();
1193 int id = getActiveConfig(display);
1194 reply->writeInt32(id);
1195 return NO_ERROR;
1196 }
1197 case SET_ACTIVE_CONFIG: {
1198 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1199 sp<IBinder> display = data.readStrongBinder();
1200 int id = data.readInt32();
1201 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001202 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001203 return NO_ERROR;
1204 }
Michael Wright28f24d02016-07-12 13:30:53 -07001205 case GET_DISPLAY_COLOR_MODES: {
1206 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001207 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001208 sp<IBinder> display = nullptr;
1209 status_t result = data.readStrongBinder(&display);
1210 if (result != NO_ERROR) {
1211 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1212 return result;
1213 }
1214 result = getDisplayColorModes(display, &colorModes);
1215 reply->writeInt32(result);
1216 if (result == NO_ERROR) {
1217 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1218 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001219 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001220 }
1221 }
1222 return NO_ERROR;
1223 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001224 case GET_DISPLAY_NATIVE_PRIMARIES: {
1225 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1226 ui::DisplayPrimaries primaries;
1227 sp<IBinder> display = nullptr;
1228
1229 status_t result = data.readStrongBinder(&display);
1230 if (result != NO_ERROR) {
1231 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1232 return result;
1233 }
1234
1235 result = getDisplayNativePrimaries(display, primaries);
1236 reply->writeInt32(result);
1237 if (result == NO_ERROR) {
1238 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1239 sizeof(ui::DisplayPrimaries));
1240 }
1241
1242 return NO_ERROR;
1243 }
Michael Wright28f24d02016-07-12 13:30:53 -07001244 case GET_ACTIVE_COLOR_MODE: {
1245 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1246 sp<IBinder> display = nullptr;
1247 status_t result = data.readStrongBinder(&display);
1248 if (result != NO_ERROR) {
1249 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1250 return result;
1251 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001252 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001253 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1254 return result;
1255 }
1256 case SET_ACTIVE_COLOR_MODE: {
1257 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1258 sp<IBinder> display = nullptr;
1259 status_t result = data.readStrongBinder(&display);
1260 if (result != NO_ERROR) {
1261 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1262 return result;
1263 }
1264 int32_t colorModeInt = 0;
1265 result = data.readInt32(&colorModeInt);
1266 if (result != NO_ERROR) {
1267 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1268 return result;
1269 }
1270 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001271 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001272 result = reply->writeInt32(result);
1273 return result;
1274 }
Svetoslavd85084b2014-03-20 10:28:31 -07001275 case CLEAR_ANIMATION_FRAME_STATS: {
1276 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1277 status_t result = clearAnimationFrameStats();
1278 reply->writeInt32(result);
1279 return NO_ERROR;
1280 }
1281 case GET_ANIMATION_FRAME_STATS: {
1282 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1283 FrameStats stats;
1284 status_t result = getAnimationFrameStats(&stats);
1285 reply->write(stats);
1286 reply->writeInt32(result);
1287 return NO_ERROR;
1288 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001289 case SET_POWER_MODE: {
1290 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1291 sp<IBinder> display = data.readStrongBinder();
1292 int32_t mode = data.readInt32();
1293 setPowerMode(display, mode);
1294 return NO_ERROR;
1295 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001296 case GET_HDR_CAPABILITIES: {
1297 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1298 sp<IBinder> display = nullptr;
1299 status_t result = data.readStrongBinder(&display);
1300 if (result != NO_ERROR) {
1301 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1302 result);
1303 return result;
1304 }
1305 HdrCapabilities capabilities;
1306 result = getHdrCapabilities(display, &capabilities);
1307 reply->writeInt32(result);
1308 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001309 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001310 }
1311 return NO_ERROR;
1312 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001313 case ENABLE_VSYNC_INJECTIONS: {
1314 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1315 bool enable = false;
1316 status_t result = data.readBool(&enable);
1317 if (result != NO_ERROR) {
1318 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1319 return result;
1320 }
1321 return enableVSyncInjections(enable);
1322 }
1323 case INJECT_VSYNC: {
1324 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1325 int64_t when = 0;
1326 status_t result = data.readInt64(&when);
1327 if (result != NO_ERROR) {
1328 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1329 return result;
1330 }
1331 return injectVSync(when);
1332 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001333 case GET_LAYER_DEBUG_INFO: {
1334 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1335 std::vector<LayerDebugInfo> outLayers;
1336 status_t result = getLayerDebugInfo(&outLayers);
1337 reply->writeInt32(result);
1338 if (result == NO_ERROR)
1339 {
1340 result = reply->writeParcelableVector(outLayers);
1341 }
1342 return result;
1343 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001344 case GET_COMPOSITION_PREFERENCE: {
1345 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001346 ui::Dataspace defaultDataspace;
1347 ui::PixelFormat defaultPixelFormat;
1348 ui::Dataspace wideColorGamutDataspace;
1349 ui::PixelFormat wideColorGamutPixelFormat;
1350 status_t error =
1351 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1352 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001353 reply->writeInt32(error);
1354 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001355 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1356 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1357 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001358 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001359 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001360 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001361 }
Ady Abraham37965d42018-11-01 13:43:32 -07001362 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001363 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001364 bool result;
1365 status_t error = getColorManagement(&result);
1366 if (error == NO_ERROR) {
1367 reply->writeBool(result);
1368 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001369 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001370 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001371 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1372 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1373
1374 sp<IBinder> display = data.readStrongBinder();
1375 ui::PixelFormat format;
1376 ui::Dataspace dataspace;
1377 uint8_t component = 0;
1378 auto result =
1379 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1380 if (result == NO_ERROR) {
1381 reply->writeUint32(static_cast<uint32_t>(format));
1382 reply->writeUint32(static_cast<uint32_t>(dataspace));
1383 reply->writeUint32(static_cast<uint32_t>(component));
1384 }
1385 return result;
1386 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001387 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1388 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1389
1390 sp<IBinder> display = nullptr;
1391 bool enable = false;
1392 int8_t componentMask = 0;
1393 uint64_t maxFrames = 0;
1394 status_t result = data.readStrongBinder(&display);
1395 if (result != NO_ERROR) {
1396 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1397 result);
1398 return result;
1399 }
1400
1401 result = data.readBool(&enable);
1402 if (result != NO_ERROR) {
1403 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1404 return result;
1405 }
1406
1407 result = data.readByte(static_cast<int8_t*>(&componentMask));
1408 if (result != NO_ERROR) {
1409 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1410 result);
1411 return result;
1412 }
1413
1414 result = data.readUint64(&maxFrames);
1415 if (result != NO_ERROR) {
1416 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1417 return result;
1418 }
1419
1420 return setDisplayContentSamplingEnabled(display, enable,
1421 static_cast<uint8_t>(componentMask), maxFrames);
1422 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001423 case GET_DISPLAYED_CONTENT_SAMPLE: {
1424 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1425
1426 sp<IBinder> display = data.readStrongBinder();
1427 uint64_t maxFrames = 0;
1428 uint64_t timestamp = 0;
1429
1430 status_t result = data.readUint64(&maxFrames);
1431 if (result != NO_ERROR) {
1432 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1433 return result;
1434 }
1435
1436 result = data.readUint64(&timestamp);
1437 if (result != NO_ERROR) {
1438 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1439 return result;
1440 }
1441
1442 DisplayedFrameStats stats;
1443 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1444 if (result == NO_ERROR) {
1445 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001446 reply->writeUint64Vector(stats.component_0_sample);
1447 reply->writeUint64Vector(stats.component_1_sample);
1448 reply->writeUint64Vector(stats.component_2_sample);
1449 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001450 }
1451 return result;
1452 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001453 case GET_PROTECTED_CONTENT_SUPPORT: {
1454 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1455 bool result;
1456 status_t error = getProtectedContentSupport(&result);
1457 if (error == NO_ERROR) {
1458 reply->writeBool(result);
1459 }
1460 return error;
1461 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001462 case IS_WIDE_COLOR_DISPLAY: {
1463 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1464 sp<IBinder> display = nullptr;
1465 status_t error = data.readStrongBinder(&display);
1466 if (error != NO_ERROR) {
1467 return error;
1468 }
1469 bool result;
1470 error = isWideColorDisplay(display, &result);
1471 if (error == NO_ERROR) {
1472 reply->writeBool(result);
1473 }
1474 return error;
1475 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001476 case GET_PHYSICAL_DISPLAY_IDS: {
1477 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1478 return reply->writeUint64Vector(getPhysicalDisplayIds());
1479 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001480 case ADD_REGION_SAMPLING_LISTENER: {
1481 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1482 Rect samplingArea;
1483 status_t result = data.read(samplingArea);
1484 if (result != NO_ERROR) {
1485 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1486 return result;
1487 }
1488 sp<IBinder> stopLayerHandle;
1489 result = data.readNullableStrongBinder(&stopLayerHandle);
1490 if (result != NO_ERROR) {
1491 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1492 return result;
1493 }
1494 sp<IRegionSamplingListener> listener;
1495 result = data.readNullableStrongBinder(&listener);
1496 if (result != NO_ERROR) {
1497 ALOGE("addRegionSamplingListener: Failed to read listener");
1498 return result;
1499 }
1500 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1501 }
1502 case REMOVE_REGION_SAMPLING_LISTENER: {
1503 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1504 sp<IRegionSamplingListener> listener;
1505 status_t result = data.readNullableStrongBinder(&listener);
1506 if (result != NO_ERROR) {
1507 ALOGE("removeRegionSamplingListener: Failed to read listener");
1508 return result;
1509 }
1510 return removeRegionSamplingListener(listener);
1511 }
Ady Abraham838de062019-02-04 10:24:03 -08001512 case SET_ALLOWED_DISPLAY_CONFIGS: {
1513 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1514 sp<IBinder> displayToken = data.readStrongBinder();
1515 std::vector<int32_t> allowedConfigs;
1516 data.readInt32Vector(&allowedConfigs);
1517 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1518 reply->writeInt32(result);
1519 return result;
1520 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001521 case GET_ALLOWED_DISPLAY_CONFIGS: {
1522 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1523 sp<IBinder> displayToken = data.readStrongBinder();
1524 std::vector<int32_t> allowedConfigs;
1525 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1526 reply->writeInt32Vector(allowedConfigs);
1527 reply->writeInt32(result);
1528 return result;
1529 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001530 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1531 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1532 sp<IBinder> displayToken;
1533 status_t error = data.readNullableStrongBinder(&displayToken);
1534 if (error != NO_ERROR) {
1535 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1536 return error;
1537 }
1538 bool support = false;
1539 error = getDisplayBrightnessSupport(displayToken, &support);
1540 reply->writeBool(support);
1541 return error;
1542 }
1543 case SET_DISPLAY_BRIGHTNESS: {
1544 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1545 sp<IBinder> displayToken;
1546 status_t error = data.readNullableStrongBinder(&displayToken);
1547 if (error != NO_ERROR) {
1548 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1549 return error;
1550 }
1551 float brightness = -1.0f;
1552 error = data.readFloat(&brightness);
1553 if (error != NO_ERROR) {
1554 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1555 return error;
1556 }
1557 return setDisplayBrightness(displayToken, brightness);
1558 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001559 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001560 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001561 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001562 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001563}
1564
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001565} // namespace android