blob: a8d6832275bc87b499b795dc07ab27ab9e757770 [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,
Ady Abrahamf0c56492020-12-17 18:04:15 -080074 const InputWindowCommands& commands, int64_t desiredPresentTime, bool isAutoTimestamp,
Ady Abraham22c7b5c2020-09-22 19:33:40 -070075 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);
Ady Abrahamf0c56492020-12-17 18:04:15 -080095 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
chaviw308ddba2020-08-11 16:23:51 -070096 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
97 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
98 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070099
chaviw308ddba2020-08-11 16:23:51 -0700100 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
101 for (const auto& [listener, callbackIds] : listenerCallbacks) {
102 SAFE_PARCEL(data.writeStrongBinder, listener);
103 SAFE_PARCEL(data.writeInt64Vector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700104 }
105
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000106 SAFE_PARCEL(data.writeUint64, transactionId);
107
chaviw308ddba2020-08-11 16:23:51 -0700108 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 }
110
111 virtual void bootFinished()
112 {
113 Parcel data, reply;
114 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
115 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
116 }
117
chaviwd2432892020-07-24 17:42:39 -0700118 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700119 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800120 Parcel data, reply;
121 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700122 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700123 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000124
chaviw8ffc7b82020-08-18 11:25:37 -0700125 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800126 }
127
chaviwd2432892020-07-24 17:42:39 -0700128 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
chaviw8ffc7b82020-08-18 11:25:37 -0700129 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -0700130 Parcel data, reply;
131 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw8ffc7b82020-08-18 11:25:37 -0700132 SAFE_PARCEL(data.writeUint64, displayOrLayerStack);
133 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw93df2ea2019-04-30 16:45:12 -0700134
chaviw8ffc7b82020-08-18 11:25:37 -0700135 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700136 }
137
chaviw3efadb12020-07-27 10:07:15 -0700138 virtual status_t captureLayers(const LayerCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700139 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -0700140 Parcel data, reply;
141 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700142 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700143 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw3efadb12020-07-27 10:07:15 -0700144
chaviw8ffc7b82020-08-18 11:25:37 -0700145 return remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
chaviwa76b2712017-09-20 12:02:26 -0700146 }
147
Jamie Gennis582270d2011-08-17 18:19:00 -0700148 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800149 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800150 {
151 Parcel data, reply;
152 int err = NO_ERROR;
153 err = data.writeInterfaceToken(
154 ISurfaceComposer::getInterfaceDescriptor());
155 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000156 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800157 "interface descriptor: %s (%d)", strerror(-err), -err);
158 return false;
159 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800160 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800161 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000162 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700163 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800164 return false;
165 }
166 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
167 &reply);
168 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000169 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700170 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800171 return false;
172 }
173 int32_t result = 0;
174 err = reply.readInt32(&result);
175 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000176 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700177 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800178 return false;
179 }
180 return result != 0;
181 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800182
Brian Anderson6b376712017-04-04 10:51:39 -0700183 virtual status_t getSupportedFrameTimestamps(
184 std::vector<FrameEvent>* outSupported) const {
185 if (!outSupported) {
186 return UNEXPECTED_NULL;
187 }
188 outSupported->clear();
189
190 Parcel data, reply;
191
192 status_t err = data.writeInterfaceToken(
193 ISurfaceComposer::getInterfaceDescriptor());
194 if (err != NO_ERROR) {
195 return err;
196 }
197
198 err = remote()->transact(
199 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
200 data, &reply);
201 if (err != NO_ERROR) {
202 return err;
203 }
204
205 int32_t result = 0;
206 err = reply.readInt32(&result);
207 if (err != NO_ERROR) {
208 return err;
209 }
210 if (result != NO_ERROR) {
211 return result;
212 }
213
214 std::vector<int32_t> supported;
215 err = reply.readInt32Vector(&supported);
216 if (err != NO_ERROR) {
217 return err;
218 }
219
220 outSupported->reserve(supported.size());
221 for (int32_t s : supported) {
222 outSupported->push_back(static_cast<FrameEvent>(s));
223 }
224 return NO_ERROR;
225 }
226
Ady Abraham62f216c2020-10-13 19:07:23 -0700227 virtual sp<IDisplayEventConnection> createDisplayEventConnection(
228 VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800229 Parcel data, reply;
230 sp<IDisplayEventConnection> result;
231 int err = data.writeInterfaceToken(
232 ISurfaceComposer::getInterfaceDescriptor());
233 if (err != NO_ERROR) {
234 return result;
235 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700236 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham62f216c2020-10-13 19:07:23 -0700237 data.writeUint32(eventRegistration.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800238 err = remote()->transact(
239 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
240 data, &reply);
241 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000242 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800243 "transaction: %s (%d)", strerror(-err), -err);
244 return result;
245 }
246 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
247 return result;
248 }
Colin Cross8e533062012-06-07 13:17:52 -0700249
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700250 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700251 {
252 Parcel data, reply;
253 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd4a61642020-09-01 14:53:46 -0700254 status_t status = data.writeString8(displayName);
255 if (status) {
256 return nullptr;
257 }
258 status = data.writeBool(secure);
259 if (status) {
260 return nullptr;
261 }
262
263 status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
264 if (status) {
265 return nullptr;
266 }
267 sp<IBinder> display;
268 status = reply.readNullableStrongBinder(&display);
269 if (status) {
270 return nullptr;
271 }
272 return display;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700273 }
274
Jesse Hall6c913be2013-08-08 12:15:49 -0700275 virtual void destroyDisplay(const sp<IBinder>& display)
276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
279 data.writeStrongBinder(display);
280 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
281 }
282
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800283 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700284 Parcel data, reply;
285 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800286 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
287 NO_ERROR) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200288 std::vector<uint64_t> rawIds;
289 if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
290 std::vector<PhysicalDisplayId> displayIds(rawIds.size());
291 std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
292 [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800293 return displayIds;
294 }
295 }
296
297 return {};
298 }
299
300 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
301 Parcel data, reply;
302 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Marin Shalamanova524a092020-07-27 21:39:55 +0200303 data.writeUint64(displayId.value);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800304 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700305 return reply.readStrongBinder();
306 }
307
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700308 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700312 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700313 data.writeInt32(mode);
314 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700315 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700316
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800317 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
318 Parcel data, reply;
319 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
320 data.writeStrongBinder(display);
321 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
322 const status_t result = reply.readInt32();
323 if (result == NO_ERROR) {
324 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
325 }
326 return result;
327 }
328
329 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
330 Parcel data, reply;
331 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
332 data.writeStrongBinder(display);
333 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
334 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100335 if (result != NO_ERROR) return result;
336 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800337 }
338
339 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700340 Parcel data, reply;
341 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700342 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700343 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800344 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700345 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800346 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700347 configs->clear();
348 configs->resize(numConfigs);
349 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800350 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
351 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700352 }
353 }
354 return result;
355 }
356
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700357 virtual status_t getDisplayStats(const sp<IBinder>& display,
358 DisplayStatInfo* stats)
359 {
360 Parcel data, reply;
361 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
362 data.writeStrongBinder(display);
363 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
364 status_t result = reply.readInt32();
365 if (result == NO_ERROR) {
366 memcpy(stats,
367 reply.readInplace(sizeof(DisplayStatInfo)),
368 sizeof(DisplayStatInfo));
369 }
370 return result;
371 }
372
Dan Stoza7f7da322014-05-02 15:26:25 -0700373 virtual int getActiveConfig(const sp<IBinder>& display)
374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
377 data.writeStrongBinder(display);
378 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
379 return reply.readInt32();
380 }
381
Michael Wright28f24d02016-07-12 13:30:53 -0700382 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700383 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700384 Parcel data, reply;
385 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
386 if (result != NO_ERROR) {
387 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
388 return result;
389 }
390 result = data.writeStrongBinder(display);
391 if (result != NO_ERROR) {
392 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
393 return result;
394 }
395 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
396 if (result != NO_ERROR) {
397 ALOGE("getDisplayColorModes failed to transact: %d", result);
398 return result;
399 }
400 result = static_cast<status_t>(reply.readInt32());
401 if (result == NO_ERROR) {
402 size_t numModes = reply.readUint32();
403 outColorModes->clear();
404 outColorModes->resize(numModes);
405 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700406 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700407 }
408 }
409 return result;
410 }
411
Daniel Solomon42d04562019-01-20 21:03:19 -0800412 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
413 ui::DisplayPrimaries& primaries) {
414 Parcel data, reply;
415 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
416 if (result != NO_ERROR) {
417 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
418 return result;
419 }
420 result = data.writeStrongBinder(display);
421 if (result != NO_ERROR) {
422 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
423 return result;
424 }
425 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
426 if (result != NO_ERROR) {
427 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
428 return result;
429 }
430 result = reply.readInt32();
431 if (result == NO_ERROR) {
432 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
433 sizeof(ui::DisplayPrimaries));
434 }
435 return result;
436 }
437
Peiyong Lina52f0292018-03-14 17:26:31 -0700438 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700439 Parcel data, reply;
440 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
441 if (result != NO_ERROR) {
442 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700443 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700444 }
445 result = data.writeStrongBinder(display);
446 if (result != NO_ERROR) {
447 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700448 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700449 }
450 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
451 if (result != NO_ERROR) {
452 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700453 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700454 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700455 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700456 }
457
458 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700459 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700460 Parcel data, reply;
461 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
462 if (result != NO_ERROR) {
463 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
464 return result;
465 }
466 result = data.writeStrongBinder(display);
467 if (result != NO_ERROR) {
468 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
469 return result;
470 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700471 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700472 if (result != NO_ERROR) {
473 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
474 return result;
475 }
476 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
477 if (result != NO_ERROR) {
478 ALOGE("setActiveColorMode failed to transact: %d", result);
479 return result;
480 }
481 return static_cast<status_t>(reply.readInt32());
482 }
483
Galia Peycheva5492cb52019-10-30 14:13:16 +0100484 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
485 bool* outSupport) const {
486 Parcel data, reply;
487 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
488 status_t result = data.writeStrongBinder(display);
489 if (result != NO_ERROR) {
490 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
491 return result;
492 }
493 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
494 &reply);
495 if (result != NO_ERROR) {
496 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
497 return result;
498 }
499 return reply.readBool(outSupport);
500 }
501
502 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
503 Parcel data, reply;
504 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
505 if (result != NO_ERROR) {
506 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
507 return;
508 }
509
510 result = data.writeStrongBinder(display);
511 if (result != NO_ERROR) {
512 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
513 return;
514 }
515 result = data.writeBool(on);
516 if (result != NO_ERROR) {
517 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
518 return;
519 }
520 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
521 if (result != NO_ERROR) {
522 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
523 return;
524 }
525 }
526
527 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
528 Parcel data, reply;
529 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
530 status_t result = data.writeStrongBinder(display);
531 if (result != NO_ERROR) {
532 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
533 return result;
534 }
535 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
536 if (result != NO_ERROR) {
537 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
538 return result;
539 }
540 return reply.readBool(outSupport);
541 }
542
543 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
544 Parcel data, reply;
545 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
546 if (result != NO_ERROR) {
547 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
548 return;
549 }
550 result = data.writeStrongBinder(display);
551 if (result != NO_ERROR) {
552 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
553 return;
554 }
555 result = data.writeBool(on);
556 if (result != NO_ERROR) {
557 ALOGE("setGameContentType failed to writeBool: %d", result);
558 return;
559 }
560 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
561 if (result != NO_ERROR) {
562 ALOGE("setGameContentType failed to transact: %d", result);
563 }
564 }
565
Svetoslavd85084b2014-03-20 10:28:31 -0700566 virtual status_t clearAnimationFrameStats() {
567 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700568 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
569 if (result != NO_ERROR) {
570 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
571 return result;
572 }
573 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
574 if (result != NO_ERROR) {
575 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
576 return result;
577 }
Svetoslavd85084b2014-03-20 10:28:31 -0700578 return reply.readInt32();
579 }
580
581 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
582 Parcel data, reply;
583 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
584 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
585 reply.read(*outStats);
586 return reply.readInt32();
587 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700588
589 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
590 HdrCapabilities* outCapabilities) const {
591 Parcel data, reply;
592 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
593 status_t result = data.writeStrongBinder(display);
594 if (result != NO_ERROR) {
595 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
596 return result;
597 }
598 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
599 data, &reply);
600 if (result != NO_ERROR) {
601 ALOGE("getHdrCapabilities failed to transact: %d", result);
602 return result;
603 }
604 result = reply.readInt32();
605 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800606 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700607 }
608 return result;
609 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700610
611 virtual status_t enableVSyncInjections(bool enable) {
612 Parcel data, reply;
613 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
614 if (result != NO_ERROR) {
615 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
616 return result;
617 }
618 result = data.writeBool(enable);
619 if (result != NO_ERROR) {
620 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
621 return result;
622 }
Steven Moreland366eb422019-04-01 19:22:32 -0700623 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
624 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700625 if (result != NO_ERROR) {
626 ALOGE("enableVSyncInjections failed to transact: %d", result);
627 return result;
628 }
629 return result;
630 }
631
632 virtual status_t injectVSync(nsecs_t when) {
633 Parcel data, reply;
634 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
635 if (result != NO_ERROR) {
636 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
637 return result;
638 }
639 result = data.writeInt64(when);
640 if (result != NO_ERROR) {
641 ALOGE("injectVSync failed to writeInt64: %d", result);
642 return result;
643 }
Steven Moreland366eb422019-04-01 19:22:32 -0700644 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
645 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700646 if (result != NO_ERROR) {
647 ALOGE("injectVSync failed to transact: %d", result);
648 return result;
649 }
650 return result;
651 }
652
Vishnu Nair43bccf82020-06-05 10:53:37 -0700653 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800654 if (!outLayers) {
655 return UNEXPECTED_NULL;
656 }
657
658 Parcel data, reply;
659
660 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
661 if (err != NO_ERROR) {
662 return err;
663 }
664
665 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
666 if (err != NO_ERROR) {
667 return err;
668 }
669
670 int32_t result = 0;
671 err = reply.readInt32(&result);
672 if (err != NO_ERROR) {
673 return err;
674 }
675 if (result != NO_ERROR) {
676 return result;
677 }
678
679 outLayers->clear();
680 return reply.readParcelableVector(outLayers);
681 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700682
Peiyong Linc6780972018-10-28 15:24:08 -0700683 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
684 ui::PixelFormat* defaultPixelFormat,
685 ui::Dataspace* wideColorGamutDataspace,
686 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700687 Parcel data, reply;
688 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
689 if (error != NO_ERROR) {
690 return error;
691 }
692 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
693 if (error != NO_ERROR) {
694 return error;
695 }
696 error = static_cast<status_t>(reply.readInt32());
697 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700698 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
699 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
700 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
701 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700702 }
703 return error;
704 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700705
Ady Abraham37965d42018-11-01 13:43:32 -0700706 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700707 Parcel data, reply;
708 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700709 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
710 bool result;
711 status_t err = reply.readBool(&result);
712 if (err == NO_ERROR) {
713 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700714 }
Ady Abraham37965d42018-11-01 13:43:32 -0700715 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700716 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700717
718 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
719 ui::PixelFormat* outFormat,
720 ui::Dataspace* outDataspace,
721 uint8_t* outComponentMask) const {
722 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
723 Parcel data, reply;
724 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
725 data.writeStrongBinder(display);
726
727 status_t error =
728 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
729 data, &reply);
730 if (error != NO_ERROR) {
731 return error;
732 }
733
734 uint32_t value = 0;
735 error = reply.readUint32(&value);
736 if (error != NO_ERROR) {
737 return error;
738 }
739 *outFormat = static_cast<ui::PixelFormat>(value);
740
741 error = reply.readUint32(&value);
742 if (error != NO_ERROR) {
743 return error;
744 }
745 *outDataspace = static_cast<ui::Dataspace>(value);
746
747 error = reply.readUint32(&value);
748 if (error != NO_ERROR) {
749 return error;
750 }
751 *outComponentMask = static_cast<uint8_t>(value);
752 return error;
753 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800754
755 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700756 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800757 Parcel data, reply;
758 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
759 data.writeStrongBinder(display);
760 data.writeBool(enable);
761 data.writeByte(static_cast<int8_t>(componentMask));
762 data.writeUint64(maxFrames);
763 status_t result =
764 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
765 &reply);
766 return result;
767 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700768
769 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
770 uint64_t timestamp,
771 DisplayedFrameStats* outStats) const {
772 if (!outStats) return BAD_VALUE;
773
774 Parcel data, reply;
775 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
776 data.writeStrongBinder(display);
777 data.writeUint64(maxFrames);
778 data.writeUint64(timestamp);
779
780 status_t result =
781 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
782
783 if (result != NO_ERROR) {
784 return result;
785 }
786
787 result = reply.readUint64(&outStats->numFrames);
788 if (result != NO_ERROR) {
789 return result;
790 }
791
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800792 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700793 if (result != NO_ERROR) {
794 return result;
795 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800796 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700797 if (result != NO_ERROR) {
798 return result;
799 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800800 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700801 if (result != NO_ERROR) {
802 return result;
803 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800804 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700805 return result;
806 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800807
808 virtual status_t getProtectedContentSupport(bool* outSupported) const {
809 Parcel data, reply;
810 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800811 status_t error =
812 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
813 if (error != NO_ERROR) {
814 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800815 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800816 error = reply.readBool(outSupported);
817 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800818 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800819
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800820 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
821 bool* outIsWideColorDisplay) const {
822 Parcel data, reply;
823 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
824 if (error != NO_ERROR) {
825 return error;
826 }
827 error = data.writeStrongBinder(token);
828 if (error != NO_ERROR) {
829 return error;
830 }
831
832 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
833 if (error != NO_ERROR) {
834 return error;
835 }
836 error = reply.readBool(outIsWideColorDisplay);
837 return error;
838 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800839
840 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
841 const sp<IBinder>& stopLayerHandle,
842 const sp<IRegionSamplingListener>& listener) {
843 Parcel data, reply;
844 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
845 if (error != NO_ERROR) {
846 ALOGE("addRegionSamplingListener: Failed to write interface token");
847 return error;
848 }
849 error = data.write(samplingArea);
850 if (error != NO_ERROR) {
851 ALOGE("addRegionSamplingListener: Failed to write sampling area");
852 return error;
853 }
854 error = data.writeStrongBinder(stopLayerHandle);
855 if (error != NO_ERROR) {
856 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
857 return error;
858 }
859 error = data.writeStrongBinder(IInterface::asBinder(listener));
860 if (error != NO_ERROR) {
861 ALOGE("addRegionSamplingListener: Failed to write listener");
862 return error;
863 }
864 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
865 if (error != NO_ERROR) {
866 ALOGE("addRegionSamplingListener: Failed to transact");
867 }
868 return error;
869 }
870
871 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
872 Parcel data, reply;
873 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
874 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800875 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800876 return error;
877 }
878 error = data.writeStrongBinder(IInterface::asBinder(listener));
879 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800880 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800881 return error;
882 }
883 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
884 &reply);
885 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800886 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800887 }
888 return error;
889 }
Ady Abraham838de062019-02-04 10:24:03 -0800890
Ana Krulec0782b882019-10-15 17:34:54 -0700891 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200892 int32_t defaultConfig, bool allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -0700893 float primaryRefreshRateMin,
894 float primaryRefreshRateMax,
895 float appRequestRefreshRateMin,
896 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700897 Parcel data, reply;
898 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
899 if (result != NO_ERROR) {
900 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
901 return result;
902 }
903 result = data.writeStrongBinder(displayToken);
904 if (result != NO_ERROR) {
905 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
906 return result;
907 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100908 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700909 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100910 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700911 return result;
912 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200913 result = data.writeBool(allowGroupSwitching);
914 if (result != NO_ERROR) {
915 ALOGE("setDesiredDisplayConfigSpecs failed to write allowGroupSwitching: %d", result);
916 return result;
917 }
Steven Thomasf734df42020-04-13 21:09:28 -0700918 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700919 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700920 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700921 return result;
922 }
Steven Thomasf734df42020-04-13 21:09:28 -0700923 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700924 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700925 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
926 return result;
927 }
928 result = data.writeFloat(appRequestRefreshRateMin);
929 if (result != NO_ERROR) {
930 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
931 result);
932 return result;
933 }
934 result = data.writeFloat(appRequestRefreshRateMax);
935 if (result != NO_ERROR) {
936 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
937 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700938 return result;
939 }
940
941 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
942 &reply);
943 if (result != NO_ERROR) {
944 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
945 return result;
946 }
947 return reply.readInt32();
948 }
949
Ana Krulec234bb162019-11-10 22:55:55 +0100950 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100951 int32_t* outDefaultConfig,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200952 bool* outAllowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -0700953 float* outPrimaryRefreshRateMin,
954 float* outPrimaryRefreshRateMax,
955 float* outAppRequestRefreshRateMin,
956 float* outAppRequestRefreshRateMax) {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200957 if (!outDefaultConfig || !outAllowGroupSwitching || !outPrimaryRefreshRateMin ||
958 !outPrimaryRefreshRateMax || !outAppRequestRefreshRateMin ||
959 !outAppRequestRefreshRateMax) {
Steven Thomasf734df42020-04-13 21:09:28 -0700960 return BAD_VALUE;
961 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800962 Parcel data, reply;
963 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
964 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100965 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800966 return result;
967 }
968 result = data.writeStrongBinder(displayToken);
969 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100970 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800971 return result;
972 }
Ana Krulec234bb162019-11-10 22:55:55 +0100973 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
974 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800975 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100976 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800977 return result;
978 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100979 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800980 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100981 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100982 return result;
983 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200984 result = reply.readBool(outAllowGroupSwitching);
985 if (result != NO_ERROR) {
986 ALOGE("getDesiredDisplayConfigSpecs failed to read allowGroupSwitching: %d", result);
987 return result;
988 }
Steven Thomasf734df42020-04-13 21:09:28 -0700989 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +0100990 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700991 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100992 return result;
993 }
Steven Thomasf734df42020-04-13 21:09:28 -0700994 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +0100995 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700996 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
997 return result;
998 }
999 result = reply.readFloat(outAppRequestRefreshRateMin);
1000 if (result != NO_ERROR) {
1001 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
1002 result);
1003 return result;
1004 }
1005 result = reply.readFloat(outAppRequestRefreshRateMax);
1006 if (result != NO_ERROR) {
1007 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
1008 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001009 return result;
1010 }
1011 return reply.readInt32();
1012 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001013
1014 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1015 bool* outSupport) const {
1016 Parcel data, reply;
1017 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1018 if (error != NO_ERROR) {
1019 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1020 return error;
1021 }
1022 error = data.writeStrongBinder(displayToken);
1023 if (error != NO_ERROR) {
1024 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1025 return error;
1026 }
1027 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1028 if (error != NO_ERROR) {
1029 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1030 return error;
1031 }
1032 bool support;
1033 error = reply.readBool(&support);
1034 if (error != NO_ERROR) {
1035 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1036 return error;
1037 }
1038 *outSupport = support;
1039 return NO_ERROR;
1040 }
1041
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001042 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001043 Parcel data, reply;
1044 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1045 if (error != NO_ERROR) {
1046 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1047 return error;
1048 }
1049 error = data.writeStrongBinder(displayToken);
1050 if (error != NO_ERROR) {
1051 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1052 return error;
1053 }
1054 error = data.writeFloat(brightness);
1055 if (error != NO_ERROR) {
1056 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1057 return error;
1058 }
1059 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1060 if (error != NO_ERROR) {
1061 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1062 return error;
1063 }
1064 return NO_ERROR;
1065 }
Ady Abraham8532d012019-05-08 14:50:56 -07001066
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001067 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001068 Parcel data, reply;
1069 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1070 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001071 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001072 return error;
1073 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001074 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001075 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001076 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001077 return error;
1078 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001079 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001080 IBinder::FLAG_ONEWAY);
1081 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001082 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001083 return error;
1084 }
1085 return NO_ERROR;
1086 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001087
1088 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1089 float lightPosY, float lightPosZ, float lightRadius) {
1090 Parcel data, reply;
1091 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1092 if (error != NO_ERROR) {
1093 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1094 return error;
1095 }
1096
1097 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1098 ambientColor.a, spotColor.r, spotColor.g,
1099 spotColor.b, spotColor.a, lightPosY,
1100 lightPosZ, lightRadius};
1101
1102 error = data.writeFloatVector(shadowConfig);
1103 if (error != NO_ERROR) {
1104 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1105 return error;
1106 }
1107
1108 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1109 IBinder::FLAG_ONEWAY);
1110 if (error != NO_ERROR) {
1111 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1112 return error;
1113 }
1114 return NO_ERROR;
1115 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001116
1117 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
Marin Shalamanov46084422020-10-13 12:33:42 +02001118 int8_t compatibility, bool shouldBeSeamless) {
Steven Thomas62a4cf82020-01-31 12:04:03 -08001119 Parcel data, reply;
1120 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1121 if (err != NO_ERROR) {
1122 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1123 return err;
1124 }
1125
1126 err = data.writeStrongBinder(IInterface::asBinder(surface));
1127 if (err != NO_ERROR) {
1128 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1129 return err;
1130 }
1131
1132 err = data.writeFloat(frameRate);
1133 if (err != NO_ERROR) {
1134 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1135 return err;
1136 }
1137
1138 err = data.writeByte(compatibility);
1139 if (err != NO_ERROR) {
1140 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1141 return err;
1142 }
1143
Marin Shalamanov46084422020-10-13 12:33:42 +02001144 err = data.writeBool(shouldBeSeamless);
1145 if (err != NO_ERROR) {
1146 ALOGE("setFrameRate: failed writing bool: %s (%d)", strerror(-err), -err);
1147 return err;
1148 }
1149
Ady Abraham60e42ea2020-03-09 19:17:31 -07001150 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001151 if (err != NO_ERROR) {
1152 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1153 return err;
1154 }
Steven Thomasd4071902020-03-24 16:02:53 -07001155
1156 return reply.readInt32();
1157 }
1158
1159 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1160 if (!outToken) return BAD_VALUE;
1161
1162 Parcel data, reply;
1163 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1164 if (err != NO_ERROR) {
1165 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1166 strerror(-err), -err);
1167 return err;
1168 }
1169
1170 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1171 &reply);
1172 if (err != NO_ERROR) {
1173 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1174 err);
1175 return err;
1176 }
1177
1178 err = reply.readInt32();
1179 if (err != NO_ERROR) {
1180 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1181 return err;
1182 }
1183
1184 err = reply.readStrongBinder(outToken);
1185 if (err != NO_ERROR) {
1186 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1187 strerror(-err), err);
1188 return err;
1189 }
1190
Steven Thomas62a4cf82020-01-31 12:04:03 -08001191 return NO_ERROR;
1192 }
Ady Abraham74e17562020-08-24 18:18:19 -07001193
1194 virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
1195 int64_t frameTimelineVsyncId) {
1196 Parcel data, reply;
1197 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1198 if (err != NO_ERROR) {
1199 ALOGE("setFrameTimelineVsync: failed writing interface token: %s (%d)", strerror(-err),
1200 -err);
1201 return err;
1202 }
1203
1204 err = data.writeStrongBinder(IInterface::asBinder(surface));
1205 if (err != NO_ERROR) {
1206 ALOGE("setFrameTimelineVsync: failed writing strong binder: %s (%d)", strerror(-err),
1207 -err);
1208 return err;
1209 }
1210
1211 err = data.writeInt64(frameTimelineVsyncId);
1212 if (err != NO_ERROR) {
1213 ALOGE("setFrameTimelineVsync: failed writing int64_t: %s (%d)", strerror(-err), -err);
1214 return err;
1215 }
1216
1217 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_VSYNC, data, &reply);
1218 if (err != NO_ERROR) {
1219 ALOGE("setFrameTimelineVsync: failed to transact: %s (%d)", strerror(-err), err);
1220 return err;
1221 }
1222
1223 return reply.readInt32();
1224 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00001225
1226 virtual status_t addTransactionTraceListener(
1227 const sp<gui::ITransactionTraceListener>& listener) {
1228 Parcel data, reply;
1229 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
1230 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
1231
1232 return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply);
1233 }
Ana Krulec31f2b3c2020-12-14 14:30:09 -08001234
1235 /**
1236 * Get priority of the RenderEngine in surface flinger.
1237 */
1238 virtual int getGPUContextPriority() {
1239 Parcel data, reply;
1240 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1241 status_t err =
1242 remote()->transact(BnSurfaceComposer::GET_GPU_CONTEXT_PRIORITY, data, &reply);
1243 if (err != NO_ERROR) {
1244 ALOGE("getGPUContextPriority failed to read data: %s (%d)", strerror(-err), err);
1245 return 0;
1246 }
1247 return reply.readInt32();
1248 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001249};
1250
Dan Stozad723bd72014-11-18 10:24:03 -08001251// Out-of-line virtual method definition to trigger vtable emission in this
1252// translation unit (see clang warning -Wweak-vtables)
1253BpSurfaceComposer::~BpSurfaceComposer() {}
1254
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001255IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1256
1257// ----------------------------------------------------------------------
1258
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001259status_t BnSurfaceComposer::onTransact(
1260 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1261{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001262 switch(code) {
1263 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001264 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001265 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001266 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001267 return NO_ERROR;
1268 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001269 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001270 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001271
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001272 int64_t frameTimelineVsyncId;
1273 SAFE_PARCEL(data.readInt64, &frameTimelineVsyncId);
chaviw308ddba2020-08-11 16:23:51 -07001274 uint32_t count = 0;
1275 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001276 Vector<ComposerState> state;
1277 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001278 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001279 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001280 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001281 state.add(s);
1282 }
Dan Stozad723bd72014-11-18 10:24:03 -08001283
chaviw308ddba2020-08-11 16:23:51 -07001284 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001285 DisplayState d;
1286 Vector<DisplayState> displays;
1287 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001288 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001289 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001290 displays.add(d);
1291 }
Dan Stozad723bd72014-11-18 10:24:03 -08001292
chaviw308ddba2020-08-11 16:23:51 -07001293 uint32_t stateFlags = 0;
1294 SAFE_PARCEL(data.readUint32, &stateFlags);
1295 sp<IBinder> applyToken;
1296 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001297 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001298 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001299
chaviw308ddba2020-08-11 16:23:51 -07001300 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -08001301 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -07001302 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -08001303 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -07001304
Marissa Wall947d34e2019-03-29 14:03:53 -07001305 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001306 sp<IBinder> tmpBinder;
1307 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1308 uncachedBuffer.token = tmpBinder;
1309 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001310
chaviw308ddba2020-08-11 16:23:51 -07001311 bool hasListenerCallbacks = false;
1312 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001313
Marissa Wall3dad52d2019-03-22 14:03:19 -07001314 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001315 int32_t listenersSize = 0;
1316 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001317 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001318 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001319 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001320 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1321 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001322 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +00001323
1324 uint64_t transactionId = -1;
1325 SAFE_PARCEL(data.readUint64, &transactionId);
1326
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001327 return setTransactionState(frameTimelineVsyncId, state, displays, stateFlags,
1328 applyToken, inputWindowCommands, desiredPresentTime,
Ady Abrahamf0c56492020-12-17 18:04:15 -08001329 isAutoTimestamp, uncachedBuffer, hasListenerCallbacks,
1330 listenerCallbacks, transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -07001331 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001332 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001333 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001334 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001335 return NO_ERROR;
1336 }
chaviwd2432892020-07-24 17:42:39 -07001337 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001338 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001339 DisplayCaptureArgs 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 captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001345 }
chaviwd2432892020-07-24 17:42:39 -07001346 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001347 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001348 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001349 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001350 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001351 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1352
1353 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001354 }
chaviwa76b2712017-09-20 12:02:26 -07001355 case CAPTURE_LAYERS: {
1356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001357 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001358 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001359 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001360 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1361
1362 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001363 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001364 case AUTHENTICATE_SURFACE: {
1365 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001366 sp<IGraphicBufferProducer> bufferProducer =
1367 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1368 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001369 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001370 return NO_ERROR;
1371 }
Brian Anderson6b376712017-04-04 10:51:39 -07001372 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1373 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1374 std::vector<FrameEvent> supportedTimestamps;
1375 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1376 status_t err = reply->writeInt32(result);
1377 if (err != NO_ERROR) {
1378 return err;
1379 }
1380 if (result != NO_ERROR) {
1381 return result;
1382 }
1383
1384 std::vector<int32_t> supported;
1385 supported.reserve(supportedTimestamps.size());
1386 for (FrameEvent s : supportedTimestamps) {
1387 supported.push_back(static_cast<int32_t>(s));
1388 }
1389 return reply->writeInt32Vector(supported);
1390 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001391 case CREATE_DISPLAY_EVENT_CONNECTION: {
1392 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001393 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
Ady Abraham62f216c2020-10-13 19:07:23 -07001394 EventRegistrationFlags eventRegistration =
1395 static_cast<EventRegistration>(data.readUint32());
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001396
1397 sp<IDisplayEventConnection> connection(
Ady Abraham62f216c2020-10-13 19:07:23 -07001398 createDisplayEventConnection(vsyncSource, eventRegistration));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001399 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001400 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001401 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001402 case CREATE_DISPLAY: {
1403 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001404 String8 displayName;
1405 SAFE_PARCEL(data.readString8, &displayName);
1406 bool secure = false;
1407 SAFE_PARCEL(data.readBool, &secure);
1408 sp<IBinder> display = createDisplay(displayName, secure);
1409 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001410 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001411 }
1412 case DESTROY_DISPLAY: {
1413 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1414 sp<IBinder> display = data.readStrongBinder();
1415 destroyDisplay(display);
1416 return NO_ERROR;
1417 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001418 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001419 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001420 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001421 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001422 reply->writeStrongBinder(display);
1423 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001424 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001425 case GET_DISPLAY_STATE: {
1426 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1427 ui::DisplayState state;
1428 const sp<IBinder> display = data.readStrongBinder();
1429 const status_t result = getDisplayState(display, &state);
1430 reply->writeInt32(result);
1431 if (result == NO_ERROR) {
1432 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1433 sizeof(ui::DisplayState));
1434 }
1435 return NO_ERROR;
1436 }
1437 case GET_DISPLAY_INFO: {
1438 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1439 DisplayInfo info;
1440 const sp<IBinder> display = data.readStrongBinder();
1441 const status_t result = getDisplayInfo(display, &info);
1442 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001443 if (result != NO_ERROR) return result;
1444 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001445 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001446 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001447 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001448 Vector<DisplayConfig> configs;
1449 const sp<IBinder> display = data.readStrongBinder();
1450 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001451 reply->writeInt32(result);
1452 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001453 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001454 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001455 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1456 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001457 }
1458 }
1459 return NO_ERROR;
1460 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001461 case GET_DISPLAY_STATS: {
1462 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1463 DisplayStatInfo stats;
1464 sp<IBinder> display = data.readStrongBinder();
1465 status_t result = getDisplayStats(display, &stats);
1466 reply->writeInt32(result);
1467 if (result == NO_ERROR) {
1468 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1469 &stats, sizeof(DisplayStatInfo));
1470 }
1471 return NO_ERROR;
1472 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001473 case GET_ACTIVE_CONFIG: {
1474 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1475 sp<IBinder> display = data.readStrongBinder();
1476 int id = getActiveConfig(display);
1477 reply->writeInt32(id);
1478 return NO_ERROR;
1479 }
Michael Wright28f24d02016-07-12 13:30:53 -07001480 case GET_DISPLAY_COLOR_MODES: {
1481 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001482 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001483 sp<IBinder> display = nullptr;
1484 status_t result = data.readStrongBinder(&display);
1485 if (result != NO_ERROR) {
1486 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1487 return result;
1488 }
1489 result = getDisplayColorModes(display, &colorModes);
1490 reply->writeInt32(result);
1491 if (result == NO_ERROR) {
1492 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1493 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001494 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001495 }
1496 }
1497 return NO_ERROR;
1498 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001499 case GET_DISPLAY_NATIVE_PRIMARIES: {
1500 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1501 ui::DisplayPrimaries primaries;
1502 sp<IBinder> display = nullptr;
1503
1504 status_t result = data.readStrongBinder(&display);
1505 if (result != NO_ERROR) {
1506 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1507 return result;
1508 }
1509
1510 result = getDisplayNativePrimaries(display, primaries);
1511 reply->writeInt32(result);
1512 if (result == NO_ERROR) {
1513 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1514 sizeof(ui::DisplayPrimaries));
1515 }
1516
1517 return NO_ERROR;
1518 }
Michael Wright28f24d02016-07-12 13:30:53 -07001519 case GET_ACTIVE_COLOR_MODE: {
1520 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1521 sp<IBinder> display = nullptr;
1522 status_t result = data.readStrongBinder(&display);
1523 if (result != NO_ERROR) {
1524 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1525 return result;
1526 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001527 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001528 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1529 return result;
1530 }
1531 case SET_ACTIVE_COLOR_MODE: {
1532 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1533 sp<IBinder> display = nullptr;
1534 status_t result = data.readStrongBinder(&display);
1535 if (result != NO_ERROR) {
1536 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1537 return result;
1538 }
1539 int32_t colorModeInt = 0;
1540 result = data.readInt32(&colorModeInt);
1541 if (result != NO_ERROR) {
1542 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1543 return result;
1544 }
1545 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001546 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001547 result = reply->writeInt32(result);
1548 return result;
1549 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001550
1551 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1552 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1553 sp<IBinder> display = nullptr;
1554 status_t result = data.readStrongBinder(&display);
1555 if (result != NO_ERROR) {
1556 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1557 return result;
1558 }
1559 bool supported = false;
1560 result = getAutoLowLatencyModeSupport(display, &supported);
1561 if (result == NO_ERROR) {
1562 result = reply->writeBool(supported);
1563 }
1564 return result;
1565 }
1566
1567 case SET_AUTO_LOW_LATENCY_MODE: {
1568 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1569 sp<IBinder> display = nullptr;
1570 status_t result = data.readStrongBinder(&display);
1571 if (result != NO_ERROR) {
1572 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1573 return result;
1574 }
1575 bool setAllm = false;
1576 result = data.readBool(&setAllm);
1577 if (result != NO_ERROR) {
1578 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1579 return result;
1580 }
1581 setAutoLowLatencyMode(display, setAllm);
1582 return result;
1583 }
1584
1585 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1586 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1587 sp<IBinder> display = nullptr;
1588 status_t result = data.readStrongBinder(&display);
1589 if (result != NO_ERROR) {
1590 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1591 return result;
1592 }
1593 bool supported = false;
1594 result = getGameContentTypeSupport(display, &supported);
1595 if (result == NO_ERROR) {
1596 result = reply->writeBool(supported);
1597 }
1598 return result;
1599 }
1600
1601 case SET_GAME_CONTENT_TYPE: {
1602 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1603 sp<IBinder> display = nullptr;
1604 status_t result = data.readStrongBinder(&display);
1605 if (result != NO_ERROR) {
1606 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1607 return result;
1608 }
1609 bool setGameContentTypeOn = false;
1610 result = data.readBool(&setGameContentTypeOn);
1611 if (result != NO_ERROR) {
1612 ALOGE("setGameContentType failed to readBool: %d", result);
1613 return result;
1614 }
1615 setGameContentType(display, setGameContentTypeOn);
1616 return result;
1617 }
1618
Svetoslavd85084b2014-03-20 10:28:31 -07001619 case CLEAR_ANIMATION_FRAME_STATS: {
1620 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1621 status_t result = clearAnimationFrameStats();
1622 reply->writeInt32(result);
1623 return NO_ERROR;
1624 }
1625 case GET_ANIMATION_FRAME_STATS: {
1626 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1627 FrameStats stats;
1628 status_t result = getAnimationFrameStats(&stats);
1629 reply->write(stats);
1630 reply->writeInt32(result);
1631 return NO_ERROR;
1632 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001633 case SET_POWER_MODE: {
1634 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1635 sp<IBinder> display = data.readStrongBinder();
1636 int32_t mode = data.readInt32();
1637 setPowerMode(display, mode);
1638 return NO_ERROR;
1639 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001640 case GET_HDR_CAPABILITIES: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1642 sp<IBinder> display = nullptr;
1643 status_t result = data.readStrongBinder(&display);
1644 if (result != NO_ERROR) {
1645 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1646 result);
1647 return result;
1648 }
1649 HdrCapabilities capabilities;
1650 result = getHdrCapabilities(display, &capabilities);
1651 reply->writeInt32(result);
1652 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001653 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001654 }
1655 return NO_ERROR;
1656 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001657 case ENABLE_VSYNC_INJECTIONS: {
1658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1659 bool enable = false;
1660 status_t result = data.readBool(&enable);
1661 if (result != NO_ERROR) {
1662 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1663 return result;
1664 }
1665 return enableVSyncInjections(enable);
1666 }
1667 case INJECT_VSYNC: {
1668 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1669 int64_t when = 0;
1670 status_t result = data.readInt64(&when);
1671 if (result != NO_ERROR) {
1672 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1673 return result;
1674 }
1675 return injectVSync(when);
1676 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001677 case GET_LAYER_DEBUG_INFO: {
1678 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1679 std::vector<LayerDebugInfo> outLayers;
1680 status_t result = getLayerDebugInfo(&outLayers);
1681 reply->writeInt32(result);
1682 if (result == NO_ERROR)
1683 {
1684 result = reply->writeParcelableVector(outLayers);
1685 }
1686 return result;
1687 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001688 case GET_COMPOSITION_PREFERENCE: {
1689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001690 ui::Dataspace defaultDataspace;
1691 ui::PixelFormat defaultPixelFormat;
1692 ui::Dataspace wideColorGamutDataspace;
1693 ui::PixelFormat wideColorGamutPixelFormat;
1694 status_t error =
1695 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1696 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001697 reply->writeInt32(error);
1698 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001699 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1700 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1701 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001702 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001703 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001704 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001705 }
Ady Abraham37965d42018-11-01 13:43:32 -07001706 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001707 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001708 bool result;
1709 status_t error = getColorManagement(&result);
1710 if (error == NO_ERROR) {
1711 reply->writeBool(result);
1712 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001713 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001714 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001715 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1716 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1717
1718 sp<IBinder> display = data.readStrongBinder();
1719 ui::PixelFormat format;
1720 ui::Dataspace dataspace;
1721 uint8_t component = 0;
1722 auto result =
1723 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1724 if (result == NO_ERROR) {
1725 reply->writeUint32(static_cast<uint32_t>(format));
1726 reply->writeUint32(static_cast<uint32_t>(dataspace));
1727 reply->writeUint32(static_cast<uint32_t>(component));
1728 }
1729 return result;
1730 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001731 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1732 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1733
1734 sp<IBinder> display = nullptr;
1735 bool enable = false;
1736 int8_t componentMask = 0;
1737 uint64_t maxFrames = 0;
1738 status_t result = data.readStrongBinder(&display);
1739 if (result != NO_ERROR) {
1740 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1741 result);
1742 return result;
1743 }
1744
1745 result = data.readBool(&enable);
1746 if (result != NO_ERROR) {
1747 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1748 return result;
1749 }
1750
1751 result = data.readByte(static_cast<int8_t*>(&componentMask));
1752 if (result != NO_ERROR) {
1753 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1754 result);
1755 return result;
1756 }
1757
1758 result = data.readUint64(&maxFrames);
1759 if (result != NO_ERROR) {
1760 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1761 return result;
1762 }
1763
1764 return setDisplayContentSamplingEnabled(display, enable,
1765 static_cast<uint8_t>(componentMask), maxFrames);
1766 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001767 case GET_DISPLAYED_CONTENT_SAMPLE: {
1768 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1769
1770 sp<IBinder> display = data.readStrongBinder();
1771 uint64_t maxFrames = 0;
1772 uint64_t timestamp = 0;
1773
1774 status_t result = data.readUint64(&maxFrames);
1775 if (result != NO_ERROR) {
1776 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1777 return result;
1778 }
1779
1780 result = data.readUint64(&timestamp);
1781 if (result != NO_ERROR) {
1782 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1783 return result;
1784 }
1785
1786 DisplayedFrameStats stats;
1787 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1788 if (result == NO_ERROR) {
1789 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001790 reply->writeUint64Vector(stats.component_0_sample);
1791 reply->writeUint64Vector(stats.component_1_sample);
1792 reply->writeUint64Vector(stats.component_2_sample);
1793 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001794 }
1795 return result;
1796 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001797 case GET_PROTECTED_CONTENT_SUPPORT: {
1798 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1799 bool result;
1800 status_t error = getProtectedContentSupport(&result);
1801 if (error == NO_ERROR) {
1802 reply->writeBool(result);
1803 }
1804 return error;
1805 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001806 case IS_WIDE_COLOR_DISPLAY: {
1807 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1808 sp<IBinder> display = nullptr;
1809 status_t error = data.readStrongBinder(&display);
1810 if (error != NO_ERROR) {
1811 return error;
1812 }
1813 bool result;
1814 error = isWideColorDisplay(display, &result);
1815 if (error == NO_ERROR) {
1816 reply->writeBool(result);
1817 }
1818 return error;
1819 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001820 case GET_PHYSICAL_DISPLAY_IDS: {
1821 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001822 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1823 std::vector<uint64_t> rawIds(ids.size());
1824 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1825 [](PhysicalDisplayId id) { return id.value; });
1826 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001827 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001828 case ADD_REGION_SAMPLING_LISTENER: {
1829 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1830 Rect samplingArea;
1831 status_t result = data.read(samplingArea);
1832 if (result != NO_ERROR) {
1833 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1834 return result;
1835 }
1836 sp<IBinder> stopLayerHandle;
1837 result = data.readNullableStrongBinder(&stopLayerHandle);
1838 if (result != NO_ERROR) {
1839 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1840 return result;
1841 }
1842 sp<IRegionSamplingListener> listener;
1843 result = data.readNullableStrongBinder(&listener);
1844 if (result != NO_ERROR) {
1845 ALOGE("addRegionSamplingListener: Failed to read listener");
1846 return result;
1847 }
1848 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1849 }
1850 case REMOVE_REGION_SAMPLING_LISTENER: {
1851 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1852 sp<IRegionSamplingListener> listener;
1853 status_t result = data.readNullableStrongBinder(&listener);
1854 if (result != NO_ERROR) {
1855 ALOGE("removeRegionSamplingListener: Failed to read listener");
1856 return result;
1857 }
1858 return removeRegionSamplingListener(listener);
1859 }
Ana Krulec0782b882019-10-15 17:34:54 -07001860 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1861 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1862 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001863 int32_t defaultConfig;
1864 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001865 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001866 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001867 return result;
1868 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001869 bool allowGroupSwitching;
1870 result = data.readBool(&allowGroupSwitching);
1871 if (result != NO_ERROR) {
1872 ALOGE("setDesiredDisplayConfigSpecs: failed to read allowGroupSwitching: %d",
1873 result);
1874 return result;
1875 }
Steven Thomasf734df42020-04-13 21:09:28 -07001876 float primaryRefreshRateMin;
1877 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001878 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001879 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1880 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001881 return result;
1882 }
Steven Thomasf734df42020-04-13 21:09:28 -07001883 float primaryRefreshRateMax;
1884 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001885 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001886 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1887 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001888 return result;
1889 }
Steven Thomasf734df42020-04-13 21:09:28 -07001890 float appRequestRefreshRateMin;
1891 result = data.readFloat(&appRequestRefreshRateMin);
1892 if (result != NO_ERROR) {
1893 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1894 result);
1895 return result;
1896 }
1897 float appRequestRefreshRateMax;
1898 result = data.readFloat(&appRequestRefreshRateMax);
1899 if (result != NO_ERROR) {
1900 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1901 result);
1902 return result;
1903 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001904 result = setDesiredDisplayConfigSpecs(displayToken, defaultConfig, allowGroupSwitching,
1905 primaryRefreshRateMin, primaryRefreshRateMax,
1906 appRequestRefreshRateMin,
1907 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001908 if (result != NO_ERROR) {
1909 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1910 "%d",
1911 result);
1912 return result;
1913 }
1914 reply->writeInt32(result);
1915 return result;
1916 }
Ana Krulec234bb162019-11-10 22:55:55 +01001917 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1918 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1919 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001920 int32_t defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001921 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -07001922 float primaryRefreshRateMin;
1923 float primaryRefreshRateMax;
1924 float appRequestRefreshRateMin;
1925 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001926
Steven Thomasf734df42020-04-13 21:09:28 -07001927 status_t result =
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001928 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig, &allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -07001929 &primaryRefreshRateMin, &primaryRefreshRateMax,
1930 &appRequestRefreshRateMin,
1931 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001932 if (result != NO_ERROR) {
1933 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1934 "%d",
1935 result);
1936 return result;
1937 }
1938
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001939 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001940 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001941 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001942 return result;
1943 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001944 result = reply->writeBool(allowGroupSwitching);
1945 if (result != NO_ERROR) {
1946 ALOGE("getDesiredDisplayConfigSpecs: failed to write allowGroupSwitching: %d",
1947 result);
1948 return result;
1949 }
Steven Thomasf734df42020-04-13 21:09:28 -07001950 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001951 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001952 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1953 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001954 return result;
1955 }
Steven Thomasf734df42020-04-13 21:09:28 -07001956 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001957 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001958 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1959 result);
1960 return result;
1961 }
1962 result = reply->writeFloat(appRequestRefreshRateMin);
1963 if (result != NO_ERROR) {
1964 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1965 result);
1966 return result;
1967 }
1968 result = reply->writeFloat(appRequestRefreshRateMax);
1969 if (result != NO_ERROR) {
1970 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1971 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001972 return result;
1973 }
1974 reply->writeInt32(result);
1975 return result;
1976 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001977 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1978 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1979 sp<IBinder> displayToken;
1980 status_t error = data.readNullableStrongBinder(&displayToken);
1981 if (error != NO_ERROR) {
1982 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1983 return error;
1984 }
1985 bool support = false;
1986 error = getDisplayBrightnessSupport(displayToken, &support);
1987 reply->writeBool(support);
1988 return error;
1989 }
1990 case SET_DISPLAY_BRIGHTNESS: {
1991 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1992 sp<IBinder> displayToken;
1993 status_t error = data.readNullableStrongBinder(&displayToken);
1994 if (error != NO_ERROR) {
1995 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1996 return error;
1997 }
1998 float brightness = -1.0f;
1999 error = data.readFloat(&brightness);
2000 if (error != NO_ERROR) {
2001 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
2002 return error;
2003 }
2004 return setDisplayBrightness(displayToken, brightness);
2005 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01002006 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07002007 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01002008 int32_t boostId;
2009 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07002010 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01002011 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07002012 return error;
2013 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01002014 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07002015 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08002016 case SET_GLOBAL_SHADOW_SETTINGS: {
2017 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2018
2019 std::vector<float> shadowConfig;
2020 status_t error = data.readFloatVector(&shadowConfig);
2021 if (error != NO_ERROR || shadowConfig.size() != 11) {
2022 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
2023 return error;
2024 }
2025
2026 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
2027 shadowConfig[3]};
2028 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
2029 float lightPosY = shadowConfig[8];
2030 float lightPosZ = shadowConfig[9];
2031 float lightRadius = shadowConfig[10];
2032 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
2033 lightRadius);
2034 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08002035 case SET_FRAME_RATE: {
2036 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2037 sp<IBinder> binder;
2038 status_t err = data.readStrongBinder(&binder);
2039 if (err != NO_ERROR) {
2040 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
2041 return err;
2042 }
2043 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2044 if (!surface) {
2045 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
2046 strerror(-err), -err);
2047 return err;
2048 }
2049 float frameRate;
2050 err = data.readFloat(&frameRate);
2051 if (err != NO_ERROR) {
2052 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2053 return err;
2054 }
2055 int8_t compatibility;
2056 err = data.readByte(&compatibility);
2057 if (err != NO_ERROR) {
2058 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2059 return err;
2060 }
Marin Shalamanov46084422020-10-13 12:33:42 +02002061 bool shouldBeSeamless;
2062 err = data.readBool(&shouldBeSeamless);
2063 if (err != NO_ERROR) {
2064 ALOGE("setFrameRate: failed to read bool: %s (%d)", strerror(-err), -err);
2065 return err;
2066 }
2067 status_t result = setFrameRate(surface, frameRate, compatibility, shouldBeSeamless);
Steven Thomas62a4cf82020-01-31 12:04:03 -08002068 reply->writeInt32(result);
2069 return NO_ERROR;
2070 }
Steven Thomasd4071902020-03-24 16:02:53 -07002071 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2072 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2073 sp<IBinder> token;
2074 status_t result = acquireFrameRateFlexibilityToken(&token);
2075 reply->writeInt32(result);
2076 if (result == NO_ERROR) {
2077 reply->writeStrongBinder(token);
2078 }
2079 return NO_ERROR;
2080 }
Ady Abraham74e17562020-08-24 18:18:19 -07002081 case SET_FRAME_TIMELINE_VSYNC: {
2082 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2083 sp<IBinder> binder;
2084 status_t err = data.readStrongBinder(&binder);
2085 if (err != NO_ERROR) {
2086 ALOGE("setFrameTimelineVsync: failed to read strong binder: %s (%d)",
2087 strerror(-err), -err);
2088 return err;
2089 }
2090 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2091 if (!surface) {
2092 ALOGE("setFrameTimelineVsync: failed to cast to IGraphicBufferProducer: %s (%d)",
2093 strerror(-err), -err);
2094 return err;
2095 }
2096 int64_t frameTimelineVsyncId;
2097 err = data.readInt64(&frameTimelineVsyncId);
2098 if (err != NO_ERROR) {
2099 ALOGE("setFrameTimelineVsync: failed to read int64_t: %s (%d)", strerror(-err),
2100 -err);
2101 return err;
2102 }
2103
2104 status_t result = setFrameTimelineVsync(surface, frameTimelineVsyncId);
2105 reply->writeInt32(result);
2106 return NO_ERROR;
2107 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00002108 case ADD_TRANSACTION_TRACE_LISTENER: {
2109 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2110 sp<gui::ITransactionTraceListener> listener;
2111 SAFE_PARCEL(data.readStrongBinder, &listener);
2112
2113 return addTransactionTraceListener(listener);
2114 }
Ana Krulec31f2b3c2020-12-14 14:30:09 -08002115 case GET_GPU_CONTEXT_PRIORITY: {
2116 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2117 int priority = getGPUContextPriority();
2118 SAFE_PARCEL(reply->writeInt32, priority);
2119 return NO_ERROR;
2120 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002121 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002122 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002123 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002124 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002125}
2126
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002127} // namespace android