blob: 6f922339352a0c8d93de84067997307aeafdbf83 [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,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200891 int32_t defaultConfig, bool allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -0700892 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 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200912 result = data.writeBool(allowGroupSwitching);
913 if (result != NO_ERROR) {
914 ALOGE("setDesiredDisplayConfigSpecs failed to write allowGroupSwitching: %d", result);
915 return result;
916 }
Steven Thomasf734df42020-04-13 21:09:28 -0700917 result = data.writeFloat(primaryRefreshRateMin);
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 primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700920 return result;
921 }
Steven Thomasf734df42020-04-13 21:09:28 -0700922 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700923 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700924 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
925 return result;
926 }
927 result = data.writeFloat(appRequestRefreshRateMin);
928 if (result != NO_ERROR) {
929 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
930 result);
931 return result;
932 }
933 result = data.writeFloat(appRequestRefreshRateMax);
934 if (result != NO_ERROR) {
935 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
936 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700937 return result;
938 }
939
940 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
941 &reply);
942 if (result != NO_ERROR) {
943 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
944 return result;
945 }
946 return reply.readInt32();
947 }
948
Ana Krulec234bb162019-11-10 22:55:55 +0100949 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100950 int32_t* outDefaultConfig,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200951 bool* outAllowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -0700952 float* outPrimaryRefreshRateMin,
953 float* outPrimaryRefreshRateMax,
954 float* outAppRequestRefreshRateMin,
955 float* outAppRequestRefreshRateMax) {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200956 if (!outDefaultConfig || !outAllowGroupSwitching || !outPrimaryRefreshRateMin ||
957 !outPrimaryRefreshRateMax || !outAppRequestRefreshRateMin ||
958 !outAppRequestRefreshRateMax) {
Steven Thomasf734df42020-04-13 21:09:28 -0700959 return BAD_VALUE;
960 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800961 Parcel data, reply;
962 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
963 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100964 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800965 return result;
966 }
967 result = data.writeStrongBinder(displayToken);
968 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100969 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800970 return result;
971 }
Ana Krulec234bb162019-11-10 22:55:55 +0100972 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
973 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800974 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100975 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800976 return result;
977 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100978 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800979 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100980 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100981 return result;
982 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200983 result = reply.readBool(outAllowGroupSwitching);
984 if (result != NO_ERROR) {
985 ALOGE("getDesiredDisplayConfigSpecs failed to read allowGroupSwitching: %d", result);
986 return result;
987 }
Steven Thomasf734df42020-04-13 21:09:28 -0700988 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +0100989 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700990 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100991 return result;
992 }
Steven Thomasf734df42020-04-13 21:09:28 -0700993 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +0100994 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700995 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
996 return result;
997 }
998 result = reply.readFloat(outAppRequestRefreshRateMin);
999 if (result != NO_ERROR) {
1000 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
1001 result);
1002 return result;
1003 }
1004 result = reply.readFloat(outAppRequestRefreshRateMax);
1005 if (result != NO_ERROR) {
1006 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
1007 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001008 return result;
1009 }
1010 return reply.readInt32();
1011 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001012
1013 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1014 bool* outSupport) const {
1015 Parcel data, reply;
1016 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1017 if (error != NO_ERROR) {
1018 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1019 return error;
1020 }
1021 error = data.writeStrongBinder(displayToken);
1022 if (error != NO_ERROR) {
1023 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1024 return error;
1025 }
1026 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1027 if (error != NO_ERROR) {
1028 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1029 return error;
1030 }
1031 bool support;
1032 error = reply.readBool(&support);
1033 if (error != NO_ERROR) {
1034 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1035 return error;
1036 }
1037 *outSupport = support;
1038 return NO_ERROR;
1039 }
1040
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001041 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001042 Parcel data, reply;
1043 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1044 if (error != NO_ERROR) {
1045 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1046 return error;
1047 }
1048 error = data.writeStrongBinder(displayToken);
1049 if (error != NO_ERROR) {
1050 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1051 return error;
1052 }
1053 error = data.writeFloat(brightness);
1054 if (error != NO_ERROR) {
1055 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1056 return error;
1057 }
1058 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1059 if (error != NO_ERROR) {
1060 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1061 return error;
1062 }
1063 return NO_ERROR;
1064 }
Ady Abraham8532d012019-05-08 14:50:56 -07001065
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001066 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001067 Parcel data, reply;
1068 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1069 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001070 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001071 return error;
1072 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001073 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001074 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001075 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001076 return error;
1077 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001078 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001079 IBinder::FLAG_ONEWAY);
1080 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001081 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001082 return error;
1083 }
1084 return NO_ERROR;
1085 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001086
1087 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1088 float lightPosY, float lightPosZ, float lightRadius) {
1089 Parcel data, reply;
1090 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1091 if (error != NO_ERROR) {
1092 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1093 return error;
1094 }
1095
1096 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1097 ambientColor.a, spotColor.r, spotColor.g,
1098 spotColor.b, spotColor.a, lightPosY,
1099 lightPosZ, lightRadius};
1100
1101 error = data.writeFloatVector(shadowConfig);
1102 if (error != NO_ERROR) {
1103 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1104 return error;
1105 }
1106
1107 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1108 IBinder::FLAG_ONEWAY);
1109 if (error != NO_ERROR) {
1110 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1111 return error;
1112 }
1113 return NO_ERROR;
1114 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001115
1116 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1117 int8_t compatibility) {
1118 Parcel data, reply;
1119 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1120 if (err != NO_ERROR) {
1121 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1122 return err;
1123 }
1124
1125 err = data.writeStrongBinder(IInterface::asBinder(surface));
1126 if (err != NO_ERROR) {
1127 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1128 return err;
1129 }
1130
1131 err = data.writeFloat(frameRate);
1132 if (err != NO_ERROR) {
1133 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1134 return err;
1135 }
1136
1137 err = data.writeByte(compatibility);
1138 if (err != NO_ERROR) {
1139 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1140 return err;
1141 }
1142
Ady Abraham60e42ea2020-03-09 19:17:31 -07001143 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001144 if (err != NO_ERROR) {
1145 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1146 return err;
1147 }
Steven Thomasd4071902020-03-24 16:02:53 -07001148
1149 return reply.readInt32();
1150 }
1151
1152 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1153 if (!outToken) return BAD_VALUE;
1154
1155 Parcel data, reply;
1156 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1157 if (err != NO_ERROR) {
1158 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1159 strerror(-err), -err);
1160 return err;
1161 }
1162
1163 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1164 &reply);
1165 if (err != NO_ERROR) {
1166 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1167 err);
1168 return err;
1169 }
1170
1171 err = reply.readInt32();
1172 if (err != NO_ERROR) {
1173 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1174 return err;
1175 }
1176
1177 err = reply.readStrongBinder(outToken);
1178 if (err != NO_ERROR) {
1179 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1180 strerror(-err), err);
1181 return err;
1182 }
1183
Steven Thomas62a4cf82020-01-31 12:04:03 -08001184 return NO_ERROR;
1185 }
Ady Abraham74e17562020-08-24 18:18:19 -07001186
1187 virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
1188 int64_t frameTimelineVsyncId) {
1189 Parcel data, reply;
1190 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1191 if (err != NO_ERROR) {
1192 ALOGE("setFrameTimelineVsync: failed writing interface token: %s (%d)", strerror(-err),
1193 -err);
1194 return err;
1195 }
1196
1197 err = data.writeStrongBinder(IInterface::asBinder(surface));
1198 if (err != NO_ERROR) {
1199 ALOGE("setFrameTimelineVsync: failed writing strong binder: %s (%d)", strerror(-err),
1200 -err);
1201 return err;
1202 }
1203
1204 err = data.writeInt64(frameTimelineVsyncId);
1205 if (err != NO_ERROR) {
1206 ALOGE("setFrameTimelineVsync: failed writing int64_t: %s (%d)", strerror(-err), -err);
1207 return err;
1208 }
1209
1210 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_VSYNC, data, &reply);
1211 if (err != NO_ERROR) {
1212 ALOGE("setFrameTimelineVsync: failed to transact: %s (%d)", strerror(-err), err);
1213 return err;
1214 }
1215
1216 return reply.readInt32();
1217 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00001218
1219 virtual status_t addTransactionTraceListener(
1220 const sp<gui::ITransactionTraceListener>& listener) {
1221 Parcel data, reply;
1222 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
1223 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
1224
1225 return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply);
1226 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001227};
1228
Dan Stozad723bd72014-11-18 10:24:03 -08001229// Out-of-line virtual method definition to trigger vtable emission in this
1230// translation unit (see clang warning -Wweak-vtables)
1231BpSurfaceComposer::~BpSurfaceComposer() {}
1232
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001233IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1234
1235// ----------------------------------------------------------------------
1236
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001237status_t BnSurfaceComposer::onTransact(
1238 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1239{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001240 switch(code) {
1241 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001242 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001243 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001244 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001245 return NO_ERROR;
1246 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001247 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001248 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001249
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001250 int64_t frameTimelineVsyncId;
1251 SAFE_PARCEL(data.readInt64, &frameTimelineVsyncId);
chaviw308ddba2020-08-11 16:23:51 -07001252 uint32_t count = 0;
1253 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001254 Vector<ComposerState> state;
1255 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001256 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001257 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001258 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001259 state.add(s);
1260 }
Dan Stozad723bd72014-11-18 10:24:03 -08001261
chaviw308ddba2020-08-11 16:23:51 -07001262 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001263 DisplayState d;
1264 Vector<DisplayState> displays;
1265 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001266 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001267 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001268 displays.add(d);
1269 }
Dan Stozad723bd72014-11-18 10:24:03 -08001270
chaviw308ddba2020-08-11 16:23:51 -07001271 uint32_t stateFlags = 0;
1272 SAFE_PARCEL(data.readUint32, &stateFlags);
1273 sp<IBinder> applyToken;
1274 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001275 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001276 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001277
chaviw308ddba2020-08-11 16:23:51 -07001278 int64_t desiredPresentTime = 0;
1279 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -07001280
Marissa Wall947d34e2019-03-29 14:03:53 -07001281 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001282 sp<IBinder> tmpBinder;
1283 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1284 uncachedBuffer.token = tmpBinder;
1285 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001286
chaviw308ddba2020-08-11 16:23:51 -07001287 bool hasListenerCallbacks = false;
1288 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001289
Marissa Wall3dad52d2019-03-22 14:03:19 -07001290 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001291 int32_t listenersSize = 0;
1292 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001293 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001294 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001295 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001296 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1297 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001298 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +00001299
1300 uint64_t transactionId = -1;
1301 SAFE_PARCEL(data.readUint64, &transactionId);
1302
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001303 return setTransactionState(frameTimelineVsyncId, state, displays, stateFlags,
1304 applyToken, inputWindowCommands, desiredPresentTime,
1305 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
1306 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -07001307 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001308 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001309 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001310 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001311 return NO_ERROR;
1312 }
chaviwd2432892020-07-24 17:42:39 -07001313 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001314 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001315 DisplayCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001316 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001317 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001318 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1319
1320 return captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001321 }
chaviwd2432892020-07-24 17:42:39 -07001322 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001323 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001324 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001325 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001326 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001327 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1328
1329 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001330 }
chaviwa76b2712017-09-20 12:02:26 -07001331 case CAPTURE_LAYERS: {
1332 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001333 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001334 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001335 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001336 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1337
1338 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001339 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001340 case AUTHENTICATE_SURFACE: {
1341 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001342 sp<IGraphicBufferProducer> bufferProducer =
1343 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1344 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001345 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001346 return NO_ERROR;
1347 }
Brian Anderson6b376712017-04-04 10:51:39 -07001348 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1349 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1350 std::vector<FrameEvent> supportedTimestamps;
1351 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1352 status_t err = reply->writeInt32(result);
1353 if (err != NO_ERROR) {
1354 return err;
1355 }
1356 if (result != NO_ERROR) {
1357 return result;
1358 }
1359
1360 std::vector<int32_t> supported;
1361 supported.reserve(supportedTimestamps.size());
1362 for (FrameEvent s : supportedTimestamps) {
1363 supported.push_back(static_cast<int32_t>(s));
1364 }
1365 return reply->writeInt32Vector(supported);
1366 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001367 case CREATE_DISPLAY_EVENT_CONNECTION: {
1368 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001369 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1370 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1371
1372 sp<IDisplayEventConnection> connection(
1373 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001374 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001375 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001376 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001377 case CREATE_DISPLAY: {
1378 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001379 String8 displayName;
1380 SAFE_PARCEL(data.readString8, &displayName);
1381 bool secure = false;
1382 SAFE_PARCEL(data.readBool, &secure);
1383 sp<IBinder> display = createDisplay(displayName, secure);
1384 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001385 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001386 }
1387 case DESTROY_DISPLAY: {
1388 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1389 sp<IBinder> display = data.readStrongBinder();
1390 destroyDisplay(display);
1391 return NO_ERROR;
1392 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001393 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001394 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001395 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001396 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001397 reply->writeStrongBinder(display);
1398 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001399 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001400 case GET_DISPLAY_STATE: {
1401 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1402 ui::DisplayState state;
1403 const sp<IBinder> display = data.readStrongBinder();
1404 const status_t result = getDisplayState(display, &state);
1405 reply->writeInt32(result);
1406 if (result == NO_ERROR) {
1407 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1408 sizeof(ui::DisplayState));
1409 }
1410 return NO_ERROR;
1411 }
1412 case GET_DISPLAY_INFO: {
1413 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1414 DisplayInfo info;
1415 const sp<IBinder> display = data.readStrongBinder();
1416 const status_t result = getDisplayInfo(display, &info);
1417 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001418 if (result != NO_ERROR) return result;
1419 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001420 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001421 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001422 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001423 Vector<DisplayConfig> configs;
1424 const sp<IBinder> display = data.readStrongBinder();
1425 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001426 reply->writeInt32(result);
1427 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001428 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001429 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001430 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1431 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001432 }
1433 }
1434 return NO_ERROR;
1435 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001436 case GET_DISPLAY_STATS: {
1437 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1438 DisplayStatInfo stats;
1439 sp<IBinder> display = data.readStrongBinder();
1440 status_t result = getDisplayStats(display, &stats);
1441 reply->writeInt32(result);
1442 if (result == NO_ERROR) {
1443 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1444 &stats, sizeof(DisplayStatInfo));
1445 }
1446 return NO_ERROR;
1447 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001448 case GET_ACTIVE_CONFIG: {
1449 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1450 sp<IBinder> display = data.readStrongBinder();
1451 int id = getActiveConfig(display);
1452 reply->writeInt32(id);
1453 return NO_ERROR;
1454 }
Michael Wright28f24d02016-07-12 13:30:53 -07001455 case GET_DISPLAY_COLOR_MODES: {
1456 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001457 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001458 sp<IBinder> display = nullptr;
1459 status_t result = data.readStrongBinder(&display);
1460 if (result != NO_ERROR) {
1461 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1462 return result;
1463 }
1464 result = getDisplayColorModes(display, &colorModes);
1465 reply->writeInt32(result);
1466 if (result == NO_ERROR) {
1467 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1468 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001469 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001470 }
1471 }
1472 return NO_ERROR;
1473 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001474 case GET_DISPLAY_NATIVE_PRIMARIES: {
1475 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1476 ui::DisplayPrimaries primaries;
1477 sp<IBinder> display = nullptr;
1478
1479 status_t result = data.readStrongBinder(&display);
1480 if (result != NO_ERROR) {
1481 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1482 return result;
1483 }
1484
1485 result = getDisplayNativePrimaries(display, primaries);
1486 reply->writeInt32(result);
1487 if (result == NO_ERROR) {
1488 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1489 sizeof(ui::DisplayPrimaries));
1490 }
1491
1492 return NO_ERROR;
1493 }
Michael Wright28f24d02016-07-12 13:30:53 -07001494 case GET_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 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001502 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001503 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1504 return result;
1505 }
1506 case SET_ACTIVE_COLOR_MODE: {
1507 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1508 sp<IBinder> display = nullptr;
1509 status_t result = data.readStrongBinder(&display);
1510 if (result != NO_ERROR) {
1511 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1512 return result;
1513 }
1514 int32_t colorModeInt = 0;
1515 result = data.readInt32(&colorModeInt);
1516 if (result != NO_ERROR) {
1517 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1518 return result;
1519 }
1520 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001521 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001522 result = reply->writeInt32(result);
1523 return result;
1524 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001525
1526 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1527 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1528 sp<IBinder> display = nullptr;
1529 status_t result = data.readStrongBinder(&display);
1530 if (result != NO_ERROR) {
1531 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1532 return result;
1533 }
1534 bool supported = false;
1535 result = getAutoLowLatencyModeSupport(display, &supported);
1536 if (result == NO_ERROR) {
1537 result = reply->writeBool(supported);
1538 }
1539 return result;
1540 }
1541
1542 case SET_AUTO_LOW_LATENCY_MODE: {
1543 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1544 sp<IBinder> display = nullptr;
1545 status_t result = data.readStrongBinder(&display);
1546 if (result != NO_ERROR) {
1547 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1548 return result;
1549 }
1550 bool setAllm = false;
1551 result = data.readBool(&setAllm);
1552 if (result != NO_ERROR) {
1553 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1554 return result;
1555 }
1556 setAutoLowLatencyMode(display, setAllm);
1557 return result;
1558 }
1559
1560 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1561 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1562 sp<IBinder> display = nullptr;
1563 status_t result = data.readStrongBinder(&display);
1564 if (result != NO_ERROR) {
1565 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1566 return result;
1567 }
1568 bool supported = false;
1569 result = getGameContentTypeSupport(display, &supported);
1570 if (result == NO_ERROR) {
1571 result = reply->writeBool(supported);
1572 }
1573 return result;
1574 }
1575
1576 case SET_GAME_CONTENT_TYPE: {
1577 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1578 sp<IBinder> display = nullptr;
1579 status_t result = data.readStrongBinder(&display);
1580 if (result != NO_ERROR) {
1581 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1582 return result;
1583 }
1584 bool setGameContentTypeOn = false;
1585 result = data.readBool(&setGameContentTypeOn);
1586 if (result != NO_ERROR) {
1587 ALOGE("setGameContentType failed to readBool: %d", result);
1588 return result;
1589 }
1590 setGameContentType(display, setGameContentTypeOn);
1591 return result;
1592 }
1593
Svetoslavd85084b2014-03-20 10:28:31 -07001594 case CLEAR_ANIMATION_FRAME_STATS: {
1595 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1596 status_t result = clearAnimationFrameStats();
1597 reply->writeInt32(result);
1598 return NO_ERROR;
1599 }
1600 case GET_ANIMATION_FRAME_STATS: {
1601 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1602 FrameStats stats;
1603 status_t result = getAnimationFrameStats(&stats);
1604 reply->write(stats);
1605 reply->writeInt32(result);
1606 return NO_ERROR;
1607 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001608 case SET_POWER_MODE: {
1609 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1610 sp<IBinder> display = data.readStrongBinder();
1611 int32_t mode = data.readInt32();
1612 setPowerMode(display, mode);
1613 return NO_ERROR;
1614 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001615 case GET_HDR_CAPABILITIES: {
1616 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1617 sp<IBinder> display = nullptr;
1618 status_t result = data.readStrongBinder(&display);
1619 if (result != NO_ERROR) {
1620 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1621 result);
1622 return result;
1623 }
1624 HdrCapabilities capabilities;
1625 result = getHdrCapabilities(display, &capabilities);
1626 reply->writeInt32(result);
1627 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001628 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001629 }
1630 return NO_ERROR;
1631 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001632 case ENABLE_VSYNC_INJECTIONS: {
1633 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1634 bool enable = false;
1635 status_t result = data.readBool(&enable);
1636 if (result != NO_ERROR) {
1637 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1638 return result;
1639 }
1640 return enableVSyncInjections(enable);
1641 }
1642 case INJECT_VSYNC: {
1643 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1644 int64_t when = 0;
1645 status_t result = data.readInt64(&when);
1646 if (result != NO_ERROR) {
1647 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1648 return result;
1649 }
1650 return injectVSync(when);
1651 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001652 case GET_LAYER_DEBUG_INFO: {
1653 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1654 std::vector<LayerDebugInfo> outLayers;
1655 status_t result = getLayerDebugInfo(&outLayers);
1656 reply->writeInt32(result);
1657 if (result == NO_ERROR)
1658 {
1659 result = reply->writeParcelableVector(outLayers);
1660 }
1661 return result;
1662 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001663 case GET_COMPOSITION_PREFERENCE: {
1664 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001665 ui::Dataspace defaultDataspace;
1666 ui::PixelFormat defaultPixelFormat;
1667 ui::Dataspace wideColorGamutDataspace;
1668 ui::PixelFormat wideColorGamutPixelFormat;
1669 status_t error =
1670 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1671 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001672 reply->writeInt32(error);
1673 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001674 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1675 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1676 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001677 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001678 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001679 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001680 }
Ady Abraham37965d42018-11-01 13:43:32 -07001681 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001682 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001683 bool result;
1684 status_t error = getColorManagement(&result);
1685 if (error == NO_ERROR) {
1686 reply->writeBool(result);
1687 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001688 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001689 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001690 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1691 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1692
1693 sp<IBinder> display = data.readStrongBinder();
1694 ui::PixelFormat format;
1695 ui::Dataspace dataspace;
1696 uint8_t component = 0;
1697 auto result =
1698 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1699 if (result == NO_ERROR) {
1700 reply->writeUint32(static_cast<uint32_t>(format));
1701 reply->writeUint32(static_cast<uint32_t>(dataspace));
1702 reply->writeUint32(static_cast<uint32_t>(component));
1703 }
1704 return result;
1705 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001706 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1707 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1708
1709 sp<IBinder> display = nullptr;
1710 bool enable = false;
1711 int8_t componentMask = 0;
1712 uint64_t maxFrames = 0;
1713 status_t result = data.readStrongBinder(&display);
1714 if (result != NO_ERROR) {
1715 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1716 result);
1717 return result;
1718 }
1719
1720 result = data.readBool(&enable);
1721 if (result != NO_ERROR) {
1722 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1723 return result;
1724 }
1725
1726 result = data.readByte(static_cast<int8_t*>(&componentMask));
1727 if (result != NO_ERROR) {
1728 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1729 result);
1730 return result;
1731 }
1732
1733 result = data.readUint64(&maxFrames);
1734 if (result != NO_ERROR) {
1735 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1736 return result;
1737 }
1738
1739 return setDisplayContentSamplingEnabled(display, enable,
1740 static_cast<uint8_t>(componentMask), maxFrames);
1741 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001742 case GET_DISPLAYED_CONTENT_SAMPLE: {
1743 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1744
1745 sp<IBinder> display = data.readStrongBinder();
1746 uint64_t maxFrames = 0;
1747 uint64_t timestamp = 0;
1748
1749 status_t result = data.readUint64(&maxFrames);
1750 if (result != NO_ERROR) {
1751 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1752 return result;
1753 }
1754
1755 result = data.readUint64(&timestamp);
1756 if (result != NO_ERROR) {
1757 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1758 return result;
1759 }
1760
1761 DisplayedFrameStats stats;
1762 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1763 if (result == NO_ERROR) {
1764 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001765 reply->writeUint64Vector(stats.component_0_sample);
1766 reply->writeUint64Vector(stats.component_1_sample);
1767 reply->writeUint64Vector(stats.component_2_sample);
1768 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001769 }
1770 return result;
1771 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001772 case GET_PROTECTED_CONTENT_SUPPORT: {
1773 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1774 bool result;
1775 status_t error = getProtectedContentSupport(&result);
1776 if (error == NO_ERROR) {
1777 reply->writeBool(result);
1778 }
1779 return error;
1780 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001781 case IS_WIDE_COLOR_DISPLAY: {
1782 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1783 sp<IBinder> display = nullptr;
1784 status_t error = data.readStrongBinder(&display);
1785 if (error != NO_ERROR) {
1786 return error;
1787 }
1788 bool result;
1789 error = isWideColorDisplay(display, &result);
1790 if (error == NO_ERROR) {
1791 reply->writeBool(result);
1792 }
1793 return error;
1794 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001795 case GET_PHYSICAL_DISPLAY_IDS: {
1796 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001797 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1798 std::vector<uint64_t> rawIds(ids.size());
1799 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1800 [](PhysicalDisplayId id) { return id.value; });
1801 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001802 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001803 case ADD_REGION_SAMPLING_LISTENER: {
1804 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1805 Rect samplingArea;
1806 status_t result = data.read(samplingArea);
1807 if (result != NO_ERROR) {
1808 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1809 return result;
1810 }
1811 sp<IBinder> stopLayerHandle;
1812 result = data.readNullableStrongBinder(&stopLayerHandle);
1813 if (result != NO_ERROR) {
1814 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1815 return result;
1816 }
1817 sp<IRegionSamplingListener> listener;
1818 result = data.readNullableStrongBinder(&listener);
1819 if (result != NO_ERROR) {
1820 ALOGE("addRegionSamplingListener: Failed to read listener");
1821 return result;
1822 }
1823 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1824 }
1825 case REMOVE_REGION_SAMPLING_LISTENER: {
1826 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1827 sp<IRegionSamplingListener> listener;
1828 status_t result = data.readNullableStrongBinder(&listener);
1829 if (result != NO_ERROR) {
1830 ALOGE("removeRegionSamplingListener: Failed to read listener");
1831 return result;
1832 }
1833 return removeRegionSamplingListener(listener);
1834 }
Ana Krulec0782b882019-10-15 17:34:54 -07001835 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1836 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1837 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001838 int32_t defaultConfig;
1839 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001840 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001841 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001842 return result;
1843 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001844 bool allowGroupSwitching;
1845 result = data.readBool(&allowGroupSwitching);
1846 if (result != NO_ERROR) {
1847 ALOGE("setDesiredDisplayConfigSpecs: failed to read allowGroupSwitching: %d",
1848 result);
1849 return result;
1850 }
Steven Thomasf734df42020-04-13 21:09:28 -07001851 float primaryRefreshRateMin;
1852 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001853 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001854 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1855 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001856 return result;
1857 }
Steven Thomasf734df42020-04-13 21:09:28 -07001858 float primaryRefreshRateMax;
1859 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001860 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001861 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1862 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001863 return result;
1864 }
Steven Thomasf734df42020-04-13 21:09:28 -07001865 float appRequestRefreshRateMin;
1866 result = data.readFloat(&appRequestRefreshRateMin);
1867 if (result != NO_ERROR) {
1868 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1869 result);
1870 return result;
1871 }
1872 float appRequestRefreshRateMax;
1873 result = data.readFloat(&appRequestRefreshRateMax);
1874 if (result != NO_ERROR) {
1875 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1876 result);
1877 return result;
1878 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001879 result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, allowGroupSwitching,
1880 primaryRefreshRateMin, primaryRefreshRateMax,
1881 appRequestRefreshRateMin,
1882 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001883 if (result != NO_ERROR) {
1884 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1885 "%d",
1886 result);
1887 return result;
1888 }
1889 reply->writeInt32(result);
1890 return result;
1891 }
Ana Krulec234bb162019-11-10 22:55:55 +01001892 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1893 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1894 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001895 int32_t defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001896 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -07001897 float primaryRefreshRateMin;
1898 float primaryRefreshRateMax;
1899 float appRequestRefreshRateMin;
1900 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001901
Steven Thomasf734df42020-04-13 21:09:28 -07001902 status_t result =
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001903 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig, &allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -07001904 &primaryRefreshRateMin, &primaryRefreshRateMax,
1905 &appRequestRefreshRateMin,
1906 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001907 if (result != NO_ERROR) {
1908 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1909 "%d",
1910 result);
1911 return result;
1912 }
1913
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001914 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001915 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001916 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001917 return result;
1918 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001919 result = reply->writeBool(allowGroupSwitching);
1920 if (result != NO_ERROR) {
1921 ALOGE("getDesiredDisplayConfigSpecs: failed to write allowGroupSwitching: %d",
1922 result);
1923 return result;
1924 }
Steven Thomasf734df42020-04-13 21:09:28 -07001925 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001926 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001927 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1928 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001929 return result;
1930 }
Steven Thomasf734df42020-04-13 21:09:28 -07001931 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001932 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001933 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1934 result);
1935 return result;
1936 }
1937 result = reply->writeFloat(appRequestRefreshRateMin);
1938 if (result != NO_ERROR) {
1939 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1940 result);
1941 return result;
1942 }
1943 result = reply->writeFloat(appRequestRefreshRateMax);
1944 if (result != NO_ERROR) {
1945 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1946 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001947 return result;
1948 }
1949 reply->writeInt32(result);
1950 return result;
1951 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001952 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1953 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1954 sp<IBinder> displayToken;
1955 status_t error = data.readNullableStrongBinder(&displayToken);
1956 if (error != NO_ERROR) {
1957 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1958 return error;
1959 }
1960 bool support = false;
1961 error = getDisplayBrightnessSupport(displayToken, &support);
1962 reply->writeBool(support);
1963 return error;
1964 }
1965 case SET_DISPLAY_BRIGHTNESS: {
1966 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1967 sp<IBinder> displayToken;
1968 status_t error = data.readNullableStrongBinder(&displayToken);
1969 if (error != NO_ERROR) {
1970 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1971 return error;
1972 }
1973 float brightness = -1.0f;
1974 error = data.readFloat(&brightness);
1975 if (error != NO_ERROR) {
1976 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1977 return error;
1978 }
1979 return setDisplayBrightness(displayToken, brightness);
1980 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001981 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001982 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001983 int32_t boostId;
1984 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001985 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001986 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001987 return error;
1988 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001989 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001990 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001991 case SET_GLOBAL_SHADOW_SETTINGS: {
1992 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1993
1994 std::vector<float> shadowConfig;
1995 status_t error = data.readFloatVector(&shadowConfig);
1996 if (error != NO_ERROR || shadowConfig.size() != 11) {
1997 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1998 return error;
1999 }
2000
2001 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
2002 shadowConfig[3]};
2003 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
2004 float lightPosY = shadowConfig[8];
2005 float lightPosZ = shadowConfig[9];
2006 float lightRadius = shadowConfig[10];
2007 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
2008 lightRadius);
2009 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08002010 case SET_FRAME_RATE: {
2011 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2012 sp<IBinder> binder;
2013 status_t err = data.readStrongBinder(&binder);
2014 if (err != NO_ERROR) {
2015 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
2016 return err;
2017 }
2018 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2019 if (!surface) {
2020 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
2021 strerror(-err), -err);
2022 return err;
2023 }
2024 float frameRate;
2025 err = data.readFloat(&frameRate);
2026 if (err != NO_ERROR) {
2027 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2028 return err;
2029 }
2030 int8_t compatibility;
2031 err = data.readByte(&compatibility);
2032 if (err != NO_ERROR) {
2033 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2034 return err;
2035 }
2036 status_t result = setFrameRate(surface, frameRate, compatibility);
2037 reply->writeInt32(result);
2038 return NO_ERROR;
2039 }
Steven Thomasd4071902020-03-24 16:02:53 -07002040 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2041 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2042 sp<IBinder> token;
2043 status_t result = acquireFrameRateFlexibilityToken(&token);
2044 reply->writeInt32(result);
2045 if (result == NO_ERROR) {
2046 reply->writeStrongBinder(token);
2047 }
2048 return NO_ERROR;
2049 }
Ady Abraham74e17562020-08-24 18:18:19 -07002050 case SET_FRAME_TIMELINE_VSYNC: {
2051 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2052 sp<IBinder> binder;
2053 status_t err = data.readStrongBinder(&binder);
2054 if (err != NO_ERROR) {
2055 ALOGE("setFrameTimelineVsync: failed to read strong binder: %s (%d)",
2056 strerror(-err), -err);
2057 return err;
2058 }
2059 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2060 if (!surface) {
2061 ALOGE("setFrameTimelineVsync: failed to cast to IGraphicBufferProducer: %s (%d)",
2062 strerror(-err), -err);
2063 return err;
2064 }
2065 int64_t frameTimelineVsyncId;
2066 err = data.readInt64(&frameTimelineVsyncId);
2067 if (err != NO_ERROR) {
2068 ALOGE("setFrameTimelineVsync: failed to read int64_t: %s (%d)", strerror(-err),
2069 -err);
2070 return err;
2071 }
2072
2073 status_t result = setFrameTimelineVsync(surface, frameTimelineVsyncId);
2074 reply->writeInt32(result);
2075 return NO_ERROR;
2076 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00002077 case ADD_TRANSACTION_TRACE_LISTENER: {
2078 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2079 sp<gui::ITransactionTraceListener> listener;
2080 SAFE_PARCEL(data.readStrongBinder, &listener);
2081
2082 return addTransactionTraceListener(listener);
2083 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002084 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002085 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002086 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002087 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002088}
2089
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002090} // namespace android