blob: 6fd53cf47a6c5b7a3a006380f0d542ef35c2b938 [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
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080037#include <ui/DisplayConfig.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070039#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080040#include <ui/DisplayState.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070041#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Jamie Gennis134f0422011-03-08 12:18:54 -080043#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045// ---------------------------------------------------------------------------
46
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047namespace android {
48
Peiyong Lin9f034472018-03-28 15:29:00 -070049using ui::ColorMode;
50
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
52{
53public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070054 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 : BpInterface<ISurfaceComposer>(impl)
56 {
57 }
58
Dan Stozad723bd72014-11-18 10:24:03 -080059 virtual ~BpSurfaceComposer();
60
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 Parcel data, reply;
64 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
65 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070066 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 }
68
Marissa Wall713b63f2018-10-17 15:42:43 -070069 virtual void setTransactionState(const Vector<ComposerState>& state,
70 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080071 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080072 const InputWindowCommands& commands,
Marissa Wall78b72202019-03-15 14:58:34 -070073 int64_t desiredPresentTime,
Valerie Hau9dab9732019-08-20 09:29:25 -070074 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
Marissa Wall3dad52d2019-03-22 14:03:19 -070075 const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 Parcel data, reply;
77 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080078
79 data.writeUint32(static_cast<uint32_t>(state.size()));
80 for (const auto& s : state) {
81 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(static_cast<uint32_t>(displays.size()));
85 for (const auto& d : displays) {
86 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070087 }
Dan Stozad723bd72014-11-18 10:24:03 -080088
89 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070090 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080091 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080092 data.writeInt64(desiredPresentTime);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070093 data.writeStrongBinder(uncacheBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070094 data.writeUint64(uncacheBuffer.id);
Valerie Hau9dab9732019-08-20 09:29:25 -070095 data.writeBool(hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070096
97 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
98 for (const auto& [listener, callbackIds] : listenerCallbacks) {
Valerie Hau5de3ad22019-08-20 07:47:43 -070099 data.writeStrongBinder(listener);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700100 data.writeInt64Vector(callbackIds);
101 }
102 }
103
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700104 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 }
106
107 virtual void bootFinished()
108 {
109 Parcel data, reply;
110 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
111 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
112 }
113
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000114 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Dominik Laskowski718f9602019-11-09 20:01:35 -0800115 bool& outCapturedSecureLayers, ui::Dataspace reqDataspace,
116 ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700117 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Dominik Laskowski718f9602019-11-09 20:01:35 -0800118 ui::Rotation rotation, bool captureSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800119 Parcel data, reply;
120 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
121 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700122 data.writeInt32(static_cast<int32_t>(reqDataspace));
123 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700124 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800125 data.writeUint32(reqWidth);
126 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800127 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700128 data.writeInt32(static_cast<int32_t>(rotation));
Robert Carrfa8855f2019-02-19 10:05:00 -0800129 data.writeInt32(static_cast<int32_t>(captureSecureLayers));
Ana Krulec2d41e422018-07-26 12:07:43 -0700130 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
131 if (result != NO_ERROR) {
132 ALOGE("captureScreen failed to transact: %d", result);
133 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000134 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700135 result = reply.readInt32();
136 if (result != NO_ERROR) {
137 ALOGE("captureScreen failed to readInt32: %d", result);
138 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000139 }
140
141 *outBuffer = new GraphicBuffer();
142 reply.read(**outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -0700143 outCapturedSecureLayers = reply.readBool();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700144
Ana Krulec2d41e422018-07-26 12:07:43 -0700145 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800146 }
147
chaviw93df2ea2019-04-30 16:45:12 -0700148 virtual status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
149 sp<GraphicBuffer>* outBuffer) {
150 Parcel data, reply;
151 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
152 data.writeUint64(displayOrLayerStack);
153 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN_BY_ID, data, &reply);
154 if (result != NO_ERROR) {
155 ALOGE("captureScreen failed to transact: %d", result);
156 return result;
157 }
158 result = reply.readInt32();
159 if (result != NO_ERROR) {
160 ALOGE("captureScreen failed to readInt32: %d", result);
161 return result;
162 }
163
164 *outDataspace = static_cast<ui::Dataspace>(reply.readInt32());
165 *outBuffer = new GraphicBuffer();
166 reply.read(**outBuffer);
167 return result;
168 }
169
Robert Carr866455f2019-04-02 16:28:26 -0700170 virtual status_t captureLayers(
171 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
172 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
173 const Rect& sourceCrop,
174 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
175 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700176 Parcel data, reply;
177 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
178 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700179 data.writeInt32(static_cast<int32_t>(reqDataspace));
180 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800181 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700182 data.writeInt32(excludeLayers.size());
183 for (auto el : excludeLayers) {
184 data.writeStrongBinder(el);
185 }
chaviw7206d492017-11-10 16:16:12 -0800186 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800187 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700188 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
189 if (result != NO_ERROR) {
190 ALOGE("captureLayers failed to transact: %d", result);
191 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000192 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700193 result = reply.readInt32();
194 if (result != NO_ERROR) {
195 ALOGE("captureLayers failed to readInt32: %d", result);
196 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000197 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700198
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000199 *outBuffer = new GraphicBuffer();
200 reply.read(**outBuffer);
201
Ana Krulec2d41e422018-07-26 12:07:43 -0700202 return result;
chaviwa76b2712017-09-20 12:02:26 -0700203 }
204
Jamie Gennis582270d2011-08-17 18:19:00 -0700205 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800206 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800207 {
208 Parcel data, reply;
209 int err = NO_ERROR;
210 err = data.writeInterfaceToken(
211 ISurfaceComposer::getInterfaceDescriptor());
212 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000213 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800214 "interface descriptor: %s (%d)", strerror(-err), -err);
215 return false;
216 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800217 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800218 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000219 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700220 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800221 return false;
222 }
223 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
224 &reply);
225 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000226 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700227 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800228 return false;
229 }
230 int32_t result = 0;
231 err = reply.readInt32(&result);
232 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000233 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700234 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800235 return false;
236 }
237 return result != 0;
238 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800239
Brian Anderson6b376712017-04-04 10:51:39 -0700240 virtual status_t getSupportedFrameTimestamps(
241 std::vector<FrameEvent>* outSupported) const {
242 if (!outSupported) {
243 return UNEXPECTED_NULL;
244 }
245 outSupported->clear();
246
247 Parcel data, reply;
248
249 status_t err = data.writeInterfaceToken(
250 ISurfaceComposer::getInterfaceDescriptor());
251 if (err != NO_ERROR) {
252 return err;
253 }
254
255 err = remote()->transact(
256 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
257 data, &reply);
258 if (err != NO_ERROR) {
259 return err;
260 }
261
262 int32_t result = 0;
263 err = reply.readInt32(&result);
264 if (err != NO_ERROR) {
265 return err;
266 }
267 if (result != NO_ERROR) {
268 return result;
269 }
270
271 std::vector<int32_t> supported;
272 err = reply.readInt32Vector(&supported);
273 if (err != NO_ERROR) {
274 return err;
275 }
276
277 outSupported->reserve(supported.size());
278 for (int32_t s : supported) {
279 outSupported->push_back(static_cast<FrameEvent>(s));
280 }
281 return NO_ERROR;
282 }
283
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700284 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
285 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800286 Parcel data, reply;
287 sp<IDisplayEventConnection> result;
288 int err = data.writeInterfaceToken(
289 ISurfaceComposer::getInterfaceDescriptor());
290 if (err != NO_ERROR) {
291 return result;
292 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700293 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700294 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800295 err = remote()->transact(
296 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
297 data, &reply);
298 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000299 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800300 "transaction: %s (%d)", strerror(-err), -err);
301 return result;
302 }
303 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
304 return result;
305 }
Colin Cross8e533062012-06-07 13:17:52 -0700306
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700307 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700311 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700312 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700313 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
314 return reply.readStrongBinder();
315 }
316
Jesse Hall6c913be2013-08-08 12:15:49 -0700317 virtual void destroyDisplay(const sp<IBinder>& display)
318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
321 data.writeStrongBinder(display);
322 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
323 }
324
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800325 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700326 Parcel data, reply;
327 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800328 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
329 NO_ERROR) {
330 std::vector<PhysicalDisplayId> displayIds;
331 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
332 return displayIds;
333 }
334 }
335
336 return {};
337 }
338
339 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
340 Parcel data, reply;
341 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
342 data.writeUint64(displayId);
343 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700344 return reply.readStrongBinder();
345 }
346
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700347 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700348 {
349 Parcel data, reply;
350 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700351 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700352 data.writeInt32(mode);
353 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700354 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700355
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800356 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
357 Parcel data, reply;
358 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
359 data.writeStrongBinder(display);
360 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
361 const status_t result = reply.readInt32();
362 if (result == NO_ERROR) {
363 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
364 }
365 return result;
366 }
367
368 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
369 Parcel data, reply;
370 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
371 data.writeStrongBinder(display);
372 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
373 const status_t result = reply.readInt32();
374 if (result == NO_ERROR) {
375 memcpy(info, reply.readInplace(sizeof(DisplayInfo)), sizeof(DisplayInfo));
376 }
377 return result;
378 }
379
380 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700381 Parcel data, reply;
382 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700383 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700384 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800385 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700386 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800387 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700388 configs->clear();
389 configs->resize(numConfigs);
390 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800391 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
392 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700393 }
394 }
395 return result;
396 }
397
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700398 virtual status_t getDisplayStats(const sp<IBinder>& display,
399 DisplayStatInfo* stats)
400 {
401 Parcel data, reply;
402 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
403 data.writeStrongBinder(display);
404 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
405 status_t result = reply.readInt32();
406 if (result == NO_ERROR) {
407 memcpy(stats,
408 reply.readInplace(sizeof(DisplayStatInfo)),
409 sizeof(DisplayStatInfo));
410 }
411 return result;
412 }
413
Dan Stoza7f7da322014-05-02 15:26:25 -0700414 virtual int getActiveConfig(const sp<IBinder>& display)
415 {
416 Parcel data, reply;
417 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
418 data.writeStrongBinder(display);
419 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
420 return reply.readInt32();
421 }
422
Michael Wright28f24d02016-07-12 13:30:53 -0700423 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700424 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700425 Parcel data, reply;
426 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
427 if (result != NO_ERROR) {
428 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
429 return result;
430 }
431 result = data.writeStrongBinder(display);
432 if (result != NO_ERROR) {
433 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
434 return result;
435 }
436 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
437 if (result != NO_ERROR) {
438 ALOGE("getDisplayColorModes failed to transact: %d", result);
439 return result;
440 }
441 result = static_cast<status_t>(reply.readInt32());
442 if (result == NO_ERROR) {
443 size_t numModes = reply.readUint32();
444 outColorModes->clear();
445 outColorModes->resize(numModes);
446 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700447 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700448 }
449 }
450 return result;
451 }
452
Daniel Solomon42d04562019-01-20 21:03:19 -0800453 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
454 ui::DisplayPrimaries& primaries) {
455 Parcel data, reply;
456 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
457 if (result != NO_ERROR) {
458 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
459 return result;
460 }
461 result = data.writeStrongBinder(display);
462 if (result != NO_ERROR) {
463 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
464 return result;
465 }
466 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
467 if (result != NO_ERROR) {
468 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
469 return result;
470 }
471 result = reply.readInt32();
472 if (result == NO_ERROR) {
473 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
474 sizeof(ui::DisplayPrimaries));
475 }
476 return result;
477 }
478
Peiyong Lina52f0292018-03-14 17:26:31 -0700479 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700480 Parcel data, reply;
481 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
482 if (result != NO_ERROR) {
483 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700484 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700485 }
486 result = data.writeStrongBinder(display);
487 if (result != NO_ERROR) {
488 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700489 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700490 }
491 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
492 if (result != NO_ERROR) {
493 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700494 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700495 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700496 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700497 }
498
499 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700500 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700501 Parcel data, reply;
502 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
503 if (result != NO_ERROR) {
504 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
505 return result;
506 }
507 result = data.writeStrongBinder(display);
508 if (result != NO_ERROR) {
509 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
510 return result;
511 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700512 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700513 if (result != NO_ERROR) {
514 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
515 return result;
516 }
517 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
518 if (result != NO_ERROR) {
519 ALOGE("setActiveColorMode failed to transact: %d", result);
520 return result;
521 }
522 return static_cast<status_t>(reply.readInt32());
523 }
524
Galia Peycheva5492cb52019-10-30 14:13:16 +0100525 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
526 bool* outSupport) const {
527 Parcel data, reply;
528 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
529 status_t result = data.writeStrongBinder(display);
530 if (result != NO_ERROR) {
531 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
532 return result;
533 }
534 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
535 &reply);
536 if (result != NO_ERROR) {
537 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
538 return result;
539 }
540 return reply.readBool(outSupport);
541 }
542
543 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
544 Parcel data, reply;
545 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
546 if (result != NO_ERROR) {
547 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
548 return;
549 }
550
551 result = data.writeStrongBinder(display);
552 if (result != NO_ERROR) {
553 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
554 return;
555 }
556 result = data.writeBool(on);
557 if (result != NO_ERROR) {
558 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
559 return;
560 }
561 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
562 if (result != NO_ERROR) {
563 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
564 return;
565 }
566 }
567
568 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
569 Parcel data, reply;
570 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
571 status_t result = data.writeStrongBinder(display);
572 if (result != NO_ERROR) {
573 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
574 return result;
575 }
576 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
577 if (result != NO_ERROR) {
578 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
579 return result;
580 }
581 return reply.readBool(outSupport);
582 }
583
584 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
585 Parcel data, reply;
586 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
587 if (result != NO_ERROR) {
588 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
589 return;
590 }
591 result = data.writeStrongBinder(display);
592 if (result != NO_ERROR) {
593 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
594 return;
595 }
596 result = data.writeBool(on);
597 if (result != NO_ERROR) {
598 ALOGE("setGameContentType failed to writeBool: %d", result);
599 return;
600 }
601 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
602 if (result != NO_ERROR) {
603 ALOGE("setGameContentType failed to transact: %d", result);
604 }
605 }
606
Svetoslavd85084b2014-03-20 10:28:31 -0700607 virtual status_t clearAnimationFrameStats() {
608 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700609 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
610 if (result != NO_ERROR) {
611 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
612 return result;
613 }
614 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
615 if (result != NO_ERROR) {
616 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
617 return result;
618 }
Svetoslavd85084b2014-03-20 10:28:31 -0700619 return reply.readInt32();
620 }
621
622 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
623 Parcel data, reply;
624 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
625 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
626 reply.read(*outStats);
627 return reply.readInt32();
628 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700629
630 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
631 HdrCapabilities* outCapabilities) const {
632 Parcel data, reply;
633 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
634 status_t result = data.writeStrongBinder(display);
635 if (result != NO_ERROR) {
636 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
637 return result;
638 }
639 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
640 data, &reply);
641 if (result != NO_ERROR) {
642 ALOGE("getHdrCapabilities failed to transact: %d", result);
643 return result;
644 }
645 result = reply.readInt32();
646 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800647 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700648 }
649 return result;
650 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700651
652 virtual status_t enableVSyncInjections(bool enable) {
653 Parcel data, reply;
654 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
655 if (result != NO_ERROR) {
656 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
657 return result;
658 }
659 result = data.writeBool(enable);
660 if (result != NO_ERROR) {
661 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
662 return result;
663 }
Steven Moreland366eb422019-04-01 19:22:32 -0700664 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
665 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700666 if (result != NO_ERROR) {
667 ALOGE("enableVSyncInjections failed to transact: %d", result);
668 return result;
669 }
670 return result;
671 }
672
673 virtual status_t injectVSync(nsecs_t when) {
674 Parcel data, reply;
675 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
676 if (result != NO_ERROR) {
677 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
678 return result;
679 }
680 result = data.writeInt64(when);
681 if (result != NO_ERROR) {
682 ALOGE("injectVSync failed to writeInt64: %d", result);
683 return result;
684 }
Steven Moreland366eb422019-04-01 19:22:32 -0700685 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
686 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700687 if (result != NO_ERROR) {
688 ALOGE("injectVSync failed to transact: %d", result);
689 return result;
690 }
691 return result;
692 }
693
Kalle Raitaa099a242017-01-11 11:17:29 -0800694 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
695 {
696 if (!outLayers) {
697 return UNEXPECTED_NULL;
698 }
699
700 Parcel data, reply;
701
702 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
703 if (err != NO_ERROR) {
704 return err;
705 }
706
707 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
708 if (err != NO_ERROR) {
709 return err;
710 }
711
712 int32_t result = 0;
713 err = reply.readInt32(&result);
714 if (err != NO_ERROR) {
715 return err;
716 }
717 if (result != NO_ERROR) {
718 return result;
719 }
720
721 outLayers->clear();
722 return reply.readParcelableVector(outLayers);
723 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700724
Peiyong Linc6780972018-10-28 15:24:08 -0700725 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
726 ui::PixelFormat* defaultPixelFormat,
727 ui::Dataspace* wideColorGamutDataspace,
728 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700729 Parcel data, reply;
730 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
731 if (error != NO_ERROR) {
732 return error;
733 }
734 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
735 if (error != NO_ERROR) {
736 return error;
737 }
738 error = static_cast<status_t>(reply.readInt32());
739 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700740 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
741 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
742 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
743 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700744 }
745 return error;
746 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700747
Ady Abraham37965d42018-11-01 13:43:32 -0700748 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700749 Parcel data, reply;
750 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700751 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
752 bool result;
753 status_t err = reply.readBool(&result);
754 if (err == NO_ERROR) {
755 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700756 }
Ady Abraham37965d42018-11-01 13:43:32 -0700757 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700758 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700759
760 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
761 ui::PixelFormat* outFormat,
762 ui::Dataspace* outDataspace,
763 uint8_t* outComponentMask) const {
764 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
765 Parcel data, reply;
766 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
767 data.writeStrongBinder(display);
768
769 status_t error =
770 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
771 data, &reply);
772 if (error != NO_ERROR) {
773 return error;
774 }
775
776 uint32_t value = 0;
777 error = reply.readUint32(&value);
778 if (error != NO_ERROR) {
779 return error;
780 }
781 *outFormat = static_cast<ui::PixelFormat>(value);
782
783 error = reply.readUint32(&value);
784 if (error != NO_ERROR) {
785 return error;
786 }
787 *outDataspace = static_cast<ui::Dataspace>(value);
788
789 error = reply.readUint32(&value);
790 if (error != NO_ERROR) {
791 return error;
792 }
793 *outComponentMask = static_cast<uint8_t>(value);
794 return error;
795 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800796
797 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700798 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800799 Parcel data, reply;
800 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
801 data.writeStrongBinder(display);
802 data.writeBool(enable);
803 data.writeByte(static_cast<int8_t>(componentMask));
804 data.writeUint64(maxFrames);
805 status_t result =
806 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
807 &reply);
808 return result;
809 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700810
811 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
812 uint64_t timestamp,
813 DisplayedFrameStats* outStats) const {
814 if (!outStats) return BAD_VALUE;
815
816 Parcel data, reply;
817 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
818 data.writeStrongBinder(display);
819 data.writeUint64(maxFrames);
820 data.writeUint64(timestamp);
821
822 status_t result =
823 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
824
825 if (result != NO_ERROR) {
826 return result;
827 }
828
829 result = reply.readUint64(&outStats->numFrames);
830 if (result != NO_ERROR) {
831 return result;
832 }
833
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800834 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700835 if (result != NO_ERROR) {
836 return result;
837 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800838 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700839 if (result != NO_ERROR) {
840 return result;
841 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800842 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700843 if (result != NO_ERROR) {
844 return result;
845 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800846 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700847 return result;
848 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800849
850 virtual status_t getProtectedContentSupport(bool* outSupported) const {
851 Parcel data, reply;
852 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800853 status_t error =
854 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
855 if (error != NO_ERROR) {
856 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800857 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800858 error = reply.readBool(outSupported);
859 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800860 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800861
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800862 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
863 bool* outIsWideColorDisplay) const {
864 Parcel data, reply;
865 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
866 if (error != NO_ERROR) {
867 return error;
868 }
869 error = data.writeStrongBinder(token);
870 if (error != NO_ERROR) {
871 return error;
872 }
873
874 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
875 if (error != NO_ERROR) {
876 return error;
877 }
878 error = reply.readBool(outIsWideColorDisplay);
879 return error;
880 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800881
882 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
883 const sp<IBinder>& stopLayerHandle,
884 const sp<IRegionSamplingListener>& listener) {
885 Parcel data, reply;
886 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
887 if (error != NO_ERROR) {
888 ALOGE("addRegionSamplingListener: Failed to write interface token");
889 return error;
890 }
891 error = data.write(samplingArea);
892 if (error != NO_ERROR) {
893 ALOGE("addRegionSamplingListener: Failed to write sampling area");
894 return error;
895 }
896 error = data.writeStrongBinder(stopLayerHandle);
897 if (error != NO_ERROR) {
898 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
899 return error;
900 }
901 error = data.writeStrongBinder(IInterface::asBinder(listener));
902 if (error != NO_ERROR) {
903 ALOGE("addRegionSamplingListener: Failed to write listener");
904 return error;
905 }
906 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
907 if (error != NO_ERROR) {
908 ALOGE("addRegionSamplingListener: Failed to transact");
909 }
910 return error;
911 }
912
913 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
914 Parcel data, reply;
915 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
916 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800917 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800918 return error;
919 }
920 error = data.writeStrongBinder(IInterface::asBinder(listener));
921 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800922 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800923 return error;
924 }
925 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
926 &reply);
927 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800928 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800929 }
930 return error;
931 }
Ady Abraham838de062019-02-04 10:24:03 -0800932
Ana Krulec0782b882019-10-15 17:34:54 -0700933 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100934 int32_t defaultConfig, float minRefreshRate,
Ana Krulec0782b882019-10-15 17:34:54 -0700935 float maxRefreshRate) {
936 Parcel data, reply;
937 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
938 if (result != NO_ERROR) {
939 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
940 return result;
941 }
942 result = data.writeStrongBinder(displayToken);
943 if (result != NO_ERROR) {
944 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
945 return result;
946 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100947 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700948 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100949 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700950 return result;
951 }
952 result = data.writeFloat(minRefreshRate);
953 if (result != NO_ERROR) {
954 ALOGE("setDesiredDisplayConfigSpecs failed to write minRefreshRate: %d", result);
955 return result;
956 }
957 result = data.writeFloat(maxRefreshRate);
958 if (result != NO_ERROR) {
959 ALOGE("setDesiredDisplayConfigSpecs failed to write maxRefreshRate: %d", result);
960 return result;
961 }
962
963 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
964 &reply);
965 if (result != NO_ERROR) {
966 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
967 return result;
968 }
969 return reply.readInt32();
970 }
971
Ana Krulec234bb162019-11-10 22:55:55 +0100972 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100973 int32_t* outDefaultConfig,
Ana Krulec234bb162019-11-10 22:55:55 +0100974 float* outMinRefreshRate,
975 float* outMaxRefreshRate) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100976 if (!outDefaultConfig || !outMinRefreshRate || !outMaxRefreshRate) return BAD_VALUE;
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800977 Parcel data, reply;
978 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
979 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100980 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800981 return result;
982 }
983 result = data.writeStrongBinder(displayToken);
984 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100985 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800986 return result;
987 }
Ana Krulec234bb162019-11-10 22:55:55 +0100988 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
989 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800990 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100991 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800992 return result;
993 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100994 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800995 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100996 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100997 return result;
998 }
999 result = reply.readFloat(outMinRefreshRate);
1000 if (result != NO_ERROR) {
1001 ALOGE("getDesiredDisplayConfigSpecs failed to read minRefreshRate: %d", result);
1002 return result;
1003 }
1004 result = reply.readFloat(outMaxRefreshRate);
1005 if (result != NO_ERROR) {
1006 ALOGE("getDesiredDisplayConfigSpecs failed to read maxRefreshRate: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001007 return result;
1008 }
1009 return reply.readInt32();
1010 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001011
1012 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1013 bool* outSupport) const {
1014 Parcel data, reply;
1015 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1016 if (error != NO_ERROR) {
1017 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1018 return error;
1019 }
1020 error = data.writeStrongBinder(displayToken);
1021 if (error != NO_ERROR) {
1022 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1023 return error;
1024 }
1025 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1026 if (error != NO_ERROR) {
1027 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1028 return error;
1029 }
1030 bool support;
1031 error = reply.readBool(&support);
1032 if (error != NO_ERROR) {
1033 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1034 return error;
1035 }
1036 *outSupport = support;
1037 return NO_ERROR;
1038 }
1039
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001040 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001041 Parcel data, reply;
1042 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1043 if (error != NO_ERROR) {
1044 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1045 return error;
1046 }
1047 error = data.writeStrongBinder(displayToken);
1048 if (error != NO_ERROR) {
1049 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1050 return error;
1051 }
1052 error = data.writeFloat(brightness);
1053 if (error != NO_ERROR) {
1054 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1055 return error;
1056 }
1057 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1058 if (error != NO_ERROR) {
1059 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1060 return error;
1061 }
1062 return NO_ERROR;
1063 }
Ady Abraham8532d012019-05-08 14:50:56 -07001064
1065 virtual status_t notifyPowerHint(int32_t hintId) {
1066 Parcel data, reply;
1067 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1068 if (error != NO_ERROR) {
1069 ALOGE("notifyPowerHint: failed to write interface token: %d", error);
1070 return error;
1071 }
1072 error = data.writeInt32(hintId);
1073 if (error != NO_ERROR) {
1074 ALOGE("notifyPowerHint: failed to write hintId: %d", error);
1075 return error;
1076 }
1077 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_HINT, data, &reply,
1078 IBinder::FLAG_ONEWAY);
1079 if (error != NO_ERROR) {
1080 ALOGE("notifyPowerHint: failed to transact: %d", error);
1081 return error;
1082 }
1083 return NO_ERROR;
1084 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001085
1086 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1087 float lightPosY, float lightPosZ, float lightRadius) {
1088 Parcel data, reply;
1089 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1090 if (error != NO_ERROR) {
1091 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1092 return error;
1093 }
1094
1095 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1096 ambientColor.a, spotColor.r, spotColor.g,
1097 spotColor.b, spotColor.a, lightPosY,
1098 lightPosZ, lightRadius};
1099
1100 error = data.writeFloatVector(shadowConfig);
1101 if (error != NO_ERROR) {
1102 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1103 return error;
1104 }
1105
1106 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1107 IBinder::FLAG_ONEWAY);
1108 if (error != NO_ERROR) {
1109 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1110 return error;
1111 }
1112 return NO_ERROR;
1113 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001114
1115 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1116 int8_t compatibility) {
1117 Parcel data, reply;
1118 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1119 if (err != NO_ERROR) {
1120 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1121 return err;
1122 }
1123
1124 err = data.writeStrongBinder(IInterface::asBinder(surface));
1125 if (err != NO_ERROR) {
1126 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1127 return err;
1128 }
1129
1130 err = data.writeFloat(frameRate);
1131 if (err != NO_ERROR) {
1132 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1133 return err;
1134 }
1135
1136 err = data.writeByte(compatibility);
1137 if (err != NO_ERROR) {
1138 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1139 return err;
1140 }
1141
Ady Abraham60e42ea2020-03-09 19:17:31 -07001142 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001143 if (err != NO_ERROR) {
1144 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1145 return err;
1146 }
Steven Thomasd4071902020-03-24 16:02:53 -07001147
1148 return reply.readInt32();
1149 }
1150
1151 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1152 if (!outToken) return BAD_VALUE;
1153
1154 Parcel data, reply;
1155 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1156 if (err != NO_ERROR) {
1157 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1158 strerror(-err), -err);
1159 return err;
1160 }
1161
1162 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1163 &reply);
1164 if (err != NO_ERROR) {
1165 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1166 err);
1167 return err;
1168 }
1169
1170 err = reply.readInt32();
1171 if (err != NO_ERROR) {
1172 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1173 return err;
1174 }
1175
1176 err = reply.readStrongBinder(outToken);
1177 if (err != NO_ERROR) {
1178 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1179 strerror(-err), err);
1180 return err;
1181 }
1182
Steven Thomas62a4cf82020-01-31 12:04:03 -08001183 return NO_ERROR;
1184 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001185};
1186
Dan Stozad723bd72014-11-18 10:24:03 -08001187// Out-of-line virtual method definition to trigger vtable emission in this
1188// translation unit (see clang warning -Wweak-vtables)
1189BpSurfaceComposer::~BpSurfaceComposer() {}
1190
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001191IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1192
1193// ----------------------------------------------------------------------
1194
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001195status_t BnSurfaceComposer::onTransact(
1196 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1197{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001198 switch(code) {
1199 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001200 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001201 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001202 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001203 return NO_ERROR;
1204 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001205 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001206 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001207
1208 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001209 if (count > data.dataSize()) {
1210 return BAD_VALUE;
1211 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001212 Vector<ComposerState> state;
1213 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001214 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001215 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001216 if (s.read(data) == BAD_VALUE) {
1217 return BAD_VALUE;
1218 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001219 state.add(s);
1220 }
Dan Stozad723bd72014-11-18 10:24:03 -08001221
1222 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001223 if (count > data.dataSize()) {
1224 return BAD_VALUE;
1225 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001226 DisplayState d;
1227 Vector<DisplayState> displays;
1228 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001229 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001230 if (d.read(data) == BAD_VALUE) {
1231 return BAD_VALUE;
1232 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001233 displays.add(d);
1234 }
Dan Stozad723bd72014-11-18 10:24:03 -08001235
1236 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001237 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001238 InputWindowCommands inputWindowCommands;
1239 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001240
1241 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001242
Marissa Wall947d34e2019-03-29 14:03:53 -07001243 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001244 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001245 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001246
Valerie Hau9dab9732019-08-20 09:29:25 -07001247 bool hasListenerCallbacks = data.readBool();
1248
Marissa Wall3dad52d2019-03-22 14:03:19 -07001249 std::vector<ListenerCallbacks> listenerCallbacks;
1250 int32_t listenersSize = data.readInt32();
1251 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001252 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001253 std::vector<CallbackId> callbackIds;
1254 data.readInt64Vector(&callbackIds);
1255 listenerCallbacks.emplace_back(listener, callbackIds);
1256 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001257 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001258 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1259 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001260 return NO_ERROR;
1261 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001262 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001263 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001264 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001265 return NO_ERROR;
1266 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001267 case CAPTURE_SCREEN: {
1268 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1269 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001270 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1271 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001272 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001273 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001274 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001275 uint32_t reqWidth = data.readUint32();
1276 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001277 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001278 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001279 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001280
Robert Carr108b2c72019-04-02 16:32:58 -07001281 bool capturedSecureLayers = false;
1282 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1283 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
Dominik Laskowski718f9602019-11-09 20:01:35 -08001284 useIdentityTransform, ui::toRotation(rotation),
Robert Carr108b2c72019-04-02 16:32:58 -07001285 captureSecureLayers);
1286
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001287 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001288 if (res == NO_ERROR) {
1289 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001290 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001291 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001292 return NO_ERROR;
1293 }
chaviw93df2ea2019-04-30 16:45:12 -07001294 case CAPTURE_SCREEN_BY_ID: {
1295 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1296 uint64_t displayOrLayerStack = data.readUint64();
1297 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1298 sp<GraphicBuffer> outBuffer;
1299 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1300 reply->writeInt32(res);
1301 if (res == NO_ERROR) {
1302 reply->writeInt32(static_cast<int32_t>(outDataspace));
1303 reply->write(*outBuffer);
1304 }
1305 return NO_ERROR;
1306 }
chaviwa76b2712017-09-20 12:02:26 -07001307 case CAPTURE_LAYERS: {
1308 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1309 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001310 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1311 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001312 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001313 Rect sourceCrop(Rect::EMPTY_RECT);
1314 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001315
1316 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1317 int numExcludeHandles = data.readInt32();
Ady Abraham0a525092020-03-03 12:51:24 -08001318 if (numExcludeHandles >= static_cast<int>(MAX_LAYERS)) {
1319 return BAD_VALUE;
1320 }
Robert Carr866455f2019-04-02 16:28:26 -07001321 excludeHandles.reserve(numExcludeHandles);
1322 for (int i = 0; i < numExcludeHandles; i++) {
1323 excludeHandles.emplace(data.readStrongBinder());
1324 }
1325
chaviw7206d492017-11-10 16:16:12 -08001326 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001327 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001328
Robert Carr866455f2019-04-02 16:28:26 -07001329 status_t res =
1330 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1331 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001332 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001333 if (res == NO_ERROR) {
1334 reply->write(*outBuffer);
1335 }
chaviwa76b2712017-09-20 12:02:26 -07001336 return NO_ERROR;
1337 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001338 case AUTHENTICATE_SURFACE: {
1339 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001340 sp<IGraphicBufferProducer> bufferProducer =
1341 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1342 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001343 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001344 return NO_ERROR;
1345 }
Brian Anderson6b376712017-04-04 10:51:39 -07001346 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1347 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1348 std::vector<FrameEvent> supportedTimestamps;
1349 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1350 status_t err = reply->writeInt32(result);
1351 if (err != NO_ERROR) {
1352 return err;
1353 }
1354 if (result != NO_ERROR) {
1355 return result;
1356 }
1357
1358 std::vector<int32_t> supported;
1359 supported.reserve(supportedTimestamps.size());
1360 for (FrameEvent s : supportedTimestamps) {
1361 supported.push_back(static_cast<int32_t>(s));
1362 }
1363 return reply->writeInt32Vector(supported);
1364 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001365 case CREATE_DISPLAY_EVENT_CONNECTION: {
1366 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001367 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1368 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1369
1370 sp<IDisplayEventConnection> connection(
1371 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001372 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001373 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001374 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001375 case CREATE_DISPLAY: {
1376 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001377 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001378 bool secure = bool(data.readInt32());
1379 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001380 reply->writeStrongBinder(display);
1381 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001382 }
1383 case DESTROY_DISPLAY: {
1384 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1385 sp<IBinder> display = data.readStrongBinder();
1386 destroyDisplay(display);
1387 return NO_ERROR;
1388 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001389 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001390 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001391 PhysicalDisplayId displayId = data.readUint64();
1392 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001393 reply->writeStrongBinder(display);
1394 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001395 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001396 case GET_DISPLAY_STATE: {
1397 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1398 ui::DisplayState state;
1399 const sp<IBinder> display = data.readStrongBinder();
1400 const status_t result = getDisplayState(display, &state);
1401 reply->writeInt32(result);
1402 if (result == NO_ERROR) {
1403 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1404 sizeof(ui::DisplayState));
1405 }
1406 return NO_ERROR;
1407 }
1408 case GET_DISPLAY_INFO: {
1409 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1410 DisplayInfo info;
1411 const sp<IBinder> display = data.readStrongBinder();
1412 const status_t result = getDisplayInfo(display, &info);
1413 reply->writeInt32(result);
1414 if (result == NO_ERROR) {
1415 memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo));
1416 }
1417 return NO_ERROR;
1418 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001419 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001420 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001421 Vector<DisplayConfig> configs;
1422 const sp<IBinder> display = data.readStrongBinder();
1423 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001424 reply->writeInt32(result);
1425 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001426 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001427 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001428 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1429 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001430 }
1431 }
1432 return NO_ERROR;
1433 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001434 case GET_DISPLAY_STATS: {
1435 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1436 DisplayStatInfo stats;
1437 sp<IBinder> display = data.readStrongBinder();
1438 status_t result = getDisplayStats(display, &stats);
1439 reply->writeInt32(result);
1440 if (result == NO_ERROR) {
1441 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1442 &stats, sizeof(DisplayStatInfo));
1443 }
1444 return NO_ERROR;
1445 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001446 case GET_ACTIVE_CONFIG: {
1447 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1448 sp<IBinder> display = data.readStrongBinder();
1449 int id = getActiveConfig(display);
1450 reply->writeInt32(id);
1451 return NO_ERROR;
1452 }
Michael Wright28f24d02016-07-12 13:30:53 -07001453 case GET_DISPLAY_COLOR_MODES: {
1454 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001455 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001456 sp<IBinder> display = nullptr;
1457 status_t result = data.readStrongBinder(&display);
1458 if (result != NO_ERROR) {
1459 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1460 return result;
1461 }
1462 result = getDisplayColorModes(display, &colorModes);
1463 reply->writeInt32(result);
1464 if (result == NO_ERROR) {
1465 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1466 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001467 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001468 }
1469 }
1470 return NO_ERROR;
1471 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001472 case GET_DISPLAY_NATIVE_PRIMARIES: {
1473 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1474 ui::DisplayPrimaries primaries;
1475 sp<IBinder> display = nullptr;
1476
1477 status_t result = data.readStrongBinder(&display);
1478 if (result != NO_ERROR) {
1479 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1480 return result;
1481 }
1482
1483 result = getDisplayNativePrimaries(display, primaries);
1484 reply->writeInt32(result);
1485 if (result == NO_ERROR) {
1486 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1487 sizeof(ui::DisplayPrimaries));
1488 }
1489
1490 return NO_ERROR;
1491 }
Michael Wright28f24d02016-07-12 13:30:53 -07001492 case GET_ACTIVE_COLOR_MODE: {
1493 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1494 sp<IBinder> display = nullptr;
1495 status_t result = data.readStrongBinder(&display);
1496 if (result != NO_ERROR) {
1497 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1498 return result;
1499 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001500 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001501 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1502 return result;
1503 }
1504 case SET_ACTIVE_COLOR_MODE: {
1505 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1506 sp<IBinder> display = nullptr;
1507 status_t result = data.readStrongBinder(&display);
1508 if (result != NO_ERROR) {
1509 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1510 return result;
1511 }
1512 int32_t colorModeInt = 0;
1513 result = data.readInt32(&colorModeInt);
1514 if (result != NO_ERROR) {
1515 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1516 return result;
1517 }
1518 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001519 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001520 result = reply->writeInt32(result);
1521 return result;
1522 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001523
1524 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1525 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1526 sp<IBinder> display = nullptr;
1527 status_t result = data.readStrongBinder(&display);
1528 if (result != NO_ERROR) {
1529 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1530 return result;
1531 }
1532 bool supported = false;
1533 result = getAutoLowLatencyModeSupport(display, &supported);
1534 if (result == NO_ERROR) {
1535 result = reply->writeBool(supported);
1536 }
1537 return result;
1538 }
1539
1540 case SET_AUTO_LOW_LATENCY_MODE: {
1541 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1542 sp<IBinder> display = nullptr;
1543 status_t result = data.readStrongBinder(&display);
1544 if (result != NO_ERROR) {
1545 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1546 return result;
1547 }
1548 bool setAllm = false;
1549 result = data.readBool(&setAllm);
1550 if (result != NO_ERROR) {
1551 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1552 return result;
1553 }
1554 setAutoLowLatencyMode(display, setAllm);
1555 return result;
1556 }
1557
1558 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1559 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1560 sp<IBinder> display = nullptr;
1561 status_t result = data.readStrongBinder(&display);
1562 if (result != NO_ERROR) {
1563 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1564 return result;
1565 }
1566 bool supported = false;
1567 result = getGameContentTypeSupport(display, &supported);
1568 if (result == NO_ERROR) {
1569 result = reply->writeBool(supported);
1570 }
1571 return result;
1572 }
1573
1574 case SET_GAME_CONTENT_TYPE: {
1575 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1576 sp<IBinder> display = nullptr;
1577 status_t result = data.readStrongBinder(&display);
1578 if (result != NO_ERROR) {
1579 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1580 return result;
1581 }
1582 bool setGameContentTypeOn = false;
1583 result = data.readBool(&setGameContentTypeOn);
1584 if (result != NO_ERROR) {
1585 ALOGE("setGameContentType failed to readBool: %d", result);
1586 return result;
1587 }
1588 setGameContentType(display, setGameContentTypeOn);
1589 return result;
1590 }
1591
Svetoslavd85084b2014-03-20 10:28:31 -07001592 case CLEAR_ANIMATION_FRAME_STATS: {
1593 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1594 status_t result = clearAnimationFrameStats();
1595 reply->writeInt32(result);
1596 return NO_ERROR;
1597 }
1598 case GET_ANIMATION_FRAME_STATS: {
1599 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1600 FrameStats stats;
1601 status_t result = getAnimationFrameStats(&stats);
1602 reply->write(stats);
1603 reply->writeInt32(result);
1604 return NO_ERROR;
1605 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001606 case SET_POWER_MODE: {
1607 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1608 sp<IBinder> display = data.readStrongBinder();
1609 int32_t mode = data.readInt32();
1610 setPowerMode(display, mode);
1611 return NO_ERROR;
1612 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001613 case GET_HDR_CAPABILITIES: {
1614 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1615 sp<IBinder> display = nullptr;
1616 status_t result = data.readStrongBinder(&display);
1617 if (result != NO_ERROR) {
1618 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1619 result);
1620 return result;
1621 }
1622 HdrCapabilities capabilities;
1623 result = getHdrCapabilities(display, &capabilities);
1624 reply->writeInt32(result);
1625 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001626 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001627 }
1628 return NO_ERROR;
1629 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001630 case ENABLE_VSYNC_INJECTIONS: {
1631 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1632 bool enable = false;
1633 status_t result = data.readBool(&enable);
1634 if (result != NO_ERROR) {
1635 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1636 return result;
1637 }
1638 return enableVSyncInjections(enable);
1639 }
1640 case INJECT_VSYNC: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1642 int64_t when = 0;
1643 status_t result = data.readInt64(&when);
1644 if (result != NO_ERROR) {
1645 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1646 return result;
1647 }
1648 return injectVSync(when);
1649 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001650 case GET_LAYER_DEBUG_INFO: {
1651 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1652 std::vector<LayerDebugInfo> outLayers;
1653 status_t result = getLayerDebugInfo(&outLayers);
1654 reply->writeInt32(result);
1655 if (result == NO_ERROR)
1656 {
1657 result = reply->writeParcelableVector(outLayers);
1658 }
1659 return result;
1660 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001661 case GET_COMPOSITION_PREFERENCE: {
1662 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001663 ui::Dataspace defaultDataspace;
1664 ui::PixelFormat defaultPixelFormat;
1665 ui::Dataspace wideColorGamutDataspace;
1666 ui::PixelFormat wideColorGamutPixelFormat;
1667 status_t error =
1668 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1669 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001670 reply->writeInt32(error);
1671 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001672 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1673 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1674 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001675 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001676 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001677 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001678 }
Ady Abraham37965d42018-11-01 13:43:32 -07001679 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001680 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001681 bool result;
1682 status_t error = getColorManagement(&result);
1683 if (error == NO_ERROR) {
1684 reply->writeBool(result);
1685 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001686 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001687 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001688 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1690
1691 sp<IBinder> display = data.readStrongBinder();
1692 ui::PixelFormat format;
1693 ui::Dataspace dataspace;
1694 uint8_t component = 0;
1695 auto result =
1696 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1697 if (result == NO_ERROR) {
1698 reply->writeUint32(static_cast<uint32_t>(format));
1699 reply->writeUint32(static_cast<uint32_t>(dataspace));
1700 reply->writeUint32(static_cast<uint32_t>(component));
1701 }
1702 return result;
1703 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001704 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1705 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1706
1707 sp<IBinder> display = nullptr;
1708 bool enable = false;
1709 int8_t componentMask = 0;
1710 uint64_t maxFrames = 0;
1711 status_t result = data.readStrongBinder(&display);
1712 if (result != NO_ERROR) {
1713 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1714 result);
1715 return result;
1716 }
1717
1718 result = data.readBool(&enable);
1719 if (result != NO_ERROR) {
1720 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1721 return result;
1722 }
1723
1724 result = data.readByte(static_cast<int8_t*>(&componentMask));
1725 if (result != NO_ERROR) {
1726 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1727 result);
1728 return result;
1729 }
1730
1731 result = data.readUint64(&maxFrames);
1732 if (result != NO_ERROR) {
1733 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1734 return result;
1735 }
1736
1737 return setDisplayContentSamplingEnabled(display, enable,
1738 static_cast<uint8_t>(componentMask), maxFrames);
1739 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001740 case GET_DISPLAYED_CONTENT_SAMPLE: {
1741 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1742
1743 sp<IBinder> display = data.readStrongBinder();
1744 uint64_t maxFrames = 0;
1745 uint64_t timestamp = 0;
1746
1747 status_t result = data.readUint64(&maxFrames);
1748 if (result != NO_ERROR) {
1749 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1750 return result;
1751 }
1752
1753 result = data.readUint64(&timestamp);
1754 if (result != NO_ERROR) {
1755 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1756 return result;
1757 }
1758
1759 DisplayedFrameStats stats;
1760 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1761 if (result == NO_ERROR) {
1762 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001763 reply->writeUint64Vector(stats.component_0_sample);
1764 reply->writeUint64Vector(stats.component_1_sample);
1765 reply->writeUint64Vector(stats.component_2_sample);
1766 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001767 }
1768 return result;
1769 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001770 case GET_PROTECTED_CONTENT_SUPPORT: {
1771 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1772 bool result;
1773 status_t error = getProtectedContentSupport(&result);
1774 if (error == NO_ERROR) {
1775 reply->writeBool(result);
1776 }
1777 return error;
1778 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001779 case IS_WIDE_COLOR_DISPLAY: {
1780 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1781 sp<IBinder> display = nullptr;
1782 status_t error = data.readStrongBinder(&display);
1783 if (error != NO_ERROR) {
1784 return error;
1785 }
1786 bool result;
1787 error = isWideColorDisplay(display, &result);
1788 if (error == NO_ERROR) {
1789 reply->writeBool(result);
1790 }
1791 return error;
1792 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001793 case GET_PHYSICAL_DISPLAY_IDS: {
1794 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1795 return reply->writeUint64Vector(getPhysicalDisplayIds());
1796 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001797 case ADD_REGION_SAMPLING_LISTENER: {
1798 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1799 Rect samplingArea;
1800 status_t result = data.read(samplingArea);
1801 if (result != NO_ERROR) {
1802 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1803 return result;
1804 }
1805 sp<IBinder> stopLayerHandle;
1806 result = data.readNullableStrongBinder(&stopLayerHandle);
1807 if (result != NO_ERROR) {
1808 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1809 return result;
1810 }
1811 sp<IRegionSamplingListener> listener;
1812 result = data.readNullableStrongBinder(&listener);
1813 if (result != NO_ERROR) {
1814 ALOGE("addRegionSamplingListener: Failed to read listener");
1815 return result;
1816 }
1817 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1818 }
1819 case REMOVE_REGION_SAMPLING_LISTENER: {
1820 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1821 sp<IRegionSamplingListener> listener;
1822 status_t result = data.readNullableStrongBinder(&listener);
1823 if (result != NO_ERROR) {
1824 ALOGE("removeRegionSamplingListener: Failed to read listener");
1825 return result;
1826 }
1827 return removeRegionSamplingListener(listener);
1828 }
Ana Krulec0782b882019-10-15 17:34:54 -07001829 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1830 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1831 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001832 int32_t defaultConfig;
1833 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001834 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001835 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001836 return result;
1837 }
1838 float minRefreshRate;
1839 result = data.readFloat(&minRefreshRate);
1840 if (result != NO_ERROR) {
1841 ALOGE("setDesiredDisplayConfigSpecs: failed to read minRefreshRate: %d", result);
1842 return result;
1843 }
1844 float maxRefreshRate;
1845 result = data.readFloat(&maxRefreshRate);
1846 if (result != NO_ERROR) {
1847 ALOGE("setDesiredDisplayConfigSpecs: failed to read maxRefreshRate: %d", result);
1848 return result;
1849 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001850 result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, minRefreshRate,
Ana Krulec0782b882019-10-15 17:34:54 -07001851 maxRefreshRate);
1852 if (result != NO_ERROR) {
1853 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1854 "%d",
1855 result);
1856 return result;
1857 }
1858 reply->writeInt32(result);
1859 return result;
1860 }
Ana Krulec234bb162019-11-10 22:55:55 +01001861 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1862 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1863 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001864 int32_t defaultConfig;
Ana Krulec234bb162019-11-10 22:55:55 +01001865 float minRefreshRate;
1866 float maxRefreshRate;
1867
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001868 status_t result = getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
Ana Krulec234bb162019-11-10 22:55:55 +01001869 &minRefreshRate, &maxRefreshRate);
1870 if (result != NO_ERROR) {
1871 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1872 "%d",
1873 result);
1874 return result;
1875 }
1876
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001877 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001878 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001879 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001880 return result;
1881 }
1882 result = reply->writeFloat(minRefreshRate);
1883 if (result != NO_ERROR) {
1884 ALOGE("getDesiredDisplayConfigSpecs: failed to write minRefreshRate: %d", result);
1885 return result;
1886 }
1887 result = reply->writeFloat(maxRefreshRate);
1888 if (result != NO_ERROR) {
1889 ALOGE("getDesiredDisplayConfigSpecs: failed to write maxRefreshRate: %d", result);
1890 return result;
1891 }
1892 reply->writeInt32(result);
1893 return result;
1894 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001895 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1896 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1897 sp<IBinder> displayToken;
1898 status_t error = data.readNullableStrongBinder(&displayToken);
1899 if (error != NO_ERROR) {
1900 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1901 return error;
1902 }
1903 bool support = false;
1904 error = getDisplayBrightnessSupport(displayToken, &support);
1905 reply->writeBool(support);
1906 return error;
1907 }
1908 case SET_DISPLAY_BRIGHTNESS: {
1909 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1910 sp<IBinder> displayToken;
1911 status_t error = data.readNullableStrongBinder(&displayToken);
1912 if (error != NO_ERROR) {
1913 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1914 return error;
1915 }
1916 float brightness = -1.0f;
1917 error = data.readFloat(&brightness);
1918 if (error != NO_ERROR) {
1919 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1920 return error;
1921 }
1922 return setDisplayBrightness(displayToken, brightness);
1923 }
Ady Abraham8532d012019-05-08 14:50:56 -07001924 case NOTIFY_POWER_HINT: {
1925 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1926 int32_t hintId;
1927 status_t error = data.readInt32(&hintId);
1928 if (error != NO_ERROR) {
1929 ALOGE("notifyPowerHint: failed to read hintId: %d", error);
1930 return error;
1931 }
1932 return notifyPowerHint(hintId);
1933 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001934 case SET_GLOBAL_SHADOW_SETTINGS: {
1935 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1936
1937 std::vector<float> shadowConfig;
1938 status_t error = data.readFloatVector(&shadowConfig);
1939 if (error != NO_ERROR || shadowConfig.size() != 11) {
1940 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1941 return error;
1942 }
1943
1944 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1945 shadowConfig[3]};
1946 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1947 float lightPosY = shadowConfig[8];
1948 float lightPosZ = shadowConfig[9];
1949 float lightRadius = shadowConfig[10];
1950 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1951 lightRadius);
1952 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001953 case SET_FRAME_RATE: {
1954 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1955 sp<IBinder> binder;
1956 status_t err = data.readStrongBinder(&binder);
1957 if (err != NO_ERROR) {
1958 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1959 return err;
1960 }
1961 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1962 if (!surface) {
1963 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1964 strerror(-err), -err);
1965 return err;
1966 }
1967 float frameRate;
1968 err = data.readFloat(&frameRate);
1969 if (err != NO_ERROR) {
1970 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
1971 return err;
1972 }
1973 int8_t compatibility;
1974 err = data.readByte(&compatibility);
1975 if (err != NO_ERROR) {
1976 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
1977 return err;
1978 }
1979 status_t result = setFrameRate(surface, frameRate, compatibility);
1980 reply->writeInt32(result);
1981 return NO_ERROR;
1982 }
Steven Thomasd4071902020-03-24 16:02:53 -07001983 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
1984 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1985 sp<IBinder> token;
1986 status_t result = acquireFrameRateFlexibilityToken(&token);
1987 reply->writeInt32(result);
1988 if (result == NO_ERROR) {
1989 reply->writeStrongBinder(token);
1990 }
1991 return NO_ERROR;
1992 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001993 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001994 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001995 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001996 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001997}
1998
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001999} // namespace android