blob: 4357f798dfa6c7fbdcde807c0c958a968a61ecc4 [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>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080029#include <gui/ISurfaceComposer.h>
30#include <gui/ISurfaceComposerClient.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080031#include <gui/LayerDebugInfo.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070032#include <gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080033
Michael Wright28f24d02016-07-12 13:30:53 -070034#include <system/graphics.h>
35
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070037#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070038#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Jamie Gennis134f0422011-03-08 12:18:54 -080040#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080041
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042// ---------------------------------------------------------------------------
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044namespace android {
45
Peiyong Lin9f034472018-03-28 15:29:00 -070046using ui::ColorMode;
47
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
49{
50public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070051 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 : BpInterface<ISurfaceComposer>(impl)
53 {
54 }
55
Dan Stozad723bd72014-11-18 10:24:03 -080056 virtual ~BpSurfaceComposer();
57
Mathias Agopian7e27f052010-05-28 14:22:23 -070058 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 Parcel data, reply;
61 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
62 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070063 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 }
65
Marissa Wall713b63f2018-10-17 15:42:43 -070066 virtual void setTransactionState(const Vector<ComposerState>& state,
67 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080068 const sp<IBinder>& applyToken,
Marissa Wall17b4e452018-12-26 16:32:34 -080069 const InputWindowCommands& commands,
70 int64_t desiredPresentTime) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 Parcel data, reply;
72 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080073
74 data.writeUint32(static_cast<uint32_t>(state.size()));
75 for (const auto& s : state) {
76 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070077 }
Dan Stozad723bd72014-11-18 10:24:03 -080078
79 data.writeUint32(static_cast<uint32_t>(displays.size()));
80 for (const auto& d : displays) {
81 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070085 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080086 commands.write(data);
Marissa Wall17b4e452018-12-26 16:32:34 -080087 data.writeInt64(desiredPresentTime);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070088 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 }
90
91 virtual void bootFinished()
92 {
93 Parcel data, reply;
94 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
95 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
96 }
97
Chavi Weingarten40482ff2017-11-30 01:51:40 +000098 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -070099 const ui::Dataspace reqDataspace,
100 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
101 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
102 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800103 Parcel data, reply;
104 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
105 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700106 data.writeInt32(static_cast<int32_t>(reqDataspace));
107 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700108 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800109 data.writeUint32(reqWidth);
110 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800111 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700112 data.writeInt32(static_cast<int32_t>(rotation));
Ana Krulec2d41e422018-07-26 12:07:43 -0700113 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
114 if (result != NO_ERROR) {
115 ALOGE("captureScreen failed to transact: %d", result);
116 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000117 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700118 result = reply.readInt32();
119 if (result != NO_ERROR) {
120 ALOGE("captureScreen failed to readInt32: %d", result);
121 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000122 }
123
124 *outBuffer = new GraphicBuffer();
125 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700126
Ana Krulec2d41e422018-07-26 12:07:43 -0700127 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800128 }
129
chaviwa76b2712017-09-20 12:02:26 -0700130 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700131 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
132 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800133 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700134 Parcel data, reply;
135 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
136 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700137 data.writeInt32(static_cast<int32_t>(reqDataspace));
138 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800139 data.write(sourceCrop);
140 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800141 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700142 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
143 if (result != NO_ERROR) {
144 ALOGE("captureLayers failed to transact: %d", result);
145 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000146 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700147 result = reply.readInt32();
148 if (result != NO_ERROR) {
149 ALOGE("captureLayers failed to readInt32: %d", result);
150 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000151 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700152
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000153 *outBuffer = new GraphicBuffer();
154 reply.read(**outBuffer);
155
Ana Krulec2d41e422018-07-26 12:07:43 -0700156 return result;
chaviwa76b2712017-09-20 12:02:26 -0700157 }
158
Jamie Gennis582270d2011-08-17 18:19:00 -0700159 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800160 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800161 {
162 Parcel data, reply;
163 int err = NO_ERROR;
164 err = data.writeInterfaceToken(
165 ISurfaceComposer::getInterfaceDescriptor());
166 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000167 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800168 "interface descriptor: %s (%d)", strerror(-err), -err);
169 return false;
170 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800171 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800172 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000173 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700174 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800175 return false;
176 }
177 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
178 &reply);
179 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000180 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700181 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800182 return false;
183 }
184 int32_t result = 0;
185 err = reply.readInt32(&result);
186 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000187 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700188 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800189 return false;
190 }
191 return result != 0;
192 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800193
Brian Anderson6b376712017-04-04 10:51:39 -0700194 virtual status_t getSupportedFrameTimestamps(
195 std::vector<FrameEvent>* outSupported) const {
196 if (!outSupported) {
197 return UNEXPECTED_NULL;
198 }
199 outSupported->clear();
200
201 Parcel data, reply;
202
203 status_t err = data.writeInterfaceToken(
204 ISurfaceComposer::getInterfaceDescriptor());
205 if (err != NO_ERROR) {
206 return err;
207 }
208
209 err = remote()->transact(
210 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
211 data, &reply);
212 if (err != NO_ERROR) {
213 return err;
214 }
215
216 int32_t result = 0;
217 err = reply.readInt32(&result);
218 if (err != NO_ERROR) {
219 return err;
220 }
221 if (result != NO_ERROR) {
222 return result;
223 }
224
225 std::vector<int32_t> supported;
226 err = reply.readInt32Vector(&supported);
227 if (err != NO_ERROR) {
228 return err;
229 }
230
231 outSupported->reserve(supported.size());
232 for (int32_t s : supported) {
233 outSupported->push_back(static_cast<FrameEvent>(s));
234 }
235 return NO_ERROR;
236 }
237
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700238 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800239 {
240 Parcel data, reply;
241 sp<IDisplayEventConnection> result;
242 int err = data.writeInterfaceToken(
243 ISurfaceComposer::getInterfaceDescriptor());
244 if (err != NO_ERROR) {
245 return result;
246 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700247 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800248 err = remote()->transact(
249 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
250 data, &reply);
251 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000252 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800253 "transaction: %s (%d)", strerror(-err), -err);
254 return result;
255 }
256 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
257 return result;
258 }
Colin Cross8e533062012-06-07 13:17:52 -0700259
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700260 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700261 {
262 Parcel data, reply;
263 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700264 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700265 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700266 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
267 return reply.readStrongBinder();
268 }
269
Jesse Hall6c913be2013-08-08 12:15:49 -0700270 virtual void destroyDisplay(const sp<IBinder>& display)
271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
274 data.writeStrongBinder(display);
275 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
276 }
277
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800278 virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700279 Parcel data, reply;
280 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800281 if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
282 NO_ERROR) {
283 std::vector<PhysicalDisplayId> displayIds;
284 if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
285 return displayIds;
286 }
287 }
288
289 return {};
290 }
291
292 virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
293 Parcel data, reply;
294 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
295 data.writeUint64(displayId);
296 remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700297 return reply.readStrongBinder();
298 }
299
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700300 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700301 {
302 Parcel data, reply;
303 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700304 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700305 data.writeInt32(mode);
306 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700307 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700308
Dan Stoza7f7da322014-05-02 15:26:25 -0700309 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
310 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700311 {
312 Parcel data, reply;
313 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700314 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700315 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
316 status_t result = reply.readInt32();
317 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800318 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700319 configs->clear();
320 configs->resize(numConfigs);
321 for (size_t c = 0; c < numConfigs; ++c) {
322 memcpy(&(configs->editItemAt(c)),
323 reply.readInplace(sizeof(DisplayInfo)),
324 sizeof(DisplayInfo));
325 }
326 }
327 return result;
328 }
329
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700330 virtual status_t getDisplayStats(const sp<IBinder>& display,
331 DisplayStatInfo* stats)
332 {
333 Parcel data, reply;
334 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
335 data.writeStrongBinder(display);
336 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
337 status_t result = reply.readInt32();
338 if (result == NO_ERROR) {
339 memcpy(stats,
340 reply.readInplace(sizeof(DisplayStatInfo)),
341 sizeof(DisplayStatInfo));
342 }
343 return result;
344 }
345
Dan Stoza7f7da322014-05-02 15:26:25 -0700346 virtual int getActiveConfig(const sp<IBinder>& display)
347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
350 data.writeStrongBinder(display);
351 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
352 return reply.readInt32();
353 }
354
355 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
356 {
357 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700358 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
359 if (result != NO_ERROR) {
360 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
361 return result;
362 }
363 result = data.writeStrongBinder(display);
364 if (result != NO_ERROR) {
365 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
366 return result;
367 }
368 result = data.writeInt32(id);
369 if (result != NO_ERROR) {
370 ALOGE("setActiveConfig failed to writeInt32: %d", result);
371 return result;
372 }
373 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
374 if (result != NO_ERROR) {
375 ALOGE("setActiveConfig failed to transact: %d", result);
376 return result;
377 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700378 return reply.readInt32();
379 }
Svetoslavd85084b2014-03-20 10:28:31 -0700380
Michael Wright28f24d02016-07-12 13:30:53 -0700381 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700382 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700383 Parcel data, reply;
384 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
385 if (result != NO_ERROR) {
386 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
387 return result;
388 }
389 result = data.writeStrongBinder(display);
390 if (result != NO_ERROR) {
391 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
392 return result;
393 }
394 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
395 if (result != NO_ERROR) {
396 ALOGE("getDisplayColorModes failed to transact: %d", result);
397 return result;
398 }
399 result = static_cast<status_t>(reply.readInt32());
400 if (result == NO_ERROR) {
401 size_t numModes = reply.readUint32();
402 outColorModes->clear();
403 outColorModes->resize(numModes);
404 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700405 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700406 }
407 }
408 return result;
409 }
410
Daniel Solomon42d04562019-01-20 21:03:19 -0800411 virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display,
412 ui::DisplayPrimaries& primaries) {
413 Parcel data, reply;
414 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
415 if (result != NO_ERROR) {
416 ALOGE("getDisplayNativePrimaries failed to writeInterfaceToken: %d", result);
417 return result;
418 }
419 result = data.writeStrongBinder(display);
420 if (result != NO_ERROR) {
421 ALOGE("getDisplayNativePrimaries failed to writeStrongBinder: %d", result);
422 return result;
423 }
424 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES, data, &reply);
425 if (result != NO_ERROR) {
426 ALOGE("getDisplayNativePrimaries failed to transact: %d", result);
427 return result;
428 }
429 result = reply.readInt32();
430 if (result == NO_ERROR) {
431 memcpy(&primaries, reply.readInplace(sizeof(ui::DisplayPrimaries)),
432 sizeof(ui::DisplayPrimaries));
433 }
434 return result;
435 }
436
Peiyong Lina52f0292018-03-14 17:26:31 -0700437 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700438 Parcel data, reply;
439 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
440 if (result != NO_ERROR) {
441 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700442 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700443 }
444 result = data.writeStrongBinder(display);
445 if (result != NO_ERROR) {
446 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700447 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700448 }
449 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
450 if (result != NO_ERROR) {
451 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700452 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700453 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700454 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700455 }
456
457 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700458 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700459 Parcel data, reply;
460 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
461 if (result != NO_ERROR) {
462 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
463 return result;
464 }
465 result = data.writeStrongBinder(display);
466 if (result != NO_ERROR) {
467 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
468 return result;
469 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700470 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700471 if (result != NO_ERROR) {
472 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
473 return result;
474 }
475 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
476 if (result != NO_ERROR) {
477 ALOGE("setActiveColorMode failed to transact: %d", result);
478 return result;
479 }
480 return static_cast<status_t>(reply.readInt32());
481 }
482
Svetoslavd85084b2014-03-20 10:28:31 -0700483 virtual status_t clearAnimationFrameStats() {
484 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700485 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
486 if (result != NO_ERROR) {
487 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
488 return result;
489 }
490 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
491 if (result != NO_ERROR) {
492 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
493 return result;
494 }
Svetoslavd85084b2014-03-20 10:28:31 -0700495 return reply.readInt32();
496 }
497
498 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
499 Parcel data, reply;
500 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
501 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
502 reply.read(*outStats);
503 return reply.readInt32();
504 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700505
506 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
507 HdrCapabilities* outCapabilities) const {
508 Parcel data, reply;
509 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
510 status_t result = data.writeStrongBinder(display);
511 if (result != NO_ERROR) {
512 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
513 return result;
514 }
515 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
516 data, &reply);
517 if (result != NO_ERROR) {
518 ALOGE("getHdrCapabilities failed to transact: %d", result);
519 return result;
520 }
521 result = reply.readInt32();
522 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800523 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700524 }
525 return result;
526 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700527
528 virtual status_t enableVSyncInjections(bool enable) {
529 Parcel data, reply;
530 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
531 if (result != NO_ERROR) {
532 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
533 return result;
534 }
535 result = data.writeBool(enable);
536 if (result != NO_ERROR) {
537 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
538 return result;
539 }
540 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
541 data, &reply, TF_ONE_WAY);
542 if (result != NO_ERROR) {
543 ALOGE("enableVSyncInjections failed to transact: %d", result);
544 return result;
545 }
546 return result;
547 }
548
549 virtual status_t injectVSync(nsecs_t when) {
550 Parcel data, reply;
551 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
552 if (result != NO_ERROR) {
553 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
554 return result;
555 }
556 result = data.writeInt64(when);
557 if (result != NO_ERROR) {
558 ALOGE("injectVSync failed to writeInt64: %d", result);
559 return result;
560 }
561 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
562 if (result != NO_ERROR) {
563 ALOGE("injectVSync failed to transact: %d", result);
564 return result;
565 }
566 return result;
567 }
568
Kalle Raitaa099a242017-01-11 11:17:29 -0800569 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
570 {
571 if (!outLayers) {
572 return UNEXPECTED_NULL;
573 }
574
575 Parcel data, reply;
576
577 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
578 if (err != NO_ERROR) {
579 return err;
580 }
581
582 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
583 if (err != NO_ERROR) {
584 return err;
585 }
586
587 int32_t result = 0;
588 err = reply.readInt32(&result);
589 if (err != NO_ERROR) {
590 return err;
591 }
592 if (result != NO_ERROR) {
593 return result;
594 }
595
596 outLayers->clear();
597 return reply.readParcelableVector(outLayers);
598 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700599
Peiyong Linc6780972018-10-28 15:24:08 -0700600 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
601 ui::PixelFormat* defaultPixelFormat,
602 ui::Dataspace* wideColorGamutDataspace,
603 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700604 Parcel data, reply;
605 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
606 if (error != NO_ERROR) {
607 return error;
608 }
609 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
610 if (error != NO_ERROR) {
611 return error;
612 }
613 error = static_cast<status_t>(reply.readInt32());
614 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700615 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
616 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
617 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
618 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700619 }
620 return error;
621 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700622
Ady Abraham37965d42018-11-01 13:43:32 -0700623 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700624 Parcel data, reply;
625 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700626 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
627 bool result;
628 status_t err = reply.readBool(&result);
629 if (err == NO_ERROR) {
630 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700631 }
Ady Abraham37965d42018-11-01 13:43:32 -0700632 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700633 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700634
635 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
636 ui::PixelFormat* outFormat,
637 ui::Dataspace* outDataspace,
638 uint8_t* outComponentMask) const {
639 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
640 Parcel data, reply;
641 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
642 data.writeStrongBinder(display);
643
644 status_t error =
645 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
646 data, &reply);
647 if (error != NO_ERROR) {
648 return error;
649 }
650
651 uint32_t value = 0;
652 error = reply.readUint32(&value);
653 if (error != NO_ERROR) {
654 return error;
655 }
656 *outFormat = static_cast<ui::PixelFormat>(value);
657
658 error = reply.readUint32(&value);
659 if (error != NO_ERROR) {
660 return error;
661 }
662 *outDataspace = static_cast<ui::Dataspace>(value);
663
664 error = reply.readUint32(&value);
665 if (error != NO_ERROR) {
666 return error;
667 }
668 *outComponentMask = static_cast<uint8_t>(value);
669 return error;
670 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800671
672 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
673 uint8_t componentMask,
674 uint64_t maxFrames) const {
675 Parcel data, reply;
676 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
677 data.writeStrongBinder(display);
678 data.writeBool(enable);
679 data.writeByte(static_cast<int8_t>(componentMask));
680 data.writeUint64(maxFrames);
681 status_t result =
682 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
683 &reply);
684 return result;
685 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700686
687 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
688 uint64_t timestamp,
689 DisplayedFrameStats* outStats) const {
690 if (!outStats) return BAD_VALUE;
691
692 Parcel data, reply;
693 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
694 data.writeStrongBinder(display);
695 data.writeUint64(maxFrames);
696 data.writeUint64(timestamp);
697
698 status_t result =
699 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
700
701 if (result != NO_ERROR) {
702 return result;
703 }
704
705 result = reply.readUint64(&outStats->numFrames);
706 if (result != NO_ERROR) {
707 return result;
708 }
709
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800710 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700711 if (result != NO_ERROR) {
712 return result;
713 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800714 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700715 if (result != NO_ERROR) {
716 return result;
717 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800718 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700719 if (result != NO_ERROR) {
720 return result;
721 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800722 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700723 return result;
724 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800725
726 virtual status_t getProtectedContentSupport(bool* outSupported) const {
727 Parcel data, reply;
728 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Peiyong Linb6888fa2019-01-28 13:20:58 -0800729 status_t error =
730 remote()->transact(BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT, data, &reply);
731 if (error != NO_ERROR) {
732 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800733 }
Peiyong Linb6888fa2019-01-28 13:20:58 -0800734 error = reply.readBool(outSupported);
735 return error;
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800736 }
Marissa Wallebc2c052019-01-16 19:16:55 -0800737
738 virtual status_t cacheBuffer(const sp<IBinder>& token, const sp<GraphicBuffer>& buffer,
739 int32_t* outBufferId) {
740 Parcel data, reply;
741 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
742
743 data.writeStrongBinder(token);
744 if (buffer) {
745 data.writeBool(true);
746 data.write(*buffer);
747 } else {
748 data.writeBool(false);
749 }
750
751 status_t result = remote()->transact(BnSurfaceComposer::CACHE_BUFFER, data, &reply);
752 if (result != NO_ERROR) {
753 return result;
754 }
755
756 int32_t id = -1;
757 result = reply.readInt32(&id);
758 if (result == NO_ERROR) {
759 *outBufferId = id;
760 }
761 return result;
762 }
763
764 virtual status_t uncacheBuffer(const sp<IBinder>& token, int32_t bufferId) {
765 Parcel data, reply;
766 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
767
768 data.writeStrongBinder(token);
769 data.writeInt32(bufferId);
770
771 return remote()->transact(BnSurfaceComposer::UNCACHE_BUFFER, data, &reply);
772 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800773
774 virtual status_t isWideColorDisplay(const sp<IBinder>& token,
775 bool* outIsWideColorDisplay) const {
776 Parcel data, reply;
777 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
778 if (error != NO_ERROR) {
779 return error;
780 }
781 error = data.writeStrongBinder(token);
782 if (error != NO_ERROR) {
783 return error;
784 }
785
786 error = remote()->transact(BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY, data, &reply);
787 if (error != NO_ERROR) {
788 return error;
789 }
790 error = reply.readBool(outIsWideColorDisplay);
791 return error;
792 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800793};
794
Dan Stozad723bd72014-11-18 10:24:03 -0800795// Out-of-line virtual method definition to trigger vtable emission in this
796// translation unit (see clang warning -Wweak-vtables)
797BpSurfaceComposer::~BpSurfaceComposer() {}
798
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800799IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
800
801// ----------------------------------------------------------------------
802
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800803status_t BnSurfaceComposer::onTransact(
804 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
805{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800806 switch(code) {
807 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700808 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800809 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800810 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700811 return NO_ERROR;
812 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700813 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700814 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800815
816 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700817 if (count > data.dataSize()) {
818 return BAD_VALUE;
819 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700820 Vector<ComposerState> state;
821 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800822 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700823 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700824 if (s.read(data) == BAD_VALUE) {
825 return BAD_VALUE;
826 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700827 state.add(s);
828 }
Dan Stozad723bd72014-11-18 10:24:03 -0800829
830 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700831 if (count > data.dataSize()) {
832 return BAD_VALUE;
833 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700834 DisplayState d;
835 Vector<DisplayState> displays;
836 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800837 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700838 if (d.read(data) == BAD_VALUE) {
839 return BAD_VALUE;
840 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700841 displays.add(d);
842 }
Dan Stozad723bd72014-11-18 10:24:03 -0800843
844 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700845 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800846 InputWindowCommands inputWindowCommands;
847 inputWindowCommands.read(data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800848
849 int64_t desiredPresentTime = data.readInt64();
850 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands,
851 desiredPresentTime);
Jesse Hall6c913be2013-08-08 12:15:49 -0700852 return NO_ERROR;
853 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800854 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700855 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800856 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700857 return NO_ERROR;
858 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800859 case CAPTURE_SCREEN: {
860 CHECK_INTERFACE(ISurfaceComposer, data, reply);
861 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700862 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
863 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000864 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700865 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700866 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800867 uint32_t reqWidth = data.readUint32();
868 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800869 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800870 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800871
Peiyong Lin0e003c92018-09-17 11:09:51 -0700872 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
873 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000874 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800875 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000876 if (res == NO_ERROR) {
877 reply->write(*outBuffer);
878 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700879 return NO_ERROR;
880 }
chaviwa76b2712017-09-20 12:02:26 -0700881 case CAPTURE_LAYERS: {
882 CHECK_INTERFACE(ISurfaceComposer, data, reply);
883 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700884 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
885 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000886 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800887 Rect sourceCrop(Rect::EMPTY_RECT);
888 data.read(sourceCrop);
889 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800890 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700891
Peiyong Lin0e003c92018-09-17 11:09:51 -0700892 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
893 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700894 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000895 if (res == NO_ERROR) {
896 reply->write(*outBuffer);
897 }
chaviwa76b2712017-09-20 12:02:26 -0700898 return NO_ERROR;
899 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800900 case AUTHENTICATE_SURFACE: {
901 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800902 sp<IGraphicBufferProducer> bufferProducer =
903 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
904 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800905 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700906 return NO_ERROR;
907 }
Brian Anderson6b376712017-04-04 10:51:39 -0700908 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
909 CHECK_INTERFACE(ISurfaceComposer, data, reply);
910 std::vector<FrameEvent> supportedTimestamps;
911 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
912 status_t err = reply->writeInt32(result);
913 if (err != NO_ERROR) {
914 return err;
915 }
916 if (result != NO_ERROR) {
917 return result;
918 }
919
920 std::vector<int32_t> supported;
921 supported.reserve(supportedTimestamps.size());
922 for (FrameEvent s : supportedTimestamps) {
923 supported.push_back(static_cast<int32_t>(s));
924 }
925 return reply->writeInt32Vector(supported);
926 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800927 case CREATE_DISPLAY_EVENT_CONNECTION: {
928 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700929 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
930 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800931 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800932 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700933 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700934 case CREATE_DISPLAY: {
935 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700936 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700937 bool secure = bool(data.readInt32());
938 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700939 reply->writeStrongBinder(display);
940 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700941 }
942 case DESTROY_DISPLAY: {
943 CHECK_INTERFACE(ISurfaceComposer, data, reply);
944 sp<IBinder> display = data.readStrongBinder();
945 destroyDisplay(display);
946 return NO_ERROR;
947 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800948 case GET_PHYSICAL_DISPLAY_TOKEN: {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700949 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800950 PhysicalDisplayId displayId = data.readUint64();
951 sp<IBinder> display = getPhysicalDisplayToken(displayId);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700952 reply->writeStrongBinder(display);
953 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700954 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700955 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700956 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700957 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700958 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700959 status_t result = getDisplayConfigs(display, &configs);
960 reply->writeInt32(result);
961 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800962 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700963 for (size_t c = 0; c < configs.size(); ++c) {
964 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
965 &configs[c], sizeof(DisplayInfo));
966 }
967 }
968 return NO_ERROR;
969 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700970 case GET_DISPLAY_STATS: {
971 CHECK_INTERFACE(ISurfaceComposer, data, reply);
972 DisplayStatInfo stats;
973 sp<IBinder> display = data.readStrongBinder();
974 status_t result = getDisplayStats(display, &stats);
975 reply->writeInt32(result);
976 if (result == NO_ERROR) {
977 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
978 &stats, sizeof(DisplayStatInfo));
979 }
980 return NO_ERROR;
981 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700982 case GET_ACTIVE_CONFIG: {
983 CHECK_INTERFACE(ISurfaceComposer, data, reply);
984 sp<IBinder> display = data.readStrongBinder();
985 int id = getActiveConfig(display);
986 reply->writeInt32(id);
987 return NO_ERROR;
988 }
989 case SET_ACTIVE_CONFIG: {
990 CHECK_INTERFACE(ISurfaceComposer, data, reply);
991 sp<IBinder> display = data.readStrongBinder();
992 int id = data.readInt32();
993 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700994 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700995 return NO_ERROR;
996 }
Michael Wright28f24d02016-07-12 13:30:53 -0700997 case GET_DISPLAY_COLOR_MODES: {
998 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700999 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -07001000 sp<IBinder> display = nullptr;
1001 status_t result = data.readStrongBinder(&display);
1002 if (result != NO_ERROR) {
1003 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
1004 return result;
1005 }
1006 result = getDisplayColorModes(display, &colorModes);
1007 reply->writeInt32(result);
1008 if (result == NO_ERROR) {
1009 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
1010 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -07001011 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -07001012 }
1013 }
1014 return NO_ERROR;
1015 }
Daniel Solomon42d04562019-01-20 21:03:19 -08001016 case GET_DISPLAY_NATIVE_PRIMARIES: {
1017 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1018 ui::DisplayPrimaries primaries;
1019 sp<IBinder> display = nullptr;
1020
1021 status_t result = data.readStrongBinder(&display);
1022 if (result != NO_ERROR) {
1023 ALOGE("getDisplayNativePrimaries failed to readStrongBinder: %d", result);
1024 return result;
1025 }
1026
1027 result = getDisplayNativePrimaries(display, primaries);
1028 reply->writeInt32(result);
1029 if (result == NO_ERROR) {
1030 memcpy(reply->writeInplace(sizeof(ui::DisplayPrimaries)), &primaries,
1031 sizeof(ui::DisplayPrimaries));
1032 }
1033
1034 return NO_ERROR;
1035 }
Michael Wright28f24d02016-07-12 13:30:53 -07001036 case GET_ACTIVE_COLOR_MODE: {
1037 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1038 sp<IBinder> display = nullptr;
1039 status_t result = data.readStrongBinder(&display);
1040 if (result != NO_ERROR) {
1041 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1042 return result;
1043 }
Peiyong Lina52f0292018-03-14 17:26:31 -07001044 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -07001045 result = reply->writeInt32(static_cast<int32_t>(colorMode));
1046 return result;
1047 }
1048 case SET_ACTIVE_COLOR_MODE: {
1049 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1050 sp<IBinder> display = nullptr;
1051 status_t result = data.readStrongBinder(&display);
1052 if (result != NO_ERROR) {
1053 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
1054 return result;
1055 }
1056 int32_t colorModeInt = 0;
1057 result = data.readInt32(&colorModeInt);
1058 if (result != NO_ERROR) {
1059 ALOGE("setActiveColorMode failed to readInt32: %d", result);
1060 return result;
1061 }
1062 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001063 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -07001064 result = reply->writeInt32(result);
1065 return result;
1066 }
Svetoslavd85084b2014-03-20 10:28:31 -07001067 case CLEAR_ANIMATION_FRAME_STATS: {
1068 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1069 status_t result = clearAnimationFrameStats();
1070 reply->writeInt32(result);
1071 return NO_ERROR;
1072 }
1073 case GET_ANIMATION_FRAME_STATS: {
1074 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1075 FrameStats stats;
1076 status_t result = getAnimationFrameStats(&stats);
1077 reply->write(stats);
1078 reply->writeInt32(result);
1079 return NO_ERROR;
1080 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001081 case SET_POWER_MODE: {
1082 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1083 sp<IBinder> display = data.readStrongBinder();
1084 int32_t mode = data.readInt32();
1085 setPowerMode(display, mode);
1086 return NO_ERROR;
1087 }
Dan Stozac4f471e2016-03-24 09:31:08 -07001088 case GET_HDR_CAPABILITIES: {
1089 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1090 sp<IBinder> display = nullptr;
1091 status_t result = data.readStrongBinder(&display);
1092 if (result != NO_ERROR) {
1093 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
1094 result);
1095 return result;
1096 }
1097 HdrCapabilities capabilities;
1098 result = getHdrCapabilities(display, &capabilities);
1099 reply->writeInt32(result);
1100 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -08001101 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -07001102 }
1103 return NO_ERROR;
1104 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001105 case ENABLE_VSYNC_INJECTIONS: {
1106 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1107 bool enable = false;
1108 status_t result = data.readBool(&enable);
1109 if (result != NO_ERROR) {
1110 ALOGE("enableVSyncInjections failed to readBool: %d", result);
1111 return result;
1112 }
1113 return enableVSyncInjections(enable);
1114 }
1115 case INJECT_VSYNC: {
1116 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1117 int64_t when = 0;
1118 status_t result = data.readInt64(&when);
1119 if (result != NO_ERROR) {
1120 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1121 return result;
1122 }
1123 return injectVSync(when);
1124 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001125 case GET_LAYER_DEBUG_INFO: {
1126 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1127 std::vector<LayerDebugInfo> outLayers;
1128 status_t result = getLayerDebugInfo(&outLayers);
1129 reply->writeInt32(result);
1130 if (result == NO_ERROR)
1131 {
1132 result = reply->writeParcelableVector(outLayers);
1133 }
1134 return result;
1135 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001136 case GET_COMPOSITION_PREFERENCE: {
1137 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001138 ui::Dataspace defaultDataspace;
1139 ui::PixelFormat defaultPixelFormat;
1140 ui::Dataspace wideColorGamutDataspace;
1141 ui::PixelFormat wideColorGamutPixelFormat;
1142 status_t error =
1143 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1144 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001145 reply->writeInt32(error);
1146 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001147 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1148 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1149 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001150 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001151 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001152 return error;
Peiyong Lin0256f722018-08-31 15:45:10 -07001153 }
Ady Abraham37965d42018-11-01 13:43:32 -07001154 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001155 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001156 bool result;
1157 status_t error = getColorManagement(&result);
1158 if (error == NO_ERROR) {
1159 reply->writeBool(result);
1160 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001161 return error;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001162 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001163 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1164 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1165
1166 sp<IBinder> display = data.readStrongBinder();
1167 ui::PixelFormat format;
1168 ui::Dataspace dataspace;
1169 uint8_t component = 0;
1170 auto result =
1171 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1172 if (result == NO_ERROR) {
1173 reply->writeUint32(static_cast<uint32_t>(format));
1174 reply->writeUint32(static_cast<uint32_t>(dataspace));
1175 reply->writeUint32(static_cast<uint32_t>(component));
1176 }
1177 return result;
1178 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001179 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1180 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1181
1182 sp<IBinder> display = nullptr;
1183 bool enable = false;
1184 int8_t componentMask = 0;
1185 uint64_t maxFrames = 0;
1186 status_t result = data.readStrongBinder(&display);
1187 if (result != NO_ERROR) {
1188 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1189 result);
1190 return result;
1191 }
1192
1193 result = data.readBool(&enable);
1194 if (result != NO_ERROR) {
1195 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1196 return result;
1197 }
1198
1199 result = data.readByte(static_cast<int8_t*>(&componentMask));
1200 if (result != NO_ERROR) {
1201 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1202 result);
1203 return result;
1204 }
1205
1206 result = data.readUint64(&maxFrames);
1207 if (result != NO_ERROR) {
1208 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1209 return result;
1210 }
1211
1212 return setDisplayContentSamplingEnabled(display, enable,
1213 static_cast<uint8_t>(componentMask), maxFrames);
1214 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001215 case GET_DISPLAYED_CONTENT_SAMPLE: {
1216 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1217
1218 sp<IBinder> display = data.readStrongBinder();
1219 uint64_t maxFrames = 0;
1220 uint64_t timestamp = 0;
1221
1222 status_t result = data.readUint64(&maxFrames);
1223 if (result != NO_ERROR) {
1224 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1225 return result;
1226 }
1227
1228 result = data.readUint64(&timestamp);
1229 if (result != NO_ERROR) {
1230 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1231 return result;
1232 }
1233
1234 DisplayedFrameStats stats;
1235 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1236 if (result == NO_ERROR) {
1237 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001238 reply->writeUint64Vector(stats.component_0_sample);
1239 reply->writeUint64Vector(stats.component_1_sample);
1240 reply->writeUint64Vector(stats.component_2_sample);
1241 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001242 }
1243 return result;
1244 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -08001245 case GET_PROTECTED_CONTENT_SUPPORT: {
1246 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1247 bool result;
1248 status_t error = getProtectedContentSupport(&result);
1249 if (error == NO_ERROR) {
1250 reply->writeBool(result);
1251 }
1252 return error;
1253 }
Marissa Wallebc2c052019-01-16 19:16:55 -08001254 case CACHE_BUFFER: {
1255 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1256 sp<IBinder> token;
1257 status_t result = data.readStrongBinder(&token);
1258 if (result != NO_ERROR) {
1259 ALOGE("cache buffer failure in reading token: %d", result);
1260 return result;
1261 }
1262
1263 sp<GraphicBuffer> buffer = new GraphicBuffer();
1264 if (data.readBool()) {
1265 result = data.read(*buffer);
1266 if (result != NO_ERROR) {
1267 ALOGE("cache buffer failure in reading buffer: %d", result);
1268 return result;
1269 }
1270 }
1271 int32_t bufferId = -1;
1272 status_t error = cacheBuffer(token, buffer, &bufferId);
1273 if (error == NO_ERROR) {
1274 reply->writeInt32(bufferId);
1275 }
1276 return error;
1277 }
1278 case UNCACHE_BUFFER: {
1279 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1280 sp<IBinder> token;
1281 status_t result = data.readStrongBinder(&token);
1282 if (result != NO_ERROR) {
1283 ALOGE("uncache buffer failure in reading token: %d", result);
1284 return result;
1285 }
1286
1287 int32_t bufferId = -1;
1288 result = data.readInt32(&bufferId);
1289 if (result != NO_ERROR) {
1290 ALOGE("uncache buffer failure in reading buffer id: %d", result);
1291 return result;
1292 }
1293
1294 return uncacheBuffer(token, bufferId);
1295 }
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001296 case IS_WIDE_COLOR_DISPLAY: {
1297 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1298 sp<IBinder> display = nullptr;
1299 status_t error = data.readStrongBinder(&display);
1300 if (error != NO_ERROR) {
1301 return error;
1302 }
1303 bool result;
1304 error = isWideColorDisplay(display, &result);
1305 if (error == NO_ERROR) {
1306 reply->writeBool(result);
1307 }
1308 return error;
1309 }
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001310 case GET_PHYSICAL_DISPLAY_IDS: {
1311 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1312 return reply->writeUint64Vector(getPhysicalDisplayIds());
1313 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001314 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001315 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001316 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001317 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001318}
1319
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001320} // namespace android