blob: 7b9b5d8d8888ef2edb9d394077ea1ebf97e7627f [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
chaviwd2432892020-07-24 17:42:39 -0700114 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
115 ScreenCaptureResults& captureResults) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800116 Parcel data, reply;
117 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd2432892020-07-24 17:42:39 -0700118
119 status_t result = args.write(data);
Ana Krulec2d41e422018-07-26 12:07:43 -0700120 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700121 ALOGE("captureDisplay failed to parcel args: %d", result);
122 return result;
123 }
124 result = remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
125 if (result != NO_ERROR) {
126 ALOGE("captureDisplay failed to transact: %d", result);
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000128 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700129 result = reply.readInt32();
130 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700131 ALOGE("captureDisplay failed to readInt32: %d", result);
Ana Krulec2d41e422018-07-26 12:07:43 -0700132 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000133 }
134
chaviwd2432892020-07-24 17:42:39 -0700135 captureResults.read(reply);
Ana Krulec2d41e422018-07-26 12:07:43 -0700136 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800137 }
138
chaviwd2432892020-07-24 17:42:39 -0700139 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
140 ScreenCaptureResults& captureResults) {
chaviw93df2ea2019-04-30 16:45:12 -0700141 Parcel data, reply;
142 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
143 data.writeUint64(displayOrLayerStack);
chaviwd2432892020-07-24 17:42:39 -0700144 status_t result =
145 remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700146 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700147 ALOGE("captureDisplay failed to transact: %d", result);
chaviw93df2ea2019-04-30 16:45:12 -0700148 return result;
149 }
150 result = reply.readInt32();
151 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700152 ALOGE("captureDisplay failed to readInt32: %d", result);
chaviw93df2ea2019-04-30 16:45:12 -0700153 return result;
154 }
155
chaviwd2432892020-07-24 17:42:39 -0700156 captureResults.read(reply);
chaviw93df2ea2019-04-30 16:45:12 -0700157 return result;
158 }
159
Robert Carr866455f2019-04-02 16:28:26 -0700160 virtual status_t captureLayers(
161 const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer,
162 const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
163 const Rect& sourceCrop,
164 const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeLayers, float frameScale,
165 bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700166 Parcel data, reply;
167 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
168 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700169 data.writeInt32(static_cast<int32_t>(reqDataspace));
170 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800171 data.write(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -0700172 data.writeInt32(excludeLayers.size());
173 for (auto el : excludeLayers) {
174 data.writeStrongBinder(el);
175 }
chaviw7206d492017-11-10 16:16:12 -0800176 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800177 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700178 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
179 if (result != NO_ERROR) {
180 ALOGE("captureLayers failed to transact: %d", result);
181 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000182 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700183 result = reply.readInt32();
184 if (result != NO_ERROR) {
185 ALOGE("captureLayers failed to readInt32: %d", result);
186 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000187 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700188
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000189 *outBuffer = new GraphicBuffer();
190 reply.read(**outBuffer);
191
Ana Krulec2d41e422018-07-26 12:07:43 -0700192 return result;
chaviwa76b2712017-09-20 12:02:26 -0700193 }
194
Jamie Gennis582270d2011-08-17 18:19:00 -0700195 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800196 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800197 {
198 Parcel data, reply;
199 int err = NO_ERROR;
200 err = data.writeInterfaceToken(
201 ISurfaceComposer::getInterfaceDescriptor());
202 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000203 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800204 "interface descriptor: %s (%d)", strerror(-err), -err);
205 return false;
206 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800207 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800208 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000209 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700210 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800211 return false;
212 }
213 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
214 &reply);
215 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000216 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700217 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800218 return false;
219 }
220 int32_t result = 0;
221 err = reply.readInt32(&result);
222 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000223 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700224 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800225 return false;
226 }
227 return result != 0;
228 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800229
Brian Anderson6b376712017-04-04 10:51:39 -0700230 virtual status_t getSupportedFrameTimestamps(
231 std::vector<FrameEvent>* outSupported) const {
232 if (!outSupported) {
233 return UNEXPECTED_NULL;
234 }
235 outSupported->clear();
236
237 Parcel data, reply;
238
239 status_t err = data.writeInterfaceToken(
240 ISurfaceComposer::getInterfaceDescriptor());
241 if (err != NO_ERROR) {
242 return err;
243 }
244
245 err = remote()->transact(
246 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
247 data, &reply);
248 if (err != NO_ERROR) {
249 return err;
250 }
251
252 int32_t result = 0;
253 err = reply.readInt32(&result);
254 if (err != NO_ERROR) {
255 return err;
256 }
257 if (result != NO_ERROR) {
258 return result;
259 }
260
261 std::vector<int32_t> supported;
262 err = reply.readInt32Vector(&supported);
263 if (err != NO_ERROR) {
264 return err;
265 }
266
267 outSupported->reserve(supported.size());
268 for (int32_t s : supported) {
269 outSupported->push_back(static_cast<FrameEvent>(s));
270 }
271 return NO_ERROR;
272 }
273
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700274 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
275 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800276 Parcel data, reply;
277 sp<IDisplayEventConnection> result;
278 int err = data.writeInterfaceToken(
279 ISurfaceComposer::getInterfaceDescriptor());
280 if (err != NO_ERROR) {
281 return result;
282 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700283 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700284 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800285 err = remote()->transact(
286 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
287 data, &reply);
288 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000289 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800290 "transaction: %s (%d)", strerror(-err), -err);
291 return result;
292 }
293 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
294 return result;
295 }
Colin Cross8e533062012-06-07 13:17:52 -0700296
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700297 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700301 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700302 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700303 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
304 return reply.readStrongBinder();
305 }
306
Jesse Hall6c913be2013-08-08 12:15:49 -0700307 virtual void destroyDisplay(const sp<IBinder>& display)
308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
311 data.writeStrongBinder(display);
312 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
313 }
314
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800315 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700316 Parcel data, reply;
317 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800318 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
319 NO_ERROR) {
320 std::vector<PhysicalDisplayId> displayIds;
321 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
322 return displayIds;
323 }
324 }
325
326 return {};
327 }
328
329 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
330 Parcel data, reply;
331 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
332 data.writeUint64(displayId);
333 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700334 return reply.readStrongBinder();
335 }
336
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700337 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700341 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700342 data.writeInt32(mode);
343 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700344 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700345
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800346 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
347 Parcel data, reply;
348 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
349 data.writeStrongBinder(display);
350 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
351 const status_t result = reply.readInt32();
352 if (result == NO_ERROR) {
353 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
354 }
355 return result;
356 }
357
358 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
359 Parcel data, reply;
360 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
361 data.writeStrongBinder(display);
362 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
363 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100364 if (result != NO_ERROR) return result;
365 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800366 }
367
368 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700369 Parcel data, reply;
370 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700371 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700372 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800373 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700374 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800375 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700376 configs->clear();
377 configs->resize(numConfigs);
378 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800379 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
380 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700381 }
382 }
383 return result;
384 }
385
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700386 virtual status_t getDisplayStats(const sp<IBinder>& display,
387 DisplayStatInfo* stats)
388 {
389 Parcel data, reply;
390 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
391 data.writeStrongBinder(display);
392 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
393 status_t result = reply.readInt32();
394 if (result == NO_ERROR) {
395 memcpy(stats,
396 reply.readInplace(sizeof(DisplayStatInfo)),
397 sizeof(DisplayStatInfo));
398 }
399 return result;
400 }
401
Dan Stoza7f7da322014-05-02 15:26:25 -0700402 virtual int getActiveConfig(const sp<IBinder>& display)
403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
406 data.writeStrongBinder(display);
407 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
408 return reply.readInt32();
409 }
410
Michael Wright28f24d02016-07-12 13:30:53 -0700411 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700412 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700413 Parcel data, reply;
414 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
415 if (result != NO_ERROR) {
416 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
417 return result;
418 }
419 result = data.writeStrongBinder(display);
420 if (result != NO_ERROR) {
421 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
422 return result;
423 }
424 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
425 if (result != NO_ERROR) {
426 ALOGE("getDisplayColorModes failed to transact: %d", result);
427 return result;
428 }
429 result = static_cast<status_t>(reply.readInt32());
430 if (result == NO_ERROR) {
431 size_t numModes = reply.readUint32();
432 outColorModes->clear();
433 outColorModes->resize(numModes);
434 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700435 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700436 }
437 }
438 return result;
439 }
440
Daniel Solomon42d04562019-01-20 21:03:19 -0800441 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
442 ui::DisplayPrimaries& primaries) {
443 Parcel data, reply;
444 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
445 if (result != NO_ERROR) {
446 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
447 return result;
448 }
449 result = data.writeStrongBinder(display);
450 if (result != NO_ERROR) {
451 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
452 return result;
453 }
454 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
455 if (result != NO_ERROR) {
456 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
457 return result;
458 }
459 result = reply.readInt32();
460 if (result == NO_ERROR) {
461 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
462 sizeof(ui::DisplayPrimaries));
463 }
464 return result;
465 }
466
Peiyong Lina52f0292018-03-14 17:26:31 -0700467 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700468 Parcel data, reply;
469 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
470 if (result != NO_ERROR) {
471 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700472 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700473 }
474 result = data.writeStrongBinder(display);
475 if (result != NO_ERROR) {
476 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700477 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700478 }
479 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
480 if (result != NO_ERROR) {
481 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700482 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700483 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700484 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700485 }
486
487 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700488 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700489 Parcel data, reply;
490 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
491 if (result != NO_ERROR) {
492 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
493 return result;
494 }
495 result = data.writeStrongBinder(display);
496 if (result != NO_ERROR) {
497 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
498 return result;
499 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700500 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700501 if (result != NO_ERROR) {
502 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
503 return result;
504 }
505 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
506 if (result != NO_ERROR) {
507 ALOGE("setActiveColorMode failed to transact: %d", result);
508 return result;
509 }
510 return static_cast<status_t>(reply.readInt32());
511 }
512
Galia Peycheva5492cb52019-10-30 14:13:16 +0100513 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
514 bool* outSupport) const {
515 Parcel data, reply;
516 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
517 status_t result = data.writeStrongBinder(display);
518 if (result != NO_ERROR) {
519 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
520 return result;
521 }
522 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
523 &reply);
524 if (result != NO_ERROR) {
525 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
526 return result;
527 }
528 return reply.readBool(outSupport);
529 }
530
531 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
532 Parcel data, reply;
533 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
534 if (result != NO_ERROR) {
535 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
536 return;
537 }
538
539 result = data.writeStrongBinder(display);
540 if (result != NO_ERROR) {
541 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
542 return;
543 }
544 result = data.writeBool(on);
545 if (result != NO_ERROR) {
546 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
547 return;
548 }
549 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
550 if (result != NO_ERROR) {
551 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
552 return;
553 }
554 }
555
556 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
557 Parcel data, reply;
558 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
559 status_t result = data.writeStrongBinder(display);
560 if (result != NO_ERROR) {
561 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
562 return result;
563 }
564 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
565 if (result != NO_ERROR) {
566 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
567 return result;
568 }
569 return reply.readBool(outSupport);
570 }
571
572 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
573 Parcel data, reply;
574 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
575 if (result != NO_ERROR) {
576 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
577 return;
578 }
579 result = data.writeStrongBinder(display);
580 if (result != NO_ERROR) {
581 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
582 return;
583 }
584 result = data.writeBool(on);
585 if (result != NO_ERROR) {
586 ALOGE("setGameContentType failed to writeBool: %d", result);
587 return;
588 }
589 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
590 if (result != NO_ERROR) {
591 ALOGE("setGameContentType failed to transact: %d", result);
592 }
593 }
594
Svetoslavd85084b2014-03-20 10:28:31 -0700595 virtual status_t clearAnimationFrameStats() {
596 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700597 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
598 if (result != NO_ERROR) {
599 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
600 return result;
601 }
602 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
603 if (result != NO_ERROR) {
604 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
605 return result;
606 }
Svetoslavd85084b2014-03-20 10:28:31 -0700607 return reply.readInt32();
608 }
609
610 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
611 Parcel data, reply;
612 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
613 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
614 reply.read(*outStats);
615 return reply.readInt32();
616 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700617
618 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
619 HdrCapabilities* outCapabilities) const {
620 Parcel data, reply;
621 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
622 status_t result = data.writeStrongBinder(display);
623 if (result != NO_ERROR) {
624 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
625 return result;
626 }
627 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
628 data, &reply);
629 if (result != NO_ERROR) {
630 ALOGE("getHdrCapabilities failed to transact: %d", result);
631 return result;
632 }
633 result = reply.readInt32();
634 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800635 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700636 }
637 return result;
638 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700639
640 virtual status_t enableVSyncInjections(bool enable) {
641 Parcel data, reply;
642 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
643 if (result != NO_ERROR) {
644 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
645 return result;
646 }
647 result = data.writeBool(enable);
648 if (result != NO_ERROR) {
649 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
650 return result;
651 }
Steven Moreland366eb422019-04-01 19:22:32 -0700652 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
653 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700654 if (result != NO_ERROR) {
655 ALOGE("enableVSyncInjections failed to transact: %d", result);
656 return result;
657 }
658 return result;
659 }
660
661 virtual status_t injectVSync(nsecs_t when) {
662 Parcel data, reply;
663 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
664 if (result != NO_ERROR) {
665 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
666 return result;
667 }
668 result = data.writeInt64(when);
669 if (result != NO_ERROR) {
670 ALOGE("injectVSync failed to writeInt64: %d", result);
671 return result;
672 }
Steven Moreland366eb422019-04-01 19:22:32 -0700673 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
674 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700675 if (result != NO_ERROR) {
676 ALOGE("injectVSync failed to transact: %d", result);
677 return result;
678 }
679 return result;
680 }
681
Vishnu Nair43bccf82020-06-05 10:53:37 -0700682 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800683 if (!outLayers) {
684 return UNEXPECTED_NULL;
685 }
686
687 Parcel data, reply;
688
689 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
690 if (err != NO_ERROR) {
691 return err;
692 }
693
694 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
695 if (err != NO_ERROR) {
696 return err;
697 }
698
699 int32_t result = 0;
700 err = reply.readInt32(&result);
701 if (err != NO_ERROR) {
702 return err;
703 }
704 if (result != NO_ERROR) {
705 return result;
706 }
707
708 outLayers->clear();
709 return reply.readParcelableVector(outLayers);
710 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700711
Peiyong Linc6780972018-10-28 15:24:08 -0700712 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
713 ui::PixelFormat* defaultPixelFormat,
714 ui::Dataspace* wideColorGamutDataspace,
715 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700716 Parcel data, reply;
717 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
718 if (error != NO_ERROR) {
719 return error;
720 }
721 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
722 if (error != NO_ERROR) {
723 return error;
724 }
725 error = static_cast<status_t>(reply.readInt32());
726 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700727 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
728 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
729 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
730 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700731 }
732 return error;
733 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700734
Ady Abraham37965d42018-11-01 13:43:32 -0700735 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700736 Parcel data, reply;
737 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700738 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
739 bool result;
740 status_t err = reply.readBool(&result);
741 if (err == NO_ERROR) {
742 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700743 }
Ady Abraham37965d42018-11-01 13:43:32 -0700744 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700745 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700746
747 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
748 ui::PixelFormat* outFormat,
749 ui::Dataspace* outDataspace,
750 uint8_t* outComponentMask) const {
751 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
752 Parcel data, reply;
753 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
754 data.writeStrongBinder(display);
755
756 status_t error =
757 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
758 data, &reply);
759 if (error != NO_ERROR) {
760 return error;
761 }
762
763 uint32_t value = 0;
764 error = reply.readUint32(&value);
765 if (error != NO_ERROR) {
766 return error;
767 }
768 *outFormat = static_cast<ui::PixelFormat>(value);
769
770 error = reply.readUint32(&value);
771 if (error != NO_ERROR) {
772 return error;
773 }
774 *outDataspace = static_cast<ui::Dataspace>(value);
775
776 error = reply.readUint32(&value);
777 if (error != NO_ERROR) {
778 return error;
779 }
780 *outComponentMask = static_cast<uint8_t>(value);
781 return error;
782 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800783
784 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700785 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800786 Parcel data, reply;
787 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
788 data.writeStrongBinder(display);
789 data.writeBool(enable);
790 data.writeByte(static_cast<int8_t>(componentMask));
791 data.writeUint64(maxFrames);
792 status_t result =
793 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
794 &reply);
795 return result;
796 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700797
798 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
799 uint64_t timestamp,
800 DisplayedFrameStats* outStats) const {
801 if (!outStats) return BAD_VALUE;
802
803 Parcel data, reply;
804 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
805 data.writeStrongBinder(display);
806 data.writeUint64(maxFrames);
807 data.writeUint64(timestamp);
808
809 status_t result =
810 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
811
812 if (result != NO_ERROR) {
813 return result;
814 }
815
816 result = reply.readUint64(&outStats->numFrames);
817 if (result != NO_ERROR) {
818 return result;
819 }
820
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800821 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700822 if (result != NO_ERROR) {
823 return result;
824 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800825 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700826 if (result != NO_ERROR) {
827 return result;
828 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800829 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700830 if (result != NO_ERROR) {
831 return result;
832 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800833 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700834 return result;
835 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800836
837 virtual status_t getProtectedContentSupport(bool* outSupported) const {
838 Parcel data, reply;
839 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800840 status_t error =
841 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
842 if (error != NO_ERROR) {
843 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800844 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800845 error = reply.readBool(outSupported);
846 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800847 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800848
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800849 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
850 bool* outIsWideColorDisplay) const {
851 Parcel data, reply;
852 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
853 if (error != NO_ERROR) {
854 return error;
855 }
856 error = data.writeStrongBinder(token);
857 if (error != NO_ERROR) {
858 return error;
859 }
860
861 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
862 if (error != NO_ERROR) {
863 return error;
864 }
865 error = reply.readBool(outIsWideColorDisplay);
866 return error;
867 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800868
869 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
870 const sp<IBinder>& stopLayerHandle,
871 const sp<IRegionSamplingListener>& listener) {
872 Parcel data, reply;
873 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
874 if (error != NO_ERROR) {
875 ALOGE("addRegionSamplingListener: Failed to write interface token");
876 return error;
877 }
878 error = data.write(samplingArea);
879 if (error != NO_ERROR) {
880 ALOGE("addRegionSamplingListener: Failed to write sampling area");
881 return error;
882 }
883 error = data.writeStrongBinder(stopLayerHandle);
884 if (error != NO_ERROR) {
885 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
886 return error;
887 }
888 error = data.writeStrongBinder(IInterface::asBinder(listener));
889 if (error != NO_ERROR) {
890 ALOGE("addRegionSamplingListener: Failed to write listener");
891 return error;
892 }
893 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
894 if (error != NO_ERROR) {
895 ALOGE("addRegionSamplingListener: Failed to transact");
896 }
897 return error;
898 }
899
900 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
901 Parcel data, reply;
902 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
903 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800904 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800905 return error;
906 }
907 error = data.writeStrongBinder(IInterface::asBinder(listener));
908 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800909 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800910 return error;
911 }
912 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
913 &reply);
914 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800915 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800916 }
917 return error;
918 }
Ady Abraham838de062019-02-04 10:24:03 -0800919
Ana Krulec0782b882019-10-15 17:34:54 -0700920 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700921 int32_t defaultConfig,
922 float primaryRefreshRateMin,
923 float primaryRefreshRateMax,
924 float appRequestRefreshRateMin,
925 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700926 Parcel data, reply;
927 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
928 if (result != NO_ERROR) {
929 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
930 return result;
931 }
932 result = data.writeStrongBinder(displayToken);
933 if (result != NO_ERROR) {
934 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
935 return result;
936 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100937 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700938 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100939 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700940 return result;
941 }
Steven Thomasf734df42020-04-13 21:09:28 -0700942 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700943 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700944 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700945 return result;
946 }
Steven Thomasf734df42020-04-13 21:09:28 -0700947 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700948 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700949 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
950 return result;
951 }
952 result = data.writeFloat(appRequestRefreshRateMin);
953 if (result != NO_ERROR) {
954 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
955 result);
956 return result;
957 }
958 result = data.writeFloat(appRequestRefreshRateMax);
959 if (result != NO_ERROR) {
960 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
961 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700962 return result;
963 }
964
965 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
966 &reply);
967 if (result != NO_ERROR) {
968 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
969 return result;
970 }
971 return reply.readInt32();
972 }
973
Ana Krulec234bb162019-11-10 22:55:55 +0100974 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100975 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700976 float* outPrimaryRefreshRateMin,
977 float* outPrimaryRefreshRateMax,
978 float* outAppRequestRefreshRateMin,
979 float* outAppRequestRefreshRateMax) {
980 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
981 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
982 return BAD_VALUE;
983 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800984 Parcel data, reply;
985 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
986 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100987 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800988 return result;
989 }
990 result = data.writeStrongBinder(displayToken);
991 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100992 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800993 return result;
994 }
Ana Krulec234bb162019-11-10 22:55:55 +0100995 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
996 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800997 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100998 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800999 return result;
1000 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001001 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001002 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001003 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001004 return result;
1005 }
Steven Thomasf734df42020-04-13 21:09:28 -07001006 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001007 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001008 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001009 return result;
1010 }
Steven Thomasf734df42020-04-13 21:09:28 -07001011 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001012 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001013 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
1014 return result;
1015 }
1016 result = reply.readFloat(outAppRequestRefreshRateMin);
1017 if (result != NO_ERROR) {
1018 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
1019 result);
1020 return result;
1021 }
1022 result = reply.readFloat(outAppRequestRefreshRateMax);
1023 if (result != NO_ERROR) {
1024 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
1025 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001026 return result;
1027 }
1028 return reply.readInt32();
1029 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001030
1031 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1032 bool* outSupport) const {
1033 Parcel data, reply;
1034 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1035 if (error != NO_ERROR) {
1036 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1037 return error;
1038 }
1039 error = data.writeStrongBinder(displayToken);
1040 if (error != NO_ERROR) {
1041 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1042 return error;
1043 }
1044 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1045 if (error != NO_ERROR) {
1046 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1047 return error;
1048 }
1049 bool support;
1050 error = reply.readBool(&support);
1051 if (error != NO_ERROR) {
1052 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1053 return error;
1054 }
1055 *outSupport = support;
1056 return NO_ERROR;
1057 }
1058
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001059 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001060 Parcel data, reply;
1061 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1062 if (error != NO_ERROR) {
1063 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1064 return error;
1065 }
1066 error = data.writeStrongBinder(displayToken);
1067 if (error != NO_ERROR) {
1068 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1069 return error;
1070 }
1071 error = data.writeFloat(brightness);
1072 if (error != NO_ERROR) {
1073 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1074 return error;
1075 }
1076 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1077 if (error != NO_ERROR) {
1078 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1079 return error;
1080 }
1081 return NO_ERROR;
1082 }
Ady Abraham8532d012019-05-08 14:50:56 -07001083
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001084 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001085 Parcel data, reply;
1086 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1087 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001088 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001089 return error;
1090 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001091 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001092 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001093 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001094 return error;
1095 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001096 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001097 IBinder::FLAG_ONEWAY);
1098 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001099 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001100 return error;
1101 }
1102 return NO_ERROR;
1103 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001104
1105 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1106 float lightPosY, float lightPosZ, float lightRadius) {
1107 Parcel data, reply;
1108 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1109 if (error != NO_ERROR) {
1110 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1111 return error;
1112 }
1113
1114 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1115 ambientColor.a, spotColor.r, spotColor.g,
1116 spotColor.b, spotColor.a, lightPosY,
1117 lightPosZ, lightRadius};
1118
1119 error = data.writeFloatVector(shadowConfig);
1120 if (error != NO_ERROR) {
1121 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1122 return error;
1123 }
1124
1125 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1126 IBinder::FLAG_ONEWAY);
1127 if (error != NO_ERROR) {
1128 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1129 return error;
1130 }
1131 return NO_ERROR;
1132 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001133
1134 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1135 int8_t compatibility) {
1136 Parcel data, reply;
1137 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1138 if (err != NO_ERROR) {
1139 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1140 return err;
1141 }
1142
1143 err = data.writeStrongBinder(IInterface::asBinder(surface));
1144 if (err != NO_ERROR) {
1145 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1146 return err;
1147 }
1148
1149 err = data.writeFloat(frameRate);
1150 if (err != NO_ERROR) {
1151 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1152 return err;
1153 }
1154
1155 err = data.writeByte(compatibility);
1156 if (err != NO_ERROR) {
1157 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1158 return err;
1159 }
1160
Ady Abraham60e42ea2020-03-09 19:17:31 -07001161 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001162 if (err != NO_ERROR) {
1163 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1164 return err;
1165 }
Steven Thomasd4071902020-03-24 16:02:53 -07001166
1167 return reply.readInt32();
1168 }
1169
1170 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1171 if (!outToken) return BAD_VALUE;
1172
1173 Parcel data, reply;
1174 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1175 if (err != NO_ERROR) {
1176 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1177 strerror(-err), -err);
1178 return err;
1179 }
1180
1181 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1182 &reply);
1183 if (err != NO_ERROR) {
1184 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1185 err);
1186 return err;
1187 }
1188
1189 err = reply.readInt32();
1190 if (err != NO_ERROR) {
1191 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1192 return err;
1193 }
1194
1195 err = reply.readStrongBinder(outToken);
1196 if (err != NO_ERROR) {
1197 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1198 strerror(-err), err);
1199 return err;
1200 }
1201
Steven Thomas62a4cf82020-01-31 12:04:03 -08001202 return NO_ERROR;
1203 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001204};
1205
Dan Stozad723bd72014-11-18 10:24:03 -08001206// Out-of-line virtual method definition to trigger vtable emission in this
1207// translation unit (see clang warning -Wweak-vtables)
1208BpSurfaceComposer::~BpSurfaceComposer() {}
1209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001210IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1211
1212// ----------------------------------------------------------------------
1213
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001214status_t BnSurfaceComposer::onTransact(
1215 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1216{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001217 switch(code) {
1218 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001219 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001220 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001221 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001222 return NO_ERROR;
1223 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001224 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001225 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001226
1227 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001228 if (count > data.dataSize()) {
1229 return BAD_VALUE;
1230 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001231 Vector<ComposerState> state;
1232 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001233 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001234 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001235 if (s.read(data) == BAD_VALUE) {
1236 return BAD_VALUE;
1237 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001238 state.add(s);
1239 }
Dan Stozad723bd72014-11-18 10:24:03 -08001240
1241 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001242 if (count > data.dataSize()) {
1243 return BAD_VALUE;
1244 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001245 DisplayState d;
1246 Vector<DisplayState> displays;
1247 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001248 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001249 if (d.read(data) == BAD_VALUE) {
1250 return BAD_VALUE;
1251 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001252 displays.add(d);
1253 }
Dan Stozad723bd72014-11-18 10:24:03 -08001254
1255 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001256 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001257 InputWindowCommands inputWindowCommands;
1258 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001259
1260 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001261
Marissa Wall947d34e2019-03-29 14:03:53 -07001262 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001263 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001264 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001265
Valerie Hau9dab9732019-08-20 09:29:25 -07001266 bool hasListenerCallbacks = data.readBool();
1267
Marissa Wall3dad52d2019-03-22 14:03:19 -07001268 std::vector<ListenerCallbacks> listenerCallbacks;
1269 int32_t listenersSize = data.readInt32();
1270 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001271 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001272 std::vector<CallbackId> callbackIds;
1273 data.readInt64Vector(&callbackIds);
1274 listenerCallbacks.emplace_back(listener, callbackIds);
1275 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001276 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001277 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1278 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001279 return NO_ERROR;
1280 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001281 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001282 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001283 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001284 return NO_ERROR;
1285 }
chaviwd2432892020-07-24 17:42:39 -07001286 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001287 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001288 DisplayCaptureArgs args;
1289 ScreenCaptureResults captureResults;
Dan Stozac7014012014-02-14 15:03:43 -08001290
chaviwd2432892020-07-24 17:42:39 -07001291 status_t res = args.read(data);
1292 if (res != NO_ERROR) {
1293 reply->writeInt32(res);
1294 return NO_ERROR;
1295 }
1296
1297 res = captureDisplay(args, captureResults);
Robert Carr108b2c72019-04-02 16:32:58 -07001298
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001299 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001300 if (res == NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -07001301 captureResults.write(*reply);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001302 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001303 return NO_ERROR;
1304 }
chaviwd2432892020-07-24 17:42:39 -07001305 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001306 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1307 uint64_t displayOrLayerStack = data.readUint64();
chaviwd2432892020-07-24 17:42:39 -07001308 ScreenCaptureResults captureResults;
1309 status_t res = captureDisplay(displayOrLayerStack, captureResults);
chaviw93df2ea2019-04-30 16:45:12 -07001310 reply->writeInt32(res);
1311 if (res == NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -07001312 captureResults.write(*reply);
chaviw93df2ea2019-04-30 16:45:12 -07001313 }
1314 return NO_ERROR;
1315 }
chaviwa76b2712017-09-20 12:02:26 -07001316 case CAPTURE_LAYERS: {
1317 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1318 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -07001319 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
1320 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001321 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -08001322 Rect sourceCrop(Rect::EMPTY_RECT);
1323 data.read(sourceCrop);
Robert Carr866455f2019-04-02 16:28:26 -07001324
1325 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
1326 int numExcludeHandles = data.readInt32();
Ady Abraham0a525092020-03-03 12:51:24 -08001327 if (numExcludeHandles >= static_cast<int>(MAX_LAYERS)) {
1328 return BAD_VALUE;
1329 }
Robert Carr866455f2019-04-02 16:28:26 -07001330 excludeHandles.reserve(numExcludeHandles);
1331 for (int i = 0; i < numExcludeHandles; i++) {
1332 excludeHandles.emplace(data.readStrongBinder());
1333 }
1334
chaviw7206d492017-11-10 16:16:12 -08001335 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -08001336 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -07001337
Robert Carr866455f2019-04-02 16:28:26 -07001338 status_t res =
1339 captureLayers(layerHandleBinder, &outBuffer, reqDataspace, reqPixelFormat,
1340 sourceCrop, excludeHandles, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -07001341 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001342 if (res == NO_ERROR) {
1343 reply->write(*outBuffer);
1344 }
chaviwa76b2712017-09-20 12:02:26 -07001345 return NO_ERROR;
1346 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001347 case AUTHENTICATE_SURFACE: {
1348 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001349 sp<IGraphicBufferProducer> bufferProducer =
1350 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1351 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001352 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001353 return NO_ERROR;
1354 }
Brian Anderson6b376712017-04-04 10:51:39 -07001355 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1357 std::vector<FrameEvent> supportedTimestamps;
1358 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1359 status_t err = reply->writeInt32(result);
1360 if (err != NO_ERROR) {
1361 return err;
1362 }
1363 if (result != NO_ERROR) {
1364 return result;
1365 }
1366
1367 std::vector<int32_t> supported;
1368 supported.reserve(supportedTimestamps.size());
1369 for (FrameEvent s : supportedTimestamps) {
1370 supported.push_back(static_cast<int32_t>(s));
1371 }
1372 return reply->writeInt32Vector(supported);
1373 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001374 case CREATE_DISPLAY_EVENT_CONNECTION: {
1375 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001376 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1377 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1378
1379 sp<IDisplayEventConnection> connection(
1380 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001381 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001382 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001383 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001384 case CREATE_DISPLAY: {
1385 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001386 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001387 bool secure = bool(data.readInt32());
1388 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001389 reply->writeStrongBinder(display);
1390 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001391 }
1392 case DESTROY_DISPLAY: {
1393 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1394 sp<IBinder> display = data.readStrongBinder();
1395 destroyDisplay(display);
1396 return NO_ERROR;
1397 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001398 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001399 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001400 PhysicalDisplayId displayId = data.readUint64();
1401 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001402 reply->writeStrongBinder(display);
1403 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001404 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001405 case GET_DISPLAY_STATE: {
1406 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1407 ui::DisplayState state;
1408 const sp<IBinder> display = data.readStrongBinder();
1409 const status_t result = getDisplayState(display, &state);
1410 reply->writeInt32(result);
1411 if (result == NO_ERROR) {
1412 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1413 sizeof(ui::DisplayState));
1414 }
1415 return NO_ERROR;
1416 }
1417 case GET_DISPLAY_INFO: {
1418 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1419 DisplayInfo info;
1420 const sp<IBinder> display = data.readStrongBinder();
1421 const status_t result = getDisplayInfo(display, &info);
1422 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001423 if (result != NO_ERROR) return result;
1424 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001425 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001426 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001427 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001428 Vector<DisplayConfig> configs;
1429 const sp<IBinder> display = data.readStrongBinder();
1430 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001431 reply->writeInt32(result);
1432 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001433 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001434 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001435 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1436 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001437 }
1438 }
1439 return NO_ERROR;
1440 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001441 case GET_DISPLAY_STATS: {
1442 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1443 DisplayStatInfo stats;
1444 sp<IBinder> display = data.readStrongBinder();
1445 status_t result = getDisplayStats(display, &stats);
1446 reply->writeInt32(result);
1447 if (result == NO_ERROR) {
1448 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1449 &stats, sizeof(DisplayStatInfo));
1450 }
1451 return NO_ERROR;
1452 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001453 case GET_ACTIVE_CONFIG: {
1454 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1455 sp<IBinder> display = data.readStrongBinder();
1456 int id = getActiveConfig(display);
1457 reply->writeInt32(id);
1458 return NO_ERROR;
1459 }
Michael Wright28f24d02016-07-12 13:30:53 -07001460 case GET_DISPLAY_COLOR_MODES: {
1461 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001462 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001463 sp<IBinder> display = nullptr;
1464 status_t result = data.readStrongBinder(&display);
1465 if (result != NO_ERROR) {
1466 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1467 return result;
1468 }
1469 result = getDisplayColorModes(display, &colorModes);
1470 reply->writeInt32(result);
1471 if (result == NO_ERROR) {
1472 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1473 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001474 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001475 }
1476 }
1477 return NO_ERROR;
1478 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001479 case GET_DISPLAY_NATIVE_PRIMARIES: {
1480 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1481 ui::DisplayPrimaries primaries;
1482 sp<IBinder> display = nullptr;
1483
1484 status_t result = data.readStrongBinder(&display);
1485 if (result != NO_ERROR) {
1486 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1487 return result;
1488 }
1489
1490 result = getDisplayNativePrimaries(display, primaries);
1491 reply->writeInt32(result);
1492 if (result == NO_ERROR) {
1493 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1494 sizeof(ui::DisplayPrimaries));
1495 }
1496
1497 return NO_ERROR;
1498 }
Michael Wright28f24d02016-07-12 13:30:53 -07001499 case GET_ACTIVE_COLOR_MODE: {
1500 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1501 sp<IBinder> display = nullptr;
1502 status_t result = data.readStrongBinder(&display);
1503 if (result != NO_ERROR) {
1504 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1505 return result;
1506 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001507 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001508 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1509 return result;
1510 }
1511 case SET_ACTIVE_COLOR_MODE: {
1512 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1513 sp<IBinder> display = nullptr;
1514 status_t result = data.readStrongBinder(&display);
1515 if (result != NO_ERROR) {
1516 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1517 return result;
1518 }
1519 int32_t colorModeInt = 0;
1520 result = data.readInt32(&colorModeInt);
1521 if (result != NO_ERROR) {
1522 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1523 return result;
1524 }
1525 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001526 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001527 result = reply->writeInt32(result);
1528 return result;
1529 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001530
1531 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
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("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1537 return result;
1538 }
1539 bool supported = false;
1540 result = getAutoLowLatencyModeSupport(display, &supported);
1541 if (result == NO_ERROR) {
1542 result = reply->writeBool(supported);
1543 }
1544 return result;
1545 }
1546
1547 case SET_AUTO_LOW_LATENCY_MODE: {
1548 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1549 sp<IBinder> display = nullptr;
1550 status_t result = data.readStrongBinder(&display);
1551 if (result != NO_ERROR) {
1552 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1553 return result;
1554 }
1555 bool setAllm = false;
1556 result = data.readBool(&setAllm);
1557 if (result != NO_ERROR) {
1558 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1559 return result;
1560 }
1561 setAutoLowLatencyMode(display, setAllm);
1562 return result;
1563 }
1564
1565 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1566 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1567 sp<IBinder> display = nullptr;
1568 status_t result = data.readStrongBinder(&display);
1569 if (result != NO_ERROR) {
1570 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1571 return result;
1572 }
1573 bool supported = false;
1574 result = getGameContentTypeSupport(display, &supported);
1575 if (result == NO_ERROR) {
1576 result = reply->writeBool(supported);
1577 }
1578 return result;
1579 }
1580
1581 case SET_GAME_CONTENT_TYPE: {
1582 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1583 sp<IBinder> display = nullptr;
1584 status_t result = data.readStrongBinder(&display);
1585 if (result != NO_ERROR) {
1586 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1587 return result;
1588 }
1589 bool setGameContentTypeOn = false;
1590 result = data.readBool(&setGameContentTypeOn);
1591 if (result != NO_ERROR) {
1592 ALOGE("setGameContentType failed to readBool: %d", result);
1593 return result;
1594 }
1595 setGameContentType(display, setGameContentTypeOn);
1596 return result;
1597 }
1598
Svetoslavd85084b2014-03-20 10:28:31 -07001599 case CLEAR_ANIMATION_FRAME_STATS: {
1600 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1601 status_t result = clearAnimationFrameStats();
1602 reply->writeInt32(result);
1603 return NO_ERROR;
1604 }
1605 case GET_ANIMATION_FRAME_STATS: {
1606 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1607 FrameStats stats;
1608 status_t result = getAnimationFrameStats(&stats);
1609 reply->write(stats);
1610 reply->writeInt32(result);
1611 return NO_ERROR;
1612 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001613 case SET_POWER_MODE: {
1614 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1615 sp<IBinder> display = data.readStrongBinder();
1616 int32_t mode = data.readInt32();
1617 setPowerMode(display, mode);
1618 return NO_ERROR;
1619 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001620 case GET_HDR_CAPABILITIES: {
1621 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1622 sp<IBinder> display = nullptr;
1623 status_t result = data.readStrongBinder(&display);
1624 if (result != NO_ERROR) {
1625 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1626 result);
1627 return result;
1628 }
1629 HdrCapabilities capabilities;
1630 result = getHdrCapabilities(display, &capabilities);
1631 reply->writeInt32(result);
1632 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001633 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001634 }
1635 return NO_ERROR;
1636 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001637 case ENABLE_VSYNC_INJECTIONS: {
1638 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1639 bool enable = false;
1640 status_t result = data.readBool(&enable);
1641 if (result != NO_ERROR) {
1642 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1643 return result;
1644 }
1645 return enableVSyncInjections(enable);
1646 }
1647 case INJECT_VSYNC: {
1648 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1649 int64_t when = 0;
1650 status_t result = data.readInt64(&when);
1651 if (result != NO_ERROR) {
1652 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1653 return result;
1654 }
1655 return injectVSync(when);
1656 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001657 case GET_LAYER_DEBUG_INFO: {
1658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1659 std::vector<LayerDebugInfo> outLayers;
1660 status_t result = getLayerDebugInfo(&outLayers);
1661 reply->writeInt32(result);
1662 if (result == NO_ERROR)
1663 {
1664 result = reply->writeParcelableVector(outLayers);
1665 }
1666 return result;
1667 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001668 case GET_COMPOSITION_PREFERENCE: {
1669 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001670 ui::Dataspace defaultDataspace;
1671 ui::PixelFormat defaultPixelFormat;
1672 ui::Dataspace wideColorGamutDataspace;
1673 ui::PixelFormat wideColorGamutPixelFormat;
1674 status_t error =
1675 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1676 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001677 reply->writeInt32(error);
1678 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001679 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1680 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1681 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001682 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001683 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001684 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001685 }
Ady Abraham37965d42018-11-01 13:43:32 -07001686 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001687 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001688 bool result;
1689 status_t error = getColorManagement(&result);
1690 if (error == NO_ERROR) {
1691 reply->writeBool(result);
1692 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001693 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001694 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001695 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1696 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1697
1698 sp<IBinder> display = data.readStrongBinder();
1699 ui::PixelFormat format;
1700 ui::Dataspace dataspace;
1701 uint8_t component = 0;
1702 auto result =
1703 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1704 if (result == NO_ERROR) {
1705 reply->writeUint32(static_cast<uint32_t>(format));
1706 reply->writeUint32(static_cast<uint32_t>(dataspace));
1707 reply->writeUint32(static_cast<uint32_t>(component));
1708 }
1709 return result;
1710 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001711 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1712 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1713
1714 sp<IBinder> display = nullptr;
1715 bool enable = false;
1716 int8_t componentMask = 0;
1717 uint64_t maxFrames = 0;
1718 status_t result = data.readStrongBinder(&display);
1719 if (result != NO_ERROR) {
1720 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1721 result);
1722 return result;
1723 }
1724
1725 result = data.readBool(&enable);
1726 if (result != NO_ERROR) {
1727 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1728 return result;
1729 }
1730
1731 result = data.readByte(static_cast<int8_t*>(&componentMask));
1732 if (result != NO_ERROR) {
1733 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1734 result);
1735 return result;
1736 }
1737
1738 result = data.readUint64(&maxFrames);
1739 if (result != NO_ERROR) {
1740 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1741 return result;
1742 }
1743
1744 return setDisplayContentSamplingEnabled(display, enable,
1745 static_cast<uint8_t>(componentMask), maxFrames);
1746 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001747 case GET_DISPLAYED_CONTENT_SAMPLE: {
1748 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1749
1750 sp<IBinder> display = data.readStrongBinder();
1751 uint64_t maxFrames = 0;
1752 uint64_t timestamp = 0;
1753
1754 status_t result = data.readUint64(&maxFrames);
1755 if (result != NO_ERROR) {
1756 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1757 return result;
1758 }
1759
1760 result = data.readUint64(&timestamp);
1761 if (result != NO_ERROR) {
1762 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1763 return result;
1764 }
1765
1766 DisplayedFrameStats stats;
1767 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1768 if (result == NO_ERROR) {
1769 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001770 reply->writeUint64Vector(stats.component_0_sample);
1771 reply->writeUint64Vector(stats.component_1_sample);
1772 reply->writeUint64Vector(stats.component_2_sample);
1773 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001774 }
1775 return result;
1776 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001777 case GET_PROTECTED_CONTENT_SUPPORT: {
1778 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1779 bool result;
1780 status_t error = getProtectedContentSupport(&result);
1781 if (error == NO_ERROR) {
1782 reply->writeBool(result);
1783 }
1784 return error;
1785 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001786 case IS_WIDE_COLOR_DISPLAY: {
1787 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1788 sp<IBinder> display = nullptr;
1789 status_t error = data.readStrongBinder(&display);
1790 if (error != NO_ERROR) {
1791 return error;
1792 }
1793 bool result;
1794 error = isWideColorDisplay(display, &result);
1795 if (error == NO_ERROR) {
1796 reply->writeBool(result);
1797 }
1798 return error;
1799 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001800 case GET_PHYSICAL_DISPLAY_IDS: {
1801 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1802 return reply->writeUint64Vector(getPhysicalDisplayIds());
1803 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001804 case ADD_REGION_SAMPLING_LISTENER: {
1805 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1806 Rect samplingArea;
1807 status_t result = data.read(samplingArea);
1808 if (result != NO_ERROR) {
1809 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1810 return result;
1811 }
1812 sp<IBinder> stopLayerHandle;
1813 result = data.readNullableStrongBinder(&stopLayerHandle);
1814 if (result != NO_ERROR) {
1815 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1816 return result;
1817 }
1818 sp<IRegionSamplingListener> listener;
1819 result = data.readNullableStrongBinder(&listener);
1820 if (result != NO_ERROR) {
1821 ALOGE("addRegionSamplingListener: Failed to read listener");
1822 return result;
1823 }
1824 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1825 }
1826 case REMOVE_REGION_SAMPLING_LISTENER: {
1827 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1828 sp<IRegionSamplingListener> listener;
1829 status_t result = data.readNullableStrongBinder(&listener);
1830 if (result != NO_ERROR) {
1831 ALOGE("removeRegionSamplingListener: Failed to read listener");
1832 return result;
1833 }
1834 return removeRegionSamplingListener(listener);
1835 }
Ana Krulec0782b882019-10-15 17:34:54 -07001836 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1837 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1838 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001839 int32_t defaultConfig;
1840 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001841 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001842 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001843 return result;
1844 }
Steven Thomasf734df42020-04-13 21:09:28 -07001845 float primaryRefreshRateMin;
1846 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001847 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001848 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1849 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001850 return result;
1851 }
Steven Thomasf734df42020-04-13 21:09:28 -07001852 float primaryRefreshRateMax;
1853 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001854 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001855 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1856 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001857 return result;
1858 }
Steven Thomasf734df42020-04-13 21:09:28 -07001859 float appRequestRefreshRateMin;
1860 result = data.readFloat(&appRequestRefreshRateMin);
1861 if (result != NO_ERROR) {
1862 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1863 result);
1864 return result;
1865 }
1866 float appRequestRefreshRateMax;
1867 result = data.readFloat(&appRequestRefreshRateMax);
1868 if (result != NO_ERROR) {
1869 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1870 result);
1871 return result;
1872 }
1873 result =
1874 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1875 primaryRefreshRateMax, appRequestRefreshRateMin,
1876 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001877 if (result != NO_ERROR) {
1878 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1879 "%d",
1880 result);
1881 return result;
1882 }
1883 reply->writeInt32(result);
1884 return result;
1885 }
Ana Krulec234bb162019-11-10 22:55:55 +01001886 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1887 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1888 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001889 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001890 float primaryRefreshRateMin;
1891 float primaryRefreshRateMax;
1892 float appRequestRefreshRateMin;
1893 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001894
Steven Thomasf734df42020-04-13 21:09:28 -07001895 status_t result =
1896 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1897 &primaryRefreshRateMin, &primaryRefreshRateMax,
1898 &appRequestRefreshRateMin,
1899 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001900 if (result != NO_ERROR) {
1901 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1902 "%d",
1903 result);
1904 return result;
1905 }
1906
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001907 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001908 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001909 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001910 return result;
1911 }
Steven Thomasf734df42020-04-13 21:09:28 -07001912 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001913 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001914 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1915 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001916 return result;
1917 }
Steven Thomasf734df42020-04-13 21:09:28 -07001918 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001919 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001920 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1921 result);
1922 return result;
1923 }
1924 result = reply->writeFloat(appRequestRefreshRateMin);
1925 if (result != NO_ERROR) {
1926 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1927 result);
1928 return result;
1929 }
1930 result = reply->writeFloat(appRequestRefreshRateMax);
1931 if (result != NO_ERROR) {
1932 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1933 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001934 return result;
1935 }
1936 reply->writeInt32(result);
1937 return result;
1938 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001939 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1940 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1941 sp<IBinder> displayToken;
1942 status_t error = data.readNullableStrongBinder(&displayToken);
1943 if (error != NO_ERROR) {
1944 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1945 return error;
1946 }
1947 bool support = false;
1948 error = getDisplayBrightnessSupport(displayToken, &support);
1949 reply->writeBool(support);
1950 return error;
1951 }
1952 case SET_DISPLAY_BRIGHTNESS: {
1953 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1954 sp<IBinder> displayToken;
1955 status_t error = data.readNullableStrongBinder(&displayToken);
1956 if (error != NO_ERROR) {
1957 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1958 return error;
1959 }
1960 float brightness = -1.0f;
1961 error = data.readFloat(&brightness);
1962 if (error != NO_ERROR) {
1963 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1964 return error;
1965 }
1966 return setDisplayBrightness(displayToken, brightness);
1967 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001968 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001969 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001970 int32_t boostId;
1971 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001972 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001973 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001974 return error;
1975 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001976 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001977 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001978 case SET_GLOBAL_SHADOW_SETTINGS: {
1979 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1980
1981 std::vector<float> shadowConfig;
1982 status_t error = data.readFloatVector(&shadowConfig);
1983 if (error != NO_ERROR || shadowConfig.size() != 11) {
1984 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1985 return error;
1986 }
1987
1988 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1989 shadowConfig[3]};
1990 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1991 float lightPosY = shadowConfig[8];
1992 float lightPosZ = shadowConfig[9];
1993 float lightRadius = shadowConfig[10];
1994 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1995 lightRadius);
1996 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001997 case SET_FRAME_RATE: {
1998 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1999 sp<IBinder> binder;
2000 status_t err = data.readStrongBinder(&binder);
2001 if (err != NO_ERROR) {
2002 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
2003 return err;
2004 }
2005 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2006 if (!surface) {
2007 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
2008 strerror(-err), -err);
2009 return err;
2010 }
2011 float frameRate;
2012 err = data.readFloat(&frameRate);
2013 if (err != NO_ERROR) {
2014 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2015 return err;
2016 }
2017 int8_t compatibility;
2018 err = data.readByte(&compatibility);
2019 if (err != NO_ERROR) {
2020 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2021 return err;
2022 }
2023 status_t result = setFrameRate(surface, frameRate, compatibility);
2024 reply->writeInt32(result);
2025 return NO_ERROR;
2026 }
Steven Thomasd4071902020-03-24 16:02:53 -07002027 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2028 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2029 sp<IBinder> token;
2030 status_t result = acquireFrameRateFlexibilityToken(&token);
2031 reply->writeInt32(result);
2032 if (result == NO_ERROR) {
2033 reply->writeStrongBinder(token);
2034 }
2035 return NO_ERROR;
2036 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002037 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002038 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002039 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002040 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002041}
2042
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002043} // namespace android