blob: c7c75dac9bf9a8223c66be023f1e843995aedd2b [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
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/IPCThreadState.h>
25#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiand0566bc2011-11-17 17:49:17 -080027#include <gui/IDisplayEventConnection.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080028#include <gui/IGraphicBufferProducer.h>
Dan Stoza84ab9372018-12-17 15:27:57 -080029#include <gui/IRegionSamplingListener.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080030#include <gui/ISurfaceComposer.h>
31#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080032#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070033#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080037#include <ui/DisplayConfig.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070039#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080040#include <ui/DisplayState.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070041#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Jamie Gennis134f0422011-03-08 12:18:54 -080043#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045// ---------------------------------------------------------------------------
46
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047namespace android {
48
Peiyong Lin9f034472018-03-28 15:29:00 -070049using ui::ColorMode;
50
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
52{
53public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070054 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 : BpInterface<ISurfaceComposer>(impl)
56 {
57 }
58
Dan Stozad723bd72014-11-18 10:24:03 -080059 virtual ~BpSurfaceComposer();
60
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 Parcel data, reply;
64 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
65 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070066 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 }
68
chaviw308ddba2020-08-11 16:23:51 -070069 virtual status_t setTransactionState(
70 const Vector<ComposerState>& state, const Vector<DisplayState>& displays,
71 uint32_t flags, const sp<IBinder>& applyToken, const InputWindowCommands& commands,
72 int64_t desiredPresentTime, const client_cache_t& uncacheBuffer,
73 bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080076
chaviw308ddba2020-08-11 16:23:51 -070077 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080078 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070079 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070080 }
Dan Stozad723bd72014-11-18 10:24:03 -080081
chaviw308ddba2020-08-11 16:23:51 -070082 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080083 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070084 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
chaviw308ddba2020-08-11 16:23:51 -070087 SAFE_PARCEL(data.writeUint32, flags);
88 SAFE_PARCEL(data.writeStrongBinder, applyToken);
89 SAFE_PARCEL(commands.write, data);
90 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
91 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
92 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
93 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070094
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
96 for (const auto& [listener, callbackIds] : listenerCallbacks) {
97 SAFE_PARCEL(data.writeStrongBinder, listener);
98 SAFE_PARCEL(data.writeInt64Vector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -070099 }
100
chaviw308ddba2020-08-11 16:23:51 -0700101 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 }
103
104 virtual void bootFinished()
105 {
106 Parcel data, reply;
107 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
108 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
109 }
110
chaviwd2432892020-07-24 17:42:39 -0700111 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700112 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800113 Parcel data, reply;
114 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700115 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700116 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000117
chaviw8ffc7b82020-08-18 11:25:37 -0700118 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800119 }
120
chaviwd2432892020-07-24 17:42:39 -0700121 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
chaviw8ffc7b82020-08-18 11:25:37 -0700122 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -0700123 Parcel data, reply;
124 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw8ffc7b82020-08-18 11:25:37 -0700125 SAFE_PARCEL(data.writeUint64, displayOrLayerStack);
126 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw93df2ea2019-04-30 16:45:12 -0700127
chaviw8ffc7b82020-08-18 11:25:37 -0700128 return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700129 }
130
chaviw3efadb12020-07-27 10:07:15 -0700131 virtual status_t captureLayers(const LayerCaptureArgs& args,
chaviw8ffc7b82020-08-18 11:25:37 -0700132 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -0700133 Parcel data, reply;
134 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(args.write, data);
chaviw8ffc7b82020-08-18 11:25:37 -0700136 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener));
chaviw3efadb12020-07-27 10:07:15 -0700137
chaviw8ffc7b82020-08-18 11:25:37 -0700138 return remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
chaviwa76b2712017-09-20 12:02:26 -0700139 }
140
Jamie Gennis582270d2011-08-17 18:19:00 -0700141 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800142 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800143 {
144 Parcel data, reply;
145 int err = NO_ERROR;
146 err = data.writeInterfaceToken(
147 ISurfaceComposer::getInterfaceDescriptor());
148 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000149 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800150 "interface descriptor: %s (%d)", strerror(-err), -err);
151 return false;
152 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800153 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800154 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000155 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700156 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800157 return false;
158 }
159 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
160 &reply);
161 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000162 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700163 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800164 return false;
165 }
166 int32_t result = 0;
167 err = reply.readInt32(&result);
168 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000169 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700170 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800171 return false;
172 }
173 return result != 0;
174 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800175
Brian Anderson6b376712017-04-04 10:51:39 -0700176 virtual status_t getSupportedFrameTimestamps(
177 std::vector<FrameEvent>* outSupported) const {
178 if (!outSupported) {
179 return UNEXPECTED_NULL;
180 }
181 outSupported->clear();
182
183 Parcel data, reply;
184
185 status_t err = data.writeInterfaceToken(
186 ISurfaceComposer::getInterfaceDescriptor());
187 if (err != NO_ERROR) {
188 return err;
189 }
190
191 err = remote()->transact(
192 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
193 data, &reply);
194 if (err != NO_ERROR) {
195 return err;
196 }
197
198 int32_t result = 0;
199 err = reply.readInt32(&result);
200 if (err != NO_ERROR) {
201 return err;
202 }
203 if (result != NO_ERROR) {
204 return result;
205 }
206
207 std::vector<int32_t> supported;
208 err = reply.readInt32Vector(&supported);
209 if (err != NO_ERROR) {
210 return err;
211 }
212
213 outSupported->reserve(supported.size());
214 for (int32_t s : supported) {
215 outSupported->push_back(static_cast<FrameEvent>(s));
216 }
217 return NO_ERROR;
218 }
219
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700220 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
221 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800222 Parcel data, reply;
223 sp<IDisplayEventConnection> result;
224 int err = data.writeInterfaceToken(
225 ISurfaceComposer::getInterfaceDescriptor());
226 if (err != NO_ERROR) {
227 return result;
228 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700229 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700230 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800231 err = remote()->transact(
232 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
233 data, &reply);
234 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000235 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800236 "transaction: %s (%d)", strerror(-err), -err);
237 return result;
238 }
239 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
240 return result;
241 }
Colin Cross8e533062012-06-07 13:17:52 -0700242
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700243 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700244 {
245 Parcel data, reply;
246 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd4a61642020-09-01 14:53:46 -0700247 status_t status = data.writeString8(displayName);
248 if (status) {
249 return nullptr;
250 }
251 status = data.writeBool(secure);
252 if (status) {
253 return nullptr;
254 }
255
256 status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
257 if (status) {
258 return nullptr;
259 }
260 sp<IBinder> display;
261 status = reply.readNullableStrongBinder(&display);
262 if (status) {
263 return nullptr;
264 }
265 return display;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700266 }
267
Jesse Hall6c913be2013-08-08 12:15:49 -0700268 virtual void destroyDisplay(const sp<IBinder>& display)
269 {
270 Parcel data, reply;
271 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
272 data.writeStrongBinder(display);
273 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
274 }
275
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800276 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700277 Parcel data, reply;
278 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800279 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
280 NO_ERROR) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200281 std::vector<uint64_t> rawIds;
282 if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
283 std::vector<PhysicalDisplayId> displayIds(rawIds.size());
284 std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
285 [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800286 return displayIds;
287 }
288 }
289
290 return {};
291 }
292
293 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
294 Parcel data, reply;
295 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Marin Shalamanova524a092020-07-27 21:39:55 +0200296 data.writeUint64(displayId.value);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800297 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700298 return reply.readStrongBinder();
299 }
300
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700301 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700302 {
303 Parcel data, reply;
304 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700305 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700306 data.writeInt32(mode);
307 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700308 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700309
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800310 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
311 Parcel data, reply;
312 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
313 data.writeStrongBinder(display);
314 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
315 const status_t result = reply.readInt32();
316 if (result == NO_ERROR) {
317 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
318 }
319 return result;
320 }
321
322 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
323 Parcel data, reply;
324 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
325 data.writeStrongBinder(display);
326 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
327 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100328 if (result != NO_ERROR) return result;
329 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800330 }
331
332 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700333 Parcel data, reply;
334 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700335 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700336 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800337 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700338 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800339 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700340 configs->clear();
341 configs->resize(numConfigs);
342 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800343 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
344 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700345 }
346 }
347 return result;
348 }
349
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700350 virtual status_t getDisplayStats(const sp<IBinder>& display,
351 DisplayStatInfo* stats)
352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
355 data.writeStrongBinder(display);
356 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
357 status_t result = reply.readInt32();
358 if (result == NO_ERROR) {
359 memcpy(stats,
360 reply.readInplace(sizeof(DisplayStatInfo)),
361 sizeof(DisplayStatInfo));
362 }
363 return result;
364 }
365
Dan Stoza7f7da322014-05-02 15:26:25 -0700366 virtual int getActiveConfig(const sp<IBinder>& display)
367 {
368 Parcel data, reply;
369 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
370 data.writeStrongBinder(display);
371 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
372 return reply.readInt32();
373 }
374
Michael Wright28f24d02016-07-12 13:30:53 -0700375 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700376 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700377 Parcel data, reply;
378 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
379 if (result != NO_ERROR) {
380 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
381 return result;
382 }
383 result = data.writeStrongBinder(display);
384 if (result != NO_ERROR) {
385 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
386 return result;
387 }
388 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
389 if (result != NO_ERROR) {
390 ALOGE("getDisplayColorModes failed to transact: %d", result);
391 return result;
392 }
393 result = static_cast<status_t>(reply.readInt32());
394 if (result == NO_ERROR) {
395 size_t numModes = reply.readUint32();
396 outColorModes->clear();
397 outColorModes->resize(numModes);
398 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700399 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700400 }
401 }
402 return result;
403 }
404
Daniel Solomon42d04562019-01-20 21:03:19 -0800405 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
406 ui::DisplayPrimaries& primaries) {
407 Parcel data, reply;
408 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
409 if (result != NO_ERROR) {
410 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
411 return result;
412 }
413 result = data.writeStrongBinder(display);
414 if (result != NO_ERROR) {
415 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
416 return result;
417 }
418 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
419 if (result != NO_ERROR) {
420 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
421 return result;
422 }
423 result = reply.readInt32();
424 if (result == NO_ERROR) {
425 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
426 sizeof(ui::DisplayPrimaries));
427 }
428 return result;
429 }
430
Peiyong Lina52f0292018-03-14 17:26:31 -0700431 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700432 Parcel data, reply;
433 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
434 if (result != NO_ERROR) {
435 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700436 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700437 }
438 result = data.writeStrongBinder(display);
439 if (result != NO_ERROR) {
440 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700441 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700442 }
443 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
444 if (result != NO_ERROR) {
445 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700446 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700447 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700448 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700449 }
450
451 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700452 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700453 Parcel data, reply;
454 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
455 if (result != NO_ERROR) {
456 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
457 return result;
458 }
459 result = data.writeStrongBinder(display);
460 if (result != NO_ERROR) {
461 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
462 return result;
463 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700464 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700465 if (result != NO_ERROR) {
466 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
467 return result;
468 }
469 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
470 if (result != NO_ERROR) {
471 ALOGE("setActiveColorMode failed to transact: %d", result);
472 return result;
473 }
474 return static_cast<status_t>(reply.readInt32());
475 }
476
Galia Peycheva5492cb52019-10-30 14:13:16 +0100477 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
478 bool* outSupport) const {
479 Parcel data, reply;
480 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
481 status_t result = data.writeStrongBinder(display);
482 if (result != NO_ERROR) {
483 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
484 return result;
485 }
486 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
487 &reply);
488 if (result != NO_ERROR) {
489 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
490 return result;
491 }
492 return reply.readBool(outSupport);
493 }
494
495 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
496 Parcel data, reply;
497 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
498 if (result != NO_ERROR) {
499 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
500 return;
501 }
502
503 result = data.writeStrongBinder(display);
504 if (result != NO_ERROR) {
505 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
506 return;
507 }
508 result = data.writeBool(on);
509 if (result != NO_ERROR) {
510 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
511 return;
512 }
513 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
514 if (result != NO_ERROR) {
515 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
516 return;
517 }
518 }
519
520 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
521 Parcel data, reply;
522 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
523 status_t result = data.writeStrongBinder(display);
524 if (result != NO_ERROR) {
525 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
526 return result;
527 }
528 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
529 if (result != NO_ERROR) {
530 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
531 return result;
532 }
533 return reply.readBool(outSupport);
534 }
535
536 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
537 Parcel data, reply;
538 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
539 if (result != NO_ERROR) {
540 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
541 return;
542 }
543 result = data.writeStrongBinder(display);
544 if (result != NO_ERROR) {
545 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
546 return;
547 }
548 result = data.writeBool(on);
549 if (result != NO_ERROR) {
550 ALOGE("setGameContentType failed to writeBool: %d", result);
551 return;
552 }
553 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
554 if (result != NO_ERROR) {
555 ALOGE("setGameContentType failed to transact: %d", result);
556 }
557 }
558
Svetoslavd85084b2014-03-20 10:28:31 -0700559 virtual status_t clearAnimationFrameStats() {
560 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700561 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
562 if (result != NO_ERROR) {
563 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
564 return result;
565 }
566 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
567 if (result != NO_ERROR) {
568 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
569 return result;
570 }
Svetoslavd85084b2014-03-20 10:28:31 -0700571 return reply.readInt32();
572 }
573
574 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
575 Parcel data, reply;
576 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
577 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
578 reply.read(*outStats);
579 return reply.readInt32();
580 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700581
582 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
583 HdrCapabilities* outCapabilities) const {
584 Parcel data, reply;
585 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
586 status_t result = data.writeStrongBinder(display);
587 if (result != NO_ERROR) {
588 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
589 return result;
590 }
591 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
592 data, &reply);
593 if (result != NO_ERROR) {
594 ALOGE("getHdrCapabilities failed to transact: %d", result);
595 return result;
596 }
597 result = reply.readInt32();
598 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800599 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700600 }
601 return result;
602 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700603
604 virtual status_t enableVSyncInjections(bool enable) {
605 Parcel data, reply;
606 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
607 if (result != NO_ERROR) {
608 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
609 return result;
610 }
611 result = data.writeBool(enable);
612 if (result != NO_ERROR) {
613 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
614 return result;
615 }
Steven Moreland366eb422019-04-01 19:22:32 -0700616 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
617 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700618 if (result != NO_ERROR) {
619 ALOGE("enableVSyncInjections failed to transact: %d", result);
620 return result;
621 }
622 return result;
623 }
624
625 virtual status_t injectVSync(nsecs_t when) {
626 Parcel data, reply;
627 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
628 if (result != NO_ERROR) {
629 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
630 return result;
631 }
632 result = data.writeInt64(when);
633 if (result != NO_ERROR) {
634 ALOGE("injectVSync failed to writeInt64: %d", result);
635 return result;
636 }
Steven Moreland366eb422019-04-01 19:22:32 -0700637 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
638 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700639 if (result != NO_ERROR) {
640 ALOGE("injectVSync failed to transact: %d", result);
641 return result;
642 }
643 return result;
644 }
645
Vishnu Nair43bccf82020-06-05 10:53:37 -0700646 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800647 if (!outLayers) {
648 return UNEXPECTED_NULL;
649 }
650
651 Parcel data, reply;
652
653 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
654 if (err != NO_ERROR) {
655 return err;
656 }
657
658 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
659 if (err != NO_ERROR) {
660 return err;
661 }
662
663 int32_t result = 0;
664 err = reply.readInt32(&result);
665 if (err != NO_ERROR) {
666 return err;
667 }
668 if (result != NO_ERROR) {
669 return result;
670 }
671
672 outLayers->clear();
673 return reply.readParcelableVector(outLayers);
674 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700675
Peiyong Linc6780972018-10-28 15:24:08 -0700676 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
677 ui::PixelFormat* defaultPixelFormat,
678 ui::Dataspace* wideColorGamutDataspace,
679 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700680 Parcel data, reply;
681 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
682 if (error != NO_ERROR) {
683 return error;
684 }
685 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
686 if (error != NO_ERROR) {
687 return error;
688 }
689 error = static_cast<status_t>(reply.readInt32());
690 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700691 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
692 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
693 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
694 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700695 }
696 return error;
697 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700698
Ady Abraham37965d42018-11-01 13:43:32 -0700699 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700700 Parcel data, reply;
701 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700702 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
703 bool result;
704 status_t err = reply.readBool(&result);
705 if (err == NO_ERROR) {
706 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700707 }
Ady Abraham37965d42018-11-01 13:43:32 -0700708 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700709 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700710
711 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
712 ui::PixelFormat* outFormat,
713 ui::Dataspace* outDataspace,
714 uint8_t* outComponentMask) const {
715 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
716 Parcel data, reply;
717 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
718 data.writeStrongBinder(display);
719
720 status_t error =
721 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
722 data, &reply);
723 if (error != NO_ERROR) {
724 return error;
725 }
726
727 uint32_t value = 0;
728 error = reply.readUint32(&value);
729 if (error != NO_ERROR) {
730 return error;
731 }
732 *outFormat = static_cast<ui::PixelFormat>(value);
733
734 error = reply.readUint32(&value);
735 if (error != NO_ERROR) {
736 return error;
737 }
738 *outDataspace = static_cast<ui::Dataspace>(value);
739
740 error = reply.readUint32(&value);
741 if (error != NO_ERROR) {
742 return error;
743 }
744 *outComponentMask = static_cast<uint8_t>(value);
745 return error;
746 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800747
748 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700749 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800750 Parcel data, reply;
751 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
752 data.writeStrongBinder(display);
753 data.writeBool(enable);
754 data.writeByte(static_cast<int8_t>(componentMask));
755 data.writeUint64(maxFrames);
756 status_t result =
757 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
758 &reply);
759 return result;
760 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700761
762 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
763 uint64_t timestamp,
764 DisplayedFrameStats* outStats) const {
765 if (!outStats) return BAD_VALUE;
766
767 Parcel data, reply;
768 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
769 data.writeStrongBinder(display);
770 data.writeUint64(maxFrames);
771 data.writeUint64(timestamp);
772
773 status_t result =
774 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
775
776 if (result != NO_ERROR) {
777 return result;
778 }
779
780 result = reply.readUint64(&outStats->numFrames);
781 if (result != NO_ERROR) {
782 return result;
783 }
784
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800785 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700786 if (result != NO_ERROR) {
787 return result;
788 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800789 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700790 if (result != NO_ERROR) {
791 return result;
792 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800793 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700794 if (result != NO_ERROR) {
795 return result;
796 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800797 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700798 return result;
799 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800800
801 virtual status_t getProtectedContentSupport(bool* outSupported) const {
802 Parcel data, reply;
803 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800804 status_t error =
805 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
806 if (error != NO_ERROR) {
807 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800808 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800809 error = reply.readBool(outSupported);
810 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800811 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800812
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800813 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
814 bool* outIsWideColorDisplay) const {
815 Parcel data, reply;
816 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
817 if (error != NO_ERROR) {
818 return error;
819 }
820 error = data.writeStrongBinder(token);
821 if (error != NO_ERROR) {
822 return error;
823 }
824
825 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
826 if (error != NO_ERROR) {
827 return error;
828 }
829 error = reply.readBool(outIsWideColorDisplay);
830 return error;
831 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800832
833 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
834 const sp<IBinder>& stopLayerHandle,
835 const sp<IRegionSamplingListener>& listener) {
836 Parcel data, reply;
837 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
838 if (error != NO_ERROR) {
839 ALOGE("addRegionSamplingListener: Failed to write interface token");
840 return error;
841 }
842 error = data.write(samplingArea);
843 if (error != NO_ERROR) {
844 ALOGE("addRegionSamplingListener: Failed to write sampling area");
845 return error;
846 }
847 error = data.writeStrongBinder(stopLayerHandle);
848 if (error != NO_ERROR) {
849 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
850 return error;
851 }
852 error = data.writeStrongBinder(IInterface::asBinder(listener));
853 if (error != NO_ERROR) {
854 ALOGE("addRegionSamplingListener: Failed to write listener");
855 return error;
856 }
857 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
858 if (error != NO_ERROR) {
859 ALOGE("addRegionSamplingListener: Failed to transact");
860 }
861 return error;
862 }
863
864 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
865 Parcel data, reply;
866 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
867 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800868 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800869 return error;
870 }
871 error = data.writeStrongBinder(IInterface::asBinder(listener));
872 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800873 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800874 return error;
875 }
876 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
877 &reply);
878 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800879 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800880 }
881 return error;
882 }
Ady Abraham838de062019-02-04 10:24:03 -0800883
Ana Krulec0782b882019-10-15 17:34:54 -0700884 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700885 int32_t defaultConfig,
886 float primaryRefreshRateMin,
887 float primaryRefreshRateMax,
888 float appRequestRefreshRateMin,
889 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700890 Parcel data, reply;
891 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
892 if (result != NO_ERROR) {
893 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
894 return result;
895 }
896 result = data.writeStrongBinder(displayToken);
897 if (result != NO_ERROR) {
898 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
899 return result;
900 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100901 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700902 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100903 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700904 return result;
905 }
Steven Thomasf734df42020-04-13 21:09:28 -0700906 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700907 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700908 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700909 return result;
910 }
Steven Thomasf734df42020-04-13 21:09:28 -0700911 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700912 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700913 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
914 return result;
915 }
916 result = data.writeFloat(appRequestRefreshRateMin);
917 if (result != NO_ERROR) {
918 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
919 result);
920 return result;
921 }
922 result = data.writeFloat(appRequestRefreshRateMax);
923 if (result != NO_ERROR) {
924 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
925 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700926 return result;
927 }
928
929 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
930 &reply);
931 if (result != NO_ERROR) {
932 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
933 return result;
934 }
935 return reply.readInt32();
936 }
937
Ana Krulec234bb162019-11-10 22:55:55 +0100938 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100939 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700940 float* outPrimaryRefreshRateMin,
941 float* outPrimaryRefreshRateMax,
942 float* outAppRequestRefreshRateMin,
943 float* outAppRequestRefreshRateMax) {
944 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
945 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
946 return BAD_VALUE;
947 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800948 Parcel data, reply;
949 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
950 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100951 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800952 return result;
953 }
954 result = data.writeStrongBinder(displayToken);
955 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100956 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800957 return result;
958 }
Ana Krulec234bb162019-11-10 22:55:55 +0100959 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
960 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800961 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100962 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800963 return result;
964 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100965 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800966 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100967 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100968 return result;
969 }
Steven Thomasf734df42020-04-13 21:09:28 -0700970 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +0100971 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700972 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100973 return result;
974 }
Steven Thomasf734df42020-04-13 21:09:28 -0700975 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +0100976 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700977 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
978 return result;
979 }
980 result = reply.readFloat(outAppRequestRefreshRateMin);
981 if (result != NO_ERROR) {
982 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
983 result);
984 return result;
985 }
986 result = reply.readFloat(outAppRequestRefreshRateMax);
987 if (result != NO_ERROR) {
988 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
989 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800990 return result;
991 }
992 return reply.readInt32();
993 }
Dan Gittik57e63c52019-01-18 16:37:54 +0000994
995 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
996 bool* outSupport) const {
997 Parcel data, reply;
998 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
999 if (error != NO_ERROR) {
1000 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1001 return error;
1002 }
1003 error = data.writeStrongBinder(displayToken);
1004 if (error != NO_ERROR) {
1005 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1006 return error;
1007 }
1008 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1009 if (error != NO_ERROR) {
1010 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1011 return error;
1012 }
1013 bool support;
1014 error = reply.readBool(&support);
1015 if (error != NO_ERROR) {
1016 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1017 return error;
1018 }
1019 *outSupport = support;
1020 return NO_ERROR;
1021 }
1022
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001023 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001024 Parcel data, reply;
1025 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1026 if (error != NO_ERROR) {
1027 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1028 return error;
1029 }
1030 error = data.writeStrongBinder(displayToken);
1031 if (error != NO_ERROR) {
1032 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1033 return error;
1034 }
1035 error = data.writeFloat(brightness);
1036 if (error != NO_ERROR) {
1037 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1038 return error;
1039 }
1040 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1041 if (error != NO_ERROR) {
1042 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1043 return error;
1044 }
1045 return NO_ERROR;
1046 }
Ady Abraham8532d012019-05-08 14:50:56 -07001047
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001048 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001049 Parcel data, reply;
1050 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1051 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001052 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001053 return error;
1054 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001055 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001056 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001057 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001058 return error;
1059 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001060 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001061 IBinder::FLAG_ONEWAY);
1062 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001063 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001064 return error;
1065 }
1066 return NO_ERROR;
1067 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001068
1069 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1070 float lightPosY, float lightPosZ, float lightRadius) {
1071 Parcel data, reply;
1072 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1073 if (error != NO_ERROR) {
1074 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1075 return error;
1076 }
1077
1078 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1079 ambientColor.a, spotColor.r, spotColor.g,
1080 spotColor.b, spotColor.a, lightPosY,
1081 lightPosZ, lightRadius};
1082
1083 error = data.writeFloatVector(shadowConfig);
1084 if (error != NO_ERROR) {
1085 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1086 return error;
1087 }
1088
1089 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1090 IBinder::FLAG_ONEWAY);
1091 if (error != NO_ERROR) {
1092 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1093 return error;
1094 }
1095 return NO_ERROR;
1096 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001097
1098 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1099 int8_t compatibility) {
1100 Parcel data, reply;
1101 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1102 if (err != NO_ERROR) {
1103 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1104 return err;
1105 }
1106
1107 err = data.writeStrongBinder(IInterface::asBinder(surface));
1108 if (err != NO_ERROR) {
1109 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1110 return err;
1111 }
1112
1113 err = data.writeFloat(frameRate);
1114 if (err != NO_ERROR) {
1115 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1116 return err;
1117 }
1118
1119 err = data.writeByte(compatibility);
1120 if (err != NO_ERROR) {
1121 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1122 return err;
1123 }
1124
Ady Abraham60e42ea2020-03-09 19:17:31 -07001125 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001126 if (err != NO_ERROR) {
1127 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1128 return err;
1129 }
Steven Thomasd4071902020-03-24 16:02:53 -07001130
1131 return reply.readInt32();
1132 }
1133
1134 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1135 if (!outToken) return BAD_VALUE;
1136
1137 Parcel data, reply;
1138 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1139 if (err != NO_ERROR) {
1140 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1141 strerror(-err), -err);
1142 return err;
1143 }
1144
1145 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1146 &reply);
1147 if (err != NO_ERROR) {
1148 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1149 err);
1150 return err;
1151 }
1152
1153 err = reply.readInt32();
1154 if (err != NO_ERROR) {
1155 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1156 return err;
1157 }
1158
1159 err = reply.readStrongBinder(outToken);
1160 if (err != NO_ERROR) {
1161 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1162 strerror(-err), err);
1163 return err;
1164 }
1165
Steven Thomas62a4cf82020-01-31 12:04:03 -08001166 return NO_ERROR;
1167 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001168};
1169
Dan Stozad723bd72014-11-18 10:24:03 -08001170// Out-of-line virtual method definition to trigger vtable emission in this
1171// translation unit (see clang warning -Wweak-vtables)
1172BpSurfaceComposer::~BpSurfaceComposer() {}
1173
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001174IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1175
1176// ----------------------------------------------------------------------
1177
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001178status_t BnSurfaceComposer::onTransact(
1179 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1180{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001181 switch(code) {
1182 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001183 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001184 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001185 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001186 return NO_ERROR;
1187 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001188 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001189 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001190
chaviw308ddba2020-08-11 16:23:51 -07001191 uint32_t count = 0;
1192 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -07001193 Vector<ComposerState> state;
1194 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001195 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001196 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -07001197 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -07001198 state.add(s);
1199 }
Dan Stozad723bd72014-11-18 10:24:03 -08001200
chaviw308ddba2020-08-11 16:23:51 -07001201 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -07001202 DisplayState d;
1203 Vector<DisplayState> displays;
1204 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001205 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001206 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -07001207 displays.add(d);
1208 }
Dan Stozad723bd72014-11-18 10:24:03 -08001209
chaviw308ddba2020-08-11 16:23:51 -07001210 uint32_t stateFlags = 0;
1211 SAFE_PARCEL(data.readUint32, &stateFlags);
1212 sp<IBinder> applyToken;
1213 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -08001214 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -07001215 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001216
chaviw308ddba2020-08-11 16:23:51 -07001217 int64_t desiredPresentTime = 0;
1218 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Marissa Wall78b72202019-03-15 14:58:34 -07001219
Marissa Wall947d34e2019-03-29 14:03:53 -07001220 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -07001221 sp<IBinder> tmpBinder;
1222 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
1223 uncachedBuffer.token = tmpBinder;
1224 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -07001225
chaviw308ddba2020-08-11 16:23:51 -07001226 bool hasListenerCallbacks = false;
1227 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -07001228
Marissa Wall3dad52d2019-03-22 14:03:19 -07001229 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -07001230 int32_t listenersSize = 0;
1231 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -07001232 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -07001233 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001234 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -07001235 SAFE_PARCEL(data.readInt64Vector, &callbackIds);
1236 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -07001237 }
chaviw308ddba2020-08-11 16:23:51 -07001238 return setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
1239 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1240 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001241 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001242 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001243 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001244 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001245 return NO_ERROR;
1246 }
chaviwd2432892020-07-24 17:42:39 -07001247 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001248 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001249 DisplayCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001250 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001251 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001252 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1253
1254 return captureDisplay(args, captureListener);
Jesse Hall6c913be2013-08-08 12:15:49 -07001255 }
chaviwd2432892020-07-24 17:42:39 -07001256 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001257 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw308ddba2020-08-11 16:23:51 -07001258 uint64_t displayOrLayerStack = 0;
chaviw8ffc7b82020-08-18 11:25:37 -07001259 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001260 SAFE_PARCEL(data.readUint64, &displayOrLayerStack);
chaviw8ffc7b82020-08-18 11:25:37 -07001261 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1262
1263 return captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07001264 }
chaviwa76b2712017-09-20 12:02:26 -07001265 case CAPTURE_LAYERS: {
1266 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001267 LayerCaptureArgs args;
chaviw8ffc7b82020-08-18 11:25:37 -07001268 sp<IScreenCaptureListener> captureListener;
chaviw308ddba2020-08-11 16:23:51 -07001269 SAFE_PARCEL(args.read, data);
chaviw8ffc7b82020-08-18 11:25:37 -07001270 SAFE_PARCEL(data.readStrongBinder, &captureListener);
1271
1272 return captureLayers(args, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07001273 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001274 case AUTHENTICATE_SURFACE: {
1275 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001276 sp<IGraphicBufferProducer> bufferProducer =
1277 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1278 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001279 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001280 return NO_ERROR;
1281 }
Brian Anderson6b376712017-04-04 10:51:39 -07001282 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1283 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1284 std::vector<FrameEvent> supportedTimestamps;
1285 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1286 status_t err = reply->writeInt32(result);
1287 if (err != NO_ERROR) {
1288 return err;
1289 }
1290 if (result != NO_ERROR) {
1291 return result;
1292 }
1293
1294 std::vector<int32_t> supported;
1295 supported.reserve(supportedTimestamps.size());
1296 for (FrameEvent s : supportedTimestamps) {
1297 supported.push_back(static_cast<int32_t>(s));
1298 }
1299 return reply->writeInt32Vector(supported);
1300 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001301 case CREATE_DISPLAY_EVENT_CONNECTION: {
1302 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001303 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1304 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1305
1306 sp<IDisplayEventConnection> connection(
1307 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001308 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001309 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001310 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001311 case CREATE_DISPLAY: {
1312 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd4a61642020-09-01 14:53:46 -07001313 String8 displayName;
1314 SAFE_PARCEL(data.readString8, &displayName);
1315 bool secure = false;
1316 SAFE_PARCEL(data.readBool, &secure);
1317 sp<IBinder> display = createDisplay(displayName, secure);
1318 SAFE_PARCEL(reply->writeStrongBinder, display);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001319 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001320 }
1321 case DESTROY_DISPLAY: {
1322 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1323 sp<IBinder> display = data.readStrongBinder();
1324 destroyDisplay(display);
1325 return NO_ERROR;
1326 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001327 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001328 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001329 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001330 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001331 reply->writeStrongBinder(display);
1332 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001333 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001334 case GET_DISPLAY_STATE: {
1335 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1336 ui::DisplayState state;
1337 const sp<IBinder> display = data.readStrongBinder();
1338 const status_t result = getDisplayState(display, &state);
1339 reply->writeInt32(result);
1340 if (result == NO_ERROR) {
1341 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1342 sizeof(ui::DisplayState));
1343 }
1344 return NO_ERROR;
1345 }
1346 case GET_DISPLAY_INFO: {
1347 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1348 DisplayInfo info;
1349 const sp<IBinder> display = data.readStrongBinder();
1350 const status_t result = getDisplayInfo(display, &info);
1351 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001352 if (result != NO_ERROR) return result;
1353 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001354 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001355 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001357 Vector<DisplayConfig> configs;
1358 const sp<IBinder> display = data.readStrongBinder();
1359 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001360 reply->writeInt32(result);
1361 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001362 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001363 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001364 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1365 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001366 }
1367 }
1368 return NO_ERROR;
1369 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001370 case GET_DISPLAY_STATS: {
1371 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1372 DisplayStatInfo stats;
1373 sp<IBinder> display = data.readStrongBinder();
1374 status_t result = getDisplayStats(display, &stats);
1375 reply->writeInt32(result);
1376 if (result == NO_ERROR) {
1377 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1378 &stats, sizeof(DisplayStatInfo));
1379 }
1380 return NO_ERROR;
1381 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001382 case GET_ACTIVE_CONFIG: {
1383 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1384 sp<IBinder> display = data.readStrongBinder();
1385 int id = getActiveConfig(display);
1386 reply->writeInt32(id);
1387 return NO_ERROR;
1388 }
Michael Wright28f24d02016-07-12 13:30:53 -07001389 case GET_DISPLAY_COLOR_MODES: {
1390 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001391 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001392 sp<IBinder> display = nullptr;
1393 status_t result = data.readStrongBinder(&display);
1394 if (result != NO_ERROR) {
1395 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1396 return result;
1397 }
1398 result = getDisplayColorModes(display, &colorModes);
1399 reply->writeInt32(result);
1400 if (result == NO_ERROR) {
1401 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1402 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001403 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001404 }
1405 }
1406 return NO_ERROR;
1407 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001408 case GET_DISPLAY_NATIVE_PRIMARIES: {
1409 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1410 ui::DisplayPrimaries primaries;
1411 sp<IBinder> display = nullptr;
1412
1413 status_t result = data.readStrongBinder(&display);
1414 if (result != NO_ERROR) {
1415 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1416 return result;
1417 }
1418
1419 result = getDisplayNativePrimaries(display, primaries);
1420 reply->writeInt32(result);
1421 if (result == NO_ERROR) {
1422 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1423 sizeof(ui::DisplayPrimaries));
1424 }
1425
1426 return NO_ERROR;
1427 }
Michael Wright28f24d02016-07-12 13:30:53 -07001428 case GET_ACTIVE_COLOR_MODE: {
1429 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1430 sp<IBinder> display = nullptr;
1431 status_t result = data.readStrongBinder(&display);
1432 if (result != NO_ERROR) {
1433 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1434 return result;
1435 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001436 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001437 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1438 return result;
1439 }
1440 case SET_ACTIVE_COLOR_MODE: {
1441 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1442 sp<IBinder> display = nullptr;
1443 status_t result = data.readStrongBinder(&display);
1444 if (result != NO_ERROR) {
1445 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1446 return result;
1447 }
1448 int32_t colorModeInt = 0;
1449 result = data.readInt32(&colorModeInt);
1450 if (result != NO_ERROR) {
1451 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1452 return result;
1453 }
1454 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001455 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001456 result = reply->writeInt32(result);
1457 return result;
1458 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001459
1460 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1461 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1462 sp<IBinder> display = nullptr;
1463 status_t result = data.readStrongBinder(&display);
1464 if (result != NO_ERROR) {
1465 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1466 return result;
1467 }
1468 bool supported = false;
1469 result = getAutoLowLatencyModeSupport(display, &supported);
1470 if (result == NO_ERROR) {
1471 result = reply->writeBool(supported);
1472 }
1473 return result;
1474 }
1475
1476 case SET_AUTO_LOW_LATENCY_MODE: {
1477 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1478 sp<IBinder> display = nullptr;
1479 status_t result = data.readStrongBinder(&display);
1480 if (result != NO_ERROR) {
1481 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1482 return result;
1483 }
1484 bool setAllm = false;
1485 result = data.readBool(&setAllm);
1486 if (result != NO_ERROR) {
1487 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1488 return result;
1489 }
1490 setAutoLowLatencyMode(display, setAllm);
1491 return result;
1492 }
1493
1494 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1495 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1496 sp<IBinder> display = nullptr;
1497 status_t result = data.readStrongBinder(&display);
1498 if (result != NO_ERROR) {
1499 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1500 return result;
1501 }
1502 bool supported = false;
1503 result = getGameContentTypeSupport(display, &supported);
1504 if (result == NO_ERROR) {
1505 result = reply->writeBool(supported);
1506 }
1507 return result;
1508 }
1509
1510 case SET_GAME_CONTENT_TYPE: {
1511 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1512 sp<IBinder> display = nullptr;
1513 status_t result = data.readStrongBinder(&display);
1514 if (result != NO_ERROR) {
1515 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1516 return result;
1517 }
1518 bool setGameContentTypeOn = false;
1519 result = data.readBool(&setGameContentTypeOn);
1520 if (result != NO_ERROR) {
1521 ALOGE("setGameContentType failed to readBool: %d", result);
1522 return result;
1523 }
1524 setGameContentType(display, setGameContentTypeOn);
1525 return result;
1526 }
1527
Svetoslavd85084b2014-03-20 10:28:31 -07001528 case CLEAR_ANIMATION_FRAME_STATS: {
1529 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1530 status_t result = clearAnimationFrameStats();
1531 reply->writeInt32(result);
1532 return NO_ERROR;
1533 }
1534 case GET_ANIMATION_FRAME_STATS: {
1535 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1536 FrameStats stats;
1537 status_t result = getAnimationFrameStats(&stats);
1538 reply->write(stats);
1539 reply->writeInt32(result);
1540 return NO_ERROR;
1541 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001542 case SET_POWER_MODE: {
1543 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1544 sp<IBinder> display = data.readStrongBinder();
1545 int32_t mode = data.readInt32();
1546 setPowerMode(display, mode);
1547 return NO_ERROR;
1548 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001549 case GET_HDR_CAPABILITIES: {
1550 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1551 sp<IBinder> display = nullptr;
1552 status_t result = data.readStrongBinder(&display);
1553 if (result != NO_ERROR) {
1554 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1555 result);
1556 return result;
1557 }
1558 HdrCapabilities capabilities;
1559 result = getHdrCapabilities(display, &capabilities);
1560 reply->writeInt32(result);
1561 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001562 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001563 }
1564 return NO_ERROR;
1565 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001566 case ENABLE_VSYNC_INJECTIONS: {
1567 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1568 bool enable = false;
1569 status_t result = data.readBool(&enable);
1570 if (result != NO_ERROR) {
1571 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1572 return result;
1573 }
1574 return enableVSyncInjections(enable);
1575 }
1576 case INJECT_VSYNC: {
1577 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1578 int64_t when = 0;
1579 status_t result = data.readInt64(&when);
1580 if (result != NO_ERROR) {
1581 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1582 return result;
1583 }
1584 return injectVSync(when);
1585 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001586 case GET_LAYER_DEBUG_INFO: {
1587 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1588 std::vector<LayerDebugInfo> outLayers;
1589 status_t result = getLayerDebugInfo(&outLayers);
1590 reply->writeInt32(result);
1591 if (result == NO_ERROR)
1592 {
1593 result = reply->writeParcelableVector(outLayers);
1594 }
1595 return result;
1596 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001597 case GET_COMPOSITION_PREFERENCE: {
1598 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001599 ui::Dataspace defaultDataspace;
1600 ui::PixelFormat defaultPixelFormat;
1601 ui::Dataspace wideColorGamutDataspace;
1602 ui::PixelFormat wideColorGamutPixelFormat;
1603 status_t error =
1604 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1605 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001606 reply->writeInt32(error);
1607 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001608 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1609 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1610 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001611 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001612 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001613 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001614 }
Ady Abraham37965d42018-11-01 13:43:32 -07001615 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001616 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001617 bool result;
1618 status_t error = getColorManagement(&result);
1619 if (error == NO_ERROR) {
1620 reply->writeBool(result);
1621 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001622 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001623 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001624 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1625 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1626
1627 sp<IBinder> display = data.readStrongBinder();
1628 ui::PixelFormat format;
1629 ui::Dataspace dataspace;
1630 uint8_t component = 0;
1631 auto result =
1632 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1633 if (result == NO_ERROR) {
1634 reply->writeUint32(static_cast<uint32_t>(format));
1635 reply->writeUint32(static_cast<uint32_t>(dataspace));
1636 reply->writeUint32(static_cast<uint32_t>(component));
1637 }
1638 return result;
1639 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001640 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1641 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1642
1643 sp<IBinder> display = nullptr;
1644 bool enable = false;
1645 int8_t componentMask = 0;
1646 uint64_t maxFrames = 0;
1647 status_t result = data.readStrongBinder(&display);
1648 if (result != NO_ERROR) {
1649 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1650 result);
1651 return result;
1652 }
1653
1654 result = data.readBool(&enable);
1655 if (result != NO_ERROR) {
1656 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1657 return result;
1658 }
1659
1660 result = data.readByte(static_cast<int8_t*>(&componentMask));
1661 if (result != NO_ERROR) {
1662 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1663 result);
1664 return result;
1665 }
1666
1667 result = data.readUint64(&maxFrames);
1668 if (result != NO_ERROR) {
1669 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1670 return result;
1671 }
1672
1673 return setDisplayContentSamplingEnabled(display, enable,
1674 static_cast<uint8_t>(componentMask), maxFrames);
1675 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001676 case GET_DISPLAYED_CONTENT_SAMPLE: {
1677 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1678
1679 sp<IBinder> display = data.readStrongBinder();
1680 uint64_t maxFrames = 0;
1681 uint64_t timestamp = 0;
1682
1683 status_t result = data.readUint64(&maxFrames);
1684 if (result != NO_ERROR) {
1685 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1686 return result;
1687 }
1688
1689 result = data.readUint64(&timestamp);
1690 if (result != NO_ERROR) {
1691 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1692 return result;
1693 }
1694
1695 DisplayedFrameStats stats;
1696 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1697 if (result == NO_ERROR) {
1698 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001699 reply->writeUint64Vector(stats.component_0_sample);
1700 reply->writeUint64Vector(stats.component_1_sample);
1701 reply->writeUint64Vector(stats.component_2_sample);
1702 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001703 }
1704 return result;
1705 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001706 case GET_PROTECTED_CONTENT_SUPPORT: {
1707 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1708 bool result;
1709 status_t error = getProtectedContentSupport(&result);
1710 if (error == NO_ERROR) {
1711 reply->writeBool(result);
1712 }
1713 return error;
1714 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001715 case IS_WIDE_COLOR_DISPLAY: {
1716 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1717 sp<IBinder> display = nullptr;
1718 status_t error = data.readStrongBinder(&display);
1719 if (error != NO_ERROR) {
1720 return error;
1721 }
1722 bool result;
1723 error = isWideColorDisplay(display, &result);
1724 if (error == NO_ERROR) {
1725 reply->writeBool(result);
1726 }
1727 return error;
1728 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001729 case GET_PHYSICAL_DISPLAY_IDS: {
1730 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001731 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1732 std::vector<uint64_t> rawIds(ids.size());
1733 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1734 [](PhysicalDisplayId id) { return id.value; });
1735 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001736 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001737 case ADD_REGION_SAMPLING_LISTENER: {
1738 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1739 Rect samplingArea;
1740 status_t result = data.read(samplingArea);
1741 if (result != NO_ERROR) {
1742 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1743 return result;
1744 }
1745 sp<IBinder> stopLayerHandle;
1746 result = data.readNullableStrongBinder(&stopLayerHandle);
1747 if (result != NO_ERROR) {
1748 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1749 return result;
1750 }
1751 sp<IRegionSamplingListener> listener;
1752 result = data.readNullableStrongBinder(&listener);
1753 if (result != NO_ERROR) {
1754 ALOGE("addRegionSamplingListener: Failed to read listener");
1755 return result;
1756 }
1757 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1758 }
1759 case REMOVE_REGION_SAMPLING_LISTENER: {
1760 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1761 sp<IRegionSamplingListener> listener;
1762 status_t result = data.readNullableStrongBinder(&listener);
1763 if (result != NO_ERROR) {
1764 ALOGE("removeRegionSamplingListener: Failed to read listener");
1765 return result;
1766 }
1767 return removeRegionSamplingListener(listener);
1768 }
Ana Krulec0782b882019-10-15 17:34:54 -07001769 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1770 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1771 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001772 int32_t defaultConfig;
1773 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001774 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001775 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001776 return result;
1777 }
Steven Thomasf734df42020-04-13 21:09:28 -07001778 float primaryRefreshRateMin;
1779 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001780 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001781 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1782 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001783 return result;
1784 }
Steven Thomasf734df42020-04-13 21:09:28 -07001785 float primaryRefreshRateMax;
1786 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001787 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001788 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1789 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001790 return result;
1791 }
Steven Thomasf734df42020-04-13 21:09:28 -07001792 float appRequestRefreshRateMin;
1793 result = data.readFloat(&appRequestRefreshRateMin);
1794 if (result != NO_ERROR) {
1795 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1796 result);
1797 return result;
1798 }
1799 float appRequestRefreshRateMax;
1800 result = data.readFloat(&appRequestRefreshRateMax);
1801 if (result != NO_ERROR) {
1802 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1803 result);
1804 return result;
1805 }
1806 result =
1807 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1808 primaryRefreshRateMax, appRequestRefreshRateMin,
1809 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001810 if (result != NO_ERROR) {
1811 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1812 "%d",
1813 result);
1814 return result;
1815 }
1816 reply->writeInt32(result);
1817 return result;
1818 }
Ana Krulec234bb162019-11-10 22:55:55 +01001819 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1820 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1821 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001822 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001823 float primaryRefreshRateMin;
1824 float primaryRefreshRateMax;
1825 float appRequestRefreshRateMin;
1826 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001827
Steven Thomasf734df42020-04-13 21:09:28 -07001828 status_t result =
1829 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1830 &primaryRefreshRateMin, &primaryRefreshRateMax,
1831 &appRequestRefreshRateMin,
1832 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001833 if (result != NO_ERROR) {
1834 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1835 "%d",
1836 result);
1837 return result;
1838 }
1839
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001840 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001841 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001842 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001843 return result;
1844 }
Steven Thomasf734df42020-04-13 21:09:28 -07001845 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001846 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001847 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1848 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001849 return result;
1850 }
Steven Thomasf734df42020-04-13 21:09:28 -07001851 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001852 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001853 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1854 result);
1855 return result;
1856 }
1857 result = reply->writeFloat(appRequestRefreshRateMin);
1858 if (result != NO_ERROR) {
1859 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1860 result);
1861 return result;
1862 }
1863 result = reply->writeFloat(appRequestRefreshRateMax);
1864 if (result != NO_ERROR) {
1865 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1866 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001867 return result;
1868 }
1869 reply->writeInt32(result);
1870 return result;
1871 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001872 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1873 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1874 sp<IBinder> displayToken;
1875 status_t error = data.readNullableStrongBinder(&displayToken);
1876 if (error != NO_ERROR) {
1877 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1878 return error;
1879 }
1880 bool support = false;
1881 error = getDisplayBrightnessSupport(displayToken, &support);
1882 reply->writeBool(support);
1883 return error;
1884 }
1885 case SET_DISPLAY_BRIGHTNESS: {
1886 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1887 sp<IBinder> displayToken;
1888 status_t error = data.readNullableStrongBinder(&displayToken);
1889 if (error != NO_ERROR) {
1890 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1891 return error;
1892 }
1893 float brightness = -1.0f;
1894 error = data.readFloat(&brightness);
1895 if (error != NO_ERROR) {
1896 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1897 return error;
1898 }
1899 return setDisplayBrightness(displayToken, brightness);
1900 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001901 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001902 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001903 int32_t boostId;
1904 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001905 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001906 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001907 return error;
1908 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001909 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001910 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001911 case SET_GLOBAL_SHADOW_SETTINGS: {
1912 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1913
1914 std::vector<float> shadowConfig;
1915 status_t error = data.readFloatVector(&shadowConfig);
1916 if (error != NO_ERROR || shadowConfig.size() != 11) {
1917 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1918 return error;
1919 }
1920
1921 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1922 shadowConfig[3]};
1923 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1924 float lightPosY = shadowConfig[8];
1925 float lightPosZ = shadowConfig[9];
1926 float lightRadius = shadowConfig[10];
1927 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1928 lightRadius);
1929 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001930 case SET_FRAME_RATE: {
1931 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1932 sp<IBinder> binder;
1933 status_t err = data.readStrongBinder(&binder);
1934 if (err != NO_ERROR) {
1935 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1936 return err;
1937 }
1938 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1939 if (!surface) {
1940 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1941 strerror(-err), -err);
1942 return err;
1943 }
1944 float frameRate;
1945 err = data.readFloat(&frameRate);
1946 if (err != NO_ERROR) {
1947 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
1948 return err;
1949 }
1950 int8_t compatibility;
1951 err = data.readByte(&compatibility);
1952 if (err != NO_ERROR) {
1953 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
1954 return err;
1955 }
1956 status_t result = setFrameRate(surface, frameRate, compatibility);
1957 reply->writeInt32(result);
1958 return NO_ERROR;
1959 }
Steven Thomasd4071902020-03-24 16:02:53 -07001960 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
1961 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1962 sp<IBinder> token;
1963 status_t result = acquireFrameRateFlexibilityToken(&token);
1964 reply->writeInt32(result);
1965 if (result == NO_ERROR) {
1966 reply->writeStrongBinder(token);
1967 }
1968 return NO_ERROR;
1969 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001970 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001971 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001972 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001973 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001974}
1975
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001976} // namespace android