blob: bd4d62c4f70301abcc3309384740be792c2bb730 [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,
798 uint8_t componentMask,
799 uint64_t maxFrames) const {
800 Parcel data, reply;
801 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
802 data.writeStrongBinder(display);
803 data.writeBool(enable);
804 data.writeByte(static_cast<int8_t>(componentMask));
805 data.writeUint64(maxFrames);
806 status_t result =
807 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
808 &reply);
809 return result;
810 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700811
812 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
813 uint64_t timestamp,
814 DisplayedFrameStats* outStats) const {
815 if (!outStats) return BAD_VALUE;
816
817 Parcel data, reply;
818 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
819 data.writeStrongBinder(display);
820 data.writeUint64(maxFrames);
821 data.writeUint64(timestamp);
822
823 status_t result =
824 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
825
826 if (result != NO_ERROR) {
827 return result;
828 }
829
830 result = reply.readUint64(&outStats->numFrames);
831 if (result != NO_ERROR) {
832 return result;
833 }
834
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800835 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700836 if (result != NO_ERROR) {
837 return result;
838 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800839 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700840 if (result != NO_ERROR) {
841 return result;
842 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800843 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700844 if (result != NO_ERROR) {
845 return result;
846 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800847 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700848 return result;
849 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800850
851 virtual status_t getProtectedContentSupport(bool* outSupported) const {
852 Parcel data, reply;
853 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800854 status_t error =
855 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
856 if (error != NO_ERROR) {
857 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800858 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800859 error = reply.readBool(outSupported);
860 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800861 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800862
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800863 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
864 bool* outIsWideColorDisplay) const {
865 Parcel data, reply;
866 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
867 if (error != NO_ERROR) {
868 return error;
869 }
870 error = data.writeStrongBinder(token);
871 if (error != NO_ERROR) {
872 return error;
873 }
874
875 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
876 if (error != NO_ERROR) {
877 return error;
878 }
879 error = reply.readBool(outIsWideColorDisplay);
880 return error;
881 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800882
883 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
884 const sp<IBinder>& stopLayerHandle,
885 const sp<IRegionSamplingListener>& listener) {
886 Parcel data, reply;
887 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
888 if (error != NO_ERROR) {
889 ALOGE("addRegionSamplingListener: Failed to write interface token");
890 return error;
891 }
892 error = data.write(samplingArea);
893 if (error != NO_ERROR) {
894 ALOGE("addRegionSamplingListener: Failed to write sampling area");
895 return error;
896 }
897 error = data.writeStrongBinder(stopLayerHandle);
898 if (error != NO_ERROR) {
899 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
900 return error;
901 }
902 error = data.writeStrongBinder(IInterface::asBinder(listener));
903 if (error != NO_ERROR) {
904 ALOGE("addRegionSamplingListener: Failed to write listener");
905 return error;
906 }
907 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
908 if (error != NO_ERROR) {
909 ALOGE("addRegionSamplingListener: Failed to transact");
910 }
911 return error;
912 }
913
914 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
915 Parcel data, reply;
916 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
917 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800918 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800919 return error;
920 }
921 error = data.writeStrongBinder(IInterface::asBinder(listener));
922 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800923 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800924 return error;
925 }
926 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
927 &reply);
928 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800929 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800930 }
931 return error;
932 }
Ady Abraham838de062019-02-04 10:24:03 -0800933
Ana Krulec0782b882019-10-15 17:34:54 -0700934 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100935 int32_t defaultConfig, float minRefreshRate,
Ana Krulec0782b882019-10-15 17:34:54 -0700936 float maxRefreshRate) {
937 Parcel data, reply;
938 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
939 if (result != NO_ERROR) {
940 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
941 return result;
942 }
943 result = data.writeStrongBinder(displayToken);
944 if (result != NO_ERROR) {
945 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
946 return result;
947 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100948 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700949 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100950 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700951 return result;
952 }
953 result = data.writeFloat(minRefreshRate);
954 if (result != NO_ERROR) {
955 ALOGE("setDesiredDisplayConfigSpecs failed to write minRefreshRate: %d", result);
956 return result;
957 }
958 result = data.writeFloat(maxRefreshRate);
959 if (result != NO_ERROR) {
960 ALOGE("setDesiredDisplayConfigSpecs failed to write maxRefreshRate: %d", result);
961 return result;
962 }
963
964 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
965 &reply);
966 if (result != NO_ERROR) {
967 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
968 return result;
969 }
970 return reply.readInt32();
971 }
972
Ana Krulec234bb162019-11-10 22:55:55 +0100973 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100974 int32_t* outDefaultConfig,
Ana Krulec234bb162019-11-10 22:55:55 +0100975 float* outMinRefreshRate,
976 float* outMaxRefreshRate) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100977 if (!outDefaultConfig || !outMinRefreshRate || !outMaxRefreshRate) return BAD_VALUE;
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800978 Parcel data, reply;
979 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
980 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100981 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800982 return result;
983 }
984 result = data.writeStrongBinder(displayToken);
985 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100986 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800987 return result;
988 }
Ana Krulec234bb162019-11-10 22:55:55 +0100989 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
990 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800991 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100992 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800993 return result;
994 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100995 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800996 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100997 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100998 return result;
999 }
1000 result = reply.readFloat(outMinRefreshRate);
1001 if (result != NO_ERROR) {
1002 ALOGE("getDesiredDisplayConfigSpecs failed to read minRefreshRate: %d", result);
1003 return result;
1004 }
1005 result = reply.readFloat(outMaxRefreshRate);
1006 if (result != NO_ERROR) {
1007 ALOGE("getDesiredDisplayConfigSpecs failed to read maxRefreshRate: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001008 return result;
1009 }
1010 return reply.readInt32();
1011 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001012
1013 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1014 bool* outSupport) const {
1015 Parcel data, reply;
1016 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1017 if (error != NO_ERROR) {
1018 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1019 return error;
1020 }
1021 error = data.writeStrongBinder(displayToken);
1022 if (error != NO_ERROR) {
1023 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1024 return error;
1025 }
1026 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1027 if (error != NO_ERROR) {
1028 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1029 return error;
1030 }
1031 bool support;
1032 error = reply.readBool(&support);
1033 if (error != NO_ERROR) {
1034 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1035 return error;
1036 }
1037 *outSupport = support;
1038 return NO_ERROR;
1039 }
1040
1041 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const {
1042 Parcel data, reply;
1043 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1044 if (error != NO_ERROR) {
1045 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1046 return error;
1047 }
1048 error = data.writeStrongBinder(displayToken);
1049 if (error != NO_ERROR) {
1050 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1051 return error;
1052 }
1053 error = data.writeFloat(brightness);
1054 if (error != NO_ERROR) {
1055 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1056 return error;
1057 }
1058 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1059 if (error != NO_ERROR) {
1060 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1061 return error;
1062 }
1063 return NO_ERROR;
1064 }
Ady Abraham8532d012019-05-08 14:50:56 -07001065
1066 virtual status_t notifyPowerHint(int32_t hintId) {
1067 Parcel data, reply;
1068 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1069 if (error != NO_ERROR) {
1070 ALOGE("notifyPowerHint: failed to write interface token: %d", error);
1071 return error;
1072 }
1073 error = data.writeInt32(hintId);
1074 if (error != NO_ERROR) {
1075 ALOGE("notifyPowerHint: failed to write hintId: %d", error);
1076 return error;
1077 }
1078 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_HINT, data, &reply,
1079 IBinder::FLAG_ONEWAY);
1080 if (error != NO_ERROR) {
1081 ALOGE("notifyPowerHint: failed to transact: %d", error);
1082 return error;
1083 }
1084 return NO_ERROR;
1085 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001086
1087 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1088 float lightPosY, float lightPosZ, float lightRadius) {
1089 Parcel data, reply;
1090 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1091 if (error != NO_ERROR) {
1092 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1093 return error;
1094 }
1095
1096 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1097 ambientColor.a, spotColor.r, spotColor.g,
1098 spotColor.b, spotColor.a, lightPosY,
1099 lightPosZ, lightRadius};
1100
1101 error = data.writeFloatVector(shadowConfig);
1102 if (error != NO_ERROR) {
1103 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1104 return error;
1105 }
1106
1107 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1108 IBinder::FLAG_ONEWAY);
1109 if (error != NO_ERROR) {
1110 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1111 return error;
1112 }
1113 return NO_ERROR;
1114 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001115
1116 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1117 int8_t compatibility) {
1118 Parcel data, reply;
1119 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1120 if (err != NO_ERROR) {
1121 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1122 return err;
1123 }
1124
1125 err = data.writeStrongBinder(IInterface::asBinder(surface));
1126 if (err != NO_ERROR) {
1127 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1128 return err;
1129 }
1130
1131 err = data.writeFloat(frameRate);
1132 if (err != NO_ERROR) {
1133 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1134 return err;
1135 }
1136
1137 err = data.writeByte(compatibility);
1138 if (err != NO_ERROR) {
1139 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1140 return err;
1141 }
1142
Ady Abraham60e42ea2020-03-09 19:17:31 -07001143 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001144 if (err != NO_ERROR) {
1145 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1146 return err;
1147 }
Steven Thomasd4071902020-03-24 16:02:53 -07001148
1149 return reply.readInt32();
1150 }
1151
1152 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1153 if (!outToken) return BAD_VALUE;
1154
1155 Parcel data, reply;
1156 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1157 if (err != NO_ERROR) {
1158 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1159 strerror(-err), -err);
1160 return err;
1161 }
1162
1163 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1164 &reply);
1165 if (err != NO_ERROR) {
1166 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1167 err);
1168 return err;
1169 }
1170
1171 err = reply.readInt32();
1172 if (err != NO_ERROR) {
1173 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1174 return err;
1175 }
1176
1177 err = reply.readStrongBinder(outToken);
1178 if (err != NO_ERROR) {
1179 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1180 strerror(-err), err);
1181 return err;
1182 }
1183
Steven Thomas62a4cf82020-01-31 12:04:03 -08001184 return NO_ERROR;
1185 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001186};
1187
Dan Stozad723bd72014-11-18 10:24:03 -08001188// Out-of-line virtual method definition to trigger vtable emission in this
1189// translation unit (see clang warning -Wweak-vtables)
1190BpSurfaceComposer::~BpSurfaceComposer() {}
1191
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001192IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1193
1194// ----------------------------------------------------------------------
1195
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001196status_t BnSurfaceComposer::onTransact(
1197 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1198{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001199 switch(code) {
1200 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001201 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001202 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001203 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001204 return NO_ERROR;
1205 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001206 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001207 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001208
1209 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001210 if (count > data.dataSize()) {
1211 return BAD_VALUE;
1212 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001213 Vector<ComposerState> state;
1214 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001215 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001216 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001217 if (s.read(data) == BAD_VALUE) {
1218 return BAD_VALUE;
1219 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001220 state.add(s);
1221 }
Dan Stozad723bd72014-11-18 10:24:03 -08001222
1223 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001224 if (count > data.dataSize()) {
1225 return BAD_VALUE;
1226 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001227 DisplayState d;
1228 Vector<DisplayState> displays;
1229 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001230 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001231 if (d.read(data) == BAD_VALUE) {
1232 return BAD_VALUE;
1233 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001234 displays.add(d);
1235 }
Dan Stozad723bd72014-11-18 10:24:03 -08001236
1237 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001238 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001239 InputWindowCommands inputWindowCommands;
1240 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001241
1242 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001243
Marissa Wall947d34e2019-03-29 14:03:53 -07001244 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001245 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001246 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001247
Valerie Hau9dab9732019-08-20 09:29:25 -07001248 bool hasListenerCallbacks = data.readBool();
1249
Marissa Wall3dad52d2019-03-22 14:03:19 -07001250 std::vector<ListenerCallbacks> listenerCallbacks;
1251 int32_t listenersSize = data.readInt32();
1252 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001253 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001254 std::vector<CallbackId> callbackIds;
1255 data.readInt64Vector(&callbackIds);
1256 listenerCallbacks.emplace_back(listener, callbackIds);
1257 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001258 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001259 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1260 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001261 return NO_ERROR;
1262 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001263 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001264 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001265 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001266 return NO_ERROR;
1267 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001268 case CAPTURE_SCREEN: {
1269 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1270 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001271 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1272 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001273 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001274 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001275 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001276 uint32_t reqWidth = data.readUint32();
1277 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001278 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001279 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001280 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001281
Robert Carr108b2c72019-04-02 16:32:58 -07001282 bool capturedSecureLayers = false;
1283 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1284 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
Dominik Laskowski718f9602019-11-09 20:01:35 -08001285 useIdentityTransform, ui::toRotation(rotation),
Robert Carr108b2c72019-04-02 16:32:58 -07001286 captureSecureLayers);
1287
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001288 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001289 if (res == NO_ERROR) {
1290 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001291 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001292 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001293 return NO_ERROR;
1294 }
chaviw93df2ea2019-04-30 16:45:12 -07001295 case CAPTURE_SCREEN_BY_ID: {
1296 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1297 uint64_t displayOrLayerStack = data.readUint64();
1298 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1299 sp<GraphicBuffer> outBuffer;
1300 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1301 reply->writeInt32(res);
1302 if (res == NO_ERROR) {
1303 reply->writeInt32(static_cast<int32_t>(outDataspace));
1304 reply->write(*outBuffer);
1305 }
1306 return NO_ERROR;
1307 }
chaviwa76b2712017-09-20 12:02:26 -07001308 case CAPTURE_LAYERS: {
1309 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1310 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001311 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1312 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001313 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001314 Rect sourceCrop(Rect::EMPTY_RECT);
1315 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001316
1317 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1318 int numExcludeHandles = data.readInt32();
Ady Abraham0a525092020-03-03 12:51:24 -08001319 if (numExcludeHandles >= static_cast<int>(MAX_LAYERS)) {
1320 return BAD_VALUE;
1321 }
Robert Carr866455f2019-04-02 16:28:26 -07001322 excludeHandles.reserve(numExcludeHandles);
1323 for (int i = 0; i < numExcludeHandles; i++) {
1324 excludeHandles.emplace(data.readStrongBinder());
1325 }
1326
chaviw7206d492017-11-10 16:16:12 -08001327 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001328 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001329
Robert Carr866455f2019-04-02 16:28:26 -07001330 status_t res =
1331 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1332 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001333 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001334 if (res == NO_ERROR) {
1335 reply->write(*outBuffer);
1336 }
chaviwa76b2712017-09-20 12:02:26 -07001337 return NO_ERROR;
1338 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001339 case AUTHENTICATE_SURFACE: {
1340 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001341 sp<IGraphicBufferProducer> bufferProducer =
1342 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1343 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001344 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001345 return NO_ERROR;
1346 }
Brian Anderson6b376712017-04-04 10:51:39 -07001347 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1348 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1349 std::vector<FrameEvent> supportedTimestamps;
1350 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1351 status_t err = reply->writeInt32(result);
1352 if (err != NO_ERROR) {
1353 return err;
1354 }
1355 if (result != NO_ERROR) {
1356 return result;
1357 }
1358
1359 std::vector<int32_t> supported;
1360 supported.reserve(supportedTimestamps.size());
1361 for (FrameEvent s : supportedTimestamps) {
1362 supported.push_back(static_cast<int32_t>(s));
1363 }
1364 return reply->writeInt32Vector(supported);
1365 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001366 case CREATE_DISPLAY_EVENT_CONNECTION: {
1367 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001368 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1369 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1370
1371 sp<IDisplayEventConnection> connection(
1372 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001373 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001374 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001375 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001376 case CREATE_DISPLAY: {
1377 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001378 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001379 bool secure = bool(data.readInt32());
1380 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001381 reply->writeStrongBinder(display);
1382 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001383 }
1384 case DESTROY_DISPLAY: {
1385 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1386 sp<IBinder> display = data.readStrongBinder();
1387 destroyDisplay(display);
1388 return NO_ERROR;
1389 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001390 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001391 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001392 PhysicalDisplayId displayId = data.readUint64();
1393 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001394 reply->writeStrongBinder(display);
1395 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001396 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001397 case GET_DISPLAY_STATE: {
1398 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1399 ui::DisplayState state;
1400 const sp<IBinder> display = data.readStrongBinder();
1401 const status_t result = getDisplayState(display, &state);
1402 reply->writeInt32(result);
1403 if (result == NO_ERROR) {
1404 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1405 sizeof(ui::DisplayState));
1406 }
1407 return NO_ERROR;
1408 }
1409 case GET_DISPLAY_INFO: {
1410 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1411 DisplayInfo info;
1412 const sp<IBinder> display = data.readStrongBinder();
1413 const status_t result = getDisplayInfo(display, &info);
1414 reply->writeInt32(result);
1415 if (result == NO_ERROR) {
1416 memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo));
1417 }
1418 return NO_ERROR;
1419 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001420 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001421 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001422 Vector<DisplayConfig> configs;
1423 const sp<IBinder> display = data.readStrongBinder();
1424 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001425 reply->writeInt32(result);
1426 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001427 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001428 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001429 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1430 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001431 }
1432 }
1433 return NO_ERROR;
1434 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001435 case GET_DISPLAY_STATS: {
1436 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1437 DisplayStatInfo stats;
1438 sp<IBinder> display = data.readStrongBinder();
1439 status_t result = getDisplayStats(display, &stats);
1440 reply->writeInt32(result);
1441 if (result == NO_ERROR) {
1442 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1443 &stats, sizeof(DisplayStatInfo));
1444 }
1445 return NO_ERROR;
1446 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001447 case GET_ACTIVE_CONFIG: {
1448 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1449 sp<IBinder> display = data.readStrongBinder();
1450 int id = getActiveConfig(display);
1451 reply->writeInt32(id);
1452 return NO_ERROR;
1453 }
Michael Wright28f24d02016-07-12 13:30:53 -07001454 case GET_DISPLAY_COLOR_MODES: {
1455 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001456 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001457 sp<IBinder> display = nullptr;
1458 status_t result = data.readStrongBinder(&display);
1459 if (result != NO_ERROR) {
1460 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1461 return result;
1462 }
1463 result = getDisplayColorModes(display, &colorModes);
1464 reply->writeInt32(result);
1465 if (result == NO_ERROR) {
1466 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1467 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001468 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001469 }
1470 }
1471 return NO_ERROR;
1472 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001473 case GET_DISPLAY_NATIVE_PRIMARIES: {
1474 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1475 ui::DisplayPrimaries primaries;
1476 sp<IBinder> display = nullptr;
1477
1478 status_t result = data.readStrongBinder(&display);
1479 if (result != NO_ERROR) {
1480 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1481 return result;
1482 }
1483
1484 result = getDisplayNativePrimaries(display, primaries);
1485 reply->writeInt32(result);
1486 if (result == NO_ERROR) {
1487 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1488 sizeof(ui::DisplayPrimaries));
1489 }
1490
1491 return NO_ERROR;
1492 }
Michael Wright28f24d02016-07-12 13:30:53 -07001493 case GET_ACTIVE_COLOR_MODE: {
1494 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1495 sp<IBinder> display = nullptr;
1496 status_t result = data.readStrongBinder(&display);
1497 if (result != NO_ERROR) {
1498 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1499 return result;
1500 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001501 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001502 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1503 return result;
1504 }
1505 case SET_ACTIVE_COLOR_MODE: {
1506 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1507 sp<IBinder> display = nullptr;
1508 status_t result = data.readStrongBinder(&display);
1509 if (result != NO_ERROR) {
1510 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1511 return result;
1512 }
1513 int32_t colorModeInt = 0;
1514 result = data.readInt32(&colorModeInt);
1515 if (result != NO_ERROR) {
1516 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1517 return result;
1518 }
1519 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001520 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001521 result = reply->writeInt32(result);
1522 return result;
1523 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001524
1525 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1526 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1527 sp<IBinder> display = nullptr;
1528 status_t result = data.readStrongBinder(&display);
1529 if (result != NO_ERROR) {
1530 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1531 return result;
1532 }
1533 bool supported = false;
1534 result = getAutoLowLatencyModeSupport(display, &supported);
1535 if (result == NO_ERROR) {
1536 result = reply->writeBool(supported);
1537 }
1538 return result;
1539 }
1540
1541 case SET_AUTO_LOW_LATENCY_MODE: {
1542 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1543 sp<IBinder> display = nullptr;
1544 status_t result = data.readStrongBinder(&display);
1545 if (result != NO_ERROR) {
1546 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1547 return result;
1548 }
1549 bool setAllm = false;
1550 result = data.readBool(&setAllm);
1551 if (result != NO_ERROR) {
1552 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1553 return result;
1554 }
1555 setAutoLowLatencyMode(display, setAllm);
1556 return result;
1557 }
1558
1559 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1560 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1561 sp<IBinder> display = nullptr;
1562 status_t result = data.readStrongBinder(&display);
1563 if (result != NO_ERROR) {
1564 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1565 return result;
1566 }
1567 bool supported = false;
1568 result = getGameContentTypeSupport(display, &supported);
1569 if (result == NO_ERROR) {
1570 result = reply->writeBool(supported);
1571 }
1572 return result;
1573 }
1574
1575 case SET_GAME_CONTENT_TYPE: {
1576 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1577 sp<IBinder> display = nullptr;
1578 status_t result = data.readStrongBinder(&display);
1579 if (result != NO_ERROR) {
1580 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1581 return result;
1582 }
1583 bool setGameContentTypeOn = false;
1584 result = data.readBool(&setGameContentTypeOn);
1585 if (result != NO_ERROR) {
1586 ALOGE("setGameContentType failed to readBool: %d", result);
1587 return result;
1588 }
1589 setGameContentType(display, setGameContentTypeOn);
1590 return result;
1591 }
1592
Svetoslavd85084b2014-03-20 10:28:31 -07001593 case CLEAR_ANIMATION_FRAME_STATS: {
1594 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1595 status_t result = clearAnimationFrameStats();
1596 reply->writeInt32(result);
1597 return NO_ERROR;
1598 }
1599 case GET_ANIMATION_FRAME_STATS: {
1600 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1601 FrameStats stats;
1602 status_t result = getAnimationFrameStats(&stats);
1603 reply->write(stats);
1604 reply->writeInt32(result);
1605 return NO_ERROR;
1606 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001607 case SET_POWER_MODE: {
1608 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1609 sp<IBinder> display = data.readStrongBinder();
1610 int32_t mode = data.readInt32();
1611 setPowerMode(display, mode);
1612 return NO_ERROR;
1613 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001614 case GET_HDR_CAPABILITIES: {
1615 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1616 sp<IBinder> display = nullptr;
1617 status_t result = data.readStrongBinder(&display);
1618 if (result != NO_ERROR) {
1619 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1620 result);
1621 return result;
1622 }
1623 HdrCapabilities capabilities;
1624 result = getHdrCapabilities(display, &capabilities);
1625 reply->writeInt32(result);
1626 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001627 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001628 }
1629 return NO_ERROR;
1630 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001631 case ENABLE_VSYNC_INJECTIONS: {
1632 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1633 bool enable = false;
1634 status_t result = data.readBool(&enable);
1635 if (result != NO_ERROR) {
1636 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1637 return result;
1638 }
1639 return enableVSyncInjections(enable);
1640 }
1641 case INJECT_VSYNC: {
1642 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1643 int64_t when = 0;
1644 status_t result = data.readInt64(&when);
1645 if (result != NO_ERROR) {
1646 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1647 return result;
1648 }
1649 return injectVSync(when);
1650 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001651 case GET_LAYER_DEBUG_INFO: {
1652 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1653 std::vector<LayerDebugInfo> outLayers;
1654 status_t result = getLayerDebugInfo(&outLayers);
1655 reply->writeInt32(result);
1656 if (result == NO_ERROR)
1657 {
1658 result = reply->writeParcelableVector(outLayers);
1659 }
1660 return result;
1661 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001662 case GET_COMPOSITION_PREFERENCE: {
1663 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001664 ui::Dataspace defaultDataspace;
1665 ui::PixelFormat defaultPixelFormat;
1666 ui::Dataspace wideColorGamutDataspace;
1667 ui::PixelFormat wideColorGamutPixelFormat;
1668 status_t error =
1669 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1670 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001671 reply->writeInt32(error);
1672 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001673 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1674 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1675 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001676 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001677 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001678 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001679 }
Ady Abraham37965d42018-11-01 13:43:32 -07001680 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001681 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001682 bool result;
1683 status_t error = getColorManagement(&result);
1684 if (error == NO_ERROR) {
1685 reply->writeBool(result);
1686 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001687 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001688 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001689 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1690 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1691
1692 sp<IBinder> display = data.readStrongBinder();
1693 ui::PixelFormat format;
1694 ui::Dataspace dataspace;
1695 uint8_t component = 0;
1696 auto result =
1697 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1698 if (result == NO_ERROR) {
1699 reply->writeUint32(static_cast<uint32_t>(format));
1700 reply->writeUint32(static_cast<uint32_t>(dataspace));
1701 reply->writeUint32(static_cast<uint32_t>(component));
1702 }
1703 return result;
1704 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001705 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1706 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1707
1708 sp<IBinder> display = nullptr;
1709 bool enable = false;
1710 int8_t componentMask = 0;
1711 uint64_t maxFrames = 0;
1712 status_t result = data.readStrongBinder(&display);
1713 if (result != NO_ERROR) {
1714 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1715 result);
1716 return result;
1717 }
1718
1719 result = data.readBool(&enable);
1720 if (result != NO_ERROR) {
1721 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1722 return result;
1723 }
1724
1725 result = data.readByte(static_cast<int8_t*>(&componentMask));
1726 if (result != NO_ERROR) {
1727 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1728 result);
1729 return result;
1730 }
1731
1732 result = data.readUint64(&maxFrames);
1733 if (result != NO_ERROR) {
1734 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1735 return result;
1736 }
1737
1738 return setDisplayContentSamplingEnabled(display, enable,
1739 static_cast<uint8_t>(componentMask), maxFrames);
1740 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001741 case GET_DISPLAYED_CONTENT_SAMPLE: {
1742 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1743
1744 sp<IBinder> display = data.readStrongBinder();
1745 uint64_t maxFrames = 0;
1746 uint64_t timestamp = 0;
1747
1748 status_t result = data.readUint64(&maxFrames);
1749 if (result != NO_ERROR) {
1750 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1751 return result;
1752 }
1753
1754 result = data.readUint64(&timestamp);
1755 if (result != NO_ERROR) {
1756 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1757 return result;
1758 }
1759
1760 DisplayedFrameStats stats;
1761 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1762 if (result == NO_ERROR) {
1763 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001764 reply->writeUint64Vector(stats.component_0_sample);
1765 reply->writeUint64Vector(stats.component_1_sample);
1766 reply->writeUint64Vector(stats.component_2_sample);
1767 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001768 }
1769 return result;
1770 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001771 case GET_PROTECTED_CONTENT_SUPPORT: {
1772 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1773 bool result;
1774 status_t error = getProtectedContentSupport(&result);
1775 if (error == NO_ERROR) {
1776 reply->writeBool(result);
1777 }
1778 return error;
1779 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001780 case IS_WIDE_COLOR_DISPLAY: {
1781 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1782 sp<IBinder> display = nullptr;
1783 status_t error = data.readStrongBinder(&display);
1784 if (error != NO_ERROR) {
1785 return error;
1786 }
1787 bool result;
1788 error = isWideColorDisplay(display, &result);
1789 if (error == NO_ERROR) {
1790 reply->writeBool(result);
1791 }
1792 return error;
1793 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001794 case GET_PHYSICAL_DISPLAY_IDS: {
1795 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1796 return reply->writeUint64Vector(getPhysicalDisplayIds());
1797 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001798 case ADD_REGION_SAMPLING_LISTENER: {
1799 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1800 Rect samplingArea;
1801 status_t result = data.read(samplingArea);
1802 if (result != NO_ERROR) {
1803 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1804 return result;
1805 }
1806 sp<IBinder> stopLayerHandle;
1807 result = data.readNullableStrongBinder(&stopLayerHandle);
1808 if (result != NO_ERROR) {
1809 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1810 return result;
1811 }
1812 sp<IRegionSamplingListener> listener;
1813 result = data.readNullableStrongBinder(&listener);
1814 if (result != NO_ERROR) {
1815 ALOGE("addRegionSamplingListener: Failed to read listener");
1816 return result;
1817 }
1818 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1819 }
1820 case REMOVE_REGION_SAMPLING_LISTENER: {
1821 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1822 sp<IRegionSamplingListener> listener;
1823 status_t result = data.readNullableStrongBinder(&listener);
1824 if (result != NO_ERROR) {
1825 ALOGE("removeRegionSamplingListener: Failed to read listener");
1826 return result;
1827 }
1828 return removeRegionSamplingListener(listener);
1829 }
Ana Krulec0782b882019-10-15 17:34:54 -07001830 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1831 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1832 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001833 int32_t defaultConfig;
1834 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001835 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001836 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001837 return result;
1838 }
1839 float minRefreshRate;
1840 result = data.readFloat(&minRefreshRate);
1841 if (result != NO_ERROR) {
1842 ALOGE("setDesiredDisplayConfigSpecs: failed to read minRefreshRate: %d", result);
1843 return result;
1844 }
1845 float maxRefreshRate;
1846 result = data.readFloat(&maxRefreshRate);
1847 if (result != NO_ERROR) {
1848 ALOGE("setDesiredDisplayConfigSpecs: failed to read maxRefreshRate: %d", result);
1849 return result;
1850 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001851 result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, minRefreshRate,
Ana Krulec0782b882019-10-15 17:34:54 -07001852 maxRefreshRate);
1853 if (result != NO_ERROR) {
1854 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1855 "%d",
1856 result);
1857 return result;
1858 }
1859 reply->writeInt32(result);
1860 return result;
1861 }
Ana Krulec234bb162019-11-10 22:55:55 +01001862 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1863 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1864 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001865 int32_t defaultConfig;
Ana Krulec234bb162019-11-10 22:55:55 +01001866 float minRefreshRate;
1867 float maxRefreshRate;
1868
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001869 status_t result = getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
Ana Krulec234bb162019-11-10 22:55:55 +01001870 &minRefreshRate, &maxRefreshRate);
1871 if (result != NO_ERROR) {
1872 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1873 "%d",
1874 result);
1875 return result;
1876 }
1877
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001878 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001879 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001880 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001881 return result;
1882 }
1883 result = reply->writeFloat(minRefreshRate);
1884 if (result != NO_ERROR) {
1885 ALOGE("getDesiredDisplayConfigSpecs: failed to write minRefreshRate: %d", result);
1886 return result;
1887 }
1888 result = reply->writeFloat(maxRefreshRate);
1889 if (result != NO_ERROR) {
1890 ALOGE("getDesiredDisplayConfigSpecs: failed to write maxRefreshRate: %d", result);
1891 return result;
1892 }
1893 reply->writeInt32(result);
1894 return result;
1895 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001896 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1897 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1898 sp<IBinder> displayToken;
1899 status_t error = data.readNullableStrongBinder(&displayToken);
1900 if (error != NO_ERROR) {
1901 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1902 return error;
1903 }
1904 bool support = false;
1905 error = getDisplayBrightnessSupport(displayToken, &support);
1906 reply->writeBool(support);
1907 return error;
1908 }
1909 case SET_DISPLAY_BRIGHTNESS: {
1910 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1911 sp<IBinder> displayToken;
1912 status_t error = data.readNullableStrongBinder(&displayToken);
1913 if (error != NO_ERROR) {
1914 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1915 return error;
1916 }
1917 float brightness = -1.0f;
1918 error = data.readFloat(&brightness);
1919 if (error != NO_ERROR) {
1920 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1921 return error;
1922 }
1923 return setDisplayBrightness(displayToken, brightness);
1924 }
Ady Abraham8532d012019-05-08 14:50:56 -07001925 case NOTIFY_POWER_HINT: {
1926 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1927 int32_t hintId;
1928 status_t error = data.readInt32(&hintId);
1929 if (error != NO_ERROR) {
1930 ALOGE("notifyPowerHint: failed to read hintId: %d", error);
1931 return error;
1932 }
1933 return notifyPowerHint(hintId);
1934 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001935 case SET_GLOBAL_SHADOW_SETTINGS: {
1936 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1937
1938 std::vector<float> shadowConfig;
1939 status_t error = data.readFloatVector(&shadowConfig);
1940 if (error != NO_ERROR || shadowConfig.size() != 11) {
1941 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1942 return error;
1943 }
1944
1945 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1946 shadowConfig[3]};
1947 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1948 float lightPosY = shadowConfig[8];
1949 float lightPosZ = shadowConfig[9];
1950 float lightRadius = shadowConfig[10];
1951 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1952 lightRadius);
1953 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001954 case SET_FRAME_RATE: {
1955 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1956 sp<IBinder> binder;
1957 status_t err = data.readStrongBinder(&binder);
1958 if (err != NO_ERROR) {
1959 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1960 return err;
1961 }
1962 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1963 if (!surface) {
1964 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1965 strerror(-err), -err);
1966 return err;
1967 }
1968 float frameRate;
1969 err = data.readFloat(&frameRate);
1970 if (err != NO_ERROR) {
1971 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
1972 return err;
1973 }
1974 int8_t compatibility;
1975 err = data.readByte(&compatibility);
1976 if (err != NO_ERROR) {
1977 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
1978 return err;
1979 }
1980 status_t result = setFrameRate(surface, frameRate, compatibility);
1981 reply->writeInt32(result);
1982 return NO_ERROR;
1983 }
Steven Thomasd4071902020-03-24 16:02:53 -07001984 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
1985 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1986 sp<IBinder> token;
1987 status_t result = acquireFrameRateFlexibilityToken(&token);
1988 reply->writeInt32(result);
1989 if (result == NO_ERROR) {
1990 reply->writeStrongBinder(token);
1991 }
1992 return NO_ERROR;
1993 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001994 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001995 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001996 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001997 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001998}
1999
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002000} // namespace android