blob: 2f6ef79af90e5b53ba98cb14080870aa5610b7b3 [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
Robert Carr1db73f62016-12-21 12:58:51 -080066 virtual sp<ISurfaceComposerClient> createScopedConnection(
67 const sp<IGraphicBufferProducer>& parent)
68 {
69 Parcel data, reply;
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 data.writeStrongBinder(IInterface::asBinder(parent));
72 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
73 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
74 }
75
Marissa Wall713b63f2018-10-17 15:42:43 -070076 virtual void setTransactionState(const Vector<ComposerState>& state,
77 const Vector<DisplayState>& displays, uint32_t flags,
chaviw273171b2018-12-26 11:46:30 -080078 const sp<IBinder>& applyToken,
79 const InputWindowCommands& commands) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 Parcel data, reply;
81 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080082
83 data.writeUint32(static_cast<uint32_t>(state.size()));
84 for (const auto& s : state) {
85 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070086 }
Dan Stozad723bd72014-11-18 10:24:03 -080087
88 data.writeUint32(static_cast<uint32_t>(displays.size()));
89 for (const auto& d : displays) {
90 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070091 }
Dan Stozad723bd72014-11-18 10:24:03 -080092
93 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070094 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080095 commands.write(data);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070096 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 }
98
99 virtual void bootFinished()
100 {
101 Parcel data, reply;
102 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
103 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
104 }
105
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000106 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700107 const ui::Dataspace reqDataspace,
108 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
109 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
110 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800111 Parcel data, reply;
112 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
113 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700114 data.writeInt32(static_cast<int32_t>(reqDataspace));
115 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700116 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800117 data.writeUint32(reqWidth);
118 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800119 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700120 data.writeInt32(static_cast<int32_t>(rotation));
Ana Krulec2d41e422018-07-26 12:07:43 -0700121 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
122 if (result != NO_ERROR) {
123 ALOGE("captureScreen failed to transact: %d", result);
124 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000125 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700126 result = reply.readInt32();
127 if (result != NO_ERROR) {
128 ALOGE("captureScreen failed to readInt32: %d", result);
129 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000130 }
131
132 *outBuffer = new GraphicBuffer();
133 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700134
Ana Krulec2d41e422018-07-26 12:07:43 -0700135 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800136 }
137
chaviwa76b2712017-09-20 12:02:26 -0700138 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700139 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
140 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800141 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700142 Parcel data, reply;
143 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
144 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700145 data.writeInt32(static_cast<int32_t>(reqDataspace));
146 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800147 data.write(sourceCrop);
148 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800149 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700150 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
151 if (result != NO_ERROR) {
152 ALOGE("captureLayers failed to transact: %d", result);
153 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000154 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700155 result = reply.readInt32();
156 if (result != NO_ERROR) {
157 ALOGE("captureLayers failed to readInt32: %d", result);
158 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000159 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700160
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000161 *outBuffer = new GraphicBuffer();
162 reply.read(**outBuffer);
163
Ana Krulec2d41e422018-07-26 12:07:43 -0700164 return result;
chaviwa76b2712017-09-20 12:02:26 -0700165 }
166
Jamie Gennis582270d2011-08-17 18:19:00 -0700167 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800168 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800169 {
170 Parcel data, reply;
171 int err = NO_ERROR;
172 err = data.writeInterfaceToken(
173 ISurfaceComposer::getInterfaceDescriptor());
174 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000175 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800176 "interface descriptor: %s (%d)", strerror(-err), -err);
177 return false;
178 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800179 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800180 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000181 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700182 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800183 return false;
184 }
185 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
186 &reply);
187 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000188 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700189 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800190 return false;
191 }
192 int32_t result = 0;
193 err = reply.readInt32(&result);
194 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000195 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700196 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800197 return false;
198 }
199 return result != 0;
200 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800201
Brian Anderson6b376712017-04-04 10:51:39 -0700202 virtual status_t getSupportedFrameTimestamps(
203 std::vector<FrameEvent>* outSupported) const {
204 if (!outSupported) {
205 return UNEXPECTED_NULL;
206 }
207 outSupported->clear();
208
209 Parcel data, reply;
210
211 status_t err = data.writeInterfaceToken(
212 ISurfaceComposer::getInterfaceDescriptor());
213 if (err != NO_ERROR) {
214 return err;
215 }
216
217 err = remote()->transact(
218 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
219 data, &reply);
220 if (err != NO_ERROR) {
221 return err;
222 }
223
224 int32_t result = 0;
225 err = reply.readInt32(&result);
226 if (err != NO_ERROR) {
227 return err;
228 }
229 if (result != NO_ERROR) {
230 return result;
231 }
232
233 std::vector<int32_t> supported;
234 err = reply.readInt32Vector(&supported);
235 if (err != NO_ERROR) {
236 return err;
237 }
238
239 outSupported->reserve(supported.size());
240 for (int32_t s : supported) {
241 outSupported->push_back(static_cast<FrameEvent>(s));
242 }
243 return NO_ERROR;
244 }
245
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700246 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800247 {
248 Parcel data, reply;
249 sp<IDisplayEventConnection> result;
250 int err = data.writeInterfaceToken(
251 ISurfaceComposer::getInterfaceDescriptor());
252 if (err != NO_ERROR) {
253 return result;
254 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700255 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800256 err = remote()->transact(
257 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
258 data, &reply);
259 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000260 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800261 "transaction: %s (%d)", strerror(-err), -err);
262 return result;
263 }
264 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
265 return result;
266 }
Colin Cross8e533062012-06-07 13:17:52 -0700267
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700268 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700269 {
270 Parcel data, reply;
271 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700272 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700273 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700274 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
275 return reply.readStrongBinder();
276 }
277
Jesse Hall6c913be2013-08-08 12:15:49 -0700278 virtual void destroyDisplay(const sp<IBinder>& display)
279 {
280 Parcel data, reply;
281 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
282 data.writeStrongBinder(display);
283 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
284 }
285
Mathias Agopiane57f2922012-08-09 16:29:12 -0700286 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
287 {
288 Parcel data, reply;
289 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
290 data.writeInt32(id);
291 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
292 return reply.readStrongBinder();
293 }
294
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700295 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700296 {
297 Parcel data, reply;
298 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700299 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700300 data.writeInt32(mode);
301 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700302 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700303
Dan Stoza7f7da322014-05-02 15:26:25 -0700304 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
305 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700309 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700310 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
311 status_t result = reply.readInt32();
312 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800313 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700314 configs->clear();
315 configs->resize(numConfigs);
316 for (size_t c = 0; c < numConfigs; ++c) {
317 memcpy(&(configs->editItemAt(c)),
318 reply.readInplace(sizeof(DisplayInfo)),
319 sizeof(DisplayInfo));
320 }
321 }
322 return result;
323 }
324
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700325 virtual status_t getDisplayStats(const sp<IBinder>& display,
326 DisplayStatInfo* stats)
327 {
328 Parcel data, reply;
329 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
330 data.writeStrongBinder(display);
331 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
332 status_t result = reply.readInt32();
333 if (result == NO_ERROR) {
334 memcpy(stats,
335 reply.readInplace(sizeof(DisplayStatInfo)),
336 sizeof(DisplayStatInfo));
337 }
338 return result;
339 }
340
Dan Stoza7f7da322014-05-02 15:26:25 -0700341 virtual int getActiveConfig(const sp<IBinder>& display)
342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
345 data.writeStrongBinder(display);
346 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
347 return reply.readInt32();
348 }
349
350 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
351 {
352 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700353 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
354 if (result != NO_ERROR) {
355 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
356 return result;
357 }
358 result = data.writeStrongBinder(display);
359 if (result != NO_ERROR) {
360 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
361 return result;
362 }
363 result = data.writeInt32(id);
364 if (result != NO_ERROR) {
365 ALOGE("setActiveConfig failed to writeInt32: %d", result);
366 return result;
367 }
368 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
369 if (result != NO_ERROR) {
370 ALOGE("setActiveConfig failed to transact: %d", result);
371 return result;
372 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700373 return reply.readInt32();
374 }
Svetoslavd85084b2014-03-20 10:28:31 -0700375
Michael Wright28f24d02016-07-12 13:30:53 -0700376 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700377 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700378 Parcel data, reply;
379 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
380 if (result != NO_ERROR) {
381 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
382 return result;
383 }
384 result = data.writeStrongBinder(display);
385 if (result != NO_ERROR) {
386 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
387 return result;
388 }
389 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
390 if (result != NO_ERROR) {
391 ALOGE("getDisplayColorModes failed to transact: %d", result);
392 return result;
393 }
394 result = static_cast<status_t>(reply.readInt32());
395 if (result == NO_ERROR) {
396 size_t numModes = reply.readUint32();
397 outColorModes->clear();
398 outColorModes->resize(numModes);
399 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700400 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700401 }
402 }
403 return result;
404 }
405
Peiyong Lina52f0292018-03-14 17:26:31 -0700406 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
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("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700411 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700412 }
413 result = data.writeStrongBinder(display);
414 if (result != NO_ERROR) {
415 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700416 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700417 }
418 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
419 if (result != NO_ERROR) {
420 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700421 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700422 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700423 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700424 }
425
426 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700427 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700428 Parcel data, reply;
429 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
430 if (result != NO_ERROR) {
431 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
432 return result;
433 }
434 result = data.writeStrongBinder(display);
435 if (result != NO_ERROR) {
436 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
437 return result;
438 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700439 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700440 if (result != NO_ERROR) {
441 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
442 return result;
443 }
444 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
445 if (result != NO_ERROR) {
446 ALOGE("setActiveColorMode failed to transact: %d", result);
447 return result;
448 }
449 return static_cast<status_t>(reply.readInt32());
450 }
451
Svetoslavd85084b2014-03-20 10:28:31 -0700452 virtual status_t clearAnimationFrameStats() {
453 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700454 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
455 if (result != NO_ERROR) {
456 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
457 return result;
458 }
459 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
460 if (result != NO_ERROR) {
461 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
462 return result;
463 }
Svetoslavd85084b2014-03-20 10:28:31 -0700464 return reply.readInt32();
465 }
466
467 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
468 Parcel data, reply;
469 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
470 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
471 reply.read(*outStats);
472 return reply.readInt32();
473 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700474
475 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
476 HdrCapabilities* outCapabilities) const {
477 Parcel data, reply;
478 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
479 status_t result = data.writeStrongBinder(display);
480 if (result != NO_ERROR) {
481 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
482 return result;
483 }
484 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
485 data, &reply);
486 if (result != NO_ERROR) {
487 ALOGE("getHdrCapabilities failed to transact: %d", result);
488 return result;
489 }
490 result = reply.readInt32();
491 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800492 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700493 }
494 return result;
495 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700496
497 virtual status_t enableVSyncInjections(bool enable) {
498 Parcel data, reply;
499 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
500 if (result != NO_ERROR) {
501 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
502 return result;
503 }
504 result = data.writeBool(enable);
505 if (result != NO_ERROR) {
506 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
507 return result;
508 }
509 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
510 data, &reply, TF_ONE_WAY);
511 if (result != NO_ERROR) {
512 ALOGE("enableVSyncInjections failed to transact: %d", result);
513 return result;
514 }
515 return result;
516 }
517
518 virtual status_t injectVSync(nsecs_t when) {
519 Parcel data, reply;
520 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
521 if (result != NO_ERROR) {
522 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
523 return result;
524 }
525 result = data.writeInt64(when);
526 if (result != NO_ERROR) {
527 ALOGE("injectVSync failed to writeInt64: %d", result);
528 return result;
529 }
530 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
531 if (result != NO_ERROR) {
532 ALOGE("injectVSync failed to transact: %d", result);
533 return result;
534 }
535 return result;
536 }
537
Kalle Raitaa099a242017-01-11 11:17:29 -0800538 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
539 {
540 if (!outLayers) {
541 return UNEXPECTED_NULL;
542 }
543
544 Parcel data, reply;
545
546 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
547 if (err != NO_ERROR) {
548 return err;
549 }
550
551 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
552 if (err != NO_ERROR) {
553 return err;
554 }
555
556 int32_t result = 0;
557 err = reply.readInt32(&result);
558 if (err != NO_ERROR) {
559 return err;
560 }
561 if (result != NO_ERROR) {
562 return result;
563 }
564
565 outLayers->clear();
566 return reply.readParcelableVector(outLayers);
567 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700568
Peiyong Linc6780972018-10-28 15:24:08 -0700569 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
570 ui::PixelFormat* defaultPixelFormat,
571 ui::Dataspace* wideColorGamutDataspace,
572 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700573 Parcel data, reply;
574 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
575 if (error != NO_ERROR) {
576 return error;
577 }
578 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
579 if (error != NO_ERROR) {
580 return error;
581 }
582 error = static_cast<status_t>(reply.readInt32());
583 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700584 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
585 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
586 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
587 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700588 }
589 return error;
590 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700591
Ady Abraham37965d42018-11-01 13:43:32 -0700592 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700593 Parcel data, reply;
594 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700595 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
596 bool result;
597 status_t err = reply.readBool(&result);
598 if (err == NO_ERROR) {
599 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700600 }
Ady Abraham37965d42018-11-01 13:43:32 -0700601 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700602 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700603
604 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
605 ui::PixelFormat* outFormat,
606 ui::Dataspace* outDataspace,
607 uint8_t* outComponentMask) const {
608 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
609 Parcel data, reply;
610 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
611 data.writeStrongBinder(display);
612
613 status_t error =
614 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
615 data, &reply);
616 if (error != NO_ERROR) {
617 return error;
618 }
619
620 uint32_t value = 0;
621 error = reply.readUint32(&value);
622 if (error != NO_ERROR) {
623 return error;
624 }
625 *outFormat = static_cast<ui::PixelFormat>(value);
626
627 error = reply.readUint32(&value);
628 if (error != NO_ERROR) {
629 return error;
630 }
631 *outDataspace = static_cast<ui::Dataspace>(value);
632
633 error = reply.readUint32(&value);
634 if (error != NO_ERROR) {
635 return error;
636 }
637 *outComponentMask = static_cast<uint8_t>(value);
638 return error;
639 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800640
641 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
642 uint8_t componentMask,
643 uint64_t maxFrames) const {
644 Parcel data, reply;
645 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
646 data.writeStrongBinder(display);
647 data.writeBool(enable);
648 data.writeByte(static_cast<int8_t>(componentMask));
649 data.writeUint64(maxFrames);
650 status_t result =
651 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
652 &reply);
653 return result;
654 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700655
656 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
657 uint64_t timestamp,
658 DisplayedFrameStats* outStats) const {
659 if (!outStats) return BAD_VALUE;
660
661 Parcel data, reply;
662 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
663 data.writeStrongBinder(display);
664 data.writeUint64(maxFrames);
665 data.writeUint64(timestamp);
666
667 status_t result =
668 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
669
670 if (result != NO_ERROR) {
671 return result;
672 }
673
674 result = reply.readUint64(&outStats->numFrames);
675 if (result != NO_ERROR) {
676 return result;
677 }
678
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800679 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700680 if (result != NO_ERROR) {
681 return result;
682 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800683 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700684 if (result != NO_ERROR) {
685 return result;
686 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800687 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700688 if (result != NO_ERROR) {
689 return result;
690 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800691 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700692 return result;
693 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800694};
695
Dan Stozad723bd72014-11-18 10:24:03 -0800696// Out-of-line virtual method definition to trigger vtable emission in this
697// translation unit (see clang warning -Wweak-vtables)
698BpSurfaceComposer::~BpSurfaceComposer() {}
699
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800700IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
701
702// ----------------------------------------------------------------------
703
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800704status_t BnSurfaceComposer::onTransact(
705 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
706{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800707 switch(code) {
708 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700709 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800710 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800711 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700712 return NO_ERROR;
713 }
Robert Carr1db73f62016-12-21 12:58:51 -0800714 case CREATE_SCOPED_CONNECTION: {
715 CHECK_INTERFACE(ISurfaceComposer, data, reply);
716 sp<IGraphicBufferProducer> bufferProducer =
717 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
718 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
719 reply->writeStrongBinder(b);
720 return NO_ERROR;
721 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700722 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700723 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800724
725 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700726 if (count > data.dataSize()) {
727 return BAD_VALUE;
728 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700729 Vector<ComposerState> state;
730 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800731 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700732 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700733 if (s.read(data) == BAD_VALUE) {
734 return BAD_VALUE;
735 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700736 state.add(s);
737 }
Dan Stozad723bd72014-11-18 10:24:03 -0800738
739 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700740 if (count > data.dataSize()) {
741 return BAD_VALUE;
742 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700743 DisplayState d;
744 Vector<DisplayState> displays;
745 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800746 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700747 if (d.read(data) == BAD_VALUE) {
748 return BAD_VALUE;
749 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700750 displays.add(d);
751 }
Dan Stozad723bd72014-11-18 10:24:03 -0800752
753 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700754 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800755 InputWindowCommands inputWindowCommands;
756 inputWindowCommands.read(data);
757 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands);
Jesse Hall6c913be2013-08-08 12:15:49 -0700758 return NO_ERROR;
759 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800760 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700761 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800762 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700763 return NO_ERROR;
764 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800765 case CAPTURE_SCREEN: {
766 CHECK_INTERFACE(ISurfaceComposer, data, reply);
767 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700768 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
769 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000770 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700771 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700772 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800773 uint32_t reqWidth = data.readUint32();
774 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800775 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800776 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800777
Peiyong Lin0e003c92018-09-17 11:09:51 -0700778 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
779 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000780 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800781 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000782 if (res == NO_ERROR) {
783 reply->write(*outBuffer);
784 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700785 return NO_ERROR;
786 }
chaviwa76b2712017-09-20 12:02:26 -0700787 case CAPTURE_LAYERS: {
788 CHECK_INTERFACE(ISurfaceComposer, data, reply);
789 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700790 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
791 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000792 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800793 Rect sourceCrop(Rect::EMPTY_RECT);
794 data.read(sourceCrop);
795 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800796 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700797
Peiyong Lin0e003c92018-09-17 11:09:51 -0700798 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
799 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700800 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000801 if (res == NO_ERROR) {
802 reply->write(*outBuffer);
803 }
chaviwa76b2712017-09-20 12:02:26 -0700804 return NO_ERROR;
805 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800806 case AUTHENTICATE_SURFACE: {
807 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800808 sp<IGraphicBufferProducer> bufferProducer =
809 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
810 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800811 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700812 return NO_ERROR;
813 }
Brian Anderson6b376712017-04-04 10:51:39 -0700814 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
815 CHECK_INTERFACE(ISurfaceComposer, data, reply);
816 std::vector<FrameEvent> supportedTimestamps;
817 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
818 status_t err = reply->writeInt32(result);
819 if (err != NO_ERROR) {
820 return err;
821 }
822 if (result != NO_ERROR) {
823 return result;
824 }
825
826 std::vector<int32_t> supported;
827 supported.reserve(supportedTimestamps.size());
828 for (FrameEvent s : supportedTimestamps) {
829 supported.push_back(static_cast<int32_t>(s));
830 }
831 return reply->writeInt32Vector(supported);
832 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800833 case CREATE_DISPLAY_EVENT_CONNECTION: {
834 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700835 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
836 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800837 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800838 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700839 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700840 case CREATE_DISPLAY: {
841 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700842 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700843 bool secure = bool(data.readInt32());
844 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700845 reply->writeStrongBinder(display);
846 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700847 }
848 case DESTROY_DISPLAY: {
849 CHECK_INTERFACE(ISurfaceComposer, data, reply);
850 sp<IBinder> display = data.readStrongBinder();
851 destroyDisplay(display);
852 return NO_ERROR;
853 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700854 case GET_BUILT_IN_DISPLAY: {
855 CHECK_INTERFACE(ISurfaceComposer, data, reply);
856 int32_t id = data.readInt32();
857 sp<IBinder> display(getBuiltInDisplay(id));
858 reply->writeStrongBinder(display);
859 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700860 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700861 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700862 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700863 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700864 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700865 status_t result = getDisplayConfigs(display, &configs);
866 reply->writeInt32(result);
867 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800868 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700869 for (size_t c = 0; c < configs.size(); ++c) {
870 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
871 &configs[c], sizeof(DisplayInfo));
872 }
873 }
874 return NO_ERROR;
875 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700876 case GET_DISPLAY_STATS: {
877 CHECK_INTERFACE(ISurfaceComposer, data, reply);
878 DisplayStatInfo stats;
879 sp<IBinder> display = data.readStrongBinder();
880 status_t result = getDisplayStats(display, &stats);
881 reply->writeInt32(result);
882 if (result == NO_ERROR) {
883 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
884 &stats, sizeof(DisplayStatInfo));
885 }
886 return NO_ERROR;
887 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700888 case GET_ACTIVE_CONFIG: {
889 CHECK_INTERFACE(ISurfaceComposer, data, reply);
890 sp<IBinder> display = data.readStrongBinder();
891 int id = getActiveConfig(display);
892 reply->writeInt32(id);
893 return NO_ERROR;
894 }
895 case SET_ACTIVE_CONFIG: {
896 CHECK_INTERFACE(ISurfaceComposer, data, reply);
897 sp<IBinder> display = data.readStrongBinder();
898 int id = data.readInt32();
899 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700900 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700901 return NO_ERROR;
902 }
Michael Wright28f24d02016-07-12 13:30:53 -0700903 case GET_DISPLAY_COLOR_MODES: {
904 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700905 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -0700906 sp<IBinder> display = nullptr;
907 status_t result = data.readStrongBinder(&display);
908 if (result != NO_ERROR) {
909 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
910 return result;
911 }
912 result = getDisplayColorModes(display, &colorModes);
913 reply->writeInt32(result);
914 if (result == NO_ERROR) {
915 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
916 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700917 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -0700918 }
919 }
920 return NO_ERROR;
921 }
922 case GET_ACTIVE_COLOR_MODE: {
923 CHECK_INTERFACE(ISurfaceComposer, data, reply);
924 sp<IBinder> display = nullptr;
925 status_t result = data.readStrongBinder(&display);
926 if (result != NO_ERROR) {
927 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
928 return result;
929 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700930 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -0700931 result = reply->writeInt32(static_cast<int32_t>(colorMode));
932 return result;
933 }
934 case SET_ACTIVE_COLOR_MODE: {
935 CHECK_INTERFACE(ISurfaceComposer, data, reply);
936 sp<IBinder> display = nullptr;
937 status_t result = data.readStrongBinder(&display);
938 if (result != NO_ERROR) {
939 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
940 return result;
941 }
942 int32_t colorModeInt = 0;
943 result = data.readInt32(&colorModeInt);
944 if (result != NO_ERROR) {
945 ALOGE("setActiveColorMode failed to readInt32: %d", result);
946 return result;
947 }
948 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700949 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -0700950 result = reply->writeInt32(result);
951 return result;
952 }
Svetoslavd85084b2014-03-20 10:28:31 -0700953 case CLEAR_ANIMATION_FRAME_STATS: {
954 CHECK_INTERFACE(ISurfaceComposer, data, reply);
955 status_t result = clearAnimationFrameStats();
956 reply->writeInt32(result);
957 return NO_ERROR;
958 }
959 case GET_ANIMATION_FRAME_STATS: {
960 CHECK_INTERFACE(ISurfaceComposer, data, reply);
961 FrameStats stats;
962 status_t result = getAnimationFrameStats(&stats);
963 reply->write(stats);
964 reply->writeInt32(result);
965 return NO_ERROR;
966 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700967 case SET_POWER_MODE: {
968 CHECK_INTERFACE(ISurfaceComposer, data, reply);
969 sp<IBinder> display = data.readStrongBinder();
970 int32_t mode = data.readInt32();
971 setPowerMode(display, mode);
972 return NO_ERROR;
973 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700974 case GET_HDR_CAPABILITIES: {
975 CHECK_INTERFACE(ISurfaceComposer, data, reply);
976 sp<IBinder> display = nullptr;
977 status_t result = data.readStrongBinder(&display);
978 if (result != NO_ERROR) {
979 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
980 result);
981 return result;
982 }
983 HdrCapabilities capabilities;
984 result = getHdrCapabilities(display, &capabilities);
985 reply->writeInt32(result);
986 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800987 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700988 }
989 return NO_ERROR;
990 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700991 case ENABLE_VSYNC_INJECTIONS: {
992 CHECK_INTERFACE(ISurfaceComposer, data, reply);
993 bool enable = false;
994 status_t result = data.readBool(&enable);
995 if (result != NO_ERROR) {
996 ALOGE("enableVSyncInjections failed to readBool: %d", result);
997 return result;
998 }
999 return enableVSyncInjections(enable);
1000 }
1001 case INJECT_VSYNC: {
1002 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1003 int64_t when = 0;
1004 status_t result = data.readInt64(&when);
1005 if (result != NO_ERROR) {
1006 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
1007 return result;
1008 }
1009 return injectVSync(when);
1010 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001011 case GET_LAYER_DEBUG_INFO: {
1012 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1013 std::vector<LayerDebugInfo> outLayers;
1014 status_t result = getLayerDebugInfo(&outLayers);
1015 reply->writeInt32(result);
1016 if (result == NO_ERROR)
1017 {
1018 result = reply->writeParcelableVector(outLayers);
1019 }
1020 return result;
1021 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001022 case GET_COMPOSITION_PREFERENCE: {
1023 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001024 ui::Dataspace defaultDataspace;
1025 ui::PixelFormat defaultPixelFormat;
1026 ui::Dataspace wideColorGamutDataspace;
1027 ui::PixelFormat wideColorGamutPixelFormat;
1028 status_t error =
1029 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1030 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001031 reply->writeInt32(error);
1032 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001033 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1034 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1035 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001036 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001037 }
1038 return NO_ERROR;
1039 }
Ady Abraham37965d42018-11-01 13:43:32 -07001040 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001041 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001042 bool result;
1043 status_t error = getColorManagement(&result);
1044 if (error == NO_ERROR) {
1045 reply->writeBool(result);
1046 }
1047 return result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001048 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001049 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1050 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1051
1052 sp<IBinder> display = data.readStrongBinder();
1053 ui::PixelFormat format;
1054 ui::Dataspace dataspace;
1055 uint8_t component = 0;
1056 auto result =
1057 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1058 if (result == NO_ERROR) {
1059 reply->writeUint32(static_cast<uint32_t>(format));
1060 reply->writeUint32(static_cast<uint32_t>(dataspace));
1061 reply->writeUint32(static_cast<uint32_t>(component));
1062 }
1063 return result;
1064 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001065 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1066 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1067
1068 sp<IBinder> display = nullptr;
1069 bool enable = false;
1070 int8_t componentMask = 0;
1071 uint64_t maxFrames = 0;
1072 status_t result = data.readStrongBinder(&display);
1073 if (result != NO_ERROR) {
1074 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1075 result);
1076 return result;
1077 }
1078
1079 result = data.readBool(&enable);
1080 if (result != NO_ERROR) {
1081 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1082 return result;
1083 }
1084
1085 result = data.readByte(static_cast<int8_t*>(&componentMask));
1086 if (result != NO_ERROR) {
1087 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1088 result);
1089 return result;
1090 }
1091
1092 result = data.readUint64(&maxFrames);
1093 if (result != NO_ERROR) {
1094 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1095 return result;
1096 }
1097
1098 return setDisplayContentSamplingEnabled(display, enable,
1099 static_cast<uint8_t>(componentMask), maxFrames);
1100 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001101 case GET_DISPLAYED_CONTENT_SAMPLE: {
1102 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1103
1104 sp<IBinder> display = data.readStrongBinder();
1105 uint64_t maxFrames = 0;
1106 uint64_t timestamp = 0;
1107
1108 status_t result = data.readUint64(&maxFrames);
1109 if (result != NO_ERROR) {
1110 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1111 return result;
1112 }
1113
1114 result = data.readUint64(&timestamp);
1115 if (result != NO_ERROR) {
1116 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1117 return result;
1118 }
1119
1120 DisplayedFrameStats stats;
1121 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1122 if (result == NO_ERROR) {
1123 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001124 reply->writeUint64Vector(stats.component_0_sample);
1125 reply->writeUint64Vector(stats.component_1_sample);
1126 reply->writeUint64Vector(stats.component_2_sample);
1127 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001128 }
1129 return result;
1130 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001131 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001132 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001133 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001134 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001135}
1136
1137// ----------------------------------------------------------------------------
1138
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001139};