blob: 4a120359791261dcd3bea3654ccc74d04eca4c5d [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
Marissa Wall713b63f2018-10-17 15:42:43 -070069 virtual void setTransactionState(const Vector<ComposerState>& state,
70 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080071 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080072 const InputWindowCommands& commands,
Marissa Wall78b72202019-03-15 14:58:34 -070073 int64_t desiredPresentTime,
Valerie Hau9dab9732019-08-20 09:29:25 -070074 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
Marissa Wall3dad52d2019-03-22 14:03:19 -070075 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
79 data.writeUint32(static_cast<uint32_t>(state.size()));
80 for (const auto& s : state) {
81 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(static_cast<uint32_t>(displays.size()));
85 for (const auto& d : displays) {
86 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070087 }
Dan Stozad723bd72014-11-18 10:24:03 -080088
89 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070090 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080091 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080092 data.writeInt64(desiredPresentTime);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070093 data.writeStrongBinder(uncacheBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070094 data.writeUint64(uncacheBuffer.id);
Valerie Hau9dab9732019-08-20 09:29:25 -070095 data.writeBool(hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070096
97 if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
98 for (const auto& [listener, callbackIds] : listenerCallbacks) {
Valerie Hau5de3ad22019-08-20 07:47:43 -070099 data.writeStrongBinder(listener);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700100 data.writeInt64Vector(callbackIds);
101 }
102 }
103
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700104 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 }
106
107 virtual void bootFinished()
108 {
109 Parcel data, reply;
110 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
111 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
112 }
113
chaviwd2432892020-07-24 17:42:39 -0700114 virtual status_t captureDisplay(const DisplayCaptureArgs& args,
115 ScreenCaptureResults& captureResults) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800116 Parcel data, reply;
117 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviwd2432892020-07-24 17:42:39 -0700118
119 status_t result = args.write(data);
Ana Krulec2d41e422018-07-26 12:07:43 -0700120 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700121 ALOGE("captureDisplay failed to parcel args: %d", result);
122 return result;
123 }
124 result = remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply);
125 if (result != NO_ERROR) {
126 ALOGE("captureDisplay failed to transact: %d", result);
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000128 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700129 result = reply.readInt32();
130 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700131 ALOGE("captureDisplay failed to readInt32: %d", result);
Ana Krulec2d41e422018-07-26 12:07:43 -0700132 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000133 }
134
chaviwd2432892020-07-24 17:42:39 -0700135 captureResults.read(reply);
Ana Krulec2d41e422018-07-26 12:07:43 -0700136 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800137 }
138
chaviwd2432892020-07-24 17:42:39 -0700139 virtual status_t captureDisplay(uint64_t displayOrLayerStack,
140 ScreenCaptureResults& captureResults) {
chaviw93df2ea2019-04-30 16:45:12 -0700141 Parcel data, reply;
142 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
143 data.writeUint64(displayOrLayerStack);
chaviwd2432892020-07-24 17:42:39 -0700144 status_t result =
145 remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply);
chaviw93df2ea2019-04-30 16:45:12 -0700146 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700147 ALOGE("captureDisplay failed to transact: %d", result);
chaviw93df2ea2019-04-30 16:45:12 -0700148 return result;
149 }
150 result = reply.readInt32();
151 if (result != NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -0700152 ALOGE("captureDisplay failed to readInt32: %d", result);
chaviw93df2ea2019-04-30 16:45:12 -0700153 return result;
154 }
155
chaviwd2432892020-07-24 17:42:39 -0700156 captureResults.read(reply);
chaviw93df2ea2019-04-30 16:45:12 -0700157 return result;
158 }
159
chaviw3efadb12020-07-27 10:07:15 -0700160 virtual status_t captureLayers(const LayerCaptureArgs& args,
161 ScreenCaptureResults& captureResults) {
chaviwa76b2712017-09-20 12:02:26 -0700162 Parcel data, reply;
163 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
chaviw3efadb12020-07-27 10:07:15 -0700164
165 status_t result = args.write(data);
166 if (result != NO_ERROR) {
167 ALOGE("captureLayers failed to parcel args: %d", result);
168 return result;
Robert Carr866455f2019-04-02 16:28:26 -0700169 }
chaviw3efadb12020-07-27 10:07:15 -0700170
171 result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
Ana Krulec2d41e422018-07-26 12:07:43 -0700172 if (result != NO_ERROR) {
173 ALOGE("captureLayers failed to transact: %d", result);
174 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000175 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700176 result = reply.readInt32();
177 if (result != NO_ERROR) {
178 ALOGE("captureLayers failed to readInt32: %d", result);
179 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000180 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700181
chaviw3efadb12020-07-27 10:07:15 -0700182 captureResults.read(reply);
Ana Krulec2d41e422018-07-26 12:07:43 -0700183 return result;
chaviwa76b2712017-09-20 12:02:26 -0700184 }
185
Jamie Gennis582270d2011-08-17 18:19:00 -0700186 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800187 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800188 {
189 Parcel data, reply;
190 int err = NO_ERROR;
191 err = data.writeInterfaceToken(
192 ISurfaceComposer::getInterfaceDescriptor());
193 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000194 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800195 "interface descriptor: %s (%d)", strerror(-err), -err);
196 return false;
197 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800198 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800199 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000200 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700201 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800202 return false;
203 }
204 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
205 &reply);
206 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000207 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700208 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800209 return false;
210 }
211 int32_t result = 0;
212 err = reply.readInt32(&result);
213 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000214 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700215 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800216 return false;
217 }
218 return result != 0;
219 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800220
Brian Anderson6b376712017-04-04 10:51:39 -0700221 virtual status_t getSupportedFrameTimestamps(
222 std::vector<FrameEvent>* outSupported) const {
223 if (!outSupported) {
224 return UNEXPECTED_NULL;
225 }
226 outSupported->clear();
227
228 Parcel data, reply;
229
230 status_t err = data.writeInterfaceToken(
231 ISurfaceComposer::getInterfaceDescriptor());
232 if (err != NO_ERROR) {
233 return err;
234 }
235
236 err = remote()->transact(
237 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
238 data, &reply);
239 if (err != NO_ERROR) {
240 return err;
241 }
242
243 int32_t result = 0;
244 err = reply.readInt32(&result);
245 if (err != NO_ERROR) {
246 return err;
247 }
248 if (result != NO_ERROR) {
249 return result;
250 }
251
252 std::vector<int32_t> supported;
253 err = reply.readInt32Vector(&supported);
254 if (err != NO_ERROR) {
255 return err;
256 }
257
258 outSupported->reserve(supported.size());
259 for (int32_t s : supported) {
260 outSupported->push_back(static_cast<FrameEvent>(s));
261 }
262 return NO_ERROR;
263 }
264
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700265 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource,
266 ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800267 Parcel data, reply;
268 sp<IDisplayEventConnection> result;
269 int err = data.writeInterfaceToken(
270 ISurfaceComposer::getInterfaceDescriptor());
271 if (err != NO_ERROR) {
272 return result;
273 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700274 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700275 data.writeInt32(static_cast<int32_t>(configChanged));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800276 err = remote()->transact(
277 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
278 data, &reply);
279 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000280 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800281 "transaction: %s (%d)", strerror(-err), -err);
282 return result;
283 }
284 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
285 return result;
286 }
Colin Cross8e533062012-06-07 13:17:52 -0700287
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700288 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700292 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700293 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700294 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
295 return reply.readStrongBinder();
296 }
297
Jesse Hall6c913be2013-08-08 12:15:49 -0700298 virtual void destroyDisplay(const sp<IBinder>& display)
299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
302 data.writeStrongBinder(display);
303 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
304 }
305
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800306 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700307 Parcel data, reply;
308 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800309 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
310 NO_ERROR) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200311 std::vector<uint64_t> rawIds;
312 if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
313 std::vector<PhysicalDisplayId> displayIds(rawIds.size());
314 std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
315 [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800316 return displayIds;
317 }
318 }
319
320 return {};
321 }
322
323 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
324 Parcel data, reply;
325 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Marin Shalamanova524a092020-07-27 21:39:55 +0200326 data.writeUint64(displayId.value);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800327 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700328 return reply.readStrongBinder();
329 }
330
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700331 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700332 {
333 Parcel data, reply;
334 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700335 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700336 data.writeInt32(mode);
337 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700338 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700339
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800340 virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
341 Parcel data, reply;
342 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
343 data.writeStrongBinder(display);
344 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
345 const status_t result = reply.readInt32();
346 if (result == NO_ERROR) {
347 memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
348 }
349 return result;
350 }
351
352 virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
353 Parcel data, reply;
354 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
355 data.writeStrongBinder(display);
356 remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
357 const status_t result = reply.readInt32();
Marin Shalamanov359a7e72020-02-17 17:03:07 +0100358 if (result != NO_ERROR) return result;
359 return reply.read(*info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800360 }
361
362 virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700363 Parcel data, reply;
364 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700365 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700366 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800367 const status_t result = reply.readInt32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700368 if (result == NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800369 const size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700370 configs->clear();
371 configs->resize(numConfigs);
372 for (size_t c = 0; c < numConfigs; ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800373 memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
374 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -0700375 }
376 }
377 return result;
378 }
379
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700380 virtual status_t getDisplayStats(const sp<IBinder>& display,
381 DisplayStatInfo* stats)
382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
385 data.writeStrongBinder(display);
386 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
387 status_t result = reply.readInt32();
388 if (result == NO_ERROR) {
389 memcpy(stats,
390 reply.readInplace(sizeof(DisplayStatInfo)),
391 sizeof(DisplayStatInfo));
392 }
393 return result;
394 }
395
Dan Stoza7f7da322014-05-02 15:26:25 -0700396 virtual int getActiveConfig(const sp<IBinder>& display)
397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
400 data.writeStrongBinder(display);
401 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
402 return reply.readInt32();
403 }
404
Michael Wright28f24d02016-07-12 13:30:53 -0700405 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700406 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700407 Parcel data, reply;
408 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
409 if (result != NO_ERROR) {
410 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
411 return result;
412 }
413 result = data.writeStrongBinder(display);
414 if (result != NO_ERROR) {
415 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
416 return result;
417 }
418 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
419 if (result != NO_ERROR) {
420 ALOGE("getDisplayColorModes failed to transact: %d", result);
421 return result;
422 }
423 result = static_cast<status_t>(reply.readInt32());
424 if (result == NO_ERROR) {
425 size_t numModes = reply.readUint32();
426 outColorModes->clear();
427 outColorModes->resize(numModes);
428 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700429 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700430 }
431 }
432 return result;
433 }
434
Daniel Solomon42d04562019-01-20 21:03:19 -0800435 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
436 ui::DisplayPrimaries& primaries) {
437 Parcel data, reply;
438 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
439 if (result != NO_ERROR) {
440 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
441 return result;
442 }
443 result = data.writeStrongBinder(display);
444 if (result != NO_ERROR) {
445 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
446 return result;
447 }
448 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
449 if (result != NO_ERROR) {
450 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
451 return result;
452 }
453 result = reply.readInt32();
454 if (result == NO_ERROR) {
455 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
456 sizeof(ui::DisplayPrimaries));
457 }
458 return result;
459 }
460
Peiyong Lina52f0292018-03-14 17:26:31 -0700461 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700462 Parcel data, reply;
463 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
464 if (result != NO_ERROR) {
465 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700466 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700467 }
468 result = data.writeStrongBinder(display);
469 if (result != NO_ERROR) {
470 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700471 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700472 }
473 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
474 if (result != NO_ERROR) {
475 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700476 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700477 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700478 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700479 }
480
481 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700482 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700483 Parcel data, reply;
484 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
485 if (result != NO_ERROR) {
486 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
487 return result;
488 }
489 result = data.writeStrongBinder(display);
490 if (result != NO_ERROR) {
491 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
492 return result;
493 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700494 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700495 if (result != NO_ERROR) {
496 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
497 return result;
498 }
499 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
500 if (result != NO_ERROR) {
501 ALOGE("setActiveColorMode failed to transact: %d", result);
502 return result;
503 }
504 return static_cast<status_t>(reply.readInt32());
505 }
506
Galia Peycheva5492cb52019-10-30 14:13:16 +0100507 virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display,
508 bool* outSupport) const {
509 Parcel data, reply;
510 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
511 status_t result = data.writeStrongBinder(display);
512 if (result != NO_ERROR) {
513 ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result);
514 return result;
515 }
516 result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data,
517 &reply);
518 if (result != NO_ERROR) {
519 ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result);
520 return result;
521 }
522 return reply.readBool(outSupport);
523 }
524
525 virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
526 Parcel data, reply;
527 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
528 if (result != NO_ERROR) {
529 ALOGE("setAutoLowLatencyMode failed to writeInterfaceToken: %d", result);
530 return;
531 }
532
533 result = data.writeStrongBinder(display);
534 if (result != NO_ERROR) {
535 ALOGE("setAutoLowLatencyMode failed to writeStrongBinder: %d", result);
536 return;
537 }
538 result = data.writeBool(on);
539 if (result != NO_ERROR) {
540 ALOGE("setAutoLowLatencyMode failed to writeBool: %d", result);
541 return;
542 }
543 result = remote()->transact(BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE, data, &reply);
544 if (result != NO_ERROR) {
545 ALOGE("setAutoLowLatencyMode failed to transact: %d", result);
546 return;
547 }
548 }
549
550 virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, bool* outSupport) const {
551 Parcel data, reply;
552 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
553 status_t result = data.writeStrongBinder(display);
554 if (result != NO_ERROR) {
555 ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result);
556 return result;
557 }
558 result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply);
559 if (result != NO_ERROR) {
560 ALOGE("getGameContentTypeSupport failed to transact: %d", result);
561 return result;
562 }
563 return reply.readBool(outSupport);
564 }
565
566 virtual void setGameContentType(const sp<IBinder>& display, bool on) {
567 Parcel data, reply;
568 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
569 if (result != NO_ERROR) {
570 ALOGE("setGameContentType failed to writeInterfaceToken: %d", result);
571 return;
572 }
573 result = data.writeStrongBinder(display);
574 if (result != NO_ERROR) {
575 ALOGE("setGameContentType failed to writeStrongBinder: %d", result);
576 return;
577 }
578 result = data.writeBool(on);
579 if (result != NO_ERROR) {
580 ALOGE("setGameContentType failed to writeBool: %d", result);
581 return;
582 }
583 result = remote()->transact(BnSurfaceComposer::SET_GAME_CONTENT_TYPE, data, &reply);
584 if (result != NO_ERROR) {
585 ALOGE("setGameContentType failed to transact: %d", result);
586 }
587 }
588
Svetoslavd85084b2014-03-20 10:28:31 -0700589 virtual status_t clearAnimationFrameStats() {
590 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700591 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
592 if (result != NO_ERROR) {
593 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
594 return result;
595 }
596 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
597 if (result != NO_ERROR) {
598 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
599 return result;
600 }
Svetoslavd85084b2014-03-20 10:28:31 -0700601 return reply.readInt32();
602 }
603
604 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
605 Parcel data, reply;
606 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
607 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
608 reply.read(*outStats);
609 return reply.readInt32();
610 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700611
612 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
613 HdrCapabilities* outCapabilities) const {
614 Parcel data, reply;
615 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
616 status_t result = data.writeStrongBinder(display);
617 if (result != NO_ERROR) {
618 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
619 return result;
620 }
621 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
622 data, &reply);
623 if (result != NO_ERROR) {
624 ALOGE("getHdrCapabilities failed to transact: %d", result);
625 return result;
626 }
627 result = reply.readInt32();
628 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800629 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700630 }
631 return result;
632 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700633
634 virtual status_t enableVSyncInjections(bool enable) {
635 Parcel data, reply;
636 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
637 if (result != NO_ERROR) {
638 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
639 return result;
640 }
641 result = data.writeBool(enable);
642 if (result != NO_ERROR) {
643 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
644 return result;
645 }
Steven Moreland366eb422019-04-01 19:22:32 -0700646 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS, data, &reply,
647 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700648 if (result != NO_ERROR) {
649 ALOGE("enableVSyncInjections failed to transact: %d", result);
650 return result;
651 }
652 return result;
653 }
654
655 virtual status_t injectVSync(nsecs_t when) {
656 Parcel data, reply;
657 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
658 if (result != NO_ERROR) {
659 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
660 return result;
661 }
662 result = data.writeInt64(when);
663 if (result != NO_ERROR) {
664 ALOGE("injectVSync failed to writeInt64: %d", result);
665 return result;
666 }
Steven Moreland366eb422019-04-01 19:22:32 -0700667 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply,
668 IBinder::FLAG_ONEWAY);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700669 if (result != NO_ERROR) {
670 ALOGE("injectVSync failed to transact: %d", result);
671 return result;
672 }
673 return result;
674 }
675
Vishnu Nair43bccf82020-06-05 10:53:37 -0700676 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) {
Kalle Raitaa099a242017-01-11 11:17:29 -0800677 if (!outLayers) {
678 return UNEXPECTED_NULL;
679 }
680
681 Parcel data, reply;
682
683 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
684 if (err != NO_ERROR) {
685 return err;
686 }
687
688 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
689 if (err != NO_ERROR) {
690 return err;
691 }
692
693 int32_t result = 0;
694 err = reply.readInt32(&result);
695 if (err != NO_ERROR) {
696 return err;
697 }
698 if (result != NO_ERROR) {
699 return result;
700 }
701
702 outLayers->clear();
703 return reply.readParcelableVector(outLayers);
704 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700705
Peiyong Linc6780972018-10-28 15:24:08 -0700706 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
707 ui::PixelFormat* defaultPixelFormat,
708 ui::Dataspace* wideColorGamutDataspace,
709 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700710 Parcel data, reply;
711 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
712 if (error != NO_ERROR) {
713 return error;
714 }
715 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
716 if (error != NO_ERROR) {
717 return error;
718 }
719 error = static_cast<status_t>(reply.readInt32());
720 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700721 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
722 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
723 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
724 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700725 }
726 return error;
727 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700728
Ady Abraham37965d42018-11-01 13:43:32 -0700729 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700730 Parcel data, reply;
731 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700732 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
733 bool result;
734 status_t err = reply.readBool(&result);
735 if (err == NO_ERROR) {
736 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700737 }
Ady Abraham37965d42018-11-01 13:43:32 -0700738 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700739 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700740
741 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
742 ui::PixelFormat* outFormat,
743 ui::Dataspace* outDataspace,
744 uint8_t* outComponentMask) const {
745 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
746 Parcel data, reply;
747 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
748 data.writeStrongBinder(display);
749
750 status_t error =
751 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
752 data, &reply);
753 if (error != NO_ERROR) {
754 return error;
755 }
756
757 uint32_t value = 0;
758 error = reply.readUint32(&value);
759 if (error != NO_ERROR) {
760 return error;
761 }
762 *outFormat = static_cast<ui::PixelFormat>(value);
763
764 error = reply.readUint32(&value);
765 if (error != NO_ERROR) {
766 return error;
767 }
768 *outDataspace = static_cast<ui::Dataspace>(value);
769
770 error = reply.readUint32(&value);
771 if (error != NO_ERROR) {
772 return error;
773 }
774 *outComponentMask = static_cast<uint8_t>(value);
775 return error;
776 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800777
778 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
Dominik Laskowski470df5f2020-04-02 22:27:42 -0700779 uint8_t componentMask, uint64_t maxFrames) {
Kevin DuBois74e53772018-11-19 10:52:38 -0800780 Parcel data, reply;
781 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
782 data.writeStrongBinder(display);
783 data.writeBool(enable);
784 data.writeByte(static_cast<int8_t>(componentMask));
785 data.writeUint64(maxFrames);
786 status_t result =
787 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
788 &reply);
789 return result;
790 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700791
792 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
793 uint64_t timestamp,
794 DisplayedFrameStats* outStats) const {
795 if (!outStats) return BAD_VALUE;
796
797 Parcel data, reply;
798 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
799 data.writeStrongBinder(display);
800 data.writeUint64(maxFrames);
801 data.writeUint64(timestamp);
802
803 status_t result =
804 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
805
806 if (result != NO_ERROR) {
807 return result;
808 }
809
810 result = reply.readUint64(&outStats->numFrames);
811 if (result != NO_ERROR) {
812 return result;
813 }
814
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800815 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700816 if (result != NO_ERROR) {
817 return result;
818 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800819 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700820 if (result != NO_ERROR) {
821 return result;
822 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800823 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700824 if (result != NO_ERROR) {
825 return result;
826 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800827 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700828 return result;
829 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800830
831 virtual status_t getProtectedContentSupport(bool* outSupported) const {
832 Parcel data, reply;
833 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800834 status_t error =
835 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
836 if (error != NO_ERROR) {
837 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800838 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800839 error = reply.readBool(outSupported);
840 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800841 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800842
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800843 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
844 bool* outIsWideColorDisplay) const {
845 Parcel data, reply;
846 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
847 if (error != NO_ERROR) {
848 return error;
849 }
850 error = data.writeStrongBinder(token);
851 if (error != NO_ERROR) {
852 return error;
853 }
854
855 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
856 if (error != NO_ERROR) {
857 return error;
858 }
859 error = reply.readBool(outIsWideColorDisplay);
860 return error;
861 }
Dan Stoza84ab9372018-12-17 15:27:57 -0800862
863 virtual status_t addRegionSamplingListener(const Rect& samplingArea,
864 const sp<IBinder>& stopLayerHandle,
865 const sp<IRegionSamplingListener>& listener) {
866 Parcel data, reply;
867 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
868 if (error != NO_ERROR) {
869 ALOGE("addRegionSamplingListener: Failed to write interface token");
870 return error;
871 }
872 error = data.write(samplingArea);
873 if (error != NO_ERROR) {
874 ALOGE("addRegionSamplingListener: Failed to write sampling area");
875 return error;
876 }
877 error = data.writeStrongBinder(stopLayerHandle);
878 if (error != NO_ERROR) {
879 ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
880 return error;
881 }
882 error = data.writeStrongBinder(IInterface::asBinder(listener));
883 if (error != NO_ERROR) {
884 ALOGE("addRegionSamplingListener: Failed to write listener");
885 return error;
886 }
887 error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
888 if (error != NO_ERROR) {
889 ALOGE("addRegionSamplingListener: Failed to transact");
890 }
891 return error;
892 }
893
894 virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
895 Parcel data, reply;
896 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
897 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800898 ALOGE("removeRegionSamplingListener: Failed to write interface token");
Dan Stoza84ab9372018-12-17 15:27:57 -0800899 return error;
900 }
901 error = data.writeStrongBinder(IInterface::asBinder(listener));
902 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800903 ALOGE("removeRegionSamplingListener: Failed to write listener");
Dan Stoza84ab9372018-12-17 15:27:57 -0800904 return error;
905 }
906 error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
907 &reply);
908 if (error != NO_ERROR) {
tangrobinaf45f012019-02-26 18:10:10 +0800909 ALOGE("removeRegionSamplingListener: Failed to transact");
Dan Stoza84ab9372018-12-17 15:27:57 -0800910 }
911 return error;
912 }
Ady Abraham838de062019-02-04 10:24:03 -0800913
Ana Krulec0782b882019-10-15 17:34:54 -0700914 virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Steven Thomasf734df42020-04-13 21:09:28 -0700915 int32_t defaultConfig,
916 float primaryRefreshRateMin,
917 float primaryRefreshRateMax,
918 float appRequestRefreshRateMin,
919 float appRequestRefreshRateMax) {
Ana Krulec0782b882019-10-15 17:34:54 -0700920 Parcel data, reply;
921 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
922 if (result != NO_ERROR) {
923 ALOGE("setDesiredDisplayConfigSpecs: failed to writeInterfaceToken: %d", result);
924 return result;
925 }
926 result = data.writeStrongBinder(displayToken);
927 if (result != NO_ERROR) {
928 ALOGE("setDesiredDisplayConfigSpecs: failed to write display token: %d", result);
929 return result;
930 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100931 result = data.writeInt32(defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -0700932 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100933 ALOGE("setDesiredDisplayConfigSpecs failed to write defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700934 return result;
935 }
Steven Thomasf734df42020-04-13 21:09:28 -0700936 result = data.writeFloat(primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -0700937 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700938 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMin: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -0700939 return result;
940 }
Steven Thomasf734df42020-04-13 21:09:28 -0700941 result = data.writeFloat(primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -0700942 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -0700943 ALOGE("setDesiredDisplayConfigSpecs failed to write primaryRefreshRateMax: %d", result);
944 return result;
945 }
946 result = data.writeFloat(appRequestRefreshRateMin);
947 if (result != NO_ERROR) {
948 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMin: %d",
949 result);
950 return result;
951 }
952 result = data.writeFloat(appRequestRefreshRateMax);
953 if (result != NO_ERROR) {
954 ALOGE("setDesiredDisplayConfigSpecs failed to write appRequestRefreshRateMax: %d",
955 result);
Ana Krulec0782b882019-10-15 17:34:54 -0700956 return result;
957 }
958
959 result = remote()->transact(BnSurfaceComposer::SET_DESIRED_DISPLAY_CONFIG_SPECS, data,
960 &reply);
961 if (result != NO_ERROR) {
962 ALOGE("setDesiredDisplayConfigSpecs failed to transact: %d", result);
963 return result;
964 }
965 return reply.readInt32();
966 }
967
Ana Krulec234bb162019-11-10 22:55:55 +0100968 virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100969 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -0700970 float* outPrimaryRefreshRateMin,
971 float* outPrimaryRefreshRateMax,
972 float* outAppRequestRefreshRateMin,
973 float* outAppRequestRefreshRateMax) {
974 if (!outDefaultConfig || !outPrimaryRefreshRateMin || !outPrimaryRefreshRateMax ||
975 !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) {
976 return BAD_VALUE;
977 }
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800978 Parcel data, reply;
979 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
980 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100981 ALOGE("getDesiredDisplayConfigSpecs failed to writeInterfaceToken: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800982 return result;
983 }
984 result = data.writeStrongBinder(displayToken);
985 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100986 ALOGE("getDesiredDisplayConfigSpecs failed to writeStrongBinder: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800987 return result;
988 }
Ana Krulec234bb162019-11-10 22:55:55 +0100989 result = remote()->transact(BnSurfaceComposer::GET_DESIRED_DISPLAY_CONFIG_SPECS, data,
990 &reply);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800991 if (result != NO_ERROR) {
Ana Krulec234bb162019-11-10 22:55:55 +0100992 ALOGE("getDesiredDisplayConfigSpecs failed to transact: %d", result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800993 return result;
994 }
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100995 result = reply.readInt32(outDefaultConfig);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800996 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100997 ALOGE("getDesiredDisplayConfigSpecs failed to read defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +0100998 return result;
999 }
Steven Thomasf734df42020-04-13 21:09:28 -07001000 result = reply.readFloat(outPrimaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001001 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001002 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMin: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001003 return result;
1004 }
Steven Thomasf734df42020-04-13 21:09:28 -07001005 result = reply.readFloat(outPrimaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001006 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001007 ALOGE("getDesiredDisplayConfigSpecs failed to read primaryRefreshRateMax: %d", result);
1008 return result;
1009 }
1010 result = reply.readFloat(outAppRequestRefreshRateMin);
1011 if (result != NO_ERROR) {
1012 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMin: %d",
1013 result);
1014 return result;
1015 }
1016 result = reply.readFloat(outAppRequestRefreshRateMax);
1017 if (result != NO_ERROR) {
1018 ALOGE("getDesiredDisplayConfigSpecs failed to read appRequestRefreshRateMax: %d",
1019 result);
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001020 return result;
1021 }
1022 return reply.readInt32();
1023 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001024
1025 virtual status_t getDisplayBrightnessSupport(const sp<IBinder>& displayToken,
1026 bool* outSupport) const {
1027 Parcel data, reply;
1028 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1029 if (error != NO_ERROR) {
1030 ALOGE("getDisplayBrightnessSupport: failed to write interface token: %d", error);
1031 return error;
1032 }
1033 error = data.writeStrongBinder(displayToken);
1034 if (error != NO_ERROR) {
1035 ALOGE("getDisplayBrightnessSupport: failed to write display token: %d", error);
1036 return error;
1037 }
1038 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT, data, &reply);
1039 if (error != NO_ERROR) {
1040 ALOGE("getDisplayBrightnessSupport: failed to transact: %d", error);
1041 return error;
1042 }
1043 bool support;
1044 error = reply.readBool(&support);
1045 if (error != NO_ERROR) {
1046 ALOGE("getDisplayBrightnessSupport: failed to read support: %d", error);
1047 return error;
1048 }
1049 *outSupport = support;
1050 return NO_ERROR;
1051 }
1052
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001053 virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) {
Dan Gittik57e63c52019-01-18 16:37:54 +00001054 Parcel data, reply;
1055 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1056 if (error != NO_ERROR) {
1057 ALOGE("setDisplayBrightness: failed to write interface token: %d", error);
1058 return error;
1059 }
1060 error = data.writeStrongBinder(displayToken);
1061 if (error != NO_ERROR) {
1062 ALOGE("setDisplayBrightness: failed to write display token: %d", error);
1063 return error;
1064 }
1065 error = data.writeFloat(brightness);
1066 if (error != NO_ERROR) {
1067 ALOGE("setDisplayBrightness: failed to write brightness: %d", error);
1068 return error;
1069 }
1070 error = remote()->transact(BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS, data, &reply);
1071 if (error != NO_ERROR) {
1072 ALOGE("setDisplayBrightness: failed to transact: %d", error);
1073 return error;
1074 }
1075 return NO_ERROR;
1076 }
Ady Abraham8532d012019-05-08 14:50:56 -07001077
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001078 virtual status_t notifyPowerBoost(int32_t boostId) {
Ady Abraham8532d012019-05-08 14:50:56 -07001079 Parcel data, reply;
1080 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1081 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001082 ALOGE("notifyPowerBoost: failed to write interface token: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001083 return error;
1084 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001085 error = data.writeInt32(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001086 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001087 ALOGE("notifyPowerBoost: failed to write boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001088 return error;
1089 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001090 error = remote()->transact(BnSurfaceComposer::NOTIFY_POWER_BOOST, data, &reply,
Ady Abraham8532d012019-05-08 14:50:56 -07001091 IBinder::FLAG_ONEWAY);
1092 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001093 ALOGE("notifyPowerBoost: failed to transact: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001094 return error;
1095 }
1096 return NO_ERROR;
1097 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001098
1099 virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
1100 float lightPosY, float lightPosZ, float lightRadius) {
1101 Parcel data, reply;
1102 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1103 if (error != NO_ERROR) {
1104 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
1105 return error;
1106 }
1107
1108 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
1109 ambientColor.a, spotColor.r, spotColor.g,
1110 spotColor.b, spotColor.a, lightPosY,
1111 lightPosZ, lightRadius};
1112
1113 error = data.writeFloatVector(shadowConfig);
1114 if (error != NO_ERROR) {
1115 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
1116 return error;
1117 }
1118
1119 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
1120 IBinder::FLAG_ONEWAY);
1121 if (error != NO_ERROR) {
1122 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
1123 return error;
1124 }
1125 return NO_ERROR;
1126 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001127
1128 virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
1129 int8_t compatibility) {
1130 Parcel data, reply;
1131 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1132 if (err != NO_ERROR) {
1133 ALOGE("setFrameRate: failed writing interface token: %s (%d)", strerror(-err), -err);
1134 return err;
1135 }
1136
1137 err = data.writeStrongBinder(IInterface::asBinder(surface));
1138 if (err != NO_ERROR) {
1139 ALOGE("setFrameRate: failed writing strong binder: %s (%d)", strerror(-err), -err);
1140 return err;
1141 }
1142
1143 err = data.writeFloat(frameRate);
1144 if (err != NO_ERROR) {
1145 ALOGE("setFrameRate: failed writing float: %s (%d)", strerror(-err), -err);
1146 return err;
1147 }
1148
1149 err = data.writeByte(compatibility);
1150 if (err != NO_ERROR) {
1151 ALOGE("setFrameRate: failed writing byte: %s (%d)", strerror(-err), -err);
1152 return err;
1153 }
1154
Ady Abraham60e42ea2020-03-09 19:17:31 -07001155 err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -08001156 if (err != NO_ERROR) {
1157 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
1158 return err;
1159 }
Steven Thomasd4071902020-03-24 16:02:53 -07001160
1161 return reply.readInt32();
1162 }
1163
1164 virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) {
1165 if (!outToken) return BAD_VALUE;
1166
1167 Parcel data, reply;
1168 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
1169 if (err != NO_ERROR) {
1170 ALOGE("acquireFrameRateFlexibilityToken: failed writing interface token: %s (%d)",
1171 strerror(-err), -err);
1172 return err;
1173 }
1174
1175 err = remote()->transact(BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, data,
1176 &reply);
1177 if (err != NO_ERROR) {
1178 ALOGE("acquireFrameRateFlexibilityToken: failed to transact: %s (%d)", strerror(-err),
1179 err);
1180 return err;
1181 }
1182
1183 err = reply.readInt32();
1184 if (err != NO_ERROR) {
1185 ALOGE("acquireFrameRateFlexibilityToken: call failed: %s (%d)", strerror(-err), err);
1186 return err;
1187 }
1188
1189 err = reply.readStrongBinder(outToken);
1190 if (err != NO_ERROR) {
1191 ALOGE("acquireFrameRateFlexibilityToken: failed reading binder token: %s (%d)",
1192 strerror(-err), err);
1193 return err;
1194 }
1195
Steven Thomas62a4cf82020-01-31 12:04:03 -08001196 return NO_ERROR;
1197 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001198};
1199
Dan Stozad723bd72014-11-18 10:24:03 -08001200// Out-of-line virtual method definition to trigger vtable emission in this
1201// translation unit (see clang warning -Wweak-vtables)
1202BpSurfaceComposer::~BpSurfaceComposer() {}
1203
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001204IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
1205
1206// ----------------------------------------------------------------------
1207
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001208status_t BnSurfaceComposer::onTransact(
1209 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1210{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001211 switch(code) {
1212 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001213 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001214 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001215 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -07001216 return NO_ERROR;
1217 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001218 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001219 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -08001220
1221 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001222 if (count > data.dataSize()) {
1223 return BAD_VALUE;
1224 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001225 Vector<ComposerState> state;
1226 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001227 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001228 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -07001229 if (s.read(data) == BAD_VALUE) {
1230 return BAD_VALUE;
1231 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001232 state.add(s);
1233 }
Dan Stozad723bd72014-11-18 10:24:03 -08001234
1235 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -07001236 if (count > data.dataSize()) {
1237 return BAD_VALUE;
1238 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001239 DisplayState d;
1240 Vector<DisplayState> displays;
1241 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -08001242 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -07001243 if (d.read(data) == BAD_VALUE) {
1244 return BAD_VALUE;
1245 }
Mathias Agopian8b33f032012-07-24 20:43:54 -07001246 displays.add(d);
1247 }
Dan Stozad723bd72014-11-18 10:24:03 -08001248
1249 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -07001250 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -08001251 InputWindowCommands inputWindowCommands;
1252 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -08001253
1254 int64_t desiredPresentTime = data.readInt64();
Marissa Wall78b72202019-03-15 14:58:34 -07001255
Marissa Wall947d34e2019-03-29 14:03:53 -07001256 client_cache_t uncachedBuffer;
Steven Moreland9d4ce9b2019-07-17 15:23:38 -07001257 uncachedBuffer.token = data.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -07001258 uncachedBuffer.id = data.readUint64();
Marissa Wall78b72202019-03-15 14:58:34 -07001259
Valerie Hau9dab9732019-08-20 09:29:25 -07001260 bool hasListenerCallbacks = data.readBool();
1261
Marissa Wall3dad52d2019-03-22 14:03:19 -07001262 std::vector<ListenerCallbacks> listenerCallbacks;
1263 int32_t listenersSize = data.readInt32();
1264 for (int32_t i = 0; i < listenersSize; i++) {
Valerie Hau5de3ad22019-08-20 07:47:43 -07001265 auto listener = data.readStrongBinder();
Marissa Wall3dad52d2019-03-22 14:03:19 -07001266 std::vector<CallbackId> callbackIds;
1267 data.readInt64Vector(&callbackIds);
1268 listenerCallbacks.emplace_back(listener, callbackIds);
1269 }
Marissa Wall17b4e452018-12-26 16:32:34 -08001270 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
Valerie Hau9dab9732019-08-20 09:29:25 -07001271 desiredPresentTime, uncachedBuffer, hasListenerCallbacks,
1272 listenerCallbacks);
Jesse Hall6c913be2013-08-08 12:15:49 -07001273 return NO_ERROR;
1274 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001275 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001276 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001277 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -07001278 return NO_ERROR;
1279 }
chaviwd2432892020-07-24 17:42:39 -07001280 case CAPTURE_DISPLAY: {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001281 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviwd2432892020-07-24 17:42:39 -07001282 DisplayCaptureArgs args;
1283 ScreenCaptureResults captureResults;
Dan Stozac7014012014-02-14 15:03:43 -08001284
chaviwd2432892020-07-24 17:42:39 -07001285 status_t res = args.read(data);
1286 if (res != NO_ERROR) {
1287 reply->writeInt32(res);
1288 return NO_ERROR;
1289 }
1290
1291 res = captureDisplay(args, captureResults);
Robert Carr108b2c72019-04-02 16:32:58 -07001292
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001293 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001294 if (res == NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -07001295 captureResults.write(*reply);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001296 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001297 return NO_ERROR;
1298 }
chaviwd2432892020-07-24 17:42:39 -07001299 case CAPTURE_DISPLAY_BY_ID: {
chaviw93df2ea2019-04-30 16:45:12 -07001300 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1301 uint64_t displayOrLayerStack = data.readUint64();
chaviwd2432892020-07-24 17:42:39 -07001302 ScreenCaptureResults captureResults;
1303 status_t res = captureDisplay(displayOrLayerStack, captureResults);
chaviw93df2ea2019-04-30 16:45:12 -07001304 reply->writeInt32(res);
1305 if (res == NO_ERROR) {
chaviwd2432892020-07-24 17:42:39 -07001306 captureResults.write(*reply);
chaviw93df2ea2019-04-30 16:45:12 -07001307 }
1308 return NO_ERROR;
1309 }
chaviwa76b2712017-09-20 12:02:26 -07001310 case CAPTURE_LAYERS: {
1311 CHECK_INTERFACE(ISurfaceComposer, data, reply);
chaviw3efadb12020-07-27 10:07:15 -07001312 LayerCaptureArgs args;
1313 ScreenCaptureResults captureResults;
Robert Carr866455f2019-04-02 16:28:26 -07001314
chaviw3efadb12020-07-27 10:07:15 -07001315 status_t res = args.read(data);
1316 if (res != NO_ERROR) {
1317 reply->writeInt32(res);
1318 return NO_ERROR;
Robert Carr866455f2019-04-02 16:28:26 -07001319 }
1320
chaviw3efadb12020-07-27 10:07:15 -07001321 res = captureLayers(args, captureResults);
chaviwa76b2712017-09-20 12:02:26 -07001322 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001323 if (res == NO_ERROR) {
chaviw3efadb12020-07-27 10:07:15 -07001324 captureResults.write(*reply);
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001325 }
chaviwa76b2712017-09-20 12:02:26 -07001326 return NO_ERROR;
1327 }
Jamie Gennis134f0422011-03-08 12:18:54 -08001328 case AUTHENTICATE_SURFACE: {
1329 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -08001330 sp<IGraphicBufferProducer> bufferProducer =
1331 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
1332 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -08001333 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -07001334 return NO_ERROR;
1335 }
Brian Anderson6b376712017-04-04 10:51:39 -07001336 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
1337 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1338 std::vector<FrameEvent> supportedTimestamps;
1339 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
1340 status_t err = reply->writeInt32(result);
1341 if (err != NO_ERROR) {
1342 return err;
1343 }
1344 if (result != NO_ERROR) {
1345 return result;
1346 }
1347
1348 std::vector<int32_t> supported;
1349 supported.reserve(supportedTimestamps.size());
1350 for (FrameEvent s : supportedTimestamps) {
1351 supported.push_back(static_cast<int32_t>(s));
1352 }
1353 return reply->writeInt32Vector(supported);
1354 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001355 case CREATE_DISPLAY_EVENT_CONNECTION: {
1356 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -07001357 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
1358 auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32());
1359
1360 sp<IDisplayEventConnection> connection(
1361 createDisplayEventConnection(vsyncSource, configChanged));
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001362 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001363 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001364 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001365 case CREATE_DISPLAY: {
1366 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001367 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -07001368 bool secure = bool(data.readInt32());
1369 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001370 reply->writeStrongBinder(display);
1371 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001372 }
1373 case DESTROY_DISPLAY: {
1374 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1375 sp<IBinder> display = data.readStrongBinder();
1376 destroyDisplay(display);
1377 return NO_ERROR;
1378 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001379 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001380 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001381 PhysicalDisplayId displayId(data.readUint64());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001382 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -07001383 reply->writeStrongBinder(display);
1384 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -07001385 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001386 case GET_DISPLAY_STATE: {
1387 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1388 ui::DisplayState state;
1389 const sp<IBinder> display = data.readStrongBinder();
1390 const status_t result = getDisplayState(display, &state);
1391 reply->writeInt32(result);
1392 if (result == NO_ERROR) {
1393 memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
1394 sizeof(ui::DisplayState));
1395 }
1396 return NO_ERROR;
1397 }
1398 case GET_DISPLAY_INFO: {
1399 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1400 DisplayInfo info;
1401 const sp<IBinder> display = data.readStrongBinder();
1402 const status_t result = getDisplayInfo(display, &info);
1403 reply->writeInt32(result);
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001404 if (result != NO_ERROR) return result;
1405 return reply->write(info);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001406 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001407 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -07001408 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001409 Vector<DisplayConfig> configs;
1410 const sp<IBinder> display = data.readStrongBinder();
1411 const status_t result = getDisplayConfigs(display, &configs);
Dan Stoza7f7da322014-05-02 15:26:25 -07001412 reply->writeInt32(result);
1413 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -08001414 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -07001415 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001416 memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
1417 sizeof(DisplayConfig));
Dan Stoza7f7da322014-05-02 15:26:25 -07001418 }
1419 }
1420 return NO_ERROR;
1421 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -07001422 case GET_DISPLAY_STATS: {
1423 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1424 DisplayStatInfo stats;
1425 sp<IBinder> display = data.readStrongBinder();
1426 status_t result = getDisplayStats(display, &stats);
1427 reply->writeInt32(result);
1428 if (result == NO_ERROR) {
1429 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
1430 &stats, sizeof(DisplayStatInfo));
1431 }
1432 return NO_ERROR;
1433 }
Dan Stoza7f7da322014-05-02 15:26:25 -07001434 case GET_ACTIVE_CONFIG: {
1435 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1436 sp<IBinder> display = data.readStrongBinder();
1437 int id = getActiveConfig(display);
1438 reply->writeInt32(id);
1439 return NO_ERROR;
1440 }
Michael Wright28f24d02016-07-12 13:30:53 -07001441 case GET_DISPLAY_COLOR_MODES: {
1442 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -07001443 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001444 sp<IBinder> display = nullptr;
1445 status_t result = data.readStrongBinder(&display);
1446 if (result != NO_ERROR) {
1447 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1448 return result;
1449 }
1450 result = getDisplayColorModes(display, &colorModes);
1451 reply->writeInt32(result);
1452 if (result == NO_ERROR) {
1453 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1454 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001455 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001456 }
1457 }
1458 return NO_ERROR;
1459 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001460 case GET_DISPLAY_NATIVE_PRIMARIES: {
1461 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1462 ui::DisplayPrimaries primaries;
1463 sp<IBinder> display = nullptr;
1464
1465 status_t result = data.readStrongBinder(&display);
1466 if (result != NO_ERROR) {
1467 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1468 return result;
1469 }
1470
1471 result = getDisplayNativePrimaries(display, primaries);
1472 reply->writeInt32(result);
1473 if (result == NO_ERROR) {
1474 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1475 sizeof(ui::DisplayPrimaries));
1476 }
1477
1478 return NO_ERROR;
1479 }
Michael Wright28f24d02016-07-12 13:30:53 -07001480 case GET_ACTIVE_COLOR_MODE: {
1481 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1482 sp<IBinder> display = nullptr;
1483 status_t result = data.readStrongBinder(&display);
1484 if (result != NO_ERROR) {
1485 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1486 return result;
1487 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001488 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001489 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1490 return result;
1491 }
1492 case SET_ACTIVE_COLOR_MODE: {
1493 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1494 sp<IBinder> display = nullptr;
1495 status_t result = data.readStrongBinder(&display);
1496 if (result != NO_ERROR) {
1497 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1498 return result;
1499 }
1500 int32_t colorModeInt = 0;
1501 result = data.readInt32(&colorModeInt);
1502 if (result != NO_ERROR) {
1503 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1504 return result;
1505 }
1506 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001507 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001508 result = reply->writeInt32(result);
1509 return result;
1510 }
Galia Peycheva5492cb52019-10-30 14:13:16 +01001511
1512 case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: {
1513 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1514 sp<IBinder> display = nullptr;
1515 status_t result = data.readStrongBinder(&display);
1516 if (result != NO_ERROR) {
1517 ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result);
1518 return result;
1519 }
1520 bool supported = false;
1521 result = getAutoLowLatencyModeSupport(display, &supported);
1522 if (result == NO_ERROR) {
1523 result = reply->writeBool(supported);
1524 }
1525 return result;
1526 }
1527
1528 case SET_AUTO_LOW_LATENCY_MODE: {
1529 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1530 sp<IBinder> display = nullptr;
1531 status_t result = data.readStrongBinder(&display);
1532 if (result != NO_ERROR) {
1533 ALOGE("setAutoLowLatencyMode failed to readStrongBinder: %d", result);
1534 return result;
1535 }
1536 bool setAllm = false;
1537 result = data.readBool(&setAllm);
1538 if (result != NO_ERROR) {
1539 ALOGE("setAutoLowLatencyMode failed to readBool: %d", result);
1540 return result;
1541 }
1542 setAutoLowLatencyMode(display, setAllm);
1543 return result;
1544 }
1545
1546 case GET_GAME_CONTENT_TYPE_SUPPORT: {
1547 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1548 sp<IBinder> display = nullptr;
1549 status_t result = data.readStrongBinder(&display);
1550 if (result != NO_ERROR) {
1551 ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result);
1552 return result;
1553 }
1554 bool supported = false;
1555 result = getGameContentTypeSupport(display, &supported);
1556 if (result == NO_ERROR) {
1557 result = reply->writeBool(supported);
1558 }
1559 return result;
1560 }
1561
1562 case SET_GAME_CONTENT_TYPE: {
1563 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1564 sp<IBinder> display = nullptr;
1565 status_t result = data.readStrongBinder(&display);
1566 if (result != NO_ERROR) {
1567 ALOGE("setGameContentType failed to readStrongBinder: %d", result);
1568 return result;
1569 }
1570 bool setGameContentTypeOn = false;
1571 result = data.readBool(&setGameContentTypeOn);
1572 if (result != NO_ERROR) {
1573 ALOGE("setGameContentType failed to readBool: %d", result);
1574 return result;
1575 }
1576 setGameContentType(display, setGameContentTypeOn);
1577 return result;
1578 }
1579
Svetoslavd85084b2014-03-20 10:28:31 -07001580 case CLEAR_ANIMATION_FRAME_STATS: {
1581 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1582 status_t result = clearAnimationFrameStats();
1583 reply->writeInt32(result);
1584 return NO_ERROR;
1585 }
1586 case GET_ANIMATION_FRAME_STATS: {
1587 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1588 FrameStats stats;
1589 status_t result = getAnimationFrameStats(&stats);
1590 reply->write(stats);
1591 reply->writeInt32(result);
1592 return NO_ERROR;
1593 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001594 case SET_POWER_MODE: {
1595 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1596 sp<IBinder> display = data.readStrongBinder();
1597 int32_t mode = data.readInt32();
1598 setPowerMode(display, mode);
1599 return NO_ERROR;
1600 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001601 case GET_HDR_CAPABILITIES: {
1602 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1603 sp<IBinder> display = nullptr;
1604 status_t result = data.readStrongBinder(&display);
1605 if (result != NO_ERROR) {
1606 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1607 result);
1608 return result;
1609 }
1610 HdrCapabilities capabilities;
1611 result = getHdrCapabilities(display, &capabilities);
1612 reply->writeInt32(result);
1613 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001614 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001615 }
1616 return NO_ERROR;
1617 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001618 case ENABLE_VSYNC_INJECTIONS: {
1619 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1620 bool enable = false;
1621 status_t result = data.readBool(&enable);
1622 if (result != NO_ERROR) {
1623 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1624 return result;
1625 }
1626 return enableVSyncInjections(enable);
1627 }
1628 case INJECT_VSYNC: {
1629 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1630 int64_t when = 0;
1631 status_t result = data.readInt64(&when);
1632 if (result != NO_ERROR) {
1633 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1634 return result;
1635 }
1636 return injectVSync(when);
1637 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001638 case GET_LAYER_DEBUG_INFO: {
1639 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1640 std::vector<LayerDebugInfo> outLayers;
1641 status_t result = getLayerDebugInfo(&outLayers);
1642 reply->writeInt32(result);
1643 if (result == NO_ERROR)
1644 {
1645 result = reply->writeParcelableVector(outLayers);
1646 }
1647 return result;
1648 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001649 case GET_COMPOSITION_PREFERENCE: {
1650 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001651 ui::Dataspace defaultDataspace;
1652 ui::PixelFormat defaultPixelFormat;
1653 ui::Dataspace wideColorGamutDataspace;
1654 ui::PixelFormat wideColorGamutPixelFormat;
1655 status_t error =
1656 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1657 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001658 reply->writeInt32(error);
1659 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001660 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1661 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1662 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001663 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001664 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001665 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001666 }
Ady Abraham37965d42018-11-01 13:43:32 -07001667 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001668 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001669 bool result;
1670 status_t error = getColorManagement(&result);
1671 if (error == NO_ERROR) {
1672 reply->writeBool(result);
1673 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001674 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001675 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001676 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1677 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1678
1679 sp<IBinder> display = data.readStrongBinder();
1680 ui::PixelFormat format;
1681 ui::Dataspace dataspace;
1682 uint8_t component = 0;
1683 auto result =
1684 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1685 if (result == NO_ERROR) {
1686 reply->writeUint32(static_cast<uint32_t>(format));
1687 reply->writeUint32(static_cast<uint32_t>(dataspace));
1688 reply->writeUint32(static_cast<uint32_t>(component));
1689 }
1690 return result;
1691 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001692 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1693 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1694
1695 sp<IBinder> display = nullptr;
1696 bool enable = false;
1697 int8_t componentMask = 0;
1698 uint64_t maxFrames = 0;
1699 status_t result = data.readStrongBinder(&display);
1700 if (result != NO_ERROR) {
1701 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1702 result);
1703 return result;
1704 }
1705
1706 result = data.readBool(&enable);
1707 if (result != NO_ERROR) {
1708 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1709 return result;
1710 }
1711
1712 result = data.readByte(static_cast<int8_t*>(&componentMask));
1713 if (result != NO_ERROR) {
1714 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1715 result);
1716 return result;
1717 }
1718
1719 result = data.readUint64(&maxFrames);
1720 if (result != NO_ERROR) {
1721 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1722 return result;
1723 }
1724
1725 return setDisplayContentSamplingEnabled(display, enable,
1726 static_cast<uint8_t>(componentMask), maxFrames);
1727 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001728 case GET_DISPLAYED_CONTENT_SAMPLE: {
1729 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1730
1731 sp<IBinder> display = data.readStrongBinder();
1732 uint64_t maxFrames = 0;
1733 uint64_t timestamp = 0;
1734
1735 status_t result = data.readUint64(&maxFrames);
1736 if (result != NO_ERROR) {
1737 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1738 return result;
1739 }
1740
1741 result = data.readUint64(&timestamp);
1742 if (result != NO_ERROR) {
1743 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1744 return result;
1745 }
1746
1747 DisplayedFrameStats stats;
1748 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1749 if (result == NO_ERROR) {
1750 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001751 reply->writeUint64Vector(stats.component_0_sample);
1752 reply->writeUint64Vector(stats.component_1_sample);
1753 reply->writeUint64Vector(stats.component_2_sample);
1754 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001755 }
1756 return result;
1757 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001758 case GET_PROTECTED_CONTENT_SUPPORT: {
1759 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1760 bool result;
1761 status_t error = getProtectedContentSupport(&result);
1762 if (error == NO_ERROR) {
1763 reply->writeBool(result);
1764 }
1765 return error;
1766 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001767 case IS_WIDE_COLOR_DISPLAY: {
1768 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1769 sp<IBinder> display = nullptr;
1770 status_t error = data.readStrongBinder(&display);
1771 if (error != NO_ERROR) {
1772 return error;
1773 }
1774 bool result;
1775 error = isWideColorDisplay(display, &result);
1776 if (error == NO_ERROR) {
1777 reply->writeBool(result);
1778 }
1779 return error;
1780 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001781 case GET_PHYSICAL_DISPLAY_IDS: {
1782 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marin Shalamanova524a092020-07-27 21:39:55 +02001783 std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
1784 std::vector<uint64_t> rawIds(ids.size());
1785 std::transform(ids.begin(), ids.end(), rawIds.begin(),
1786 [](PhysicalDisplayId id) { return id.value; });
1787 return reply->writeUint64Vector(rawIds);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001788 }
Dan Stoza84ab9372018-12-17 15:27:57 -08001789 case ADD_REGION_SAMPLING_LISTENER: {
1790 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1791 Rect samplingArea;
1792 status_t result = data.read(samplingArea);
1793 if (result != NO_ERROR) {
1794 ALOGE("addRegionSamplingListener: Failed to read sampling area");
1795 return result;
1796 }
1797 sp<IBinder> stopLayerHandle;
1798 result = data.readNullableStrongBinder(&stopLayerHandle);
1799 if (result != NO_ERROR) {
1800 ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
1801 return result;
1802 }
1803 sp<IRegionSamplingListener> listener;
1804 result = data.readNullableStrongBinder(&listener);
1805 if (result != NO_ERROR) {
1806 ALOGE("addRegionSamplingListener: Failed to read listener");
1807 return result;
1808 }
1809 return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
1810 }
1811 case REMOVE_REGION_SAMPLING_LISTENER: {
1812 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1813 sp<IRegionSamplingListener> listener;
1814 status_t result = data.readNullableStrongBinder(&listener);
1815 if (result != NO_ERROR) {
1816 ALOGE("removeRegionSamplingListener: Failed to read listener");
1817 return result;
1818 }
1819 return removeRegionSamplingListener(listener);
1820 }
Ana Krulec0782b882019-10-15 17:34:54 -07001821 case SET_DESIRED_DISPLAY_CONFIG_SPECS: {
1822 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1823 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001824 int32_t defaultConfig;
1825 status_t result = data.readInt32(&defaultConfig);
Ana Krulec0782b882019-10-15 17:34:54 -07001826 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001827 ALOGE("setDesiredDisplayConfigSpecs: failed to read defaultConfig: %d", result);
Ana Krulec0782b882019-10-15 17:34:54 -07001828 return result;
1829 }
Steven Thomasf734df42020-04-13 21:09:28 -07001830 float primaryRefreshRateMin;
1831 result = data.readFloat(&primaryRefreshRateMin);
Ana Krulec0782b882019-10-15 17:34:54 -07001832 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001833 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMin: %d",
1834 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001835 return result;
1836 }
Steven Thomasf734df42020-04-13 21:09:28 -07001837 float primaryRefreshRateMax;
1838 result = data.readFloat(&primaryRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001839 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001840 ALOGE("setDesiredDisplayConfigSpecs: failed to read primaryRefreshRateMax: %d",
1841 result);
Ana Krulec0782b882019-10-15 17:34:54 -07001842 return result;
1843 }
Steven Thomasf734df42020-04-13 21:09:28 -07001844 float appRequestRefreshRateMin;
1845 result = data.readFloat(&appRequestRefreshRateMin);
1846 if (result != NO_ERROR) {
1847 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMin: %d",
1848 result);
1849 return result;
1850 }
1851 float appRequestRefreshRateMax;
1852 result = data.readFloat(&appRequestRefreshRateMax);
1853 if (result != NO_ERROR) {
1854 ALOGE("setDesiredDisplayConfigSpecs: failed to read appRequestRefreshRateMax: %d",
1855 result);
1856 return result;
1857 }
1858 result =
1859 setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1860 primaryRefreshRateMax, appRequestRefreshRateMin,
1861 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001862 if (result != NO_ERROR) {
1863 ALOGE("setDesiredDisplayConfigSpecs: failed to call setDesiredDisplayConfigSpecs: "
1864 "%d",
1865 result);
1866 return result;
1867 }
1868 reply->writeInt32(result);
1869 return result;
1870 }
Ana Krulec234bb162019-11-10 22:55:55 +01001871 case GET_DESIRED_DISPLAY_CONFIG_SPECS: {
1872 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1873 sp<IBinder> displayToken = data.readStrongBinder();
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001874 int32_t defaultConfig;
Steven Thomasf734df42020-04-13 21:09:28 -07001875 float primaryRefreshRateMin;
1876 float primaryRefreshRateMax;
1877 float appRequestRefreshRateMin;
1878 float appRequestRefreshRateMax;
Ana Krulec234bb162019-11-10 22:55:55 +01001879
Steven Thomasf734df42020-04-13 21:09:28 -07001880 status_t result =
1881 getDesiredDisplayConfigSpecs(displayToken, &defaultConfig,
1882 &primaryRefreshRateMin, &primaryRefreshRateMax,
1883 &appRequestRefreshRateMin,
1884 &appRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001885 if (result != NO_ERROR) {
1886 ALOGE("getDesiredDisplayConfigSpecs: failed to get getDesiredDisplayConfigSpecs: "
1887 "%d",
1888 result);
1889 return result;
1890 }
1891
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001892 result = reply->writeInt32(defaultConfig);
Ana Krulec234bb162019-11-10 22:55:55 +01001893 if (result != NO_ERROR) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001894 ALOGE("getDesiredDisplayConfigSpecs: failed to write defaultConfig: %d", result);
Ana Krulec234bb162019-11-10 22:55:55 +01001895 return result;
1896 }
Steven Thomasf734df42020-04-13 21:09:28 -07001897 result = reply->writeFloat(primaryRefreshRateMin);
Ana Krulec234bb162019-11-10 22:55:55 +01001898 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001899 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMin: %d",
1900 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001901 return result;
1902 }
Steven Thomasf734df42020-04-13 21:09:28 -07001903 result = reply->writeFloat(primaryRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001904 if (result != NO_ERROR) {
Steven Thomasf734df42020-04-13 21:09:28 -07001905 ALOGE("getDesiredDisplayConfigSpecs: failed to write primaryRefreshRateMax: %d",
1906 result);
1907 return result;
1908 }
1909 result = reply->writeFloat(appRequestRefreshRateMin);
1910 if (result != NO_ERROR) {
1911 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMin: %d",
1912 result);
1913 return result;
1914 }
1915 result = reply->writeFloat(appRequestRefreshRateMax);
1916 if (result != NO_ERROR) {
1917 ALOGE("getDesiredDisplayConfigSpecs: failed to write appRequestRefreshRateMax: %d",
1918 result);
Ana Krulec234bb162019-11-10 22:55:55 +01001919 return result;
1920 }
1921 reply->writeInt32(result);
1922 return result;
1923 }
Dan Gittik57e63c52019-01-18 16:37:54 +00001924 case GET_DISPLAY_BRIGHTNESS_SUPPORT: {
1925 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1926 sp<IBinder> displayToken;
1927 status_t error = data.readNullableStrongBinder(&displayToken);
1928 if (error != NO_ERROR) {
1929 ALOGE("getDisplayBrightnessSupport: failed to read display token: %d", error);
1930 return error;
1931 }
1932 bool support = false;
1933 error = getDisplayBrightnessSupport(displayToken, &support);
1934 reply->writeBool(support);
1935 return error;
1936 }
1937 case SET_DISPLAY_BRIGHTNESS: {
1938 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1939 sp<IBinder> displayToken;
1940 status_t error = data.readNullableStrongBinder(&displayToken);
1941 if (error != NO_ERROR) {
1942 ALOGE("setDisplayBrightness: failed to read display token: %d", error);
1943 return error;
1944 }
1945 float brightness = -1.0f;
1946 error = data.readFloat(&brightness);
1947 if (error != NO_ERROR) {
1948 ALOGE("setDisplayBrightness: failed to read brightness: %d", error);
1949 return error;
1950 }
1951 return setDisplayBrightness(displayToken, brightness);
1952 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001953 case NOTIFY_POWER_BOOST: {
Ady Abraham8532d012019-05-08 14:50:56 -07001954 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001955 int32_t boostId;
1956 status_t error = data.readInt32(&boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001957 if (error != NO_ERROR) {
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001958 ALOGE("notifyPowerBoost: failed to read boostId: %d", error);
Ady Abraham8532d012019-05-08 14:50:56 -07001959 return error;
1960 }
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001961 return notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001962 }
Vishnu Nairb13bb952019-11-15 10:24:08 -08001963 case SET_GLOBAL_SHADOW_SETTINGS: {
1964 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1965
1966 std::vector<float> shadowConfig;
1967 status_t error = data.readFloatVector(&shadowConfig);
1968 if (error != NO_ERROR || shadowConfig.size() != 11) {
1969 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
1970 return error;
1971 }
1972
1973 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
1974 shadowConfig[3]};
1975 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
1976 float lightPosY = shadowConfig[8];
1977 float lightPosZ = shadowConfig[9];
1978 float lightRadius = shadowConfig[10];
1979 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
1980 lightRadius);
1981 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001982 case SET_FRAME_RATE: {
1983 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1984 sp<IBinder> binder;
1985 status_t err = data.readStrongBinder(&binder);
1986 if (err != NO_ERROR) {
1987 ALOGE("setFrameRate: failed to read strong binder: %s (%d)", strerror(-err), -err);
1988 return err;
1989 }
1990 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
1991 if (!surface) {
1992 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer: %s (%d)",
1993 strerror(-err), -err);
1994 return err;
1995 }
1996 float frameRate;
1997 err = data.readFloat(&frameRate);
1998 if (err != NO_ERROR) {
1999 ALOGE("setFrameRate: failed to read float: %s (%d)", strerror(-err), -err);
2000 return err;
2001 }
2002 int8_t compatibility;
2003 err = data.readByte(&compatibility);
2004 if (err != NO_ERROR) {
2005 ALOGE("setFrameRate: failed to read byte: %s (%d)", strerror(-err), -err);
2006 return err;
2007 }
2008 status_t result = setFrameRate(surface, frameRate, compatibility);
2009 reply->writeInt32(result);
2010 return NO_ERROR;
2011 }
Steven Thomasd4071902020-03-24 16:02:53 -07002012 case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: {
2013 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2014 sp<IBinder> token;
2015 status_t result = acquireFrameRateFlexibilityToken(&token);
2016 reply->writeInt32(result);
2017 if (result == NO_ERROR) {
2018 reply->writeStrongBinder(token);
2019 }
2020 return NO_ERROR;
2021 }
Jesse Hall6c913be2013-08-08 12:15:49 -07002022 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07002023 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07002024 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002025 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002026}
2027
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08002028} // namespace android