blob: 964195d30d1105444c1e6ded735e7e3ac7fcb603 [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
Pablo Gamito6ee484d2020-07-30 14:26:28 +000023#include <android/gui/ITransactionTraceListener.h>
24
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070025#include <binder/Parcel.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070026#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopiand0566bc2011-11-17 17:49:17 -080029#include <gui/IDisplayEventConnection.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080030#include <gui/IGraphicBufferProducer.h>
Dan Stoza84ab9372018-12-17 15:27:57 -080031#include <gui/IRegionSamplingListener.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080032#include <gui/ISurfaceComposer.h>
33#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080034#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070035#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080036
Michael Wright28f24d02016-07-12 13:30:53 -070037#include <system/graphics.h>
38
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080039#include <ui/DisplayConfig.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070041#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080042#include <ui/DisplayState.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070043#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Jamie Gennis134f0422011-03-08 12:18:54 -080045#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080046
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047// ---------------------------------------------------------------------------
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049namespace android {
50
Peiyong Lin9f034472018-03-28 15:29:00 -070051using ui::ColorMode;
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
54{
55public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070056 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 : BpInterface<ISurfaceComposer>(impl)
58 {
59 }
60
Dan Stozad723bd72014-11-18 10:24:03 -080061 virtual ~BpSurfaceComposer();
62
Mathias Agopian7e27f052010-05-28 14:22:23 -070063 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 Parcel data, reply;
66 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
67 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070068 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 }
70
chaviw308ddba2020-08-11 16:23:51 -070071 virtual status_t setTransactionState(
Ady Abraham22c7b5c2020-09-22 19:33:40 -070072 int64_t frameTimelineVsyncId, const Vector<ComposerState>& state,
73 const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
74 const InputWindowCommands& commands, int64_t desiredPresentTime,
75 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
76 const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 Parcel data, reply;
78 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080079
Ady Abraham22c7b5c2020-09-22 19:33:40 -070080 SAFE_PARCEL(data.writeInt64, frameTimelineVsyncId);
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080082 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070083 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070084 }
Dan Stozad723bd72014-11-18 10:24:03 -080085
chaviw308ddba2020-08-11 16:23:51 -070086 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080087 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070088 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070089 }
Dan Stozad723bd72014-11-18 10:24:03 -080090
chaviw308ddba2020-08-11 16:23:51 -070091 SAFE_PARCEL(data.writeUint32, flags);
92 SAFE_PARCEL(data.writeStrongBinder, applyToken);
93 SAFE_PARCEL(commands.write, data);
94 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
95 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
96 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
97 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070098
chaviw308ddba2020-08-11 16:23:51 -070099 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
100 for (const auto& [listener, callbackIds] : listenerCallbacks) {
101 SAFE_PARCEL(data.writeStrongBinder, listener);
102 SAFE_PARCEL(data.writeInt64Vector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700103 }
104
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000105 SAFE_PARCEL(data.writeUint64, transactionId);
106
chaviw308ddba2020-08-11 16:23:51 -0700107 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108 }
109
110 virtual void bootFinished()
111 {
112 Parcel data, reply;
113 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
114 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
115 }
116
chaviwd2432892020-07-24 17:42:39 -0700117 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700118 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800119 Parcel data, reply;
120 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700121 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700122 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000123
chaviw8ffc7b82020-08-18 11:25:37 -0700124 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800125 }
126
chaviwd2432892020-07-24 17:42:39 -0700127 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
chaviw8ffc7b82020-08-18 11:25:37 -0700128 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -0700129 Parcel data, reply;
130 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw8ffc7b82020-08-18 11:25:37 -0700131 SAFE_PARCEL(data.writeUint64, displayOrLayerStack);
132 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw93df2ea2019-04-30 16:45:12 -0700133
chaviw8ffc7b82020-08-18 11:25:37 -0700134 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700135 }
136
chaviw3efadb12020-07-27 10:07:15 -0700137 virtual status_t captureLayers(const LayerCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700138 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -0700139 Parcel data, reply;
140 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700141 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700142 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw3efadb12020-07-27 10:07:15 -0700143
chaviw8ffc7b82020-08-18 11:25:37 -0700144 return remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
chaviwa76b2712017-09-20 12:02:26 -0700145 }
146
Jamie Gennis582270d2011-08-17 18:19:00 -0700147 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800148 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800149 {
150 Parcel data, reply;
151 int err = NO_ERROR;
152 err = data.writeInterfaceToken(
153 ISurfaceComposer::getInterfaceDescriptor());
154 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000155 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800156 "interface descriptor: %s (%d)", strerror(-err), -err);
157 return false;
158 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800159 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800160 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000161 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700162 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800163 return false;
164 }
165 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
166 &reply);
167 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000168 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700169 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800170 return false;
171 }
172 int32_t result = 0;
173 err = reply.readInt32(&result);
174 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000175 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700176 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800177 return false;
178 }
179 return result != 0;
180 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800181
Brian Anderson6b376712017-04-04 10:51:39 -0700182 virtual status_t getSupportedFrameTimestamps(
183 std::vector<FrameEvent>* outSupported) const {
184 if (!outSupported) {
185 return UNEXPECTED_NULL;
186 }
187 outSupported->clear();
188
189 Parcel data, reply;
190
191 status_t err = data.writeInterfaceToken(
192 ISurfaceComposer::getInterfaceDescriptor());
193 if (err != NO_ERROR) {
194 return err;
195 }
196
197 err = remote()->transact(
198 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
199 data, &reply);
200 if (err != NO_ERROR) {
201 return err;
202 }
203
204 int32_t result = 0;
205 err = reply.readInt32(&result);
206 if (err != NO_ERROR) {
207 return err;
208 }
209 if (result != NO_ERROR) {
210 return result;
211 }
212
213 std::vector<int32_t> supported;
214 err = reply.readInt32Vector(&supported);
215 if (err != NO_ERROR) {
216 return err;
217 }
218
219 outSupported->reserve(supported.size());
220 for (int32_t s : supported) {
221 outSupported->push_back(static_cast<FrameEvent>(s));
222 }
223 return NO_ERROR;
224 }
225
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700226 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
227 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800228 Parcel data, reply;
229 sp<IDisplayEventConnection> result;
230 int err = data.writeInterfaceToken(
231 ISurfaceComposer::getInterfaceDescriptor());
232 if (err != NO_ERROR) {
233 return result;
234 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700235 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700236 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800237 err = remote()->transact(
238 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
239 data, &reply);
240 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000241 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800242 "transaction: %s (%d)", strerror(-err), -err);
243 return result;
244 }
245 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
246 return result;
247 }
Colin Cross8e533062012-06-07 13:17:52 -0700248
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700249 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700250 {
251 Parcel data, reply;
252 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd4a61642020-09-01 14:53:46 -0700253 status_t status = data.writeString8(displayName);
254 if (status) {
255 return nullptr;
256 }
257 status = data.writeBool(secure);
258 if (status) {
259 return nullptr;
260 }
261
262 status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
263 if (status) {
264 return nullptr;
265 }
266 sp<IBinder> display;
267 status = reply.readNullableStrongBinder(&display);
268 if (status) {
269 return nullptr;
270 }
271 return display;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700272 }
273
Jesse Hall6c913be2013-08-08 12:15:49 -0700274 virtual void destroyDisplay(const sp<IBinder>& display)
275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
278 data.writeStrongBinder(display);
279 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
280 }
281
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800282 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700283 Parcel data, reply;
284 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800285 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
286 NO_ERROR) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200287 std::vector<uint64_t> rawIds;
288 if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
289 std::vector<PhysicalDisplayId> displayIds(rawIds.size());
290 std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
291 [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800292 return displayIds;
293 }
294 }
295
296 return {};
297 }
298
299 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
300 Parcel data, reply;
301 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Marin Shalamanova524a092020-07-27 21:39:55 +0200302 data.writeUint64(displayId.value);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800303 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700304 return reply.readStrongBinder();
305 }
306
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700307 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700311 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700312 data.writeInt32(mode);
313 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700314 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700315
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800316 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
317 Parcel data, reply;
318 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
319 data.writeStrongBinder(display);
320 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
321 const status_t result = reply.readInt32();
322 if (result == NO_ERROR) {
323 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
324 }
325 return result;
326 }
327
328 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
329 Parcel data, reply;
330 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
331 data.writeStrongBinder(display);
332 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
333 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100334 if (result != NO_ERROR) return result;
335 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800336 }
337
338 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700339 Parcel data, reply;
340 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700341 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700342 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800343 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700344 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800345 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700346 configs->clear();
347 configs->resize(numConfigs);
348 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800349 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
350 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700351 }
352 }
353 return result;
354 }
355
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700356 virtual status_t getDisplayStats(const sp<IBinder>& display,
357 DisplayStatInfo* stats)
358 {
359 Parcel data, reply;
360 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
361 data.writeStrongBinder(display);
362 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
363 status_t result = reply.readInt32();
364 if (result == NO_ERROR) {
365 memcpy(stats,
366 reply.readInplace(sizeof(DisplayStatInfo)),
367 sizeof(DisplayStatInfo));
368 }
369 return result;
370 }
371
Dan Stoza7f7da322014-05-02 15:26:25 -0700372 virtual int getActiveConfig(const sp<IBinder>& display)
373 {
374 Parcel data, reply;
375 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
376 data.writeStrongBinder(display);
377 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
378 return reply.readInt32();
379 }
380
Michael Wright28f24d02016-07-12 13:30:53 -0700381 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700382 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700383 Parcel data, reply;
384 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
385 if (result != NO_ERROR) {
386 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
387 return result;
388 }
389 result = data.writeStrongBinder(display);
390 if (result != NO_ERROR) {
391 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
392 return result;
393 }
394 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
395 if (result != NO_ERROR) {
396 ALOGE("getDisplayColorModes failed to transact: %d", result);
397 return result;
398 }
399 result = static_cast<status_t>(reply.readInt32());
400 if (result == NO_ERROR) {
401 size_t numModes = reply.readUint32();
402 outColorModes->clear();
403 outColorModes->resize(numModes);
404 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700405 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700406 }
407 }
408 return result;
409 }
410
Daniel Solomon42d04562019-01-20 21:03:19 -0800411 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
412 ui::DisplayPrimaries& primaries) {
413 Parcel data, reply;
414 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
415 if (result != NO_ERROR) {
416 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
417 return result;
418 }
419 result = data.writeStrongBinder(display);
420 if (result != NO_ERROR) {
421 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
422 return result;
423 }
424 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
425 if (result != NO_ERROR) {
426 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
427 return result;
428 }
429 result = reply.readInt32();
430 if (result == NO_ERROR) {
431 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
432 sizeof(ui::DisplayPrimaries));
433 }
434 return result;
435 }
436
Peiyong Lina52f0292018-03-14 17:26:31 -0700437 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700438 Parcel data, reply;
439 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
440 if (result != NO_ERROR) {
441 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700442 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700443 }
444 result = data.writeStrongBinder(display);
445 if (result != NO_ERROR) {
446 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700447 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700448 }
449 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
450 if (result != NO_ERROR) {
451 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700452 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700453 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700454 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700455 }
456
457 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700458 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700459 Parcel data, reply;
460 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
461 if (result != NO_ERROR) {
462 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
463 return result;
464 }
465 result = data.writeStrongBinder(display);
466 if (result != NO_ERROR) {
467 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
468 return result;
469 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700470 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700471 if (result != NO_ERROR) {
472 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
473 return result;
474 }
475 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
476 if (result != NO_ERROR) {
477 ALOGE("setActiveColorMode failed to transact: %d", result);
478 return result;
479 }
480 return static_cast<status_t>(reply.readInt32());
481 }
482
Galia Peycheva5492cb52019-10-30 14:13:16 +0100483 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
484 bool* outSupport) const {
485 Parcel data, reply;
486 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
487 status_t result = data.writeStrongBinder(display);
488 if (result != NO_ERROR) {
489 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
490 return result;
491 }
492 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
493 &reply);
494 if (result != NO_ERROR) {
495 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
496 return result;
497 }
498 return reply.readBool(outSupport);
499 }
500
501 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
502 Parcel data, reply;
503 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
504 if (result != NO_ERROR) {
505 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
506 return;
507 }
508
509 result = data.writeStrongBinder(display);
510 if (result != NO_ERROR) {
511 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
512 return;
513 }
514 result = data.writeBool(on);
515 if (result != NO_ERROR) {
516 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
517 return;
518 }
519 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
520 if (result != NO_ERROR) {
521 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
522 return;
523 }
524 }
525
526 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
527 Parcel data, reply;
528 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
529 status_t result = data.writeStrongBinder(display);
530 if (result != NO_ERROR) {
531 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
532 return result;
533 }
534 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
535 if (result != NO_ERROR) {
536 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
537 return result;
538 }
539 return reply.readBool(outSupport);
540 }
541
542 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
543 Parcel data, reply;
544 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
545 if (result != NO_ERROR) {
546 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
547 return;
548 }
549 result = data.writeStrongBinder(display);
550 if (result != NO_ERROR) {
551 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
552 return;
553 }
554 result = data.writeBool(on);
555 if (result != NO_ERROR) {
556 ALOGE("setGameContentType failed to writeBool: %d", result);
557 return;
558 }
559 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
560 if (result != NO_ERROR) {
561 ALOGE("setGameContentType failed to transact: %d", result);
562 }
563 }
564
Svetoslavd85084b2014-03-20 10:28:31 -0700565 virtual status_t clearAnimationFrameStats() {
566 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700567 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
568 if (result != NO_ERROR) {
569 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
570 return result;
571 }
572 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
573 if (result != NO_ERROR) {
574 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
575 return result;
576 }
Svetoslavd85084b2014-03-20 10:28:31 -0700577 return reply.readInt32();
578 }
579
580 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
581 Parcel data, reply;
582 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
583 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
584 reply.read(*outStats);
585 return reply.readInt32();
586 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700587
588 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
589 HdrCapabilities* outCapabilities) const {
590 Parcel data, reply;
591 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
592 status_t result = data.writeStrongBinder(display);
593 if (result != NO_ERROR) {
594 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
595 return result;
596 }
597 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
598 data, &reply);
599 if (result != NO_ERROR) {
600 ALOGE("getHdrCapabilities failed to transact: %d", result);
601 return result;
602 }
603 result = reply.readInt32();
604 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800605 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700606 }
607 return result;
608 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700609
610 virtual status_t enableVSyncInjections(bool enable) {
611 Parcel data, reply;
612 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
613 if (result != NO_ERROR) {
614 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
615 return result;
616 }
617 result = data.writeBool(enable);
618 if (result != NO_ERROR) {
619 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
620 return result;
621 }
Steven Moreland366eb422019-04-01 19:22:32 -0700622 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
623 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700624 if (result != NO_ERROR) {
625 ALOGE("enableVSyncInjections failed to transact: %d", result);
626 return result;
627 }
628 return result;
629 }
630
631 virtual status_t injectVSync(nsecs_t when) {
632 Parcel data, reply;
633 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
634 if (result != NO_ERROR) {
635 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
636 return result;
637 }
638 result = data.writeInt64(when);
639 if (result != NO_ERROR) {
640 ALOGE("injectVSync failed to writeInt64: %d", result);
641 return result;
642 }
Steven Moreland366eb422019-04-01 19:22:32 -0700643 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
644 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700645 if (result != NO_ERROR) {
646 ALOGE("injectVSync failed to transact: %d", result);
647 return result;
648 }
649 return result;
650 }
651
Vishnu Nair43bccf82020-06-05 10:53:37 -0700652 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800653 if (!outLayers) {
654 return UNEXPECTED_NULL;
655 }
656
657 Parcel data, reply;
658
659 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
660 if (err != NO_ERROR) {
661 return err;
662 }
663
664 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
665 if (err != NO_ERROR) {
666 return err;
667 }
668
669 int32_t result = 0;
670 err = reply.readInt32(&result);
671 if (err != NO_ERROR) {
672 return err;
673 }
674 if (result != NO_ERROR) {
675 return result;
676 }
677
678 outLayers->clear();
679 return reply.readParcelableVector(outLayers);
680 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700681
Peiyong Linc6780972018-10-28 15:24:08 -0700682 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
683 ui::PixelFormat* defaultPixelFormat,
684 ui::Dataspace* wideColorGamutDataspace,
685 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700686 Parcel data, reply;
687 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
688 if (error != NO_ERROR) {
689 return error;
690 }
691 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
692 if (error != NO_ERROR) {
693 return error;
694 }
695 error = static_cast<status_t>(reply.readInt32());
696 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700697 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
698 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
699 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
700 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700701 }
702 return error;
703 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700704
Ady Abraham37965d42018-11-01 13:43:32 -0700705 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700706 Parcel data, reply;
707 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700708 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
709 bool result;
710 status_t err = reply.readBool(&result);
711 if (err == NO_ERROR) {
712 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700713 }
Ady Abraham37965d42018-11-01 13:43:32 -0700714 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700715 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700716
717 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
718 ui::PixelFormat* outFormat,
719 ui::Dataspace* outDataspace,
720 uint8_t* outComponentMask) const {
721 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
722 Parcel data, reply;
723 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
724 data.writeStrongBinder(display);
725
726 status_t error =
727 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
728 data, &reply);
729 if (error != NO_ERROR) {
730 return error;
731 }
732
733 uint32_t value = 0;
734 error = reply.readUint32(&value);
735 if (error != NO_ERROR) {
736 return error;
737 }
738 *outFormat = static_cast<ui::PixelFormat>(value);
739
740 error = reply.readUint32(&value);
741 if (error != NO_ERROR) {
742 return error;
743 }
744 *outDataspace = static_cast<ui::Dataspace>(value);
745
746 error = reply.readUint32(&value);
747 if (error != NO_ERROR) {
748 return error;
749 }
750 *outComponentMask = static_cast<uint8_t>(value);
751 return error;
752 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800753
754 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700755 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800756 Parcel data, reply;
757 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
758 data.writeStrongBinder(display);
759 data.writeBool(enable);
760 data.writeByte(static_cast<int8_t>(componentMask));
761 data.writeUint64(maxFrames);
762 status_t result =
763 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
764 &reply);
765 return result;
766 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700767
768 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
769 uint64_t timestamp,
770 DisplayedFrameStats* outStats) const {
771 if (!outStats) return BAD_VALUE;
772
773 Parcel data, reply;
774 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
775 data.writeStrongBinder(display);
776 data.writeUint64(maxFrames);
777 data.writeUint64(timestamp);
778
779 status_t result =
780 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
781
782 if (result != NO_ERROR) {
783 return result;
784 }
785
786 result = reply.readUint64(&outStats->numFrames);
787 if (result != NO_ERROR) {
788 return result;
789 }
790
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800791 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700792 if (result != NO_ERROR) {
793 return result;
794 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800795 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700796 if (result != NO_ERROR) {
797 return result;
798 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800799 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700800 if (result != NO_ERROR) {
801 return result;
802 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800803 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700804 return result;
805 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800806
807 virtual status_t getProtectedContentSupport(bool* outSupported) const {
808 Parcel data, reply;
809 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800810 status_t error =
811 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
812 if (error != NO_ERROR) {
813 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800814 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800815 error = reply.readBool(outSupported);
816 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800817 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800818
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800819 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
820 bool* outIsWideColorDisplay) const {
821 Parcel data, reply;
822 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
823 if (error != NO_ERROR) {
824 return error;
825 }
826 error = data.writeStrongBinder(token);
827 if (error != NO_ERROR) {
828 return error;
829 }
830
831 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
832 if (error != NO_ERROR) {
833 return error;
834 }
835 error = reply.readBool(outIsWideColorDisplay);
836 return error;
837 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800838
839 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
840 const sp<IBinder>& stopLayerHandle,
841 const sp<IRegionSamplingListener>& listener) {
842 Parcel data, reply;
843 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
844 if (error != NO_ERROR) {
845 ALOGE("addRegionSamplingListener: Failed to write interface token");
846 return error;
847 }
848 error = data.write(samplingArea);
849 if (error != NO_ERROR) {
850 ALOGE("addRegionSamplingListener: Failed to write sampling area");
851 return error;
852 }
853 error = data.writeStrongBinder(stopLayerHandle);
854 if (error != NO_ERROR) {
855 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
856 return error;
857 }
858 error = data.writeStrongBinder(IInterface::asBinder(listener));
859 if (error != NO_ERROR) {
860 ALOGE("addRegionSamplingListener: Failed to write listener");
861 return error;
862 }
863 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
864 if (error != NO_ERROR) {
865 ALOGE("addRegionSamplingListener: Failed to transact");
866 }
867 return error;
868 }
869
870 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
871 Parcel data, reply;
872 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
873 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800874 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800875 return error;
876 }
877 error = data.writeStrongBinder(IInterface::asBinder(listener));
878 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800879 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800880 return error;
881 }
882 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
883 &reply);
884 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800885 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800886 }
887 return error;
888 }
Ady Abraham838de062019-02-04 10:24:03 -0800889
Ana Krulec0782b882019-10-15 17:34:54 -0700890 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700891 int32_t defaultConfig,
892 float primaryRefreshRateMin,
893 float primaryRefreshRateMax,
894 float appRequestRefreshRateMin,
895 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700896 Parcel data, reply;
897 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
898 if (result != NO_ERROR) {
899 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
900 return result;
901 }
902 result = data.writeStrongBinder(displayToken);
903 if (result != NO_ERROR) {
904 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
905 return result;
906 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100907 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700908 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100909 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700910 return result;
911 }
Steven Thomasf734df42020-04-13 21:09:28 -0700912 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700913 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700914 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700915 return result;
916 }
Steven Thomasf734df42020-04-13 21:09:28 -0700917 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700918 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700919 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
920 return result;
921 }
922 result = data.writeFloat(appRequestRefreshRateMin);
923 if (result != NO_ERROR) {
924 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
925 result);
926 return result;
927 }
928 result = data.writeFloat(appRequestRefreshRateMax);
929 if (result != NO_ERROR) {
930 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
931 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700932 return result;
933 }
934
935 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
936 &reply);
937 if (result != NO_ERROR) {
938 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
939 return result;
940 }
941 return reply.readInt32();
942 }
943
Ana Krulec234bb162019-11-10 22:55:55 +0100944 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100945 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700946 float* outPrimaryRefreshRateMin,
947 float* outPrimaryRefreshRateMax,
948 float* outAppRequestRefreshRateMin,
949 float* outAppRequestRefreshRateMax) {
950 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
951 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
952 return BAD_VALUE;
953 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800954 Parcel data, reply;
955 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
956 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100957 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800958 return result;
959 }
960 result = data.writeStrongBinder(displayToken);
961 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100962 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800963 return result;
964 }
Ana Krulec234bb162019-11-10 22:55:55 +0100965 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
966 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800967 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100968 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800969 return result;
970 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100971 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800972 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100973 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100974 return result;
975 }
Steven Thomasf734df42020-04-13 21:09:28 -0700976 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +0100977 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700978 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100979 return result;
980 }
Steven Thomasf734df42020-04-13 21:09:28 -0700981 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +0100982 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700983 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
984 return result;
985 }
986 result = reply.readFloat(outAppRequestRefreshRateMin);
987 if (result != NO_ERROR) {
988 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
989 result);
990 return result;
991 }
992 result = reply.readFloat(outAppRequestRefreshRateMax);
993 if (result != NO_ERROR) {
994 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
995 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800996 return result;
997 }
998 return reply.readInt32();
999 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001000
1001 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1002 bool* outSupport) const {
1003 Parcel data, reply;
1004 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1005 if (error != NO_ERROR) {
1006 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1007 return error;
1008 }
1009 error = data.writeStrongBinder(displayToken);
1010 if (error != NO_ERROR) {
1011 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1012 return error;
1013 }
1014 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1015 if (error != NO_ERROR) {
1016 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1017 return error;
1018 }
1019 bool support;
1020 error = reply.readBool(&support);
1021 if (error != NO_ERROR) {
1022 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1023 return error;
1024 }
1025 *outSupport = support;
1026 return NO_ERROR;
1027 }
1028
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001029 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001030 Parcel data, reply;
1031 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1032 if (error != NO_ERROR) {
1033 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1034 return error;
1035 }
1036 error = data.writeStrongBinder(displayToken);
1037 if (error != NO_ERROR) {
1038 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1039 return error;
1040 }
1041 error = data.writeFloat(brightness);
1042 if (error != NO_ERROR) {
1043 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1044 return error;
1045 }
1046 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1047 if (error != NO_ERROR) {
1048 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1049 return error;
1050 }
1051 return NO_ERROR;
1052 }
Ady Abraham8532d012019-05-08 14:50:56 -07001053
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001054 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001055 Parcel data, reply;
1056 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1057 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001058 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001059 return error;
1060 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001061 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001062 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001063 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001064 return error;
1065 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001066 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001067 IBinder::FLAG_ONEWAY);
1068 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001069 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001070 return error;
1071 }
1072 return NO_ERROR;
1073 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001074
1075 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1076 float lightPosY, float lightPosZ, float lightRadius) {
1077 Parcel data, reply;
1078 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1079 if (error != NO_ERROR) {
1080 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1081 return error;
1082 }
1083
1084 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1085 ambientColor.a, spotColor.r, spotColor.g,
1086 spotColor.b, spotColor.a, lightPosY,
1087 lightPosZ, lightRadius};
1088
1089 error = data.writeFloatVector(shadowConfig);
1090 if (error != NO_ERROR) {
1091 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1092 return error;
1093 }
1094
1095 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1096 IBinder::FLAG_ONEWAY);
1097 if (error != NO_ERROR) {
1098 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1099 return error;
1100 }
1101 return NO_ERROR;
1102 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001103
1104 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1105 int8_t compatibility) {
1106 Parcel data, reply;
1107 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1108 if (err != NO_ERROR) {
1109 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1110 return err;
1111 }
1112
1113 err = data.writeStrongBinder(IInterface::asBinder(surface));
1114 if (err != NO_ERROR) {
1115 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1116 return err;
1117 }
1118
1119 err = data.writeFloat(frameRate);
1120 if (err != NO_ERROR) {
1121 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1122 return err;
1123 }
1124
1125 err = data.writeByte(compatibility);
1126 if (err != NO_ERROR) {
1127 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1128 return err;
1129 }
1130
Ady Abraham60e42ea2020-03-09 19:17:31 -07001131 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001132 if (err != NO_ERROR) {
1133 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1134 return err;
1135 }
Steven Thomasd4071902020-03-24 16:02:53 -07001136
1137 return reply.readInt32();
1138 }
1139
1140 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1141 if (!outToken) return BAD_VALUE;
1142
1143 Parcel data, reply;
1144 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1145 if (err != NO_ERROR) {
1146 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1147 strerror(-err), -err);
1148 return err;
1149 }
1150
1151 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1152 &reply);
1153 if (err != NO_ERROR) {
1154 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1155 err);
1156 return err;
1157 }
1158
1159 err = reply.readInt32();
1160 if (err != NO_ERROR) {
1161 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1162 return err;
1163 }
1164
1165 err = reply.readStrongBinder(outToken);
1166 if (err != NO_ERROR) {
1167 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1168 strerror(-err), err);
1169 return err;
1170 }
1171
Steven Thomas62a4cf82020-01-31 12:04:03 -08001172 return NO_ERROR;
1173 }
Ady Abraham74e17562020-08-24 18:18:19 -07001174
1175 virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
1176 int64_t frameTimelineVsyncId) {
1177 Parcel data, reply;
1178 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1179 if (err != NO_ERROR) {
1180 ALOGE("setFrameTimelineVsync: failed writing interface token: %s (%d)", strerror(-err),
1181 -err);
1182 return err;
1183 }
1184
1185 err = data.writeStrongBinder(IInterface::asBinder(surface));
1186 if (err != NO_ERROR) {
1187 ALOGE("setFrameTimelineVsync: failed writing strong binder: %s (%d)", strerror(-err),
1188 -err);
1189 return err;
1190 }
1191
1192 err = data.writeInt64(frameTimelineVsyncId);
1193 if (err != NO_ERROR) {
1194 ALOGE("setFrameTimelineVsync: failed writing int64_t: %s (%d)", strerror(-err), -err);
1195 return err;
1196 }
1197
1198 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_VSYNC, data, &reply);
1199 if (err != NO_ERROR) {
1200 ALOGE("setFrameTimelineVsync: failed to transact: %s (%d)", strerror(-err), err);
1201 return err;
1202 }
1203
1204 return reply.readInt32();
1205 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00001206
1207 virtual status_t addTransactionTraceListener(
1208 const sp<gui::ITransactionTraceListener>& listener) {
1209 Parcel data, reply;
1210 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
1211 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
1212
1213 return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply);
1214 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001215};
1216
Dan Stozad723bd72014-11-18 10:24:03 -08001217// Out-of-line virtual method definition to trigger vtable emission in this
1218// translation unit (see clang warning -Wweak-vtables)
1219BpSurfaceComposer::~BpSurfaceComposer() {}
1220
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001221IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1222
1223// ----------------------------------------------------------------------
1224
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001225status_t BnSurfaceComposer::onTransact(
1226 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1227{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001228 switch(code) {
1229 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001230 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001231 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001232 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001233 return NO_ERROR;
1234 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001235 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001236 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001237
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001238 int64_t frameTimelineVsyncId;
1239 SAFE_PARCEL(data.readInt64, &frameTimelineVsyncId);
chaviw308ddba2020-08-11 16:23:51 -07001240 uint32_t count = 0;
1241 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001242 Vector<ComposerState> state;
1243 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001244 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001245 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001246 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001247 state.add(s);
1248 }
Dan Stozad723bd72014-11-18 10:24:03 -08001249
chaviw308ddba2020-08-11 16:23:51 -07001250 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001251 DisplayState d;
1252 Vector<DisplayState> displays;
1253 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001254 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001255 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001256 displays.add(d);
1257 }
Dan Stozad723bd72014-11-18 10:24:03 -08001258
chaviw308ddba2020-08-11 16:23:51 -07001259 uint32_t stateFlags = 0;
1260 SAFE_PARCEL(data.readUint32, &stateFlags);
1261 sp<IBinder> applyToken;
1262 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001263 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001264 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001265
chaviw308ddba2020-08-11 16:23:51 -07001266 int64_t desiredPresentTime = 0;
1267 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -07001268
Marissa Wall947d34e2019-03-29 14:03:53 -07001269 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001270 sp<IBinder> tmpBinder;
1271 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1272 uncachedBuffer.token = tmpBinder;
1273 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001274
chaviw308ddba2020-08-11 16:23:51 -07001275 bool hasListenerCallbacks = false;
1276 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001277
Marissa Wall3dad52d2019-03-22 14:03:19 -07001278 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001279 int32_t listenersSize = 0;
1280 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001281 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001282 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001283 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001284 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1285 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001286 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +00001287
1288 uint64_t transactionId = -1;
1289 SAFE_PARCEL(data.readUint64, &transactionId);
1290
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001291 return setTransactionState(frameTimelineVsyncId, state, displays, stateFlags,
1292 applyToken, inputWindowCommands, desiredPresentTime,
1293 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
1294 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -07001295 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001296 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001297 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001298 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001299 return NO_ERROR;
1300 }
chaviwd2432892020-07-24 17:42:39 -07001301 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001302 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001303 DisplayCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001304 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001305 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001306 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1307
1308 return captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001309 }
chaviwd2432892020-07-24 17:42:39 -07001310 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001311 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001312 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001313 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001314 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001315 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1316
1317 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001318 }
chaviwa76b2712017-09-20 12:02:26 -07001319 case CAPTURE_LAYERS: {
1320 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001321 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001322 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001323 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001324 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1325
1326 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001327 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001328 case AUTHENTICATE_SURFACE: {
1329 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001330 sp<IGraphicBufferProducer> bufferProducer =
1331 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1332 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001333 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001334 return NO_ERROR;
1335 }
Brian Anderson6b376712017-04-04 10:51:39 -07001336 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1337 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1338 std::vector<FrameEvent> supportedTimestamps;
1339 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1340 status_t err = reply->writeInt32(result);
1341 if (err != NO_ERROR) {
1342 return err;
1343 }
1344 if (result != NO_ERROR) {
1345 return result;
1346 }
1347
1348 std::vector<int32_t> supported;
1349 supported.reserve(supportedTimestamps.size());
1350 for (FrameEvent s : supportedTimestamps) {
1351 supported.push_back(static_cast<int32_t>(s));
1352 }
1353 return reply->writeInt32Vector(supported);
1354 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001355 case CREATE_DISPLAY_EVENT_CONNECTION: {
1356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001357 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1358 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1359
1360 sp<IDisplayEventConnection> connection(
1361 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001362 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001363 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001364 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001365 case CREATE_DISPLAY: {
1366 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001367 String8 displayName;
1368 SAFE_PARCEL(data.readString8, &displayName);
1369 bool secure = false;
1370 SAFE_PARCEL(data.readBool, &secure);
1371 sp<IBinder> display = createDisplay(displayName, secure);
1372 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001373 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001374 }
1375 case DESTROY_DISPLAY: {
1376 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1377 sp<IBinder> display = data.readStrongBinder();
1378 destroyDisplay(display);
1379 return NO_ERROR;
1380 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001381 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001382 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001383 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001384 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001385 reply->writeStrongBinder(display);
1386 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001387 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001388 case GET_DISPLAY_STATE: {
1389 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1390 ui::DisplayState state;
1391 const sp<IBinder> display = data.readStrongBinder();
1392 const status_t result = getDisplayState(display, &state);
1393 reply->writeInt32(result);
1394 if (result == NO_ERROR) {
1395 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1396 sizeof(ui::DisplayState));
1397 }
1398 return NO_ERROR;
1399 }
1400 case GET_DISPLAY_INFO: {
1401 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1402 DisplayInfo info;
1403 const sp<IBinder> display = data.readStrongBinder();
1404 const status_t result = getDisplayInfo(display, &info);
1405 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001406 if (result != NO_ERROR) return result;
1407 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001408 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001409 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001410 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001411 Vector<DisplayConfig> configs;
1412 const sp<IBinder> display = data.readStrongBinder();
1413 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001414 reply->writeInt32(result);
1415 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001416 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001417 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001418 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1419 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001420 }
1421 }
1422 return NO_ERROR;
1423 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001424 case GET_DISPLAY_STATS: {
1425 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1426 DisplayStatInfo stats;
1427 sp<IBinder> display = data.readStrongBinder();
1428 status_t result = getDisplayStats(display, &stats);
1429 reply->writeInt32(result);
1430 if (result == NO_ERROR) {
1431 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1432 &stats, sizeof(DisplayStatInfo));
1433 }
1434 return NO_ERROR;
1435 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001436 case GET_ACTIVE_CONFIG: {
1437 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1438 sp<IBinder> display = data.readStrongBinder();
1439 int id = getActiveConfig(display);
1440 reply->writeInt32(id);
1441 return NO_ERROR;
1442 }
Michael Wright28f24d02016-07-12 13:30:53 -07001443 case GET_DISPLAY_COLOR_MODES: {
1444 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001445 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001446 sp<IBinder> display = nullptr;
1447 status_t result = data.readStrongBinder(&display);
1448 if (result != NO_ERROR) {
1449 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1450 return result;
1451 }
1452 result = getDisplayColorModes(display, &colorModes);
1453 reply->writeInt32(result);
1454 if (result == NO_ERROR) {
1455 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1456 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001457 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001458 }
1459 }
1460 return NO_ERROR;
1461 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001462 case GET_DISPLAY_NATIVE_PRIMARIES: {
1463 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1464 ui::DisplayPrimaries primaries;
1465 sp<IBinder> display = nullptr;
1466
1467 status_t result = data.readStrongBinder(&display);
1468 if (result != NO_ERROR) {
1469 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1470 return result;
1471 }
1472
1473 result = getDisplayNativePrimaries(display, primaries);
1474 reply->writeInt32(result);
1475 if (result == NO_ERROR) {
1476 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1477 sizeof(ui::DisplayPrimaries));
1478 }
1479
1480 return NO_ERROR;
1481 }
Michael Wright28f24d02016-07-12 13:30:53 -07001482 case GET_ACTIVE_COLOR_MODE: {
1483 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1484 sp<IBinder> display = nullptr;
1485 status_t result = data.readStrongBinder(&display);
1486 if (result != NO_ERROR) {
1487 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1488 return result;
1489 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001490 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001491 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1492 return result;
1493 }
1494 case SET_ACTIVE_COLOR_MODE: {
1495 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1496 sp<IBinder> display = nullptr;
1497 status_t result = data.readStrongBinder(&display);
1498 if (result != NO_ERROR) {
1499 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1500 return result;
1501 }
1502 int32_t colorModeInt = 0;
1503 result = data.readInt32(&colorModeInt);
1504 if (result != NO_ERROR) {
1505 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1506 return result;
1507 }
1508 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001509 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001510 result = reply->writeInt32(result);
1511 return result;
1512 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001513
1514 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1515 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1516 sp<IBinder> display = nullptr;
1517 status_t result = data.readStrongBinder(&display);
1518 if (result != NO_ERROR) {
1519 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1520 return result;
1521 }
1522 bool supported = false;
1523 result = getAutoLowLatencyModeSupport(display, &supported);
1524 if (result == NO_ERROR) {
1525 result = reply->writeBool(supported);
1526 }
1527 return result;
1528 }
1529
1530 case SET_AUTO_LOW_LATENCY_MODE: {
1531 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1532 sp<IBinder> display = nullptr;
1533 status_t result = data.readStrongBinder(&display);
1534 if (result != NO_ERROR) {
1535 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1536 return result;
1537 }
1538 bool setAllm = false;
1539 result = data.readBool(&setAllm);
1540 if (result != NO_ERROR) {
1541 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1542 return result;
1543 }
1544 setAutoLowLatencyMode(display, setAllm);
1545 return result;
1546 }
1547
1548 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1549 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1550 sp<IBinder> display = nullptr;
1551 status_t result = data.readStrongBinder(&display);
1552 if (result != NO_ERROR) {
1553 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1554 return result;
1555 }
1556 bool supported = false;
1557 result = getGameContentTypeSupport(display, &supported);
1558 if (result == NO_ERROR) {
1559 result = reply->writeBool(supported);
1560 }
1561 return result;
1562 }
1563
1564 case SET_GAME_CONTENT_TYPE: {
1565 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1566 sp<IBinder> display = nullptr;
1567 status_t result = data.readStrongBinder(&display);
1568 if (result != NO_ERROR) {
1569 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1570 return result;
1571 }
1572 bool setGameContentTypeOn = false;
1573 result = data.readBool(&setGameContentTypeOn);
1574 if (result != NO_ERROR) {
1575 ALOGE("setGameContentType failed to readBool: %d", result);
1576 return result;
1577 }
1578 setGameContentType(display, setGameContentTypeOn);
1579 return result;
1580 }
1581
Svetoslavd85084b2014-03-20 10:28:31 -07001582 case CLEAR_ANIMATION_FRAME_STATS: {
1583 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1584 status_t result = clearAnimationFrameStats();
1585 reply->writeInt32(result);
1586 return NO_ERROR;
1587 }
1588 case GET_ANIMATION_FRAME_STATS: {
1589 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1590 FrameStats stats;
1591 status_t result = getAnimationFrameStats(&stats);
1592 reply->write(stats);
1593 reply->writeInt32(result);
1594 return NO_ERROR;
1595 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001596 case SET_POWER_MODE: {
1597 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1598 sp<IBinder> display = data.readStrongBinder();
1599 int32_t mode = data.readInt32();
1600 setPowerMode(display, mode);
1601 return NO_ERROR;
1602 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001603 case GET_HDR_CAPABILITIES: {
1604 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1605 sp<IBinder> display = nullptr;
1606 status_t result = data.readStrongBinder(&display);
1607 if (result != NO_ERROR) {
1608 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1609 result);
1610 return result;
1611 }
1612 HdrCapabilities capabilities;
1613 result = getHdrCapabilities(display, &capabilities);
1614 reply->writeInt32(result);
1615 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001616 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001617 }
1618 return NO_ERROR;
1619 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001620 case ENABLE_VSYNC_INJECTIONS: {
1621 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1622 bool enable = false;
1623 status_t result = data.readBool(&enable);
1624 if (result != NO_ERROR) {
1625 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1626 return result;
1627 }
1628 return enableVSyncInjections(enable);
1629 }
1630 case INJECT_VSYNC: {
1631 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1632 int64_t when = 0;
1633 status_t result = data.readInt64(&when);
1634 if (result != NO_ERROR) {
1635 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1636 return result;
1637 }
1638 return injectVSync(when);
1639 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001640 case GET_LAYER_DEBUG_INFO: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1642 std::vector<LayerDebugInfo> outLayers;
1643 status_t result = getLayerDebugInfo(&outLayers);
1644 reply->writeInt32(result);
1645 if (result == NO_ERROR)
1646 {
1647 result = reply->writeParcelableVector(outLayers);
1648 }
1649 return result;
1650 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001651 case GET_COMPOSITION_PREFERENCE: {
1652 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001653 ui::Dataspace defaultDataspace;
1654 ui::PixelFormat defaultPixelFormat;
1655 ui::Dataspace wideColorGamutDataspace;
1656 ui::PixelFormat wideColorGamutPixelFormat;
1657 status_t error =
1658 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1659 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001660 reply->writeInt32(error);
1661 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001662 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1663 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1664 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001665 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001666 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001667 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001668 }
Ady Abraham37965d42018-11-01 13:43:32 -07001669 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001670 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001671 bool result;
1672 status_t error = getColorManagement(&result);
1673 if (error == NO_ERROR) {
1674 reply->writeBool(result);
1675 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001676 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001677 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001678 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1679 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1680
1681 sp<IBinder> display = data.readStrongBinder();
1682 ui::PixelFormat format;
1683 ui::Dataspace dataspace;
1684 uint8_t component = 0;
1685 auto result =
1686 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1687 if (result == NO_ERROR) {
1688 reply->writeUint32(static_cast<uint32_t>(format));
1689 reply->writeUint32(static_cast<uint32_t>(dataspace));
1690 reply->writeUint32(static_cast<uint32_t>(component));
1691 }
1692 return result;
1693 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001694 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1695 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1696
1697 sp<IBinder> display = nullptr;
1698 bool enable = false;
1699 int8_t componentMask = 0;
1700 uint64_t maxFrames = 0;
1701 status_t result = data.readStrongBinder(&display);
1702 if (result != NO_ERROR) {
1703 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1704 result);
1705 return result;
1706 }
1707
1708 result = data.readBool(&enable);
1709 if (result != NO_ERROR) {
1710 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1711 return result;
1712 }
1713
1714 result = data.readByte(static_cast<int8_t*>(&componentMask));
1715 if (result != NO_ERROR) {
1716 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1717 result);
1718 return result;
1719 }
1720
1721 result = data.readUint64(&maxFrames);
1722 if (result != NO_ERROR) {
1723 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1724 return result;
1725 }
1726
1727 return setDisplayContentSamplingEnabled(display, enable,
1728 static_cast<uint8_t>(componentMask), maxFrames);
1729 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001730 case GET_DISPLAYED_CONTENT_SAMPLE: {
1731 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1732
1733 sp<IBinder> display = data.readStrongBinder();
1734 uint64_t maxFrames = 0;
1735 uint64_t timestamp = 0;
1736
1737 status_t result = data.readUint64(&maxFrames);
1738 if (result != NO_ERROR) {
1739 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1740 return result;
1741 }
1742
1743 result = data.readUint64(&timestamp);
1744 if (result != NO_ERROR) {
1745 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1746 return result;
1747 }
1748
1749 DisplayedFrameStats stats;
1750 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1751 if (result == NO_ERROR) {
1752 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001753 reply->writeUint64Vector(stats.component_0_sample);
1754 reply->writeUint64Vector(stats.component_1_sample);
1755 reply->writeUint64Vector(stats.component_2_sample);
1756 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001757 }
1758 return result;
1759 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001760 case GET_PROTECTED_CONTENT_SUPPORT: {
1761 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1762 bool result;
1763 status_t error = getProtectedContentSupport(&result);
1764 if (error == NO_ERROR) {
1765 reply->writeBool(result);
1766 }
1767 return error;
1768 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001769 case IS_WIDE_COLOR_DISPLAY: {
1770 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1771 sp<IBinder> display = nullptr;
1772 status_t error = data.readStrongBinder(&display);
1773 if (error != NO_ERROR) {
1774 return error;
1775 }
1776 bool result;
1777 error = isWideColorDisplay(display, &result);
1778 if (error == NO_ERROR) {
1779 reply->writeBool(result);
1780 }
1781 return error;
1782 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001783 case GET_PHYSICAL_DISPLAY_IDS: {
1784 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001785 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1786 std::vector<uint64_t> rawIds(ids.size());
1787 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1788 [](PhysicalDisplayId id) { return id.value; });
1789 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001790 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001791 case ADD_REGION_SAMPLING_LISTENER: {
1792 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1793 Rect samplingArea;
1794 status_t result = data.read(samplingArea);
1795 if (result != NO_ERROR) {
1796 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1797 return result;
1798 }
1799 sp<IBinder> stopLayerHandle;
1800 result = data.readNullableStrongBinder(&stopLayerHandle);
1801 if (result != NO_ERROR) {
1802 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1803 return result;
1804 }
1805 sp<IRegionSamplingListener> listener;
1806 result = data.readNullableStrongBinder(&listener);
1807 if (result != NO_ERROR) {
1808 ALOGE("addRegionSamplingListener: Failed to read listener");
1809 return result;
1810 }
1811 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1812 }
1813 case REMOVE_REGION_SAMPLING_LISTENER: {
1814 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1815 sp<IRegionSamplingListener> listener;
1816 status_t result = data.readNullableStrongBinder(&listener);
1817 if (result != NO_ERROR) {
1818 ALOGE("removeRegionSamplingListener: Failed to read listener");
1819 return result;
1820 }
1821 return removeRegionSamplingListener(listener);
1822 }
Ana Krulec0782b882019-10-15 17:34:54 -07001823 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1824 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1825 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001826 int32_t defaultConfig;
1827 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001828 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001829 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001830 return result;
1831 }
Steven Thomasf734df42020-04-13 21:09:28 -07001832 float primaryRefreshRateMin;
1833 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001834 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001835 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1836 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001837 return result;
1838 }
Steven Thomasf734df42020-04-13 21:09:28 -07001839 float primaryRefreshRateMax;
1840 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001841 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001842 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1843 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001844 return result;
1845 }
Steven Thomasf734df42020-04-13 21:09:28 -07001846 float appRequestRefreshRateMin;
1847 result = data.readFloat(&appRequestRefreshRateMin);
1848 if (result != NO_ERROR) {
1849 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1850 result);
1851 return result;
1852 }
1853 float appRequestRefreshRateMax;
1854 result = data.readFloat(&appRequestRefreshRateMax);
1855 if (result != NO_ERROR) {
1856 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1857 result);
1858 return result;
1859 }
1860 result =
1861 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1862 primaryRefreshRateMax, appRequestRefreshRateMin,
1863 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001864 if (result != NO_ERROR) {
1865 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1866 "%d",
1867 result);
1868 return result;
1869 }
1870 reply->writeInt32(result);
1871 return result;
1872 }
Ana Krulec234bb162019-11-10 22:55:55 +01001873 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1874 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1875 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001876 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001877 float primaryRefreshRateMin;
1878 float primaryRefreshRateMax;
1879 float appRequestRefreshRateMin;
1880 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001881
Steven Thomasf734df42020-04-13 21:09:28 -07001882 status_t result =
1883 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1884 &primaryRefreshRateMin, &primaryRefreshRateMax,
1885 &appRequestRefreshRateMin,
1886 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001887 if (result != NO_ERROR) {
1888 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1889 "%d",
1890 result);
1891 return result;
1892 }
1893
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001894 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001895 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001896 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001897 return result;
1898 }
Steven Thomasf734df42020-04-13 21:09:28 -07001899 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001900 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001901 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1902 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001903 return result;
1904 }
Steven Thomasf734df42020-04-13 21:09:28 -07001905 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001906 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001907 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1908 result);
1909 return result;
1910 }
1911 result = reply->writeFloat(appRequestRefreshRateMin);
1912 if (result != NO_ERROR) {
1913 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1914 result);
1915 return result;
1916 }
1917 result = reply->writeFloat(appRequestRefreshRateMax);
1918 if (result != NO_ERROR) {
1919 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1920 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001921 return result;
1922 }
1923 reply->writeInt32(result);
1924 return result;
1925 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001926 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1927 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1928 sp<IBinder> displayToken;
1929 status_t error = data.readNullableStrongBinder(&displayToken);
1930 if (error != NO_ERROR) {
1931 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1932 return error;
1933 }
1934 bool support = false;
1935 error = getDisplayBrightnessSupport(displayToken, &support);
1936 reply->writeBool(support);
1937 return error;
1938 }
1939 case SET_DISPLAY_BRIGHTNESS: {
1940 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1941 sp<IBinder> displayToken;
1942 status_t error = data.readNullableStrongBinder(&displayToken);
1943 if (error != NO_ERROR) {
1944 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1945 return error;
1946 }
1947 float brightness = -1.0f;
1948 error = data.readFloat(&brightness);
1949 if (error != NO_ERROR) {
1950 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1951 return error;
1952 }
1953 return setDisplayBrightness(displayToken, brightness);
1954 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001955 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001956 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001957 int32_t boostId;
1958 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001959 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001960 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001961 return error;
1962 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001963 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001964 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001965 case SET_GLOBAL_SHADOW_SETTINGS: {
1966 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1967
1968 std::vector<float> shadowConfig;
1969 status_t error = data.readFloatVector(&shadowConfig);
1970 if (error != NO_ERROR || shadowConfig.size() != 11) {
1971 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1972 return error;
1973 }
1974
1975 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1976 shadowConfig[3]};
1977 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1978 float lightPosY = shadowConfig[8];
1979 float lightPosZ = shadowConfig[9];
1980 float lightRadius = shadowConfig[10];
1981 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1982 lightRadius);
1983 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001984 case SET_FRAME_RATE: {
1985 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1986 sp<IBinder> binder;
1987 status_t err = data.readStrongBinder(&binder);
1988 if (err != NO_ERROR) {
1989 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1990 return err;
1991 }
1992 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1993 if (!surface) {
1994 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1995 strerror(-err), -err);
1996 return err;
1997 }
1998 float frameRate;
1999 err = data.readFloat(&frameRate);
2000 if (err != NO_ERROR) {
2001 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2002 return err;
2003 }
2004 int8_t compatibility;
2005 err = data.readByte(&compatibility);
2006 if (err != NO_ERROR) {
2007 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2008 return err;
2009 }
2010 status_t result = setFrameRate(surface, frameRate, compatibility);
2011 reply->writeInt32(result);
2012 return NO_ERROR;
2013 }
Steven Thomasd4071902020-03-24 16:02:53 -07002014 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2015 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2016 sp<IBinder> token;
2017 status_t result = acquireFrameRateFlexibilityToken(&token);
2018 reply->writeInt32(result);
2019 if (result == NO_ERROR) {
2020 reply->writeStrongBinder(token);
2021 }
2022 return NO_ERROR;
2023 }
Ady Abraham74e17562020-08-24 18:18:19 -07002024 case SET_FRAME_TIMELINE_VSYNC: {
2025 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2026 sp<IBinder> binder;
2027 status_t err = data.readStrongBinder(&binder);
2028 if (err != NO_ERROR) {
2029 ALOGE("setFrameTimelineVsync: failed to read strong binder: %s (%d)",
2030 strerror(-err), -err);
2031 return err;
2032 }
2033 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2034 if (!surface) {
2035 ALOGE("setFrameTimelineVsync: failed to cast to IGraphicBufferProducer: %s (%d)",
2036 strerror(-err), -err);
2037 return err;
2038 }
2039 int64_t frameTimelineVsyncId;
2040 err = data.readInt64(&frameTimelineVsyncId);
2041 if (err != NO_ERROR) {
2042 ALOGE("setFrameTimelineVsync: failed to read int64_t: %s (%d)", strerror(-err),
2043 -err);
2044 return err;
2045 }
2046
2047 status_t result = setFrameTimelineVsync(surface, frameTimelineVsyncId);
2048 reply->writeInt32(result);
2049 return NO_ERROR;
2050 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00002051 case ADD_TRANSACTION_TRACE_LISTENER: {
2052 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2053 sp<gui::ITransactionTraceListener> listener;
2054 SAFE_PARCEL(data.readStrongBinder, &listener);
2055
2056 return addTransactionTraceListener(listener);
2057 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002058 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002059 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002060 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002061 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002062}
2063
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002064} // namespace android