blob: e46a415f8c0c3a7d0ed731a32c1a66185231eecd [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 Abraham62f216c2020-10-13 19:07:23 -0700226 virtual sp<IDisplayEventConnection> createDisplayEventConnection(
227 VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) {
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 Abraham62f216c2020-10-13 19:07:23 -0700236 data.writeUint32(eventRegistration.get());
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,
Marin Shalamanov46084422020-10-13 12:33:42 +02001117 int8_t compatibility, bool shouldBeSeamless) {
Steven Thomas62a4cf82020-01-31 12:04:03 -08001118 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
Marin Shalamanov46084422020-10-13 12:33:42 +02001143 err = data.writeBool(shouldBeSeamless);
1144 if (err != NO_ERROR) {
1145 ALOGE("setFrameRate: failed writing bool: %s (%d)", strerror(-err), -err);
1146 return err;
1147 }
1148
Ady Abraham60e42ea2020-03-09 19:17:31 -07001149 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001150 if (err != NO_ERROR) {
1151 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1152 return err;
1153 }
Steven Thomasd4071902020-03-24 16:02:53 -07001154
1155 return reply.readInt32();
1156 }
1157
1158 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1159 if (!outToken) return BAD_VALUE;
1160
1161 Parcel data, reply;
1162 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1163 if (err != NO_ERROR) {
1164 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1165 strerror(-err), -err);
1166 return err;
1167 }
1168
1169 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1170 &reply);
1171 if (err != NO_ERROR) {
1172 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1173 err);
1174 return err;
1175 }
1176
1177 err = reply.readInt32();
1178 if (err != NO_ERROR) {
1179 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1180 return err;
1181 }
1182
1183 err = reply.readStrongBinder(outToken);
1184 if (err != NO_ERROR) {
1185 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1186 strerror(-err), err);
1187 return err;
1188 }
1189
Steven Thomas62a4cf82020-01-31 12:04:03 -08001190 return NO_ERROR;
1191 }
Ady Abraham74e17562020-08-24 18:18:19 -07001192
1193 virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
1194 int64_t frameTimelineVsyncId) {
1195 Parcel data, reply;
1196 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1197 if (err != NO_ERROR) {
1198 ALOGE("setFrameTimelineVsync: failed writing interface token: %s (%d)", strerror(-err),
1199 -err);
1200 return err;
1201 }
1202
1203 err = data.writeStrongBinder(IInterface::asBinder(surface));
1204 if (err != NO_ERROR) {
1205 ALOGE("setFrameTimelineVsync: failed writing strong binder: %s (%d)", strerror(-err),
1206 -err);
1207 return err;
1208 }
1209
1210 err = data.writeInt64(frameTimelineVsyncId);
1211 if (err != NO_ERROR) {
1212 ALOGE("setFrameTimelineVsync: failed writing int64_t: %s (%d)", strerror(-err), -err);
1213 return err;
1214 }
1215
1216 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_VSYNC, data, &reply);
1217 if (err != NO_ERROR) {
1218 ALOGE("setFrameTimelineVsync: failed to transact: %s (%d)", strerror(-err), err);
1219 return err;
1220 }
1221
1222 return reply.readInt32();
1223 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00001224
1225 virtual status_t addTransactionTraceListener(
1226 const sp<gui::ITransactionTraceListener>& listener) {
1227 Parcel data, reply;
1228 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
1229 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
1230
1231 return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply);
1232 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001233};
1234
Dan Stozad723bd72014-11-18 10:24:03 -08001235// Out-of-line virtual method definition to trigger vtable emission in this
1236// translation unit (see clang warning -Wweak-vtables)
1237BpSurfaceComposer::~BpSurfaceComposer() {}
1238
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001239IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1240
1241// ----------------------------------------------------------------------
1242
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001243status_t BnSurfaceComposer::onTransact(
1244 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1245{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001246 switch(code) {
1247 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001248 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001249 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001250 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001251 return NO_ERROR;
1252 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001253 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001254 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001255
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001256 int64_t frameTimelineVsyncId;
1257 SAFE_PARCEL(data.readInt64, &frameTimelineVsyncId);
chaviw308ddba2020-08-11 16:23:51 -07001258 uint32_t count = 0;
1259 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001260 Vector<ComposerState> state;
1261 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001262 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001263 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001264 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001265 state.add(s);
1266 }
Dan Stozad723bd72014-11-18 10:24:03 -08001267
chaviw308ddba2020-08-11 16:23:51 -07001268 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001269 DisplayState d;
1270 Vector<DisplayState> displays;
1271 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001272 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001273 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001274 displays.add(d);
1275 }
Dan Stozad723bd72014-11-18 10:24:03 -08001276
chaviw308ddba2020-08-11 16:23:51 -07001277 uint32_t stateFlags = 0;
1278 SAFE_PARCEL(data.readUint32, &stateFlags);
1279 sp<IBinder> applyToken;
1280 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001281 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001282 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001283
chaviw308ddba2020-08-11 16:23:51 -07001284 int64_t desiredPresentTime = 0;
1285 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -07001286
Marissa Wall947d34e2019-03-29 14:03:53 -07001287 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001288 sp<IBinder> tmpBinder;
1289 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1290 uncachedBuffer.token = tmpBinder;
1291 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001292
chaviw308ddba2020-08-11 16:23:51 -07001293 bool hasListenerCallbacks = false;
1294 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001295
Marissa Wall3dad52d2019-03-22 14:03:19 -07001296 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001297 int32_t listenersSize = 0;
1298 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001299 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001300 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001301 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001302 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1303 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001304 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +00001305
1306 uint64_t transactionId = -1;
1307 SAFE_PARCEL(data.readUint64, &transactionId);
1308
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001309 return setTransactionState(frameTimelineVsyncId, state, displays, stateFlags,
1310 applyToken, inputWindowCommands, desiredPresentTime,
1311 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
1312 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -07001313 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001314 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001315 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001316 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001317 return NO_ERROR;
1318 }
chaviwd2432892020-07-24 17:42:39 -07001319 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001320 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001321 DisplayCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001322 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001323 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001324 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1325
1326 return captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001327 }
chaviwd2432892020-07-24 17:42:39 -07001328 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001329 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001330 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001331 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001332 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001333 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1334
1335 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001336 }
chaviwa76b2712017-09-20 12:02:26 -07001337 case CAPTURE_LAYERS: {
1338 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001339 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001340 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001341 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001342 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1343
1344 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001345 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001346 case AUTHENTICATE_SURFACE: {
1347 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001348 sp<IGraphicBufferProducer> bufferProducer =
1349 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1350 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001351 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001352 return NO_ERROR;
1353 }
Brian Anderson6b376712017-04-04 10:51:39 -07001354 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1355 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1356 std::vector<FrameEvent> supportedTimestamps;
1357 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1358 status_t err = reply->writeInt32(result);
1359 if (err != NO_ERROR) {
1360 return err;
1361 }
1362 if (result != NO_ERROR) {
1363 return result;
1364 }
1365
1366 std::vector<int32_t> supported;
1367 supported.reserve(supportedTimestamps.size());
1368 for (FrameEvent s : supportedTimestamps) {
1369 supported.push_back(static_cast<int32_t>(s));
1370 }
1371 return reply->writeInt32Vector(supported);
1372 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001373 case CREATE_DISPLAY_EVENT_CONNECTION: {
1374 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001375 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
Ady Abraham62f216c2020-10-13 19:07:23 -07001376 EventRegistrationFlags eventRegistration =
1377 static_cast<EventRegistration>(data.readUint32());
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001378
1379 sp<IDisplayEventConnection> connection(
Ady Abraham62f216c2020-10-13 19:07:23 -07001380 createDisplayEventConnection(vsyncSource, eventRegistration));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001381 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001382 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001383 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001384 case CREATE_DISPLAY: {
1385 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001386 String8 displayName;
1387 SAFE_PARCEL(data.readString8, &displayName);
1388 bool secure = false;
1389 SAFE_PARCEL(data.readBool, &secure);
1390 sp<IBinder> display = createDisplay(displayName, secure);
1391 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001392 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001393 }
1394 case DESTROY_DISPLAY: {
1395 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1396 sp<IBinder> display = data.readStrongBinder();
1397 destroyDisplay(display);
1398 return NO_ERROR;
1399 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001400 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001401 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001402 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001403 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001404 reply->writeStrongBinder(display);
1405 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001406 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001407 case GET_DISPLAY_STATE: {
1408 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1409 ui::DisplayState state;
1410 const sp<IBinder> display = data.readStrongBinder();
1411 const status_t result = getDisplayState(display, &state);
1412 reply->writeInt32(result);
1413 if (result == NO_ERROR) {
1414 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1415 sizeof(ui::DisplayState));
1416 }
1417 return NO_ERROR;
1418 }
1419 case GET_DISPLAY_INFO: {
1420 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1421 DisplayInfo info;
1422 const sp<IBinder> display = data.readStrongBinder();
1423 const status_t result = getDisplayInfo(display, &info);
1424 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001425 if (result != NO_ERROR) return result;
1426 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001427 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001428 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001429 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001430 Vector<DisplayConfig> configs;
1431 const sp<IBinder> display = data.readStrongBinder();
1432 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001433 reply->writeInt32(result);
1434 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001435 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001436 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001437 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1438 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001439 }
1440 }
1441 return NO_ERROR;
1442 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001443 case GET_DISPLAY_STATS: {
1444 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1445 DisplayStatInfo stats;
1446 sp<IBinder> display = data.readStrongBinder();
1447 status_t result = getDisplayStats(display, &stats);
1448 reply->writeInt32(result);
1449 if (result == NO_ERROR) {
1450 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1451 &stats, sizeof(DisplayStatInfo));
1452 }
1453 return NO_ERROR;
1454 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001455 case GET_ACTIVE_CONFIG: {
1456 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1457 sp<IBinder> display = data.readStrongBinder();
1458 int id = getActiveConfig(display);
1459 reply->writeInt32(id);
1460 return NO_ERROR;
1461 }
Michael Wright28f24d02016-07-12 13:30:53 -07001462 case GET_DISPLAY_COLOR_MODES: {
1463 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001464 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001465 sp<IBinder> display = nullptr;
1466 status_t result = data.readStrongBinder(&display);
1467 if (result != NO_ERROR) {
1468 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1469 return result;
1470 }
1471 result = getDisplayColorModes(display, &colorModes);
1472 reply->writeInt32(result);
1473 if (result == NO_ERROR) {
1474 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1475 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001476 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001477 }
1478 }
1479 return NO_ERROR;
1480 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001481 case GET_DISPLAY_NATIVE_PRIMARIES: {
1482 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1483 ui::DisplayPrimaries primaries;
1484 sp<IBinder> display = nullptr;
1485
1486 status_t result = data.readStrongBinder(&display);
1487 if (result != NO_ERROR) {
1488 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1489 return result;
1490 }
1491
1492 result = getDisplayNativePrimaries(display, primaries);
1493 reply->writeInt32(result);
1494 if (result == NO_ERROR) {
1495 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1496 sizeof(ui::DisplayPrimaries));
1497 }
1498
1499 return NO_ERROR;
1500 }
Michael Wright28f24d02016-07-12 13:30:53 -07001501 case GET_ACTIVE_COLOR_MODE: {
1502 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1503 sp<IBinder> display = nullptr;
1504 status_t result = data.readStrongBinder(&display);
1505 if (result != NO_ERROR) {
1506 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1507 return result;
1508 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001509 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001510 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1511 return result;
1512 }
1513 case SET_ACTIVE_COLOR_MODE: {
1514 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1515 sp<IBinder> display = nullptr;
1516 status_t result = data.readStrongBinder(&display);
1517 if (result != NO_ERROR) {
1518 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1519 return result;
1520 }
1521 int32_t colorModeInt = 0;
1522 result = data.readInt32(&colorModeInt);
1523 if (result != NO_ERROR) {
1524 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1525 return result;
1526 }
1527 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001528 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001529 result = reply->writeInt32(result);
1530 return result;
1531 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001532
1533 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1534 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1535 sp<IBinder> display = nullptr;
1536 status_t result = data.readStrongBinder(&display);
1537 if (result != NO_ERROR) {
1538 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1539 return result;
1540 }
1541 bool supported = false;
1542 result = getAutoLowLatencyModeSupport(display, &supported);
1543 if (result == NO_ERROR) {
1544 result = reply->writeBool(supported);
1545 }
1546 return result;
1547 }
1548
1549 case SET_AUTO_LOW_LATENCY_MODE: {
1550 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1551 sp<IBinder> display = nullptr;
1552 status_t result = data.readStrongBinder(&display);
1553 if (result != NO_ERROR) {
1554 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1555 return result;
1556 }
1557 bool setAllm = false;
1558 result = data.readBool(&setAllm);
1559 if (result != NO_ERROR) {
1560 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1561 return result;
1562 }
1563 setAutoLowLatencyMode(display, setAllm);
1564 return result;
1565 }
1566
1567 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1568 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1569 sp<IBinder> display = nullptr;
1570 status_t result = data.readStrongBinder(&display);
1571 if (result != NO_ERROR) {
1572 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1573 return result;
1574 }
1575 bool supported = false;
1576 result = getGameContentTypeSupport(display, &supported);
1577 if (result == NO_ERROR) {
1578 result = reply->writeBool(supported);
1579 }
1580 return result;
1581 }
1582
1583 case SET_GAME_CONTENT_TYPE: {
1584 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1585 sp<IBinder> display = nullptr;
1586 status_t result = data.readStrongBinder(&display);
1587 if (result != NO_ERROR) {
1588 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1589 return result;
1590 }
1591 bool setGameContentTypeOn = false;
1592 result = data.readBool(&setGameContentTypeOn);
1593 if (result != NO_ERROR) {
1594 ALOGE("setGameContentType failed to readBool: %d", result);
1595 return result;
1596 }
1597 setGameContentType(display, setGameContentTypeOn);
1598 return result;
1599 }
1600
Svetoslavd85084b2014-03-20 10:28:31 -07001601 case CLEAR_ANIMATION_FRAME_STATS: {
1602 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1603 status_t result = clearAnimationFrameStats();
1604 reply->writeInt32(result);
1605 return NO_ERROR;
1606 }
1607 case GET_ANIMATION_FRAME_STATS: {
1608 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1609 FrameStats stats;
1610 status_t result = getAnimationFrameStats(&stats);
1611 reply->write(stats);
1612 reply->writeInt32(result);
1613 return NO_ERROR;
1614 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001615 case SET_POWER_MODE: {
1616 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1617 sp<IBinder> display = data.readStrongBinder();
1618 int32_t mode = data.readInt32();
1619 setPowerMode(display, mode);
1620 return NO_ERROR;
1621 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001622 case GET_HDR_CAPABILITIES: {
1623 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1624 sp<IBinder> display = nullptr;
1625 status_t result = data.readStrongBinder(&display);
1626 if (result != NO_ERROR) {
1627 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1628 result);
1629 return result;
1630 }
1631 HdrCapabilities capabilities;
1632 result = getHdrCapabilities(display, &capabilities);
1633 reply->writeInt32(result);
1634 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001635 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001636 }
1637 return NO_ERROR;
1638 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001639 case ENABLE_VSYNC_INJECTIONS: {
1640 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1641 bool enable = false;
1642 status_t result = data.readBool(&enable);
1643 if (result != NO_ERROR) {
1644 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1645 return result;
1646 }
1647 return enableVSyncInjections(enable);
1648 }
1649 case INJECT_VSYNC: {
1650 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1651 int64_t when = 0;
1652 status_t result = data.readInt64(&when);
1653 if (result != NO_ERROR) {
1654 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1655 return result;
1656 }
1657 return injectVSync(when);
1658 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001659 case GET_LAYER_DEBUG_INFO: {
1660 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1661 std::vector<LayerDebugInfo> outLayers;
1662 status_t result = getLayerDebugInfo(&outLayers);
1663 reply->writeInt32(result);
1664 if (result == NO_ERROR)
1665 {
1666 result = reply->writeParcelableVector(outLayers);
1667 }
1668 return result;
1669 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001670 case GET_COMPOSITION_PREFERENCE: {
1671 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001672 ui::Dataspace defaultDataspace;
1673 ui::PixelFormat defaultPixelFormat;
1674 ui::Dataspace wideColorGamutDataspace;
1675 ui::PixelFormat wideColorGamutPixelFormat;
1676 status_t error =
1677 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1678 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001679 reply->writeInt32(error);
1680 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001681 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1682 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1683 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001684 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001685 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001686 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001687 }
Ady Abraham37965d42018-11-01 13:43:32 -07001688 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001690 bool result;
1691 status_t error = getColorManagement(&result);
1692 if (error == NO_ERROR) {
1693 reply->writeBool(result);
1694 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001695 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001696 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001697 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1698 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1699
1700 sp<IBinder> display = data.readStrongBinder();
1701 ui::PixelFormat format;
1702 ui::Dataspace dataspace;
1703 uint8_t component = 0;
1704 auto result =
1705 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1706 if (result == NO_ERROR) {
1707 reply->writeUint32(static_cast<uint32_t>(format));
1708 reply->writeUint32(static_cast<uint32_t>(dataspace));
1709 reply->writeUint32(static_cast<uint32_t>(component));
1710 }
1711 return result;
1712 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001713 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1714 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1715
1716 sp<IBinder> display = nullptr;
1717 bool enable = false;
1718 int8_t componentMask = 0;
1719 uint64_t maxFrames = 0;
1720 status_t result = data.readStrongBinder(&display);
1721 if (result != NO_ERROR) {
1722 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1723 result);
1724 return result;
1725 }
1726
1727 result = data.readBool(&enable);
1728 if (result != NO_ERROR) {
1729 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1730 return result;
1731 }
1732
1733 result = data.readByte(static_cast<int8_t*>(&componentMask));
1734 if (result != NO_ERROR) {
1735 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1736 result);
1737 return result;
1738 }
1739
1740 result = data.readUint64(&maxFrames);
1741 if (result != NO_ERROR) {
1742 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1743 return result;
1744 }
1745
1746 return setDisplayContentSamplingEnabled(display, enable,
1747 static_cast<uint8_t>(componentMask), maxFrames);
1748 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001749 case GET_DISPLAYED_CONTENT_SAMPLE: {
1750 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1751
1752 sp<IBinder> display = data.readStrongBinder();
1753 uint64_t maxFrames = 0;
1754 uint64_t timestamp = 0;
1755
1756 status_t result = data.readUint64(&maxFrames);
1757 if (result != NO_ERROR) {
1758 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1759 return result;
1760 }
1761
1762 result = data.readUint64(&timestamp);
1763 if (result != NO_ERROR) {
1764 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1765 return result;
1766 }
1767
1768 DisplayedFrameStats stats;
1769 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1770 if (result == NO_ERROR) {
1771 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001772 reply->writeUint64Vector(stats.component_0_sample);
1773 reply->writeUint64Vector(stats.component_1_sample);
1774 reply->writeUint64Vector(stats.component_2_sample);
1775 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001776 }
1777 return result;
1778 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001779 case GET_PROTECTED_CONTENT_SUPPORT: {
1780 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1781 bool result;
1782 status_t error = getProtectedContentSupport(&result);
1783 if (error == NO_ERROR) {
1784 reply->writeBool(result);
1785 }
1786 return error;
1787 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001788 case IS_WIDE_COLOR_DISPLAY: {
1789 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1790 sp<IBinder> display = nullptr;
1791 status_t error = data.readStrongBinder(&display);
1792 if (error != NO_ERROR) {
1793 return error;
1794 }
1795 bool result;
1796 error = isWideColorDisplay(display, &result);
1797 if (error == NO_ERROR) {
1798 reply->writeBool(result);
1799 }
1800 return error;
1801 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001802 case GET_PHYSICAL_DISPLAY_IDS: {
1803 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001804 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1805 std::vector<uint64_t> rawIds(ids.size());
1806 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1807 [](PhysicalDisplayId id) { return id.value; });
1808 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001809 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001810 case ADD_REGION_SAMPLING_LISTENER: {
1811 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1812 Rect samplingArea;
1813 status_t result = data.read(samplingArea);
1814 if (result != NO_ERROR) {
1815 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1816 return result;
1817 }
1818 sp<IBinder> stopLayerHandle;
1819 result = data.readNullableStrongBinder(&stopLayerHandle);
1820 if (result != NO_ERROR) {
1821 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1822 return result;
1823 }
1824 sp<IRegionSamplingListener> listener;
1825 result = data.readNullableStrongBinder(&listener);
1826 if (result != NO_ERROR) {
1827 ALOGE("addRegionSamplingListener: Failed to read listener");
1828 return result;
1829 }
1830 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1831 }
1832 case REMOVE_REGION_SAMPLING_LISTENER: {
1833 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1834 sp<IRegionSamplingListener> listener;
1835 status_t result = data.readNullableStrongBinder(&listener);
1836 if (result != NO_ERROR) {
1837 ALOGE("removeRegionSamplingListener: Failed to read listener");
1838 return result;
1839 }
1840 return removeRegionSamplingListener(listener);
1841 }
Ana Krulec0782b882019-10-15 17:34:54 -07001842 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1843 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1844 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001845 int32_t defaultConfig;
1846 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001847 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001848 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001849 return result;
1850 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001851 bool allowGroupSwitching;
1852 result = data.readBool(&allowGroupSwitching);
1853 if (result != NO_ERROR) {
1854 ALOGE("setDesiredDisplayConfigSpecs: failed to read allowGroupSwitching: %d",
1855 result);
1856 return result;
1857 }
Steven Thomasf734df42020-04-13 21:09:28 -07001858 float primaryRefreshRateMin;
1859 result = data.readFloat(&primaryRefreshRateMin);
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 primaryRefreshRateMin: %d",
1862 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001863 return result;
1864 }
Steven Thomasf734df42020-04-13 21:09:28 -07001865 float primaryRefreshRateMax;
1866 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001867 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001868 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1869 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001870 return result;
1871 }
Steven Thomasf734df42020-04-13 21:09:28 -07001872 float appRequestRefreshRateMin;
1873 result = data.readFloat(&appRequestRefreshRateMin);
1874 if (result != NO_ERROR) {
1875 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1876 result);
1877 return result;
1878 }
1879 float appRequestRefreshRateMax;
1880 result = data.readFloat(&appRequestRefreshRateMax);
1881 if (result != NO_ERROR) {
1882 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1883 result);
1884 return result;
1885 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001886 result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, allowGroupSwitching,
1887 primaryRefreshRateMin, primaryRefreshRateMax,
1888 appRequestRefreshRateMin,
1889 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001890 if (result != NO_ERROR) {
1891 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1892 "%d",
1893 result);
1894 return result;
1895 }
1896 reply->writeInt32(result);
1897 return result;
1898 }
Ana Krulec234bb162019-11-10 22:55:55 +01001899 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1900 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1901 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001902 int32_t defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001903 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -07001904 float primaryRefreshRateMin;
1905 float primaryRefreshRateMax;
1906 float appRequestRefreshRateMin;
1907 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001908
Steven Thomasf734df42020-04-13 21:09:28 -07001909 status_t result =
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001910 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig, &allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -07001911 &primaryRefreshRateMin, &primaryRefreshRateMax,
1912 &appRequestRefreshRateMin,
1913 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001914 if (result != NO_ERROR) {
1915 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1916 "%d",
1917 result);
1918 return result;
1919 }
1920
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001921 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001922 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001923 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001924 return result;
1925 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001926 result = reply->writeBool(allowGroupSwitching);
1927 if (result != NO_ERROR) {
1928 ALOGE("getDesiredDisplayConfigSpecs: failed to write allowGroupSwitching: %d",
1929 result);
1930 return result;
1931 }
Steven Thomasf734df42020-04-13 21:09:28 -07001932 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001933 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001934 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1935 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001936 return result;
1937 }
Steven Thomasf734df42020-04-13 21:09:28 -07001938 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001939 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001940 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1941 result);
1942 return result;
1943 }
1944 result = reply->writeFloat(appRequestRefreshRateMin);
1945 if (result != NO_ERROR) {
1946 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1947 result);
1948 return result;
1949 }
1950 result = reply->writeFloat(appRequestRefreshRateMax);
1951 if (result != NO_ERROR) {
1952 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1953 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001954 return result;
1955 }
1956 reply->writeInt32(result);
1957 return result;
1958 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001959 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1960 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1961 sp<IBinder> displayToken;
1962 status_t error = data.readNullableStrongBinder(&displayToken);
1963 if (error != NO_ERROR) {
1964 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1965 return error;
1966 }
1967 bool support = false;
1968 error = getDisplayBrightnessSupport(displayToken, &support);
1969 reply->writeBool(support);
1970 return error;
1971 }
1972 case SET_DISPLAY_BRIGHTNESS: {
1973 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1974 sp<IBinder> displayToken;
1975 status_t error = data.readNullableStrongBinder(&displayToken);
1976 if (error != NO_ERROR) {
1977 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1978 return error;
1979 }
1980 float brightness = -1.0f;
1981 error = data.readFloat(&brightness);
1982 if (error != NO_ERROR) {
1983 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1984 return error;
1985 }
1986 return setDisplayBrightness(displayToken, brightness);
1987 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001988 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001989 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001990 int32_t boostId;
1991 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001992 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001993 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001994 return error;
1995 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001996 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001997 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001998 case SET_GLOBAL_SHADOW_SETTINGS: {
1999 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2000
2001 std::vector<float> shadowConfig;
2002 status_t error = data.readFloatVector(&shadowConfig);
2003 if (error != NO_ERROR || shadowConfig.size() != 11) {
2004 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
2005 return error;
2006 }
2007
2008 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
2009 shadowConfig[3]};
2010 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
2011 float lightPosY = shadowConfig[8];
2012 float lightPosZ = shadowConfig[9];
2013 float lightRadius = shadowConfig[10];
2014 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
2015 lightRadius);
2016 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08002017 case SET_FRAME_RATE: {
2018 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2019 sp<IBinder> binder;
2020 status_t err = data.readStrongBinder(&binder);
2021 if (err != NO_ERROR) {
2022 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
2023 return err;
2024 }
2025 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2026 if (!surface) {
2027 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
2028 strerror(-err), -err);
2029 return err;
2030 }
2031 float frameRate;
2032 err = data.readFloat(&frameRate);
2033 if (err != NO_ERROR) {
2034 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2035 return err;
2036 }
2037 int8_t compatibility;
2038 err = data.readByte(&compatibility);
2039 if (err != NO_ERROR) {
2040 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2041 return err;
2042 }
Marin Shalamanov46084422020-10-13 12:33:42 +02002043 bool shouldBeSeamless;
2044 err = data.readBool(&shouldBeSeamless);
2045 if (err != NO_ERROR) {
2046 ALOGE("setFrameRate: failed to read bool: %s (%d)", strerror(-err), -err);
2047 return err;
2048 }
2049 status_t result = setFrameRate(surface, frameRate, compatibility, shouldBeSeamless);
Steven Thomas62a4cf82020-01-31 12:04:03 -08002050 reply->writeInt32(result);
2051 return NO_ERROR;
2052 }
Steven Thomasd4071902020-03-24 16:02:53 -07002053 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2054 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2055 sp<IBinder> token;
2056 status_t result = acquireFrameRateFlexibilityToken(&token);
2057 reply->writeInt32(result);
2058 if (result == NO_ERROR) {
2059 reply->writeStrongBinder(token);
2060 }
2061 return NO_ERROR;
2062 }
Ady Abraham74e17562020-08-24 18:18:19 -07002063 case SET_FRAME_TIMELINE_VSYNC: {
2064 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2065 sp<IBinder> binder;
2066 status_t err = data.readStrongBinder(&binder);
2067 if (err != NO_ERROR) {
2068 ALOGE("setFrameTimelineVsync: failed to read strong binder: %s (%d)",
2069 strerror(-err), -err);
2070 return err;
2071 }
2072 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2073 if (!surface) {
2074 ALOGE("setFrameTimelineVsync: failed to cast to IGraphicBufferProducer: %s (%d)",
2075 strerror(-err), -err);
2076 return err;
2077 }
2078 int64_t frameTimelineVsyncId;
2079 err = data.readInt64(&frameTimelineVsyncId);
2080 if (err != NO_ERROR) {
2081 ALOGE("setFrameTimelineVsync: failed to read int64_t: %s (%d)", strerror(-err),
2082 -err);
2083 return err;
2084 }
2085
2086 status_t result = setFrameTimelineVsync(surface, frameTimelineVsyncId);
2087 reply->writeInt32(result);
2088 return NO_ERROR;
2089 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00002090 case ADD_TRANSACTION_TRACE_LISTENER: {
2091 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2092 sp<gui::ITransactionTraceListener> listener;
2093 SAFE_PARCEL(data.readStrongBinder, &listener);
2094
2095 return addTransactionTraceListener(listener);
2096 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002097 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002098 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002099 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002100 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002101}
2102
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002103} // namespace android