blob: 7a2f656b763a5f95db28a1f19cbf923c789ae283 [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(
72 const Vector<ComposerState>& state, const Vector<DisplayState>& displays,
73 uint32_t flags, const sp<IBinder>& applyToken, const InputWindowCommands& commands,
74 int64_t desiredPresentTime, const client_cache_t& uncacheBuffer,
75 bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 Parcel data, reply;
77 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080078
chaviw308ddba2020-08-11 16:23:51 -070079 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080080 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
chaviw308ddba2020-08-11 16:23:51 -070084 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080085 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070086 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070087 }
Dan Stozad723bd72014-11-18 10:24:03 -080088
chaviw308ddba2020-08-11 16:23:51 -070089 SAFE_PARCEL(data.writeUint32, flags);
90 SAFE_PARCEL(data.writeStrongBinder, applyToken);
91 SAFE_PARCEL(commands.write, data);
92 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
93 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
94 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
95 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070096
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
98 for (const auto& [listener, callbackIds] : listenerCallbacks) {
99 SAFE_PARCEL(data.writeStrongBinder, listener);
100 SAFE_PARCEL(data.writeInt64Vector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700101 }
102
chaviw308ddba2020-08-11 16:23:51 -0700103 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 }
105
106 virtual void bootFinished()
107 {
108 Parcel data, reply;
109 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
110 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
111 }
112
chaviwd2432892020-07-24 17:42:39 -0700113 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700114 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800115 Parcel data, reply;
116 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700117 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700118 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000119
chaviw8ffc7b82020-08-18 11:25:37 -0700120 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800121 }
122
chaviwd2432892020-07-24 17:42:39 -0700123 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
chaviw8ffc7b82020-08-18 11:25:37 -0700124 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -0700125 Parcel data, reply;
126 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw8ffc7b82020-08-18 11:25:37 -0700127 SAFE_PARCEL(data.writeUint64, displayOrLayerStack);
128 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw93df2ea2019-04-30 16:45:12 -0700129
chaviw8ffc7b82020-08-18 11:25:37 -0700130 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700131 }
132
chaviw3efadb12020-07-27 10:07:15 -0700133 virtual status_t captureLayers(const LayerCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700134 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -0700135 Parcel data, reply;
136 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700137 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700138 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw3efadb12020-07-27 10:07:15 -0700139
chaviw8ffc7b82020-08-18 11:25:37 -0700140 return remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
chaviwa76b2712017-09-20 12:02:26 -0700141 }
142
Jamie Gennis582270d2011-08-17 18:19:00 -0700143 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800144 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800145 {
146 Parcel data, reply;
147 int err = NO_ERROR;
148 err = data.writeInterfaceToken(
149 ISurfaceComposer::getInterfaceDescriptor());
150 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000151 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800152 "interface descriptor: %s (%d)", strerror(-err), -err);
153 return false;
154 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800155 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800156 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000157 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700158 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800159 return false;
160 }
161 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
162 &reply);
163 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000164 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700165 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800166 return false;
167 }
168 int32_t result = 0;
169 err = reply.readInt32(&result);
170 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000171 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700172 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800173 return false;
174 }
175 return result != 0;
176 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800177
Brian Anderson6b376712017-04-04 10:51:39 -0700178 virtual status_t getSupportedFrameTimestamps(
179 std::vector<FrameEvent>* outSupported) const {
180 if (!outSupported) {
181 return UNEXPECTED_NULL;
182 }
183 outSupported->clear();
184
185 Parcel data, reply;
186
187 status_t err = data.writeInterfaceToken(
188 ISurfaceComposer::getInterfaceDescriptor());
189 if (err != NO_ERROR) {
190 return err;
191 }
192
193 err = remote()->transact(
194 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
195 data, &reply);
196 if (err != NO_ERROR) {
197 return err;
198 }
199
200 int32_t result = 0;
201 err = reply.readInt32(&result);
202 if (err != NO_ERROR) {
203 return err;
204 }
205 if (result != NO_ERROR) {
206 return result;
207 }
208
209 std::vector<int32_t> supported;
210 err = reply.readInt32Vector(&supported);
211 if (err != NO_ERROR) {
212 return err;
213 }
214
215 outSupported->reserve(supported.size());
216 for (int32_t s : supported) {
217 outSupported->push_back(static_cast<FrameEvent>(s));
218 }
219 return NO_ERROR;
220 }
221
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700222 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
223 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800224 Parcel data, reply;
225 sp<IDisplayEventConnection> result;
226 int err = data.writeInterfaceToken(
227 ISurfaceComposer::getInterfaceDescriptor());
228 if (err != NO_ERROR) {
229 return result;
230 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700231 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700232 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800233 err = remote()->transact(
234 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
235 data, &reply);
236 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000237 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800238 "transaction: %s (%d)", strerror(-err), -err);
239 return result;
240 }
241 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
242 return result;
243 }
Colin Cross8e533062012-06-07 13:17:52 -0700244
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700245 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700246 {
247 Parcel data, reply;
248 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd4a61642020-09-01 14:53:46 -0700249 status_t status = data.writeString8(displayName);
250 if (status) {
251 return nullptr;
252 }
253 status = data.writeBool(secure);
254 if (status) {
255 return nullptr;
256 }
257
258 status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
259 if (status) {
260 return nullptr;
261 }
262 sp<IBinder> display;
263 status = reply.readNullableStrongBinder(&display);
264 if (status) {
265 return nullptr;
266 }
267 return display;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700268 }
269
Jesse Hall6c913be2013-08-08 12:15:49 -0700270 virtual void destroyDisplay(const sp<IBinder>& display)
271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
274 data.writeStrongBinder(display);
275 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
276 }
277
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800278 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700279 Parcel data, reply;
280 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800281 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
282 NO_ERROR) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200283 std::vector<uint64_t> rawIds;
284 if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
285 std::vector<PhysicalDisplayId> displayIds(rawIds.size());
286 std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
287 [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800288 return displayIds;
289 }
290 }
291
292 return {};
293 }
294
295 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
296 Parcel data, reply;
297 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Marin Shalamanova524a092020-07-27 21:39:55 +0200298 data.writeUint64(displayId.value);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800299 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700300 return reply.readStrongBinder();
301 }
302
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700303 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700304 {
305 Parcel data, reply;
306 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700307 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700308 data.writeInt32(mode);
309 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700310 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700311
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800312 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
313 Parcel data, reply;
314 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
315 data.writeStrongBinder(display);
316 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
317 const status_t result = reply.readInt32();
318 if (result == NO_ERROR) {
319 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
320 }
321 return result;
322 }
323
324 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
325 Parcel data, reply;
326 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
327 data.writeStrongBinder(display);
328 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
329 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100330 if (result != NO_ERROR) return result;
331 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800332 }
333
334 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700335 Parcel data, reply;
336 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700337 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700338 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800339 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700340 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800341 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700342 configs->clear();
343 configs->resize(numConfigs);
344 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800345 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
346 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700347 }
348 }
349 return result;
350 }
351
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700352 virtual status_t getDisplayStats(const sp<IBinder>& display,
353 DisplayStatInfo* stats)
354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
357 data.writeStrongBinder(display);
358 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
359 status_t result = reply.readInt32();
360 if (result == NO_ERROR) {
361 memcpy(stats,
362 reply.readInplace(sizeof(DisplayStatInfo)),
363 sizeof(DisplayStatInfo));
364 }
365 return result;
366 }
367
Dan Stoza7f7da322014-05-02 15:26:25 -0700368 virtual int getActiveConfig(const sp<IBinder>& display)
369 {
370 Parcel data, reply;
371 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
372 data.writeStrongBinder(display);
373 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
374 return reply.readInt32();
375 }
376
Michael Wright28f24d02016-07-12 13:30:53 -0700377 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700378 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700379 Parcel data, reply;
380 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
381 if (result != NO_ERROR) {
382 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
383 return result;
384 }
385 result = data.writeStrongBinder(display);
386 if (result != NO_ERROR) {
387 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
388 return result;
389 }
390 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
391 if (result != NO_ERROR) {
392 ALOGE("getDisplayColorModes failed to transact: %d", result);
393 return result;
394 }
395 result = static_cast<status_t>(reply.readInt32());
396 if (result == NO_ERROR) {
397 size_t numModes = reply.readUint32();
398 outColorModes->clear();
399 outColorModes->resize(numModes);
400 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700401 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700402 }
403 }
404 return result;
405 }
406
Daniel Solomon42d04562019-01-20 21:03:19 -0800407 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
408 ui::DisplayPrimaries& primaries) {
409 Parcel data, reply;
410 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
411 if (result != NO_ERROR) {
412 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
413 return result;
414 }
415 result = data.writeStrongBinder(display);
416 if (result != NO_ERROR) {
417 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
418 return result;
419 }
420 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
421 if (result != NO_ERROR) {
422 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
423 return result;
424 }
425 result = reply.readInt32();
426 if (result == NO_ERROR) {
427 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
428 sizeof(ui::DisplayPrimaries));
429 }
430 return result;
431 }
432
Peiyong Lina52f0292018-03-14 17:26:31 -0700433 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700434 Parcel data, reply;
435 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
436 if (result != NO_ERROR) {
437 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700438 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700439 }
440 result = data.writeStrongBinder(display);
441 if (result != NO_ERROR) {
442 ALOGE("getActiveColorMode failed to writeStrongBinder: %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 = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
446 if (result != NO_ERROR) {
447 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700448 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700449 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700450 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700451 }
452
453 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700454 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700455 Parcel data, reply;
456 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
457 if (result != NO_ERROR) {
458 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
459 return result;
460 }
461 result = data.writeStrongBinder(display);
462 if (result != NO_ERROR) {
463 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
464 return result;
465 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700466 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700467 if (result != NO_ERROR) {
468 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
469 return result;
470 }
471 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
472 if (result != NO_ERROR) {
473 ALOGE("setActiveColorMode failed to transact: %d", result);
474 return result;
475 }
476 return static_cast<status_t>(reply.readInt32());
477 }
478
Galia Peycheva5492cb52019-10-30 14:13:16 +0100479 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
480 bool* outSupport) const {
481 Parcel data, reply;
482 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
483 status_t result = data.writeStrongBinder(display);
484 if (result != NO_ERROR) {
485 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
486 return result;
487 }
488 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
489 &reply);
490 if (result != NO_ERROR) {
491 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
492 return result;
493 }
494 return reply.readBool(outSupport);
495 }
496
497 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
498 Parcel data, reply;
499 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
500 if (result != NO_ERROR) {
501 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
502 return;
503 }
504
505 result = data.writeStrongBinder(display);
506 if (result != NO_ERROR) {
507 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
508 return;
509 }
510 result = data.writeBool(on);
511 if (result != NO_ERROR) {
512 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
513 return;
514 }
515 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
516 if (result != NO_ERROR) {
517 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
518 return;
519 }
520 }
521
522 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
523 Parcel data, reply;
524 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
525 status_t result = data.writeStrongBinder(display);
526 if (result != NO_ERROR) {
527 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
528 return result;
529 }
530 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
531 if (result != NO_ERROR) {
532 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
533 return result;
534 }
535 return reply.readBool(outSupport);
536 }
537
538 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
539 Parcel data, reply;
540 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
541 if (result != NO_ERROR) {
542 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
543 return;
544 }
545 result = data.writeStrongBinder(display);
546 if (result != NO_ERROR) {
547 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
548 return;
549 }
550 result = data.writeBool(on);
551 if (result != NO_ERROR) {
552 ALOGE("setGameContentType failed to writeBool: %d", result);
553 return;
554 }
555 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
556 if (result != NO_ERROR) {
557 ALOGE("setGameContentType failed to transact: %d", result);
558 }
559 }
560
Svetoslavd85084b2014-03-20 10:28:31 -0700561 virtual status_t clearAnimationFrameStats() {
562 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700563 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
564 if (result != NO_ERROR) {
565 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
566 return result;
567 }
568 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
569 if (result != NO_ERROR) {
570 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
571 return result;
572 }
Svetoslavd85084b2014-03-20 10:28:31 -0700573 return reply.readInt32();
574 }
575
576 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
577 Parcel data, reply;
578 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
579 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
580 reply.read(*outStats);
581 return reply.readInt32();
582 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700583
584 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
585 HdrCapabilities* outCapabilities) const {
586 Parcel data, reply;
587 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
588 status_t result = data.writeStrongBinder(display);
589 if (result != NO_ERROR) {
590 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
591 return result;
592 }
593 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
594 data, &reply);
595 if (result != NO_ERROR) {
596 ALOGE("getHdrCapabilities failed to transact: %d", result);
597 return result;
598 }
599 result = reply.readInt32();
600 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800601 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700602 }
603 return result;
604 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700605
606 virtual status_t enableVSyncInjections(bool enable) {
607 Parcel data, reply;
608 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
609 if (result != NO_ERROR) {
610 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
611 return result;
612 }
613 result = data.writeBool(enable);
614 if (result != NO_ERROR) {
615 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
616 return result;
617 }
Steven Moreland366eb422019-04-01 19:22:32 -0700618 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
619 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700620 if (result != NO_ERROR) {
621 ALOGE("enableVSyncInjections failed to transact: %d", result);
622 return result;
623 }
624 return result;
625 }
626
627 virtual status_t injectVSync(nsecs_t when) {
628 Parcel data, reply;
629 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
630 if (result != NO_ERROR) {
631 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
632 return result;
633 }
634 result = data.writeInt64(when);
635 if (result != NO_ERROR) {
636 ALOGE("injectVSync failed to writeInt64: %d", result);
637 return result;
638 }
Steven Moreland366eb422019-04-01 19:22:32 -0700639 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
640 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700641 if (result != NO_ERROR) {
642 ALOGE("injectVSync failed to transact: %d", result);
643 return result;
644 }
645 return result;
646 }
647
Vishnu Nair43bccf82020-06-05 10:53:37 -0700648 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800649 if (!outLayers) {
650 return UNEXPECTED_NULL;
651 }
652
653 Parcel data, reply;
654
655 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
656 if (err != NO_ERROR) {
657 return err;
658 }
659
660 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
661 if (err != NO_ERROR) {
662 return err;
663 }
664
665 int32_t result = 0;
666 err = reply.readInt32(&result);
667 if (err != NO_ERROR) {
668 return err;
669 }
670 if (result != NO_ERROR) {
671 return result;
672 }
673
674 outLayers->clear();
675 return reply.readParcelableVector(outLayers);
676 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700677
Peiyong Linc6780972018-10-28 15:24:08 -0700678 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
679 ui::PixelFormat* defaultPixelFormat,
680 ui::Dataspace* wideColorGamutDataspace,
681 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700682 Parcel data, reply;
683 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
684 if (error != NO_ERROR) {
685 return error;
686 }
687 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
688 if (error != NO_ERROR) {
689 return error;
690 }
691 error = static_cast<status_t>(reply.readInt32());
692 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700693 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
694 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
695 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
696 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700697 }
698 return error;
699 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700700
Ady Abraham37965d42018-11-01 13:43:32 -0700701 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700702 Parcel data, reply;
703 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700704 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
705 bool result;
706 status_t err = reply.readBool(&result);
707 if (err == NO_ERROR) {
708 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700709 }
Ady Abraham37965d42018-11-01 13:43:32 -0700710 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700711 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700712
713 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
714 ui::PixelFormat* outFormat,
715 ui::Dataspace* outDataspace,
716 uint8_t* outComponentMask) const {
717 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
718 Parcel data, reply;
719 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
720 data.writeStrongBinder(display);
721
722 status_t error =
723 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
724 data, &reply);
725 if (error != NO_ERROR) {
726 return error;
727 }
728
729 uint32_t value = 0;
730 error = reply.readUint32(&value);
731 if (error != NO_ERROR) {
732 return error;
733 }
734 *outFormat = static_cast<ui::PixelFormat>(value);
735
736 error = reply.readUint32(&value);
737 if (error != NO_ERROR) {
738 return error;
739 }
740 *outDataspace = static_cast<ui::Dataspace>(value);
741
742 error = reply.readUint32(&value);
743 if (error != NO_ERROR) {
744 return error;
745 }
746 *outComponentMask = static_cast<uint8_t>(value);
747 return error;
748 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800749
750 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700751 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800752 Parcel data, reply;
753 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
754 data.writeStrongBinder(display);
755 data.writeBool(enable);
756 data.writeByte(static_cast<int8_t>(componentMask));
757 data.writeUint64(maxFrames);
758 status_t result =
759 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
760 &reply);
761 return result;
762 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700763
764 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
765 uint64_t timestamp,
766 DisplayedFrameStats* outStats) const {
767 if (!outStats) return BAD_VALUE;
768
769 Parcel data, reply;
770 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
771 data.writeStrongBinder(display);
772 data.writeUint64(maxFrames);
773 data.writeUint64(timestamp);
774
775 status_t result =
776 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
777
778 if (result != NO_ERROR) {
779 return result;
780 }
781
782 result = reply.readUint64(&outStats->numFrames);
783 if (result != NO_ERROR) {
784 return result;
785 }
786
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800787 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700788 if (result != NO_ERROR) {
789 return result;
790 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800791 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700792 if (result != NO_ERROR) {
793 return result;
794 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800795 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700796 if (result != NO_ERROR) {
797 return result;
798 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800799 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700800 return result;
801 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800802
803 virtual status_t getProtectedContentSupport(bool* outSupported) const {
804 Parcel data, reply;
805 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800806 status_t error =
807 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
808 if (error != NO_ERROR) {
809 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800810 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800811 error = reply.readBool(outSupported);
812 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800813 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800814
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800815 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
816 bool* outIsWideColorDisplay) const {
817 Parcel data, reply;
818 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
819 if (error != NO_ERROR) {
820 return error;
821 }
822 error = data.writeStrongBinder(token);
823 if (error != NO_ERROR) {
824 return error;
825 }
826
827 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
828 if (error != NO_ERROR) {
829 return error;
830 }
831 error = reply.readBool(outIsWideColorDisplay);
832 return error;
833 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800834
835 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
836 const sp<IBinder>& stopLayerHandle,
837 const sp<IRegionSamplingListener>& listener) {
838 Parcel data, reply;
839 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
840 if (error != NO_ERROR) {
841 ALOGE("addRegionSamplingListener: Failed to write interface token");
842 return error;
843 }
844 error = data.write(samplingArea);
845 if (error != NO_ERROR) {
846 ALOGE("addRegionSamplingListener: Failed to write sampling area");
847 return error;
848 }
849 error = data.writeStrongBinder(stopLayerHandle);
850 if (error != NO_ERROR) {
851 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
852 return error;
853 }
854 error = data.writeStrongBinder(IInterface::asBinder(listener));
855 if (error != NO_ERROR) {
856 ALOGE("addRegionSamplingListener: Failed to write listener");
857 return error;
858 }
859 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
860 if (error != NO_ERROR) {
861 ALOGE("addRegionSamplingListener: Failed to transact");
862 }
863 return error;
864 }
865
866 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
867 Parcel data, reply;
868 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
869 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800870 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800871 return error;
872 }
873 error = data.writeStrongBinder(IInterface::asBinder(listener));
874 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800875 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800876 return error;
877 }
878 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
879 &reply);
880 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800881 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800882 }
883 return error;
884 }
Ady Abraham838de062019-02-04 10:24:03 -0800885
Ana Krulec0782b882019-10-15 17:34:54 -0700886 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700887 int32_t defaultConfig,
888 float primaryRefreshRateMin,
889 float primaryRefreshRateMax,
890 float appRequestRefreshRateMin,
891 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700892 Parcel data, reply;
893 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
894 if (result != NO_ERROR) {
895 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
896 return result;
897 }
898 result = data.writeStrongBinder(displayToken);
899 if (result != NO_ERROR) {
900 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
901 return result;
902 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100903 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700904 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100905 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700906 return result;
907 }
Steven Thomasf734df42020-04-13 21:09:28 -0700908 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700909 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700910 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700911 return result;
912 }
Steven Thomasf734df42020-04-13 21:09:28 -0700913 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700914 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700915 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
916 return result;
917 }
918 result = data.writeFloat(appRequestRefreshRateMin);
919 if (result != NO_ERROR) {
920 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
921 result);
922 return result;
923 }
924 result = data.writeFloat(appRequestRefreshRateMax);
925 if (result != NO_ERROR) {
926 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
927 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700928 return result;
929 }
930
931 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
932 &reply);
933 if (result != NO_ERROR) {
934 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
935 return result;
936 }
937 return reply.readInt32();
938 }
939
Ana Krulec234bb162019-11-10 22:55:55 +0100940 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100941 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700942 float* outPrimaryRefreshRateMin,
943 float* outPrimaryRefreshRateMax,
944 float* outAppRequestRefreshRateMin,
945 float* outAppRequestRefreshRateMax) {
946 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
947 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
948 return BAD_VALUE;
949 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800950 Parcel data, reply;
951 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
952 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100953 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800954 return result;
955 }
956 result = data.writeStrongBinder(displayToken);
957 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100958 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800959 return result;
960 }
Ana Krulec234bb162019-11-10 22:55:55 +0100961 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
962 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800963 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100964 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800965 return result;
966 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100967 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800968 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100969 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100970 return result;
971 }
Steven Thomasf734df42020-04-13 21:09:28 -0700972 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +0100973 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700974 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100975 return result;
976 }
Steven Thomasf734df42020-04-13 21:09:28 -0700977 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +0100978 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700979 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
980 return result;
981 }
982 result = reply.readFloat(outAppRequestRefreshRateMin);
983 if (result != NO_ERROR) {
984 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
985 result);
986 return result;
987 }
988 result = reply.readFloat(outAppRequestRefreshRateMax);
989 if (result != NO_ERROR) {
990 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
991 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800992 return result;
993 }
994 return reply.readInt32();
995 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000996
997 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
998 bool* outSupport) const {
999 Parcel data, reply;
1000 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1001 if (error != NO_ERROR) {
1002 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1003 return error;
1004 }
1005 error = data.writeStrongBinder(displayToken);
1006 if (error != NO_ERROR) {
1007 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1008 return error;
1009 }
1010 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1011 if (error != NO_ERROR) {
1012 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1013 return error;
1014 }
1015 bool support;
1016 error = reply.readBool(&support);
1017 if (error != NO_ERROR) {
1018 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1019 return error;
1020 }
1021 *outSupport = support;
1022 return NO_ERROR;
1023 }
1024
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001025 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001026 Parcel data, reply;
1027 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1028 if (error != NO_ERROR) {
1029 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1030 return error;
1031 }
1032 error = data.writeStrongBinder(displayToken);
1033 if (error != NO_ERROR) {
1034 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1035 return error;
1036 }
1037 error = data.writeFloat(brightness);
1038 if (error != NO_ERROR) {
1039 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1040 return error;
1041 }
1042 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1043 if (error != NO_ERROR) {
1044 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1045 return error;
1046 }
1047 return NO_ERROR;
1048 }
Ady Abraham8532d012019-05-08 14:50:56 -07001049
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001050 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001051 Parcel data, reply;
1052 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1053 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001054 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001055 return error;
1056 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001057 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001058 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001059 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001060 return error;
1061 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001062 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001063 IBinder::FLAG_ONEWAY);
1064 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001065 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001066 return error;
1067 }
1068 return NO_ERROR;
1069 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001070
1071 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1072 float lightPosY, float lightPosZ, float lightRadius) {
1073 Parcel data, reply;
1074 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1075 if (error != NO_ERROR) {
1076 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1077 return error;
1078 }
1079
1080 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1081 ambientColor.a, spotColor.r, spotColor.g,
1082 spotColor.b, spotColor.a, lightPosY,
1083 lightPosZ, lightRadius};
1084
1085 error = data.writeFloatVector(shadowConfig);
1086 if (error != NO_ERROR) {
1087 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1088 return error;
1089 }
1090
1091 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1092 IBinder::FLAG_ONEWAY);
1093 if (error != NO_ERROR) {
1094 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1095 return error;
1096 }
1097 return NO_ERROR;
1098 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001099
1100 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1101 int8_t compatibility) {
1102 Parcel data, reply;
1103 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1104 if (err != NO_ERROR) {
1105 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1106 return err;
1107 }
1108
1109 err = data.writeStrongBinder(IInterface::asBinder(surface));
1110 if (err != NO_ERROR) {
1111 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1112 return err;
1113 }
1114
1115 err = data.writeFloat(frameRate);
1116 if (err != NO_ERROR) {
1117 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1118 return err;
1119 }
1120
1121 err = data.writeByte(compatibility);
1122 if (err != NO_ERROR) {
1123 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1124 return err;
1125 }
1126
Ady Abraham60e42ea2020-03-09 19:17:31 -07001127 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001128 if (err != NO_ERROR) {
1129 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1130 return err;
1131 }
Steven Thomasd4071902020-03-24 16:02:53 -07001132
1133 return reply.readInt32();
1134 }
1135
1136 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1137 if (!outToken) return BAD_VALUE;
1138
1139 Parcel data, reply;
1140 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1141 if (err != NO_ERROR) {
1142 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1143 strerror(-err), -err);
1144 return err;
1145 }
1146
1147 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1148 &reply);
1149 if (err != NO_ERROR) {
1150 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1151 err);
1152 return err;
1153 }
1154
1155 err = reply.readInt32();
1156 if (err != NO_ERROR) {
1157 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1158 return err;
1159 }
1160
1161 err = reply.readStrongBinder(outToken);
1162 if (err != NO_ERROR) {
1163 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1164 strerror(-err), err);
1165 return err;
1166 }
1167
Steven Thomas62a4cf82020-01-31 12:04:03 -08001168 return NO_ERROR;
1169 }
Ady Abraham74e17562020-08-24 18:18:19 -07001170
1171 virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface,
1172 int64_t frameTimelineVsyncId) {
1173 Parcel data, reply;
1174 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1175 if (err != NO_ERROR) {
1176 ALOGE("setFrameTimelineVsync: failed writing interface token: %s (%d)", strerror(-err),
1177 -err);
1178 return err;
1179 }
1180
1181 err = data.writeStrongBinder(IInterface::asBinder(surface));
1182 if (err != NO_ERROR) {
1183 ALOGE("setFrameTimelineVsync: failed writing strong binder: %s (%d)", strerror(-err),
1184 -err);
1185 return err;
1186 }
1187
1188 err = data.writeInt64(frameTimelineVsyncId);
1189 if (err != NO_ERROR) {
1190 ALOGE("setFrameTimelineVsync: failed writing int64_t: %s (%d)", strerror(-err), -err);
1191 return err;
1192 }
1193
1194 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_VSYNC, data, &reply);
1195 if (err != NO_ERROR) {
1196 ALOGE("setFrameTimelineVsync: failed to transact: %s (%d)", strerror(-err), err);
1197 return err;
1198 }
1199
1200 return reply.readInt32();
1201 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00001202
1203 virtual status_t addTransactionTraceListener(
1204 const sp<gui::ITransactionTraceListener>& listener) {
1205 Parcel data, reply;
1206 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
1207 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
1208
1209 return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply);
1210 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001211};
1212
Dan Stozad723bd72014-11-18 10:24:03 -08001213// Out-of-line virtual method definition to trigger vtable emission in this
1214// translation unit (see clang warning -Wweak-vtables)
1215BpSurfaceComposer::~BpSurfaceComposer() {}
1216
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001217IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1218
1219// ----------------------------------------------------------------------
1220
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001221status_t BnSurfaceComposer::onTransact(
1222 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1223{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001224 switch(code) {
1225 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001226 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001227 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001228 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001229 return NO_ERROR;
1230 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001231 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001232 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001233
chaviw308ddba2020-08-11 16:23:51 -07001234 uint32_t count = 0;
1235 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001236 Vector<ComposerState> state;
1237 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001238 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001239 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001240 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001241 state.add(s);
1242 }
Dan Stozad723bd72014-11-18 10:24:03 -08001243
chaviw308ddba2020-08-11 16:23:51 -07001244 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001245 DisplayState d;
1246 Vector<DisplayState> displays;
1247 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001248 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001249 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001250 displays.add(d);
1251 }
Dan Stozad723bd72014-11-18 10:24:03 -08001252
chaviw308ddba2020-08-11 16:23:51 -07001253 uint32_t stateFlags = 0;
1254 SAFE_PARCEL(data.readUint32, &stateFlags);
1255 sp<IBinder> applyToken;
1256 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001257 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001258 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001259
chaviw308ddba2020-08-11 16:23:51 -07001260 int64_t desiredPresentTime = 0;
1261 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -07001262
Marissa Wall947d34e2019-03-29 14:03:53 -07001263 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001264 sp<IBinder> tmpBinder;
1265 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1266 uncachedBuffer.token = tmpBinder;
1267 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001268
chaviw308ddba2020-08-11 16:23:51 -07001269 bool hasListenerCallbacks = false;
1270 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001271
Marissa Wall3dad52d2019-03-22 14:03:19 -07001272 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001273 int32_t listenersSize = 0;
1274 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001275 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001276 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001277 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001278 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1279 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001280 }
chaviw308ddba2020-08-11 16:23:51 -07001281 return setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
1282 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1283 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001284 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001285 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001286 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001287 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001288 return NO_ERROR;
1289 }
chaviwd2432892020-07-24 17:42:39 -07001290 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001291 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001292 DisplayCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001293 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001294 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001295 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1296
1297 return captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001298 }
chaviwd2432892020-07-24 17:42:39 -07001299 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001300 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001301 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001302 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001303 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001304 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1305
1306 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001307 }
chaviwa76b2712017-09-20 12:02:26 -07001308 case CAPTURE_LAYERS: {
1309 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001310 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001311 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001312 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001313 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1314
1315 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001316 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001317 case AUTHENTICATE_SURFACE: {
1318 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001319 sp<IGraphicBufferProducer> bufferProducer =
1320 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1321 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001322 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001323 return NO_ERROR;
1324 }
Brian Anderson6b376712017-04-04 10:51:39 -07001325 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1326 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1327 std::vector<FrameEvent> supportedTimestamps;
1328 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1329 status_t err = reply->writeInt32(result);
1330 if (err != NO_ERROR) {
1331 return err;
1332 }
1333 if (result != NO_ERROR) {
1334 return result;
1335 }
1336
1337 std::vector<int32_t> supported;
1338 supported.reserve(supportedTimestamps.size());
1339 for (FrameEvent s : supportedTimestamps) {
1340 supported.push_back(static_cast<int32_t>(s));
1341 }
1342 return reply->writeInt32Vector(supported);
1343 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001344 case CREATE_DISPLAY_EVENT_CONNECTION: {
1345 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001346 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1347 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1348
1349 sp<IDisplayEventConnection> connection(
1350 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001351 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001352 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001353 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001354 case CREATE_DISPLAY: {
1355 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001356 String8 displayName;
1357 SAFE_PARCEL(data.readString8, &displayName);
1358 bool secure = false;
1359 SAFE_PARCEL(data.readBool, &secure);
1360 sp<IBinder> display = createDisplay(displayName, secure);
1361 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001362 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001363 }
1364 case DESTROY_DISPLAY: {
1365 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1366 sp<IBinder> display = data.readStrongBinder();
1367 destroyDisplay(display);
1368 return NO_ERROR;
1369 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001370 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001371 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001372 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001373 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001374 reply->writeStrongBinder(display);
1375 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001376 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001377 case GET_DISPLAY_STATE: {
1378 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1379 ui::DisplayState state;
1380 const sp<IBinder> display = data.readStrongBinder();
1381 const status_t result = getDisplayState(display, &state);
1382 reply->writeInt32(result);
1383 if (result == NO_ERROR) {
1384 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1385 sizeof(ui::DisplayState));
1386 }
1387 return NO_ERROR;
1388 }
1389 case GET_DISPLAY_INFO: {
1390 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1391 DisplayInfo info;
1392 const sp<IBinder> display = data.readStrongBinder();
1393 const status_t result = getDisplayInfo(display, &info);
1394 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001395 if (result != NO_ERROR) return result;
1396 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001397 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001398 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001399 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001400 Vector<DisplayConfig> configs;
1401 const sp<IBinder> display = data.readStrongBinder();
1402 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001403 reply->writeInt32(result);
1404 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001405 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001406 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001407 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1408 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001409 }
1410 }
1411 return NO_ERROR;
1412 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001413 case GET_DISPLAY_STATS: {
1414 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1415 DisplayStatInfo stats;
1416 sp<IBinder> display = data.readStrongBinder();
1417 status_t result = getDisplayStats(display, &stats);
1418 reply->writeInt32(result);
1419 if (result == NO_ERROR) {
1420 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1421 &stats, sizeof(DisplayStatInfo));
1422 }
1423 return NO_ERROR;
1424 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001425 case GET_ACTIVE_CONFIG: {
1426 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1427 sp<IBinder> display = data.readStrongBinder();
1428 int id = getActiveConfig(display);
1429 reply->writeInt32(id);
1430 return NO_ERROR;
1431 }
Michael Wright28f24d02016-07-12 13:30:53 -07001432 case GET_DISPLAY_COLOR_MODES: {
1433 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001434 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001435 sp<IBinder> display = nullptr;
1436 status_t result = data.readStrongBinder(&display);
1437 if (result != NO_ERROR) {
1438 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1439 return result;
1440 }
1441 result = getDisplayColorModes(display, &colorModes);
1442 reply->writeInt32(result);
1443 if (result == NO_ERROR) {
1444 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1445 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001446 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001447 }
1448 }
1449 return NO_ERROR;
1450 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001451 case GET_DISPLAY_NATIVE_PRIMARIES: {
1452 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1453 ui::DisplayPrimaries primaries;
1454 sp<IBinder> display = nullptr;
1455
1456 status_t result = data.readStrongBinder(&display);
1457 if (result != NO_ERROR) {
1458 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1459 return result;
1460 }
1461
1462 result = getDisplayNativePrimaries(display, primaries);
1463 reply->writeInt32(result);
1464 if (result == NO_ERROR) {
1465 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1466 sizeof(ui::DisplayPrimaries));
1467 }
1468
1469 return NO_ERROR;
1470 }
Michael Wright28f24d02016-07-12 13:30:53 -07001471 case GET_ACTIVE_COLOR_MODE: {
1472 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1473 sp<IBinder> display = nullptr;
1474 status_t result = data.readStrongBinder(&display);
1475 if (result != NO_ERROR) {
1476 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1477 return result;
1478 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001479 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001480 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1481 return result;
1482 }
1483 case SET_ACTIVE_COLOR_MODE: {
1484 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1485 sp<IBinder> display = nullptr;
1486 status_t result = data.readStrongBinder(&display);
1487 if (result != NO_ERROR) {
1488 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1489 return result;
1490 }
1491 int32_t colorModeInt = 0;
1492 result = data.readInt32(&colorModeInt);
1493 if (result != NO_ERROR) {
1494 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1495 return result;
1496 }
1497 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001498 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001499 result = reply->writeInt32(result);
1500 return result;
1501 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001502
1503 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1504 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1505 sp<IBinder> display = nullptr;
1506 status_t result = data.readStrongBinder(&display);
1507 if (result != NO_ERROR) {
1508 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1509 return result;
1510 }
1511 bool supported = false;
1512 result = getAutoLowLatencyModeSupport(display, &supported);
1513 if (result == NO_ERROR) {
1514 result = reply->writeBool(supported);
1515 }
1516 return result;
1517 }
1518
1519 case SET_AUTO_LOW_LATENCY_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("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1525 return result;
1526 }
1527 bool setAllm = false;
1528 result = data.readBool(&setAllm);
1529 if (result != NO_ERROR) {
1530 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1531 return result;
1532 }
1533 setAutoLowLatencyMode(display, setAllm);
1534 return result;
1535 }
1536
1537 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1538 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1539 sp<IBinder> display = nullptr;
1540 status_t result = data.readStrongBinder(&display);
1541 if (result != NO_ERROR) {
1542 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1543 return result;
1544 }
1545 bool supported = false;
1546 result = getGameContentTypeSupport(display, &supported);
1547 if (result == NO_ERROR) {
1548 result = reply->writeBool(supported);
1549 }
1550 return result;
1551 }
1552
1553 case SET_GAME_CONTENT_TYPE: {
1554 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1555 sp<IBinder> display = nullptr;
1556 status_t result = data.readStrongBinder(&display);
1557 if (result != NO_ERROR) {
1558 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1559 return result;
1560 }
1561 bool setGameContentTypeOn = false;
1562 result = data.readBool(&setGameContentTypeOn);
1563 if (result != NO_ERROR) {
1564 ALOGE("setGameContentType failed to readBool: %d", result);
1565 return result;
1566 }
1567 setGameContentType(display, setGameContentTypeOn);
1568 return result;
1569 }
1570
Svetoslavd85084b2014-03-20 10:28:31 -07001571 case CLEAR_ANIMATION_FRAME_STATS: {
1572 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1573 status_t result = clearAnimationFrameStats();
1574 reply->writeInt32(result);
1575 return NO_ERROR;
1576 }
1577 case GET_ANIMATION_FRAME_STATS: {
1578 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1579 FrameStats stats;
1580 status_t result = getAnimationFrameStats(&stats);
1581 reply->write(stats);
1582 reply->writeInt32(result);
1583 return NO_ERROR;
1584 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001585 case SET_POWER_MODE: {
1586 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1587 sp<IBinder> display = data.readStrongBinder();
1588 int32_t mode = data.readInt32();
1589 setPowerMode(display, mode);
1590 return NO_ERROR;
1591 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001592 case GET_HDR_CAPABILITIES: {
1593 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1594 sp<IBinder> display = nullptr;
1595 status_t result = data.readStrongBinder(&display);
1596 if (result != NO_ERROR) {
1597 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1598 result);
1599 return result;
1600 }
1601 HdrCapabilities capabilities;
1602 result = getHdrCapabilities(display, &capabilities);
1603 reply->writeInt32(result);
1604 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001605 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001606 }
1607 return NO_ERROR;
1608 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001609 case ENABLE_VSYNC_INJECTIONS: {
1610 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1611 bool enable = false;
1612 status_t result = data.readBool(&enable);
1613 if (result != NO_ERROR) {
1614 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1615 return result;
1616 }
1617 return enableVSyncInjections(enable);
1618 }
1619 case INJECT_VSYNC: {
1620 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1621 int64_t when = 0;
1622 status_t result = data.readInt64(&when);
1623 if (result != NO_ERROR) {
1624 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1625 return result;
1626 }
1627 return injectVSync(when);
1628 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001629 case GET_LAYER_DEBUG_INFO: {
1630 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1631 std::vector<LayerDebugInfo> outLayers;
1632 status_t result = getLayerDebugInfo(&outLayers);
1633 reply->writeInt32(result);
1634 if (result == NO_ERROR)
1635 {
1636 result = reply->writeParcelableVector(outLayers);
1637 }
1638 return result;
1639 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001640 case GET_COMPOSITION_PREFERENCE: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001642 ui::Dataspace defaultDataspace;
1643 ui::PixelFormat defaultPixelFormat;
1644 ui::Dataspace wideColorGamutDataspace;
1645 ui::PixelFormat wideColorGamutPixelFormat;
1646 status_t error =
1647 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1648 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001649 reply->writeInt32(error);
1650 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001651 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1652 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1653 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001654 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001655 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001656 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001657 }
Ady Abraham37965d42018-11-01 13:43:32 -07001658 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001659 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001660 bool result;
1661 status_t error = getColorManagement(&result);
1662 if (error == NO_ERROR) {
1663 reply->writeBool(result);
1664 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001665 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001666 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001667 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1668 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1669
1670 sp<IBinder> display = data.readStrongBinder();
1671 ui::PixelFormat format;
1672 ui::Dataspace dataspace;
1673 uint8_t component = 0;
1674 auto result =
1675 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1676 if (result == NO_ERROR) {
1677 reply->writeUint32(static_cast<uint32_t>(format));
1678 reply->writeUint32(static_cast<uint32_t>(dataspace));
1679 reply->writeUint32(static_cast<uint32_t>(component));
1680 }
1681 return result;
1682 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001683 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1684 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1685
1686 sp<IBinder> display = nullptr;
1687 bool enable = false;
1688 int8_t componentMask = 0;
1689 uint64_t maxFrames = 0;
1690 status_t result = data.readStrongBinder(&display);
1691 if (result != NO_ERROR) {
1692 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1693 result);
1694 return result;
1695 }
1696
1697 result = data.readBool(&enable);
1698 if (result != NO_ERROR) {
1699 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1700 return result;
1701 }
1702
1703 result = data.readByte(static_cast<int8_t*>(&componentMask));
1704 if (result != NO_ERROR) {
1705 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1706 result);
1707 return result;
1708 }
1709
1710 result = data.readUint64(&maxFrames);
1711 if (result != NO_ERROR) {
1712 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1713 return result;
1714 }
1715
1716 return setDisplayContentSamplingEnabled(display, enable,
1717 static_cast<uint8_t>(componentMask), maxFrames);
1718 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001719 case GET_DISPLAYED_CONTENT_SAMPLE: {
1720 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1721
1722 sp<IBinder> display = data.readStrongBinder();
1723 uint64_t maxFrames = 0;
1724 uint64_t timestamp = 0;
1725
1726 status_t result = data.readUint64(&maxFrames);
1727 if (result != NO_ERROR) {
1728 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1729 return result;
1730 }
1731
1732 result = data.readUint64(&timestamp);
1733 if (result != NO_ERROR) {
1734 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1735 return result;
1736 }
1737
1738 DisplayedFrameStats stats;
1739 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1740 if (result == NO_ERROR) {
1741 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001742 reply->writeUint64Vector(stats.component_0_sample);
1743 reply->writeUint64Vector(stats.component_1_sample);
1744 reply->writeUint64Vector(stats.component_2_sample);
1745 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001746 }
1747 return result;
1748 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001749 case GET_PROTECTED_CONTENT_SUPPORT: {
1750 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1751 bool result;
1752 status_t error = getProtectedContentSupport(&result);
1753 if (error == NO_ERROR) {
1754 reply->writeBool(result);
1755 }
1756 return error;
1757 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001758 case IS_WIDE_COLOR_DISPLAY: {
1759 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1760 sp<IBinder> display = nullptr;
1761 status_t error = data.readStrongBinder(&display);
1762 if (error != NO_ERROR) {
1763 return error;
1764 }
1765 bool result;
1766 error = isWideColorDisplay(display, &result);
1767 if (error == NO_ERROR) {
1768 reply->writeBool(result);
1769 }
1770 return error;
1771 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001772 case GET_PHYSICAL_DISPLAY_IDS: {
1773 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001774 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1775 std::vector<uint64_t> rawIds(ids.size());
1776 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1777 [](PhysicalDisplayId id) { return id.value; });
1778 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001779 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001780 case ADD_REGION_SAMPLING_LISTENER: {
1781 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1782 Rect samplingArea;
1783 status_t result = data.read(samplingArea);
1784 if (result != NO_ERROR) {
1785 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1786 return result;
1787 }
1788 sp<IBinder> stopLayerHandle;
1789 result = data.readNullableStrongBinder(&stopLayerHandle);
1790 if (result != NO_ERROR) {
1791 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1792 return result;
1793 }
1794 sp<IRegionSamplingListener> listener;
1795 result = data.readNullableStrongBinder(&listener);
1796 if (result != NO_ERROR) {
1797 ALOGE("addRegionSamplingListener: Failed to read listener");
1798 return result;
1799 }
1800 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1801 }
1802 case REMOVE_REGION_SAMPLING_LISTENER: {
1803 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1804 sp<IRegionSamplingListener> listener;
1805 status_t result = data.readNullableStrongBinder(&listener);
1806 if (result != NO_ERROR) {
1807 ALOGE("removeRegionSamplingListener: Failed to read listener");
1808 return result;
1809 }
1810 return removeRegionSamplingListener(listener);
1811 }
Ana Krulec0782b882019-10-15 17:34:54 -07001812 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1813 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1814 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001815 int32_t defaultConfig;
1816 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001817 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001818 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001819 return result;
1820 }
Steven Thomasf734df42020-04-13 21:09:28 -07001821 float primaryRefreshRateMin;
1822 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001823 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001824 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1825 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001826 return result;
1827 }
Steven Thomasf734df42020-04-13 21:09:28 -07001828 float primaryRefreshRateMax;
1829 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001830 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001831 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1832 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001833 return result;
1834 }
Steven Thomasf734df42020-04-13 21:09:28 -07001835 float appRequestRefreshRateMin;
1836 result = data.readFloat(&appRequestRefreshRateMin);
1837 if (result != NO_ERROR) {
1838 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1839 result);
1840 return result;
1841 }
1842 float appRequestRefreshRateMax;
1843 result = data.readFloat(&appRequestRefreshRateMax);
1844 if (result != NO_ERROR) {
1845 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1846 result);
1847 return result;
1848 }
1849 result =
1850 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1851 primaryRefreshRateMax, appRequestRefreshRateMin,
1852 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001853 if (result != NO_ERROR) {
1854 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1855 "%d",
1856 result);
1857 return result;
1858 }
1859 reply->writeInt32(result);
1860 return result;
1861 }
Ana Krulec234bb162019-11-10 22:55:55 +01001862 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1863 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1864 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001865 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001866 float primaryRefreshRateMin;
1867 float primaryRefreshRateMax;
1868 float appRequestRefreshRateMin;
1869 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001870
Steven Thomasf734df42020-04-13 21:09:28 -07001871 status_t result =
1872 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1873 &primaryRefreshRateMin, &primaryRefreshRateMax,
1874 &appRequestRefreshRateMin,
1875 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001876 if (result != NO_ERROR) {
1877 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1878 "%d",
1879 result);
1880 return result;
1881 }
1882
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001883 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001884 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001885 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001886 return result;
1887 }
Steven Thomasf734df42020-04-13 21:09:28 -07001888 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001889 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001890 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1891 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001892 return result;
1893 }
Steven Thomasf734df42020-04-13 21:09:28 -07001894 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001895 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001896 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1897 result);
1898 return result;
1899 }
1900 result = reply->writeFloat(appRequestRefreshRateMin);
1901 if (result != NO_ERROR) {
1902 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1903 result);
1904 return result;
1905 }
1906 result = reply->writeFloat(appRequestRefreshRateMax);
1907 if (result != NO_ERROR) {
1908 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1909 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001910 return result;
1911 }
1912 reply->writeInt32(result);
1913 return result;
1914 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001915 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1916 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1917 sp<IBinder> displayToken;
1918 status_t error = data.readNullableStrongBinder(&displayToken);
1919 if (error != NO_ERROR) {
1920 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1921 return error;
1922 }
1923 bool support = false;
1924 error = getDisplayBrightnessSupport(displayToken, &support);
1925 reply->writeBool(support);
1926 return error;
1927 }
1928 case SET_DISPLAY_BRIGHTNESS: {
1929 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1930 sp<IBinder> displayToken;
1931 status_t error = data.readNullableStrongBinder(&displayToken);
1932 if (error != NO_ERROR) {
1933 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1934 return error;
1935 }
1936 float brightness = -1.0f;
1937 error = data.readFloat(&brightness);
1938 if (error != NO_ERROR) {
1939 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1940 return error;
1941 }
1942 return setDisplayBrightness(displayToken, brightness);
1943 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001944 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001945 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001946 int32_t boostId;
1947 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001948 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001949 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001950 return error;
1951 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001952 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001953 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001954 case SET_GLOBAL_SHADOW_SETTINGS: {
1955 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1956
1957 std::vector<float> shadowConfig;
1958 status_t error = data.readFloatVector(&shadowConfig);
1959 if (error != NO_ERROR || shadowConfig.size() != 11) {
1960 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1961 return error;
1962 }
1963
1964 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1965 shadowConfig[3]};
1966 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1967 float lightPosY = shadowConfig[8];
1968 float lightPosZ = shadowConfig[9];
1969 float lightRadius = shadowConfig[10];
1970 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1971 lightRadius);
1972 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001973 case SET_FRAME_RATE: {
1974 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1975 sp<IBinder> binder;
1976 status_t err = data.readStrongBinder(&binder);
1977 if (err != NO_ERROR) {
1978 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1979 return err;
1980 }
1981 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1982 if (!surface) {
1983 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1984 strerror(-err), -err);
1985 return err;
1986 }
1987 float frameRate;
1988 err = data.readFloat(&frameRate);
1989 if (err != NO_ERROR) {
1990 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
1991 return err;
1992 }
1993 int8_t compatibility;
1994 err = data.readByte(&compatibility);
1995 if (err != NO_ERROR) {
1996 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
1997 return err;
1998 }
1999 status_t result = setFrameRate(surface, frameRate, compatibility);
2000 reply->writeInt32(result);
2001 return NO_ERROR;
2002 }
Steven Thomasd4071902020-03-24 16:02:53 -07002003 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2004 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2005 sp<IBinder> token;
2006 status_t result = acquireFrameRateFlexibilityToken(&token);
2007 reply->writeInt32(result);
2008 if (result == NO_ERROR) {
2009 reply->writeStrongBinder(token);
2010 }
2011 return NO_ERROR;
2012 }
Ady Abraham74e17562020-08-24 18:18:19 -07002013 case SET_FRAME_TIMELINE_VSYNC: {
2014 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2015 sp<IBinder> binder;
2016 status_t err = data.readStrongBinder(&binder);
2017 if (err != NO_ERROR) {
2018 ALOGE("setFrameTimelineVsync: failed to read strong binder: %s (%d)",
2019 strerror(-err), -err);
2020 return err;
2021 }
2022 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
2023 if (!surface) {
2024 ALOGE("setFrameTimelineVsync: failed to cast to IGraphicBufferProducer: %s (%d)",
2025 strerror(-err), -err);
2026 return err;
2027 }
2028 int64_t frameTimelineVsyncId;
2029 err = data.readInt64(&frameTimelineVsyncId);
2030 if (err != NO_ERROR) {
2031 ALOGE("setFrameTimelineVsync: failed to read int64_t: %s (%d)", strerror(-err),
2032 -err);
2033 return err;
2034 }
2035
2036 status_t result = setFrameTimelineVsync(surface, frameTimelineVsyncId);
2037 reply->writeInt32(result);
2038 return NO_ERROR;
2039 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +00002040 case ADD_TRANSACTION_TRACE_LISTENER: {
2041 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2042 sp<gui::ITransactionTraceListener> listener;
2043 SAFE_PARCEL(data.readStrongBinder, &listener);
2044
2045 return addTransactionTraceListener(listener);
2046 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002047 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002048 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002049 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002050 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002051}
2052
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002053} // namespace android