blob: 9590df7c8f18a5e9002616f9a5f212cce87a2ef1 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// tag as surfaceflinger
18#define LOG_TAG "SurfaceFlinger"
19
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/IPCThreadState.h>
25#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiand0566bc2011-11-17 17:49:17 -080027#include <gui/IDisplayEventConnection.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080028#include <gui/IGraphicBufferProducer.h>
Dan Stoza84ab9372018-12-17 15:27:57 -080029#include <gui/IRegionSamplingListener.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080030#include <gui/ISurfaceComposer.h>
31#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080032#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070033#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070038#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070039#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Jamie Gennis134f0422011-03-08 12:18:54 -080041#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Peiyong Lin9f034472018-03-28 15:29:00 -070047using ui::ColorMode;
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
50{
51public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070052 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 : BpInterface<ISurfaceComposer>(impl)
54 {
55 }
56
Dan Stozad723bd72014-11-18 10:24:03 -080057 virtual ~BpSurfaceComposer();
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 }
66
Marissa Wall713b63f2018-10-17 15:42:43 -070067 virtual void setTransactionState(const Vector<ComposerState>& state,
68 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080069 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080070 const InputWindowCommands& commands,
Marissa Wall78b72202019-03-15 14:58:34 -070071 int64_t desiredPresentTime,
Marissa Wall947d34e2019-03-29 14:03:53 -070072 const client_cache_t& uncacheBuffer,
Marissa Wall3dad52d2019-03-22 14:03:19 -070073 const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080076
77 data.writeUint32(static_cast<uint32_t>(state.size()));
78 for (const auto& s : state) {
79 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070080 }
Dan Stozad723bd72014-11-18 10:24:03 -080081
82 data.writeUint32(static_cast<uint32_t>(displays.size()));
83 for (const auto& d : displays) {
84 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
87 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070088 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080089 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080090 data.writeInt64(desiredPresentTime);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070091 data.writeStrongBinder(uncacheBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070092 data.writeUint64(uncacheBuffer.id);
Marissa Wall3dad52d2019-03-22 14:03:19 -070093
94 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
95 for (const auto& [listener, callbackIds] : listenerCallbacks) {
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 }
Ady Abraham8532d012019-05-08 14:50:56 -0700958
959 virtual status_t notifyPowerHint(int32_t hintId) {
960 Parcel data, reply;
961 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
962 if (error != NO_ERROR) {
963 ALOGE("notifyPowerHint: failed to write interface token: %d", error);
964 return error;
965 }
966 error = data.writeInt32(hintId);
967 if (error != NO_ERROR) {
968 ALOGE("notifyPowerHint: failed to write hintId: %d", error);
969 return error;
970 }
971 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_HINT, data, &reply,
972 IBinder::FLAG_ONEWAY);
973 if (error != NO_ERROR) {
974 ALOGE("notifyPowerHint: failed to transact: %d", error);
975 return error;
976 }
977 return NO_ERROR;
978 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800979};
980
Dan Stozad723bd72014-11-18 10:24:03 -0800981// Out-of-line virtual method definition to trigger vtable emission in this
982// translation unit (see clang warning -Wweak-vtables)
983BpSurfaceComposer::~BpSurfaceComposer() {}
984
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800985IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
986
987// ----------------------------------------------------------------------
988
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800989status_t BnSurfaceComposer::onTransact(
990 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
991{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800992 switch(code) {
993 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700994 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800995 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800996 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700997 return NO_ERROR;
998 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700999 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001000 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001001
1002 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001003 if (count > data.dataSize()) {
1004 return BAD_VALUE;
1005 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001006 Vector<ComposerState> state;
1007 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001008 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001009 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001010 if (s.read(data) == BAD_VALUE) {
1011 return BAD_VALUE;
1012 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001013 state.add(s);
1014 }
Dan Stozad723bd72014-11-18 10:24:03 -08001015
1016 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001017 if (count > data.dataSize()) {
1018 return BAD_VALUE;
1019 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001020 DisplayState d;
1021 Vector<DisplayState> displays;
1022 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001023 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001024 if (d.read(data) == BAD_VALUE) {
1025 return BAD_VALUE;
1026 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001027 displays.add(d);
1028 }
Dan Stozad723bd72014-11-18 10:24:03 -08001029
1030 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001031 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001032 InputWindowCommands inputWindowCommands;
1033 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001034
1035 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001036
Marissa Wall947d34e2019-03-29 14:03:53 -07001037 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001038 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001039 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001040
Marissa Wall3dad52d2019-03-22 14:03:19 -07001041 std::vector<ListenerCallbacks> listenerCallbacks;
1042 int32_t listenersSize = data.readInt32();
1043 for (int32_t i = 0; i < listenersSize; i++) {
1044 auto listener =
1045 interface_cast<ITransactionCompletedListener>(data.readStrongBinder());
1046 std::vector<CallbackId> callbackIds;
1047 data.readInt64Vector(&callbackIds);
1048 listenerCallbacks.emplace_back(listener, callbackIds);
1049 }
1050
Marissa Wall17b4e452018-12-26 16:32:34 -08001051 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Marissa Wall3dad52d2019-03-22 14:03:19 -07001052 desiredPresentTime, uncachedBuffer, listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001053 return NO_ERROR;
1054 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001055 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001056 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001057 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001058 return NO_ERROR;
1059 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001060 case CAPTURE_SCREEN: {
1061 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1062 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001063 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1064 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001065 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001066 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001067 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001068 uint32_t reqWidth = data.readUint32();
1069 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001070 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001071 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001072 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001073
Robert Carr108b2c72019-04-02 16:32:58 -07001074 bool capturedSecureLayers = false;
1075 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1076 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1077 useIdentityTransform,
1078 static_cast<ISurfaceComposer::Rotation>(rotation),
1079 captureSecureLayers);
1080
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001081 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001082 if (res == NO_ERROR) {
1083 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001084 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001085 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001086 return NO_ERROR;
1087 }
chaviw93df2ea2019-04-30 16:45:12 -07001088 case CAPTURE_SCREEN_BY_ID: {
1089 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1090 uint64_t displayOrLayerStack = data.readUint64();
1091 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1092 sp<GraphicBuffer> outBuffer;
1093 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1094 reply->writeInt32(res);
1095 if (res == NO_ERROR) {
1096 reply->writeInt32(static_cast<int32_t>(outDataspace));
1097 reply->write(*outBuffer);
1098 }
1099 return NO_ERROR;
1100 }
chaviwa76b2712017-09-20 12:02:26 -07001101 case CAPTURE_LAYERS: {
1102 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1103 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001104 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1105 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001106 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001107 Rect sourceCrop(Rect::EMPTY_RECT);
1108 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001109
1110 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1111 int numExcludeHandles = data.readInt32();
1112 excludeHandles.reserve(numExcludeHandles);
1113 for (int i = 0; i < numExcludeHandles; i++) {
1114 excludeHandles.emplace(data.readStrongBinder());
1115 }
1116
chaviw7206d492017-11-10 16:16:12 -08001117 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001118 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001119
Robert Carr866455f2019-04-02 16:28:26 -07001120 status_t res =
1121 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1122 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001123 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001124 if (res == NO_ERROR) {
1125 reply->write(*outBuffer);
1126 }
chaviwa76b2712017-09-20 12:02:26 -07001127 return NO_ERROR;
1128 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001129 case AUTHENTICATE_SURFACE: {
1130 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001131 sp<IGraphicBufferProducer> bufferProducer =
1132 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1133 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001134 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001135 return NO_ERROR;
1136 }
Brian Anderson6b376712017-04-04 10:51:39 -07001137 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1138 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1139 std::vector<FrameEvent> supportedTimestamps;
1140 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1141 status_t err = reply->writeInt32(result);
1142 if (err != NO_ERROR) {
1143 return err;
1144 }
1145 if (result != NO_ERROR) {
1146 return result;
1147 }
1148
1149 std::vector<int32_t> supported;
1150 supported.reserve(supportedTimestamps.size());
1151 for (FrameEvent s : supportedTimestamps) {
1152 supported.push_back(static_cast<int32_t>(s));
1153 }
1154 return reply->writeInt32Vector(supported);
1155 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001156 case CREATE_DISPLAY_EVENT_CONNECTION: {
1157 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -07001158 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
1159 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001160 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001161 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001162 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001163 case CREATE_DISPLAY: {
1164 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001165 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001166 bool secure = bool(data.readInt32());
1167 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001168 reply->writeStrongBinder(display);
1169 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001170 }
1171 case DESTROY_DISPLAY: {
1172 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1173 sp<IBinder> display = data.readStrongBinder();
1174 destroyDisplay(display);
1175 return NO_ERROR;
1176 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001177 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001178 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001179 PhysicalDisplayId displayId = data.readUint64();
1180 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001181 reply->writeStrongBinder(display);
1182 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001183 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001184 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001185 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -07001186 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07001187 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -07001188 status_t result = getDisplayConfigs(display, &configs);
1189 reply->writeInt32(result);
1190 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001191 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001192 for (size_t c = 0; c < configs.size(); ++c) {
1193 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
1194 &configs[c], sizeof(DisplayInfo));
1195 }
1196 }
1197 return NO_ERROR;
1198 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001199 case GET_DISPLAY_STATS: {
1200 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1201 DisplayStatInfo stats;
1202 sp<IBinder> display = data.readStrongBinder();
1203 status_t result = getDisplayStats(display, &stats);
1204 reply->writeInt32(result);
1205 if (result == NO_ERROR) {
1206 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1207 &stats, sizeof(DisplayStatInfo));
1208 }
1209 return NO_ERROR;
1210 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001211 case GET_ACTIVE_CONFIG: {
1212 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1213 sp<IBinder> display = data.readStrongBinder();
1214 int id = getActiveConfig(display);
1215 reply->writeInt32(id);
1216 return NO_ERROR;
1217 }
1218 case SET_ACTIVE_CONFIG: {
1219 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1220 sp<IBinder> display = data.readStrongBinder();
1221 int id = data.readInt32();
1222 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -07001223 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001224 return NO_ERROR;
1225 }
Michael Wright28f24d02016-07-12 13:30:53 -07001226 case GET_DISPLAY_COLOR_MODES: {
1227 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001228 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001229 sp<IBinder> display = nullptr;
1230 status_t result = data.readStrongBinder(&display);
1231 if (result != NO_ERROR) {
1232 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1233 return result;
1234 }
1235 result = getDisplayColorModes(display, &colorModes);
1236 reply->writeInt32(result);
1237 if (result == NO_ERROR) {
1238 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1239 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001240 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001241 }
1242 }
1243 return NO_ERROR;
1244 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001245 case GET_DISPLAY_NATIVE_PRIMARIES: {
1246 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1247 ui::DisplayPrimaries primaries;
1248 sp<IBinder> display = nullptr;
1249
1250 status_t result = data.readStrongBinder(&display);
1251 if (result != NO_ERROR) {
1252 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1253 return result;
1254 }
1255
1256 result = getDisplayNativePrimaries(display, primaries);
1257 reply->writeInt32(result);
1258 if (result == NO_ERROR) {
1259 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1260 sizeof(ui::DisplayPrimaries));
1261 }
1262
1263 return NO_ERROR;
1264 }
Michael Wright28f24d02016-07-12 13:30:53 -07001265 case GET_ACTIVE_COLOR_MODE: {
1266 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1267 sp<IBinder> display = nullptr;
1268 status_t result = data.readStrongBinder(&display);
1269 if (result != NO_ERROR) {
1270 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1271 return result;
1272 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001273 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001274 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1275 return result;
1276 }
1277 case SET_ACTIVE_COLOR_MODE: {
1278 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1279 sp<IBinder> display = nullptr;
1280 status_t result = data.readStrongBinder(&display);
1281 if (result != NO_ERROR) {
1282 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1283 return result;
1284 }
1285 int32_t colorModeInt = 0;
1286 result = data.readInt32(&colorModeInt);
1287 if (result != NO_ERROR) {
1288 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1289 return result;
1290 }
1291 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001292 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001293 result = reply->writeInt32(result);
1294 return result;
1295 }
Svetoslavd85084b2014-03-20 10:28:31 -07001296 case CLEAR_ANIMATION_FRAME_STATS: {
1297 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1298 status_t result = clearAnimationFrameStats();
1299 reply->writeInt32(result);
1300 return NO_ERROR;
1301 }
1302 case GET_ANIMATION_FRAME_STATS: {
1303 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1304 FrameStats stats;
1305 status_t result = getAnimationFrameStats(&stats);
1306 reply->write(stats);
1307 reply->writeInt32(result);
1308 return NO_ERROR;
1309 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001310 case SET_POWER_MODE: {
1311 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1312 sp<IBinder> display = data.readStrongBinder();
1313 int32_t mode = data.readInt32();
1314 setPowerMode(display, mode);
1315 return NO_ERROR;
1316 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001317 case GET_HDR_CAPABILITIES: {
1318 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1319 sp<IBinder> display = nullptr;
1320 status_t result = data.readStrongBinder(&display);
1321 if (result != NO_ERROR) {
1322 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1323 result);
1324 return result;
1325 }
1326 HdrCapabilities capabilities;
1327 result = getHdrCapabilities(display, &capabilities);
1328 reply->writeInt32(result);
1329 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001330 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001331 }
1332 return NO_ERROR;
1333 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001334 case ENABLE_VSYNC_INJECTIONS: {
1335 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1336 bool enable = false;
1337 status_t result = data.readBool(&enable);
1338 if (result != NO_ERROR) {
1339 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1340 return result;
1341 }
1342 return enableVSyncInjections(enable);
1343 }
1344 case INJECT_VSYNC: {
1345 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1346 int64_t when = 0;
1347 status_t result = data.readInt64(&when);
1348 if (result != NO_ERROR) {
1349 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1350 return result;
1351 }
1352 return injectVSync(when);
1353 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001354 case GET_LAYER_DEBUG_INFO: {
1355 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1356 std::vector<LayerDebugInfo> outLayers;
1357 status_t result = getLayerDebugInfo(&outLayers);
1358 reply->writeInt32(result);
1359 if (result == NO_ERROR)
1360 {
1361 result = reply->writeParcelableVector(outLayers);
1362 }
1363 return result;
1364 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001365 case GET_COMPOSITION_PREFERENCE: {
1366 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001367 ui::Dataspace defaultDataspace;
1368 ui::PixelFormat defaultPixelFormat;
1369 ui::Dataspace wideColorGamutDataspace;
1370 ui::PixelFormat wideColorGamutPixelFormat;
1371 status_t error =
1372 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1373 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001374 reply->writeInt32(error);
1375 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001376 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1377 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1378 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001379 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001380 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001381 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001382 }
Ady Abraham37965d42018-11-01 13:43:32 -07001383 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001384 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001385 bool result;
1386 status_t error = getColorManagement(&result);
1387 if (error == NO_ERROR) {
1388 reply->writeBool(result);
1389 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001390 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001391 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001392 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1393 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1394
1395 sp<IBinder> display = data.readStrongBinder();
1396 ui::PixelFormat format;
1397 ui::Dataspace dataspace;
1398 uint8_t component = 0;
1399 auto result =
1400 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1401 if (result == NO_ERROR) {
1402 reply->writeUint32(static_cast<uint32_t>(format));
1403 reply->writeUint32(static_cast<uint32_t>(dataspace));
1404 reply->writeUint32(static_cast<uint32_t>(component));
1405 }
1406 return result;
1407 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001408 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1409 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1410
1411 sp<IBinder> display = nullptr;
1412 bool enable = false;
1413 int8_t componentMask = 0;
1414 uint64_t maxFrames = 0;
1415 status_t result = data.readStrongBinder(&display);
1416 if (result != NO_ERROR) {
1417 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1418 result);
1419 return result;
1420 }
1421
1422 result = data.readBool(&enable);
1423 if (result != NO_ERROR) {
1424 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1425 return result;
1426 }
1427
1428 result = data.readByte(static_cast<int8_t*>(&componentMask));
1429 if (result != NO_ERROR) {
1430 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1431 result);
1432 return result;
1433 }
1434
1435 result = data.readUint64(&maxFrames);
1436 if (result != NO_ERROR) {
1437 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1438 return result;
1439 }
1440
1441 return setDisplayContentSamplingEnabled(display, enable,
1442 static_cast<uint8_t>(componentMask), maxFrames);
1443 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001444 case GET_DISPLAYED_CONTENT_SAMPLE: {
1445 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1446
1447 sp<IBinder> display = data.readStrongBinder();
1448 uint64_t maxFrames = 0;
1449 uint64_t timestamp = 0;
1450
1451 status_t result = data.readUint64(&maxFrames);
1452 if (result != NO_ERROR) {
1453 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1454 return result;
1455 }
1456
1457 result = data.readUint64(&timestamp);
1458 if (result != NO_ERROR) {
1459 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1460 return result;
1461 }
1462
1463 DisplayedFrameStats stats;
1464 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1465 if (result == NO_ERROR) {
1466 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001467 reply->writeUint64Vector(stats.component_0_sample);
1468 reply->writeUint64Vector(stats.component_1_sample);
1469 reply->writeUint64Vector(stats.component_2_sample);
1470 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001471 }
1472 return result;
1473 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001474 case GET_PROTECTED_CONTENT_SUPPORT: {
1475 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1476 bool result;
1477 status_t error = getProtectedContentSupport(&result);
1478 if (error == NO_ERROR) {
1479 reply->writeBool(result);
1480 }
1481 return error;
1482 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001483 case IS_WIDE_COLOR_DISPLAY: {
1484 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1485 sp<IBinder> display = nullptr;
1486 status_t error = data.readStrongBinder(&display);
1487 if (error != NO_ERROR) {
1488 return error;
1489 }
1490 bool result;
1491 error = isWideColorDisplay(display, &result);
1492 if (error == NO_ERROR) {
1493 reply->writeBool(result);
1494 }
1495 return error;
1496 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001497 case GET_PHYSICAL_DISPLAY_IDS: {
1498 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1499 return reply->writeUint64Vector(getPhysicalDisplayIds());
1500 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001501 case ADD_REGION_SAMPLING_LISTENER: {
1502 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1503 Rect samplingArea;
1504 status_t result = data.read(samplingArea);
1505 if (result != NO_ERROR) {
1506 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1507 return result;
1508 }
1509 sp<IBinder> stopLayerHandle;
1510 result = data.readNullableStrongBinder(&stopLayerHandle);
1511 if (result != NO_ERROR) {
1512 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1513 return result;
1514 }
1515 sp<IRegionSamplingListener> listener;
1516 result = data.readNullableStrongBinder(&listener);
1517 if (result != NO_ERROR) {
1518 ALOGE("addRegionSamplingListener: Failed to read listener");
1519 return result;
1520 }
1521 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1522 }
1523 case REMOVE_REGION_SAMPLING_LISTENER: {
1524 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1525 sp<IRegionSamplingListener> listener;
1526 status_t result = data.readNullableStrongBinder(&listener);
1527 if (result != NO_ERROR) {
1528 ALOGE("removeRegionSamplingListener: Failed to read listener");
1529 return result;
1530 }
1531 return removeRegionSamplingListener(listener);
1532 }
Ady Abraham838de062019-02-04 10:24:03 -08001533 case SET_ALLOWED_DISPLAY_CONFIGS: {
1534 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1535 sp<IBinder> displayToken = data.readStrongBinder();
1536 std::vector<int32_t> allowedConfigs;
1537 data.readInt32Vector(&allowedConfigs);
1538 status_t result = setAllowedDisplayConfigs(displayToken, allowedConfigs);
1539 reply->writeInt32(result);
1540 return result;
1541 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001542 case GET_ALLOWED_DISPLAY_CONFIGS: {
1543 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1544 sp<IBinder> displayToken = data.readStrongBinder();
1545 std::vector<int32_t> allowedConfigs;
1546 status_t result = getAllowedDisplayConfigs(displayToken, &allowedConfigs);
1547 reply->writeInt32Vector(allowedConfigs);
1548 reply->writeInt32(result);
1549 return result;
1550 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001551 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1552 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1553 sp<IBinder> displayToken;
1554 status_t error = data.readNullableStrongBinder(&displayToken);
1555 if (error != NO_ERROR) {
1556 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1557 return error;
1558 }
1559 bool support = false;
1560 error = getDisplayBrightnessSupport(displayToken, &support);
1561 reply->writeBool(support);
1562 return error;
1563 }
1564 case SET_DISPLAY_BRIGHTNESS: {
1565 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1566 sp<IBinder> displayToken;
1567 status_t error = data.readNullableStrongBinder(&displayToken);
1568 if (error != NO_ERROR) {
1569 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1570 return error;
1571 }
1572 float brightness = -1.0f;
1573 error = data.readFloat(&brightness);
1574 if (error != NO_ERROR) {
1575 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1576 return error;
1577 }
1578 return setDisplayBrightness(displayToken, brightness);
1579 }
Ady Abraham8532d012019-05-08 14:50:56 -07001580 case NOTIFY_POWER_HINT: {
1581 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1582 int32_t hintId;
1583 status_t error = data.readInt32(&hintId);
1584 if (error != NO_ERROR) {
1585 ALOGE("notifyPowerHint: failed to read hintId: %d", error);
1586 return error;
1587 }
1588 return notifyPowerHint(hintId);
1589 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001590 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001591 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001592 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001593 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001594}
1595
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001596} // namespace android