blob: 6881be3e77461f3d9a0c6d84ffe384503a98ee1c [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();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100374 if (result != NO_ERROR) return result;
375 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800376 }
377
378 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700379 Parcel data, reply;
380 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700381 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700382 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800383 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700384 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800385 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700386 configs->clear();
387 configs->resize(numConfigs);
388 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800389 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
390 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700391 }
392 }
393 return result;
394 }
395
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700396 virtual status_t getDisplayStats(const sp<IBinder>& display,
397 DisplayStatInfo* stats)
398 {
399 Parcel data, reply;
400 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
401 data.writeStrongBinder(display);
402 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
403 status_t result = reply.readInt32();
404 if (result == NO_ERROR) {
405 memcpy(stats,
406 reply.readInplace(sizeof(DisplayStatInfo)),
407 sizeof(DisplayStatInfo));
408 }
409 return result;
410 }
411
Dan Stoza7f7da322014-05-02 15:26:25 -0700412 virtual int getActiveConfig(const sp<IBinder>& display)
413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
416 data.writeStrongBinder(display);
417 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
418 return reply.readInt32();
419 }
420
Michael Wright28f24d02016-07-12 13:30:53 -0700421 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700422 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700423 Parcel data, reply;
424 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
425 if (result != NO_ERROR) {
426 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
427 return result;
428 }
429 result = data.writeStrongBinder(display);
430 if (result != NO_ERROR) {
431 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
432 return result;
433 }
434 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
435 if (result != NO_ERROR) {
436 ALOGE("getDisplayColorModes failed to transact: %d", result);
437 return result;
438 }
439 result = static_cast<status_t>(reply.readInt32());
440 if (result == NO_ERROR) {
441 size_t numModes = reply.readUint32();
442 outColorModes->clear();
443 outColorModes->resize(numModes);
444 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700445 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700446 }
447 }
448 return result;
449 }
450
Daniel Solomon42d04562019-01-20 21:03:19 -0800451 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
452 ui::DisplayPrimaries& primaries) {
453 Parcel data, reply;
454 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
455 if (result != NO_ERROR) {
456 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
457 return result;
458 }
459 result = data.writeStrongBinder(display);
460 if (result != NO_ERROR) {
461 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
462 return result;
463 }
464 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
465 if (result != NO_ERROR) {
466 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
467 return result;
468 }
469 result = reply.readInt32();
470 if (result == NO_ERROR) {
471 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
472 sizeof(ui::DisplayPrimaries));
473 }
474 return result;
475 }
476
Peiyong Lina52f0292018-03-14 17:26:31 -0700477 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700478 Parcel data, reply;
479 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
480 if (result != NO_ERROR) {
481 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700482 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700483 }
484 result = data.writeStrongBinder(display);
485 if (result != NO_ERROR) {
486 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700487 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700488 }
489 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
490 if (result != NO_ERROR) {
491 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700492 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700493 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700494 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700495 }
496
497 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700498 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700499 Parcel data, reply;
500 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
501 if (result != NO_ERROR) {
502 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
503 return result;
504 }
505 result = data.writeStrongBinder(display);
506 if (result != NO_ERROR) {
507 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
508 return result;
509 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700510 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700511 if (result != NO_ERROR) {
512 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
513 return result;
514 }
515 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
516 if (result != NO_ERROR) {
517 ALOGE("setActiveColorMode failed to transact: %d", result);
518 return result;
519 }
520 return static_cast<status_t>(reply.readInt32());
521 }
522
Galia Peycheva5492cb52019-10-30 14:13:16 +0100523 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
524 bool* outSupport) const {
525 Parcel data, reply;
526 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
527 status_t result = data.writeStrongBinder(display);
528 if (result != NO_ERROR) {
529 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
530 return result;
531 }
532 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
533 &reply);
534 if (result != NO_ERROR) {
535 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
536 return result;
537 }
538 return reply.readBool(outSupport);
539 }
540
541 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
542 Parcel data, reply;
543 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
544 if (result != NO_ERROR) {
545 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
546 return;
547 }
548
549 result = data.writeStrongBinder(display);
550 if (result != NO_ERROR) {
551 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
552 return;
553 }
554 result = data.writeBool(on);
555 if (result != NO_ERROR) {
556 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
557 return;
558 }
559 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
560 if (result != NO_ERROR) {
561 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
562 return;
563 }
564 }
565
566 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
567 Parcel data, reply;
568 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
569 status_t result = data.writeStrongBinder(display);
570 if (result != NO_ERROR) {
571 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
572 return result;
573 }
574 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
575 if (result != NO_ERROR) {
576 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
577 return result;
578 }
579 return reply.readBool(outSupport);
580 }
581
582 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
583 Parcel data, reply;
584 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
585 if (result != NO_ERROR) {
586 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
587 return;
588 }
589 result = data.writeStrongBinder(display);
590 if (result != NO_ERROR) {
591 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
592 return;
593 }
594 result = data.writeBool(on);
595 if (result != NO_ERROR) {
596 ALOGE("setGameContentType failed to writeBool: %d", result);
597 return;
598 }
599 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
600 if (result != NO_ERROR) {
601 ALOGE("setGameContentType failed to transact: %d", result);
602 }
603 }
604
Svetoslavd85084b2014-03-20 10:28:31 -0700605 virtual status_t clearAnimationFrameStats() {
606 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700607 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
608 if (result != NO_ERROR) {
609 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
610 return result;
611 }
612 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
613 if (result != NO_ERROR) {
614 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
615 return result;
616 }
Svetoslavd85084b2014-03-20 10:28:31 -0700617 return reply.readInt32();
618 }
619
620 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
621 Parcel data, reply;
622 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
623 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
624 reply.read(*outStats);
625 return reply.readInt32();
626 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700627
628 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
629 HdrCapabilities* outCapabilities) const {
630 Parcel data, reply;
631 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
632 status_t result = data.writeStrongBinder(display);
633 if (result != NO_ERROR) {
634 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
635 return result;
636 }
637 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
638 data, &reply);
639 if (result != NO_ERROR) {
640 ALOGE("getHdrCapabilities failed to transact: %d", result);
641 return result;
642 }
643 result = reply.readInt32();
644 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800645 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700646 }
647 return result;
648 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700649
650 virtual status_t enableVSyncInjections(bool enable) {
651 Parcel data, reply;
652 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
653 if (result != NO_ERROR) {
654 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
655 return result;
656 }
657 result = data.writeBool(enable);
658 if (result != NO_ERROR) {
659 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
660 return result;
661 }
Steven Moreland366eb422019-04-01 19:22:32 -0700662 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
663 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700664 if (result != NO_ERROR) {
665 ALOGE("enableVSyncInjections failed to transact: %d", result);
666 return result;
667 }
668 return result;
669 }
670
671 virtual status_t injectVSync(nsecs_t when) {
672 Parcel data, reply;
673 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
674 if (result != NO_ERROR) {
675 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
676 return result;
677 }
678 result = data.writeInt64(when);
679 if (result != NO_ERROR) {
680 ALOGE("injectVSync failed to writeInt64: %d", result);
681 return result;
682 }
Steven Moreland366eb422019-04-01 19:22:32 -0700683 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
684 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700685 if (result != NO_ERROR) {
686 ALOGE("injectVSync failed to transact: %d", result);
687 return result;
688 }
689 return result;
690 }
691
Vishnu Nair43bccf82020-06-05 10:53:37 -0700692 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800693 if (!outLayers) {
694 return UNEXPECTED_NULL;
695 }
696
697 Parcel data, reply;
698
699 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
700 if (err != NO_ERROR) {
701 return err;
702 }
703
704 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
705 if (err != NO_ERROR) {
706 return err;
707 }
708
709 int32_t result = 0;
710 err = reply.readInt32(&result);
711 if (err != NO_ERROR) {
712 return err;
713 }
714 if (result != NO_ERROR) {
715 return result;
716 }
717
718 outLayers->clear();
719 return reply.readParcelableVector(outLayers);
720 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700721
Peiyong Linc6780972018-10-28 15:24:08 -0700722 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
723 ui::PixelFormat* defaultPixelFormat,
724 ui::Dataspace* wideColorGamutDataspace,
725 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700726 Parcel data, reply;
727 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
728 if (error != NO_ERROR) {
729 return error;
730 }
731 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
732 if (error != NO_ERROR) {
733 return error;
734 }
735 error = static_cast<status_t>(reply.readInt32());
736 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700737 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
738 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
739 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
740 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700741 }
742 return error;
743 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700744
Ady Abraham37965d42018-11-01 13:43:32 -0700745 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700746 Parcel data, reply;
747 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700748 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
749 bool result;
750 status_t err = reply.readBool(&result);
751 if (err == NO_ERROR) {
752 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700753 }
Ady Abraham37965d42018-11-01 13:43:32 -0700754 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700755 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700756
757 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
758 ui::PixelFormat* outFormat,
759 ui::Dataspace* outDataspace,
760 uint8_t* outComponentMask) const {
761 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
762 Parcel data, reply;
763 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
764 data.writeStrongBinder(display);
765
766 status_t error =
767 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
768 data, &reply);
769 if (error != NO_ERROR) {
770 return error;
771 }
772
773 uint32_t value = 0;
774 error = reply.readUint32(&value);
775 if (error != NO_ERROR) {
776 return error;
777 }
778 *outFormat = static_cast<ui::PixelFormat>(value);
779
780 error = reply.readUint32(&value);
781 if (error != NO_ERROR) {
782 return error;
783 }
784 *outDataspace = static_cast<ui::Dataspace>(value);
785
786 error = reply.readUint32(&value);
787 if (error != NO_ERROR) {
788 return error;
789 }
790 *outComponentMask = static_cast<uint8_t>(value);
791 return error;
792 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800793
794 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700795 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800796 Parcel data, reply;
797 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
798 data.writeStrongBinder(display);
799 data.writeBool(enable);
800 data.writeByte(static_cast<int8_t>(componentMask));
801 data.writeUint64(maxFrames);
802 status_t result =
803 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
804 &reply);
805 return result;
806 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700807
808 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
809 uint64_t timestamp,
810 DisplayedFrameStats* outStats) const {
811 if (!outStats) return BAD_VALUE;
812
813 Parcel data, reply;
814 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
815 data.writeStrongBinder(display);
816 data.writeUint64(maxFrames);
817 data.writeUint64(timestamp);
818
819 status_t result =
820 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
821
822 if (result != NO_ERROR) {
823 return result;
824 }
825
826 result = reply.readUint64(&outStats->numFrames);
827 if (result != NO_ERROR) {
828 return result;
829 }
830
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800831 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700832 if (result != NO_ERROR) {
833 return result;
834 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800835 result = reply.readUint64Vector(&outStats->component_1_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_2_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_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700844 return result;
845 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800846
847 virtual status_t getProtectedContentSupport(bool* outSupported) const {
848 Parcel data, reply;
849 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800850 status_t error =
851 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
852 if (error != NO_ERROR) {
853 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800854 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800855 error = reply.readBool(outSupported);
856 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800857 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800858
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800859 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
860 bool* outIsWideColorDisplay) const {
861 Parcel data, reply;
862 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
863 if (error != NO_ERROR) {
864 return error;
865 }
866 error = data.writeStrongBinder(token);
867 if (error != NO_ERROR) {
868 return error;
869 }
870
871 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
872 if (error != NO_ERROR) {
873 return error;
874 }
875 error = reply.readBool(outIsWideColorDisplay);
876 return error;
877 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800878
879 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
880 const sp<IBinder>& stopLayerHandle,
881 const sp<IRegionSamplingListener>& listener) {
882 Parcel data, reply;
883 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
884 if (error != NO_ERROR) {
885 ALOGE("addRegionSamplingListener: Failed to write interface token");
886 return error;
887 }
888 error = data.write(samplingArea);
889 if (error != NO_ERROR) {
890 ALOGE("addRegionSamplingListener: Failed to write sampling area");
891 return error;
892 }
893 error = data.writeStrongBinder(stopLayerHandle);
894 if (error != NO_ERROR) {
895 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
896 return error;
897 }
898 error = data.writeStrongBinder(IInterface::asBinder(listener));
899 if (error != NO_ERROR) {
900 ALOGE("addRegionSamplingListener: Failed to write listener");
901 return error;
902 }
903 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
904 if (error != NO_ERROR) {
905 ALOGE("addRegionSamplingListener: Failed to transact");
906 }
907 return error;
908 }
909
910 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
911 Parcel data, reply;
912 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
913 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800914 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800915 return error;
916 }
917 error = data.writeStrongBinder(IInterface::asBinder(listener));
918 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800919 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800920 return error;
921 }
922 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
923 &reply);
924 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800925 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800926 }
927 return error;
928 }
Ady Abraham838de062019-02-04 10:24:03 -0800929
Ana Krulec0782b882019-10-15 17:34:54 -0700930 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700931 int32_t defaultConfig,
932 float primaryRefreshRateMin,
933 float primaryRefreshRateMax,
934 float appRequestRefreshRateMin,
935 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700936 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 }
Steven Thomasf734df42020-04-13 21:09:28 -0700952 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700953 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700954 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700955 return result;
956 }
Steven Thomasf734df42020-04-13 21:09:28 -0700957 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700958 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700959 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
960 return result;
961 }
962 result = data.writeFloat(appRequestRefreshRateMin);
963 if (result != NO_ERROR) {
964 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
965 result);
966 return result;
967 }
968 result = data.writeFloat(appRequestRefreshRateMax);
969 if (result != NO_ERROR) {
970 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
971 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700972 return result;
973 }
974
975 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
976 &reply);
977 if (result != NO_ERROR) {
978 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
979 return result;
980 }
981 return reply.readInt32();
982 }
983
Ana Krulec234bb162019-11-10 22:55:55 +0100984 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100985 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700986 float* outPrimaryRefreshRateMin,
987 float* outPrimaryRefreshRateMax,
988 float* outAppRequestRefreshRateMin,
989 float* outAppRequestRefreshRateMax) {
990 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
991 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
992 return BAD_VALUE;
993 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800994 Parcel data, reply;
995 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
996 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100997 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800998 return result;
999 }
1000 result = data.writeStrongBinder(displayToken);
1001 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +01001002 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001003 return result;
1004 }
Ana Krulec234bb162019-11-10 22:55:55 +01001005 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
1006 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001007 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +01001008 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001009 return result;
1010 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001011 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001012 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001013 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001014 return result;
1015 }
Steven Thomasf734df42020-04-13 21:09:28 -07001016 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001017 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001018 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001019 return result;
1020 }
Steven Thomasf734df42020-04-13 21:09:28 -07001021 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001022 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001023 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
1024 return result;
1025 }
1026 result = reply.readFloat(outAppRequestRefreshRateMin);
1027 if (result != NO_ERROR) {
1028 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
1029 result);
1030 return result;
1031 }
1032 result = reply.readFloat(outAppRequestRefreshRateMax);
1033 if (result != NO_ERROR) {
1034 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
1035 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001036 return result;
1037 }
1038 return reply.readInt32();
1039 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001040
1041 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1042 bool* outSupport) const {
1043 Parcel data, reply;
1044 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1045 if (error != NO_ERROR) {
1046 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1047 return error;
1048 }
1049 error = data.writeStrongBinder(displayToken);
1050 if (error != NO_ERROR) {
1051 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1052 return error;
1053 }
1054 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1055 if (error != NO_ERROR) {
1056 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1057 return error;
1058 }
1059 bool support;
1060 error = reply.readBool(&support);
1061 if (error != NO_ERROR) {
1062 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1063 return error;
1064 }
1065 *outSupport = support;
1066 return NO_ERROR;
1067 }
1068
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001069 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001070 Parcel data, reply;
1071 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1072 if (error != NO_ERROR) {
1073 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1074 return error;
1075 }
1076 error = data.writeStrongBinder(displayToken);
1077 if (error != NO_ERROR) {
1078 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1079 return error;
1080 }
1081 error = data.writeFloat(brightness);
1082 if (error != NO_ERROR) {
1083 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1084 return error;
1085 }
1086 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1087 if (error != NO_ERROR) {
1088 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1089 return error;
1090 }
1091 return NO_ERROR;
1092 }
Ady Abraham8532d012019-05-08 14:50:56 -07001093
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001094 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001095 Parcel data, reply;
1096 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1097 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001098 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001099 return error;
1100 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001101 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001102 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001103 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001104 return error;
1105 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001106 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001107 IBinder::FLAG_ONEWAY);
1108 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001109 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001110 return error;
1111 }
1112 return NO_ERROR;
1113 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001114
1115 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1116 float lightPosY, float lightPosZ, float lightRadius) {
1117 Parcel data, reply;
1118 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1119 if (error != NO_ERROR) {
1120 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1121 return error;
1122 }
1123
1124 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1125 ambientColor.a, spotColor.r, spotColor.g,
1126 spotColor.b, spotColor.a, lightPosY,
1127 lightPosZ, lightRadius};
1128
1129 error = data.writeFloatVector(shadowConfig);
1130 if (error != NO_ERROR) {
1131 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1132 return error;
1133 }
1134
1135 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1136 IBinder::FLAG_ONEWAY);
1137 if (error != NO_ERROR) {
1138 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1139 return error;
1140 }
1141 return NO_ERROR;
1142 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001143
1144 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1145 int8_t compatibility) {
1146 Parcel data, reply;
1147 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1148 if (err != NO_ERROR) {
1149 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1150 return err;
1151 }
1152
1153 err = data.writeStrongBinder(IInterface::asBinder(surface));
1154 if (err != NO_ERROR) {
1155 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1156 return err;
1157 }
1158
1159 err = data.writeFloat(frameRate);
1160 if (err != NO_ERROR) {
1161 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1162 return err;
1163 }
1164
1165 err = data.writeByte(compatibility);
1166 if (err != NO_ERROR) {
1167 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1168 return err;
1169 }
1170
Ady Abraham60e42ea2020-03-09 19:17:31 -07001171 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001172 if (err != NO_ERROR) {
1173 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1174 return err;
1175 }
Steven Thomasd4071902020-03-24 16:02:53 -07001176
1177 return reply.readInt32();
1178 }
1179
1180 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1181 if (!outToken) return BAD_VALUE;
1182
1183 Parcel data, reply;
1184 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1185 if (err != NO_ERROR) {
1186 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1187 strerror(-err), -err);
1188 return err;
1189 }
1190
1191 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1192 &reply);
1193 if (err != NO_ERROR) {
1194 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1195 err);
1196 return err;
1197 }
1198
1199 err = reply.readInt32();
1200 if (err != NO_ERROR) {
1201 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1202 return err;
1203 }
1204
1205 err = reply.readStrongBinder(outToken);
1206 if (err != NO_ERROR) {
1207 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1208 strerror(-err), err);
1209 return err;
1210 }
1211
Steven Thomas62a4cf82020-01-31 12:04:03 -08001212 return NO_ERROR;
1213 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001214};
1215
Dan Stozad723bd72014-11-18 10:24:03 -08001216// Out-of-line virtual method definition to trigger vtable emission in this
1217// translation unit (see clang warning -Wweak-vtables)
1218BpSurfaceComposer::~BpSurfaceComposer() {}
1219
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001220IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1221
1222// ----------------------------------------------------------------------
1223
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001224status_t BnSurfaceComposer::onTransact(
1225 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1226{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001227 switch(code) {
1228 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001229 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001230 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001231 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001232 return NO_ERROR;
1233 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001234 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001235 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001236
1237 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001238 if (count > data.dataSize()) {
1239 return BAD_VALUE;
1240 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001241 Vector<ComposerState> state;
1242 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001243 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001244 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001245 if (s.read(data) == BAD_VALUE) {
1246 return BAD_VALUE;
1247 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001248 state.add(s);
1249 }
Dan Stozad723bd72014-11-18 10:24:03 -08001250
1251 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001252 if (count > data.dataSize()) {
1253 return BAD_VALUE;
1254 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001255 DisplayState d;
1256 Vector<DisplayState> displays;
1257 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001258 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001259 if (d.read(data) == BAD_VALUE) {
1260 return BAD_VALUE;
1261 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001262 displays.add(d);
1263 }
Dan Stozad723bd72014-11-18 10:24:03 -08001264
1265 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001266 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001267 InputWindowCommands inputWindowCommands;
1268 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001269
1270 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001271
Marissa Wall947d34e2019-03-29 14:03:53 -07001272 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001273 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001274 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001275
Valerie Hau9dab9732019-08-20 09:29:25 -07001276 bool hasListenerCallbacks = data.readBool();
1277
Marissa Wall3dad52d2019-03-22 14:03:19 -07001278 std::vector<ListenerCallbacks> listenerCallbacks;
1279 int32_t listenersSize = data.readInt32();
1280 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001281 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001282 std::vector<CallbackId> callbackIds;
1283 data.readInt64Vector(&callbackIds);
1284 listenerCallbacks.emplace_back(listener, callbackIds);
1285 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001286 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001287 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1288 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001289 return NO_ERROR;
1290 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001291 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001292 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001293 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001294 return NO_ERROR;
1295 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001296 case CAPTURE_SCREEN: {
1297 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1298 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001299 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1300 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001301 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -07001302 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -07001303 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -08001304 uint32_t reqWidth = data.readUint32();
1305 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -08001306 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -08001307 int32_t rotation = data.readInt32();
Robert Carrfa8855f2019-02-19 10:05:00 -08001308 bool captureSecureLayers = static_cast<bool>(data.readInt32());
Dan Stozac7014012014-02-14 15:03:43 -08001309
Robert Carr108b2c72019-04-02 16:32:58 -07001310 bool capturedSecureLayers = false;
1311 status_t res = captureScreen(display, &outBuffer, capturedSecureLayers, reqDataspace,
1312 reqPixelFormat, sourceCrop, reqWidth, reqHeight,
Dominik Laskowski718f9602019-11-09 20:01:35 -08001313 useIdentityTransform, ui::toRotation(rotation),
Robert Carr108b2c72019-04-02 16:32:58 -07001314 captureSecureLayers);
1315
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001316 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001317 if (res == NO_ERROR) {
1318 reply->write(*outBuffer);
Robert Carr108b2c72019-04-02 16:32:58 -07001319 reply->writeBool(capturedSecureLayers);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001320 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001321 return NO_ERROR;
1322 }
chaviw93df2ea2019-04-30 16:45:12 -07001323 case CAPTURE_SCREEN_BY_ID: {
1324 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1325 uint64_t displayOrLayerStack = data.readUint64();
1326 ui::Dataspace outDataspace = ui::Dataspace::V0_SRGB;
1327 sp<GraphicBuffer> outBuffer;
1328 status_t res = captureScreen(displayOrLayerStack, &outDataspace, &outBuffer);
1329 reply->writeInt32(res);
1330 if (res == NO_ERROR) {
1331 reply->writeInt32(static_cast<int32_t>(outDataspace));
1332 reply->write(*outBuffer);
1333 }
1334 return NO_ERROR;
1335 }
chaviwa76b2712017-09-20 12:02:26 -07001336 case CAPTURE_LAYERS: {
1337 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1338 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001339 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1340 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001341 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001342 Rect sourceCrop(Rect::EMPTY_RECT);
1343 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001344
1345 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1346 int numExcludeHandles = data.readInt32();
Ady Abraham0a525092020-03-03 12:51:24 -08001347 if (numExcludeHandles >= static_cast<int>(MAX_LAYERS)) {
1348 return BAD_VALUE;
1349 }
Robert Carr866455f2019-04-02 16:28:26 -07001350 excludeHandles.reserve(numExcludeHandles);
1351 for (int i = 0; i < numExcludeHandles; i++) {
1352 excludeHandles.emplace(data.readStrongBinder());
1353 }
1354
chaviw7206d492017-11-10 16:16:12 -08001355 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001356 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001357
Robert Carr866455f2019-04-02 16:28:26 -07001358 status_t res =
1359 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1360 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001361 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001362 if (res == NO_ERROR) {
1363 reply->write(*outBuffer);
1364 }
chaviwa76b2712017-09-20 12:02:26 -07001365 return NO_ERROR;
1366 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001367 case AUTHENTICATE_SURFACE: {
1368 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001369 sp<IGraphicBufferProducer> bufferProducer =
1370 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1371 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001372 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001373 return NO_ERROR;
1374 }
Brian Anderson6b376712017-04-04 10:51:39 -07001375 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1376 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1377 std::vector<FrameEvent> supportedTimestamps;
1378 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1379 status_t err = reply->writeInt32(result);
1380 if (err != NO_ERROR) {
1381 return err;
1382 }
1383 if (result != NO_ERROR) {
1384 return result;
1385 }
1386
1387 std::vector<int32_t> supported;
1388 supported.reserve(supportedTimestamps.size());
1389 for (FrameEvent s : supportedTimestamps) {
1390 supported.push_back(static_cast<int32_t>(s));
1391 }
1392 return reply->writeInt32Vector(supported);
1393 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001394 case CREATE_DISPLAY_EVENT_CONNECTION: {
1395 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001396 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1397 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1398
1399 sp<IDisplayEventConnection> connection(
1400 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001401 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001402 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001403 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001404 case CREATE_DISPLAY: {
1405 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001406 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001407 bool secure = bool(data.readInt32());
1408 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001409 reply->writeStrongBinder(display);
1410 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001411 }
1412 case DESTROY_DISPLAY: {
1413 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1414 sp<IBinder> display = data.readStrongBinder();
1415 destroyDisplay(display);
1416 return NO_ERROR;
1417 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001418 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001419 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001420 PhysicalDisplayId displayId = data.readUint64();
1421 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001422 reply->writeStrongBinder(display);
1423 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001424 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001425 case GET_DISPLAY_STATE: {
1426 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1427 ui::DisplayState state;
1428 const sp<IBinder> display = data.readStrongBinder();
1429 const status_t result = getDisplayState(display, &state);
1430 reply->writeInt32(result);
1431 if (result == NO_ERROR) {
1432 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1433 sizeof(ui::DisplayState));
1434 }
1435 return NO_ERROR;
1436 }
1437 case GET_DISPLAY_INFO: {
1438 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1439 DisplayInfo info;
1440 const sp<IBinder> display = data.readStrongBinder();
1441 const status_t result = getDisplayInfo(display, &info);
1442 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001443 if (result != NO_ERROR) return result;
1444 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001445 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001446 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001447 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001448 Vector<DisplayConfig> configs;
1449 const sp<IBinder> display = data.readStrongBinder();
1450 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001451 reply->writeInt32(result);
1452 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001453 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001454 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001455 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1456 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001457 }
1458 }
1459 return NO_ERROR;
1460 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001461 case GET_DISPLAY_STATS: {
1462 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1463 DisplayStatInfo stats;
1464 sp<IBinder> display = data.readStrongBinder();
1465 status_t result = getDisplayStats(display, &stats);
1466 reply->writeInt32(result);
1467 if (result == NO_ERROR) {
1468 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1469 &stats, sizeof(DisplayStatInfo));
1470 }
1471 return NO_ERROR;
1472 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001473 case GET_ACTIVE_CONFIG: {
1474 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1475 sp<IBinder> display = data.readStrongBinder();
1476 int id = getActiveConfig(display);
1477 reply->writeInt32(id);
1478 return NO_ERROR;
1479 }
Michael Wright28f24d02016-07-12 13:30:53 -07001480 case GET_DISPLAY_COLOR_MODES: {
1481 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001482 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001483 sp<IBinder> display = nullptr;
1484 status_t result = data.readStrongBinder(&display);
1485 if (result != NO_ERROR) {
1486 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1487 return result;
1488 }
1489 result = getDisplayColorModes(display, &colorModes);
1490 reply->writeInt32(result);
1491 if (result == NO_ERROR) {
1492 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1493 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001494 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001495 }
1496 }
1497 return NO_ERROR;
1498 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001499 case GET_DISPLAY_NATIVE_PRIMARIES: {
1500 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1501 ui::DisplayPrimaries primaries;
1502 sp<IBinder> display = nullptr;
1503
1504 status_t result = data.readStrongBinder(&display);
1505 if (result != NO_ERROR) {
1506 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1507 return result;
1508 }
1509
1510 result = getDisplayNativePrimaries(display, primaries);
1511 reply->writeInt32(result);
1512 if (result == NO_ERROR) {
1513 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1514 sizeof(ui::DisplayPrimaries));
1515 }
1516
1517 return NO_ERROR;
1518 }
Michael Wright28f24d02016-07-12 13:30:53 -07001519 case GET_ACTIVE_COLOR_MODE: {
1520 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1521 sp<IBinder> display = nullptr;
1522 status_t result = data.readStrongBinder(&display);
1523 if (result != NO_ERROR) {
1524 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1525 return result;
1526 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001527 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001528 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1529 return result;
1530 }
1531 case SET_ACTIVE_COLOR_MODE: {
1532 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1533 sp<IBinder> display = nullptr;
1534 status_t result = data.readStrongBinder(&display);
1535 if (result != NO_ERROR) {
1536 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1537 return result;
1538 }
1539 int32_t colorModeInt = 0;
1540 result = data.readInt32(&colorModeInt);
1541 if (result != NO_ERROR) {
1542 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1543 return result;
1544 }
1545 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001546 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001547 result = reply->writeInt32(result);
1548 return result;
1549 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001550
1551 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1552 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1553 sp<IBinder> display = nullptr;
1554 status_t result = data.readStrongBinder(&display);
1555 if (result != NO_ERROR) {
1556 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1557 return result;
1558 }
1559 bool supported = false;
1560 result = getAutoLowLatencyModeSupport(display, &supported);
1561 if (result == NO_ERROR) {
1562 result = reply->writeBool(supported);
1563 }
1564 return result;
1565 }
1566
1567 case SET_AUTO_LOW_LATENCY_MODE: {
1568 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1569 sp<IBinder> display = nullptr;
1570 status_t result = data.readStrongBinder(&display);
1571 if (result != NO_ERROR) {
1572 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1573 return result;
1574 }
1575 bool setAllm = false;
1576 result = data.readBool(&setAllm);
1577 if (result != NO_ERROR) {
1578 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1579 return result;
1580 }
1581 setAutoLowLatencyMode(display, setAllm);
1582 return result;
1583 }
1584
1585 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1586 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1587 sp<IBinder> display = nullptr;
1588 status_t result = data.readStrongBinder(&display);
1589 if (result != NO_ERROR) {
1590 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1591 return result;
1592 }
1593 bool supported = false;
1594 result = getGameContentTypeSupport(display, &supported);
1595 if (result == NO_ERROR) {
1596 result = reply->writeBool(supported);
1597 }
1598 return result;
1599 }
1600
1601 case SET_GAME_CONTENT_TYPE: {
1602 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1603 sp<IBinder> display = nullptr;
1604 status_t result = data.readStrongBinder(&display);
1605 if (result != NO_ERROR) {
1606 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1607 return result;
1608 }
1609 bool setGameContentTypeOn = false;
1610 result = data.readBool(&setGameContentTypeOn);
1611 if (result != NO_ERROR) {
1612 ALOGE("setGameContentType failed to readBool: %d", result);
1613 return result;
1614 }
1615 setGameContentType(display, setGameContentTypeOn);
1616 return result;
1617 }
1618
Svetoslavd85084b2014-03-20 10:28:31 -07001619 case CLEAR_ANIMATION_FRAME_STATS: {
1620 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1621 status_t result = clearAnimationFrameStats();
1622 reply->writeInt32(result);
1623 return NO_ERROR;
1624 }
1625 case GET_ANIMATION_FRAME_STATS: {
1626 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1627 FrameStats stats;
1628 status_t result = getAnimationFrameStats(&stats);
1629 reply->write(stats);
1630 reply->writeInt32(result);
1631 return NO_ERROR;
1632 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001633 case SET_POWER_MODE: {
1634 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1635 sp<IBinder> display = data.readStrongBinder();
1636 int32_t mode = data.readInt32();
1637 setPowerMode(display, mode);
1638 return NO_ERROR;
1639 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001640 case GET_HDR_CAPABILITIES: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1642 sp<IBinder> display = nullptr;
1643 status_t result = data.readStrongBinder(&display);
1644 if (result != NO_ERROR) {
1645 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1646 result);
1647 return result;
1648 }
1649 HdrCapabilities capabilities;
1650 result = getHdrCapabilities(display, &capabilities);
1651 reply->writeInt32(result);
1652 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001653 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001654 }
1655 return NO_ERROR;
1656 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001657 case ENABLE_VSYNC_INJECTIONS: {
1658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1659 bool enable = false;
1660 status_t result = data.readBool(&enable);
1661 if (result != NO_ERROR) {
1662 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1663 return result;
1664 }
1665 return enableVSyncInjections(enable);
1666 }
1667 case INJECT_VSYNC: {
1668 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1669 int64_t when = 0;
1670 status_t result = data.readInt64(&when);
1671 if (result != NO_ERROR) {
1672 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1673 return result;
1674 }
1675 return injectVSync(when);
1676 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001677 case GET_LAYER_DEBUG_INFO: {
1678 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1679 std::vector<LayerDebugInfo> outLayers;
1680 status_t result = getLayerDebugInfo(&outLayers);
1681 reply->writeInt32(result);
1682 if (result == NO_ERROR)
1683 {
1684 result = reply->writeParcelableVector(outLayers);
1685 }
1686 return result;
1687 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001688 case GET_COMPOSITION_PREFERENCE: {
1689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001690 ui::Dataspace defaultDataspace;
1691 ui::PixelFormat defaultPixelFormat;
1692 ui::Dataspace wideColorGamutDataspace;
1693 ui::PixelFormat wideColorGamutPixelFormat;
1694 status_t error =
1695 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1696 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001697 reply->writeInt32(error);
1698 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001699 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1700 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1701 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001702 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001703 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001704 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001705 }
Ady Abraham37965d42018-11-01 13:43:32 -07001706 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001707 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001708 bool result;
1709 status_t error = getColorManagement(&result);
1710 if (error == NO_ERROR) {
1711 reply->writeBool(result);
1712 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001713 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001714 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001715 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1716 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1717
1718 sp<IBinder> display = data.readStrongBinder();
1719 ui::PixelFormat format;
1720 ui::Dataspace dataspace;
1721 uint8_t component = 0;
1722 auto result =
1723 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1724 if (result == NO_ERROR) {
1725 reply->writeUint32(static_cast<uint32_t>(format));
1726 reply->writeUint32(static_cast<uint32_t>(dataspace));
1727 reply->writeUint32(static_cast<uint32_t>(component));
1728 }
1729 return result;
1730 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001731 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1732 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1733
1734 sp<IBinder> display = nullptr;
1735 bool enable = false;
1736 int8_t componentMask = 0;
1737 uint64_t maxFrames = 0;
1738 status_t result = data.readStrongBinder(&display);
1739 if (result != NO_ERROR) {
1740 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1741 result);
1742 return result;
1743 }
1744
1745 result = data.readBool(&enable);
1746 if (result != NO_ERROR) {
1747 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1748 return result;
1749 }
1750
1751 result = data.readByte(static_cast<int8_t*>(&componentMask));
1752 if (result != NO_ERROR) {
1753 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1754 result);
1755 return result;
1756 }
1757
1758 result = data.readUint64(&maxFrames);
1759 if (result != NO_ERROR) {
1760 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1761 return result;
1762 }
1763
1764 return setDisplayContentSamplingEnabled(display, enable,
1765 static_cast<uint8_t>(componentMask), maxFrames);
1766 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001767 case GET_DISPLAYED_CONTENT_SAMPLE: {
1768 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1769
1770 sp<IBinder> display = data.readStrongBinder();
1771 uint64_t maxFrames = 0;
1772 uint64_t timestamp = 0;
1773
1774 status_t result = data.readUint64(&maxFrames);
1775 if (result != NO_ERROR) {
1776 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1777 return result;
1778 }
1779
1780 result = data.readUint64(&timestamp);
1781 if (result != NO_ERROR) {
1782 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1783 return result;
1784 }
1785
1786 DisplayedFrameStats stats;
1787 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1788 if (result == NO_ERROR) {
1789 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001790 reply->writeUint64Vector(stats.component_0_sample);
1791 reply->writeUint64Vector(stats.component_1_sample);
1792 reply->writeUint64Vector(stats.component_2_sample);
1793 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001794 }
1795 return result;
1796 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001797 case GET_PROTECTED_CONTENT_SUPPORT: {
1798 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1799 bool result;
1800 status_t error = getProtectedContentSupport(&result);
1801 if (error == NO_ERROR) {
1802 reply->writeBool(result);
1803 }
1804 return error;
1805 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001806 case IS_WIDE_COLOR_DISPLAY: {
1807 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1808 sp<IBinder> display = nullptr;
1809 status_t error = data.readStrongBinder(&display);
1810 if (error != NO_ERROR) {
1811 return error;
1812 }
1813 bool result;
1814 error = isWideColorDisplay(display, &result);
1815 if (error == NO_ERROR) {
1816 reply->writeBool(result);
1817 }
1818 return error;
1819 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001820 case GET_PHYSICAL_DISPLAY_IDS: {
1821 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1822 return reply->writeUint64Vector(getPhysicalDisplayIds());
1823 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001824 case ADD_REGION_SAMPLING_LISTENER: {
1825 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1826 Rect samplingArea;
1827 status_t result = data.read(samplingArea);
1828 if (result != NO_ERROR) {
1829 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1830 return result;
1831 }
1832 sp<IBinder> stopLayerHandle;
1833 result = data.readNullableStrongBinder(&stopLayerHandle);
1834 if (result != NO_ERROR) {
1835 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1836 return result;
1837 }
1838 sp<IRegionSamplingListener> listener;
1839 result = data.readNullableStrongBinder(&listener);
1840 if (result != NO_ERROR) {
1841 ALOGE("addRegionSamplingListener: Failed to read listener");
1842 return result;
1843 }
1844 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1845 }
1846 case REMOVE_REGION_SAMPLING_LISTENER: {
1847 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1848 sp<IRegionSamplingListener> listener;
1849 status_t result = data.readNullableStrongBinder(&listener);
1850 if (result != NO_ERROR) {
1851 ALOGE("removeRegionSamplingListener: Failed to read listener");
1852 return result;
1853 }
1854 return removeRegionSamplingListener(listener);
1855 }
Ana Krulec0782b882019-10-15 17:34:54 -07001856 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1857 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1858 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001859 int32_t defaultConfig;
1860 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001861 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001862 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001863 return result;
1864 }
Steven Thomasf734df42020-04-13 21:09:28 -07001865 float primaryRefreshRateMin;
1866 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001867 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001868 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1869 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001870 return result;
1871 }
Steven Thomasf734df42020-04-13 21:09:28 -07001872 float primaryRefreshRateMax;
1873 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001874 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001875 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1876 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001877 return result;
1878 }
Steven Thomasf734df42020-04-13 21:09:28 -07001879 float appRequestRefreshRateMin;
1880 result = data.readFloat(&appRequestRefreshRateMin);
1881 if (result != NO_ERROR) {
1882 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1883 result);
1884 return result;
1885 }
1886 float appRequestRefreshRateMax;
1887 result = data.readFloat(&appRequestRefreshRateMax);
1888 if (result != NO_ERROR) {
1889 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1890 result);
1891 return result;
1892 }
1893 result =
1894 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1895 primaryRefreshRateMax, appRequestRefreshRateMin,
1896 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001897 if (result != NO_ERROR) {
1898 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1899 "%d",
1900 result);
1901 return result;
1902 }
1903 reply->writeInt32(result);
1904 return result;
1905 }
Ana Krulec234bb162019-11-10 22:55:55 +01001906 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1907 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1908 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001909 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001910 float primaryRefreshRateMin;
1911 float primaryRefreshRateMax;
1912 float appRequestRefreshRateMin;
1913 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001914
Steven Thomasf734df42020-04-13 21:09:28 -07001915 status_t result =
1916 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1917 &primaryRefreshRateMin, &primaryRefreshRateMax,
1918 &appRequestRefreshRateMin,
1919 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001920 if (result != NO_ERROR) {
1921 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1922 "%d",
1923 result);
1924 return result;
1925 }
1926
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001927 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001928 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001929 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001930 return result;
1931 }
Steven Thomasf734df42020-04-13 21:09:28 -07001932 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001933 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001934 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1935 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001936 return result;
1937 }
Steven Thomasf734df42020-04-13 21:09:28 -07001938 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001939 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001940 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1941 result);
1942 return result;
1943 }
1944 result = reply->writeFloat(appRequestRefreshRateMin);
1945 if (result != NO_ERROR) {
1946 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1947 result);
1948 return result;
1949 }
1950 result = reply->writeFloat(appRequestRefreshRateMax);
1951 if (result != NO_ERROR) {
1952 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1953 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001954 return result;
1955 }
1956 reply->writeInt32(result);
1957 return result;
1958 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001959 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1960 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1961 sp<IBinder> displayToken;
1962 status_t error = data.readNullableStrongBinder(&displayToken);
1963 if (error != NO_ERROR) {
1964 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1965 return error;
1966 }
1967 bool support = false;
1968 error = getDisplayBrightnessSupport(displayToken, &support);
1969 reply->writeBool(support);
1970 return error;
1971 }
1972 case SET_DISPLAY_BRIGHTNESS: {
1973 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1974 sp<IBinder> displayToken;
1975 status_t error = data.readNullableStrongBinder(&displayToken);
1976 if (error != NO_ERROR) {
1977 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1978 return error;
1979 }
1980 float brightness = -1.0f;
1981 error = data.readFloat(&brightness);
1982 if (error != NO_ERROR) {
1983 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1984 return error;
1985 }
1986 return setDisplayBrightness(displayToken, brightness);
1987 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001988 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001989 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001990 int32_t boostId;
1991 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001992 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001993 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001994 return error;
1995 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001996 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001997 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001998 case SET_GLOBAL_SHADOW_SETTINGS: {
1999 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2000
2001 std::vector<float> shadowConfig;
2002 status_t error = data.readFloatVector(&shadowConfig);
2003 if (error != NO_ERROR || shadowConfig.size() != 11) {
2004 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
2005 return error;
2006 }
2007
2008 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
2009 shadowConfig[3]};
2010 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
2011 float lightPosY = shadowConfig[8];
2012 float lightPosZ = shadowConfig[9];
2013 float lightRadius = shadowConfig[10];
2014 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
2015 lightRadius);
2016 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08002017 case SET_FRAME_RATE: {
2018 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2019 sp<IBinder> binder;
2020 status_t err = data.readStrongBinder(&binder);
2021 if (err != NO_ERROR) {
2022 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
2023 return err;
2024 }
2025 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2026 if (!surface) {
2027 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
2028 strerror(-err), -err);
2029 return err;
2030 }
2031 float frameRate;
2032 err = data.readFloat(&frameRate);
2033 if (err != NO_ERROR) {
2034 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2035 return err;
2036 }
2037 int8_t compatibility;
2038 err = data.readByte(&compatibility);
2039 if (err != NO_ERROR) {
2040 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2041 return err;
2042 }
2043 status_t result = setFrameRate(surface, frameRate, compatibility);
2044 reply->writeInt32(result);
2045 return NO_ERROR;
2046 }
Steven Thomasd4071902020-03-24 16:02:53 -07002047 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2048 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2049 sp<IBinder> token;
2050 status_t result = acquireFrameRateFlexibilityToken(&token);
2051 reply->writeInt32(result);
2052 if (result == NO_ERROR) {
2053 reply->writeStrongBinder(token);
2054 }
2055 return NO_ERROR;
2056 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002057 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002058 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002059 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002060 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002061}
2062
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002063} // namespace android