blob: a481e81131f12337773dd0e98b5b7b0a2d42b586 [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,
69 const InputWindowCommands& commands) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 Parcel data, reply;
71 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080072
73 data.writeUint32(static_cast<uint32_t>(state.size()));
74 for (const auto& s : state) {
75 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070076 }
Dan Stozad723bd72014-11-18 10:24:03 -080077
78 data.writeUint32(static_cast<uint32_t>(displays.size()));
79 for (const auto& d : displays) {
80 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070081 }
Dan Stozad723bd72014-11-18 10:24:03 -080082
83 data.writeUint32(flags);
Marissa Wall713b63f2018-10-17 15:42:43 -070084 data.writeStrongBinder(applyToken);
chaviw273171b2018-12-26 11:46:30 -080085 commands.write(data);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070086 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087 }
88
89 virtual void bootFinished()
90 {
91 Parcel data, reply;
92 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
93 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
94 }
95
Chavi Weingarten40482ff2017-11-30 01:51:40 +000096 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
Peiyong Lin0e003c92018-09-17 11:09:51 -070097 const ui::Dataspace reqDataspace,
98 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
99 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
100 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800101 Parcel data, reply;
102 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
103 data.writeStrongBinder(display);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700104 data.writeInt32(static_cast<int32_t>(reqDataspace));
105 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
Dan Stozac1879002014-05-22 15:59:05 -0700106 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800107 data.writeUint32(reqWidth);
108 data.writeUint32(reqHeight);
Dan Stozac7014012014-02-14 15:03:43 -0800109 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700110 data.writeInt32(static_cast<int32_t>(rotation));
Ana Krulec2d41e422018-07-26 12:07:43 -0700111 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
112 if (result != NO_ERROR) {
113 ALOGE("captureScreen failed to transact: %d", result);
114 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000115 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700116 result = reply.readInt32();
117 if (result != NO_ERROR) {
118 ALOGE("captureScreen failed to readInt32: %d", result);
119 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000120 }
121
122 *outBuffer = new GraphicBuffer();
123 reply.read(**outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700124
Ana Krulec2d41e422018-07-26 12:07:43 -0700125 return result;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800126 }
127
chaviwa76b2712017-09-20 12:02:26 -0700128 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700129 sp<GraphicBuffer>* outBuffer, const ui::Dataspace reqDataspace,
130 const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800131 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700132 Parcel data, reply;
133 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
134 data.writeStrongBinder(layerHandleBinder);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700135 data.writeInt32(static_cast<int32_t>(reqDataspace));
136 data.writeInt32(static_cast<int32_t>(reqPixelFormat));
chaviw7206d492017-11-10 16:16:12 -0800137 data.write(sourceCrop);
138 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800139 data.writeBool(childrenOnly);
Ana Krulec2d41e422018-07-26 12:07:43 -0700140 status_t result = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
141 if (result != NO_ERROR) {
142 ALOGE("captureLayers failed to transact: %d", result);
143 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000144 }
Ana Krulec2d41e422018-07-26 12:07:43 -0700145 result = reply.readInt32();
146 if (result != NO_ERROR) {
147 ALOGE("captureLayers failed to readInt32: %d", result);
148 return result;
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000149 }
Peiyong Lin0e003c92018-09-17 11:09:51 -0700150
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000151 *outBuffer = new GraphicBuffer();
152 reply.read(**outBuffer);
153
Ana Krulec2d41e422018-07-26 12:07:43 -0700154 return result;
chaviwa76b2712017-09-20 12:02:26 -0700155 }
156
Jamie Gennis582270d2011-08-17 18:19:00 -0700157 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800158 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800159 {
160 Parcel data, reply;
161 int err = NO_ERROR;
162 err = data.writeInterfaceToken(
163 ISurfaceComposer::getInterfaceDescriptor());
164 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000165 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800166 "interface descriptor: %s (%d)", strerror(-err), -err);
167 return false;
168 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800169 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800170 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000171 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700172 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800173 return false;
174 }
175 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
176 &reply);
177 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000178 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700179 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800180 return false;
181 }
182 int32_t result = 0;
183 err = reply.readInt32(&result);
184 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000185 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700186 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800187 return false;
188 }
189 return result != 0;
190 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800191
Brian Anderson6b376712017-04-04 10:51:39 -0700192 virtual status_t getSupportedFrameTimestamps(
193 std::vector<FrameEvent>* outSupported) const {
194 if (!outSupported) {
195 return UNEXPECTED_NULL;
196 }
197 outSupported->clear();
198
199 Parcel data, reply;
200
201 status_t err = data.writeInterfaceToken(
202 ISurfaceComposer::getInterfaceDescriptor());
203 if (err != NO_ERROR) {
204 return err;
205 }
206
207 err = remote()->transact(
208 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
209 data, &reply);
210 if (err != NO_ERROR) {
211 return err;
212 }
213
214 int32_t result = 0;
215 err = reply.readInt32(&result);
216 if (err != NO_ERROR) {
217 return err;
218 }
219 if (result != NO_ERROR) {
220 return result;
221 }
222
223 std::vector<int32_t> supported;
224 err = reply.readInt32Vector(&supported);
225 if (err != NO_ERROR) {
226 return err;
227 }
228
229 outSupported->reserve(supported.size());
230 for (int32_t s : supported) {
231 outSupported->push_back(static_cast<FrameEvent>(s));
232 }
233 return NO_ERROR;
234 }
235
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700236 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800237 {
238 Parcel data, reply;
239 sp<IDisplayEventConnection> result;
240 int err = data.writeInterfaceToken(
241 ISurfaceComposer::getInterfaceDescriptor());
242 if (err != NO_ERROR) {
243 return result;
244 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700245 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800246 err = remote()->transact(
247 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
248 data, &reply);
249 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000250 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800251 "transaction: %s (%d)", strerror(-err), -err);
252 return result;
253 }
254 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
255 return result;
256 }
Colin Cross8e533062012-06-07 13:17:52 -0700257
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700258 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700259 {
260 Parcel data, reply;
261 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700262 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700263 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700264 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
265 return reply.readStrongBinder();
266 }
267
Jesse Hall6c913be2013-08-08 12:15:49 -0700268 virtual void destroyDisplay(const sp<IBinder>& display)
269 {
270 Parcel data, reply;
271 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
272 data.writeStrongBinder(display);
273 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
274 }
275
Mathias Agopiane57f2922012-08-09 16:29:12 -0700276 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
277 {
278 Parcel data, reply;
279 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
280 data.writeInt32(id);
281 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
282 return reply.readStrongBinder();
283 }
284
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700285 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700286 {
287 Parcel data, reply;
288 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700289 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700290 data.writeInt32(mode);
291 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700292 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700293
Dan Stoza7f7da322014-05-02 15:26:25 -0700294 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
295 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700296 {
297 Parcel data, reply;
298 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700299 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700300 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
301 status_t result = reply.readInt32();
302 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800303 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700304 configs->clear();
305 configs->resize(numConfigs);
306 for (size_t c = 0; c < numConfigs; ++c) {
307 memcpy(&(configs->editItemAt(c)),
308 reply.readInplace(sizeof(DisplayInfo)),
309 sizeof(DisplayInfo));
310 }
311 }
312 return result;
313 }
314
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700315 virtual status_t getDisplayStats(const sp<IBinder>& display,
316 DisplayStatInfo* stats)
317 {
318 Parcel data, reply;
319 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
320 data.writeStrongBinder(display);
321 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
322 status_t result = reply.readInt32();
323 if (result == NO_ERROR) {
324 memcpy(stats,
325 reply.readInplace(sizeof(DisplayStatInfo)),
326 sizeof(DisplayStatInfo));
327 }
328 return result;
329 }
330
Dan Stoza7f7da322014-05-02 15:26:25 -0700331 virtual int getActiveConfig(const sp<IBinder>& display)
332 {
333 Parcel data, reply;
334 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
335 data.writeStrongBinder(display);
336 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
337 return reply.readInt32();
338 }
339
340 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
341 {
342 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700343 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
344 if (result != NO_ERROR) {
345 ALOGE("setActiveConfig failed to writeInterfaceToken: %d", result);
346 return result;
347 }
348 result = data.writeStrongBinder(display);
349 if (result != NO_ERROR) {
350 ALOGE("setActiveConfig failed to writeStrongBinder: %d", result);
351 return result;
352 }
353 result = data.writeInt32(id);
354 if (result != NO_ERROR) {
355 ALOGE("setActiveConfig failed to writeInt32: %d", result);
356 return result;
357 }
358 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
359 if (result != NO_ERROR) {
360 ALOGE("setActiveConfig failed to transact: %d", result);
361 return result;
362 }
Mathias Agopianc666cae2012-07-25 18:56:13 -0700363 return reply.readInt32();
364 }
Svetoslavd85084b2014-03-20 10:28:31 -0700365
Michael Wright28f24d02016-07-12 13:30:53 -0700366 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700367 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700368 Parcel data, reply;
369 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
370 if (result != NO_ERROR) {
371 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
372 return result;
373 }
374 result = data.writeStrongBinder(display);
375 if (result != NO_ERROR) {
376 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
377 return result;
378 }
379 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
380 if (result != NO_ERROR) {
381 ALOGE("getDisplayColorModes failed to transact: %d", result);
382 return result;
383 }
384 result = static_cast<status_t>(reply.readInt32());
385 if (result == NO_ERROR) {
386 size_t numModes = reply.readUint32();
387 outColorModes->clear();
388 outColorModes->resize(numModes);
389 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700390 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700391 }
392 }
393 return result;
394 }
395
Peiyong Lina52f0292018-03-14 17:26:31 -0700396 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700397 Parcel data, reply;
398 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
399 if (result != NO_ERROR) {
400 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700401 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700402 }
403 result = data.writeStrongBinder(display);
404 if (result != NO_ERROR) {
405 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700406 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700407 }
408 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
409 if (result != NO_ERROR) {
410 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700411 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700412 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700413 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700414 }
415
416 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700417 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700418 Parcel data, reply;
419 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
420 if (result != NO_ERROR) {
421 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
422 return result;
423 }
424 result = data.writeStrongBinder(display);
425 if (result != NO_ERROR) {
426 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
427 return result;
428 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700429 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700430 if (result != NO_ERROR) {
431 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
432 return result;
433 }
434 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
435 if (result != NO_ERROR) {
436 ALOGE("setActiveColorMode failed to transact: %d", result);
437 return result;
438 }
439 return static_cast<status_t>(reply.readInt32());
440 }
441
Svetoslavd85084b2014-03-20 10:28:31 -0700442 virtual status_t clearAnimationFrameStats() {
443 Parcel data, reply;
Ana Krulec2d41e422018-07-26 12:07:43 -0700444 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
445 if (result != NO_ERROR) {
446 ALOGE("clearAnimationFrameStats failed to writeInterfaceToken: %d", result);
447 return result;
448 }
449 result = remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
450 if (result != NO_ERROR) {
451 ALOGE("clearAnimationFrameStats failed to transact: %d", result);
452 return result;
453 }
Svetoslavd85084b2014-03-20 10:28:31 -0700454 return reply.readInt32();
455 }
456
457 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
458 Parcel data, reply;
459 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
460 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
461 reply.read(*outStats);
462 return reply.readInt32();
463 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700464
465 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
466 HdrCapabilities* outCapabilities) const {
467 Parcel data, reply;
468 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
469 status_t result = data.writeStrongBinder(display);
470 if (result != NO_ERROR) {
471 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
472 return result;
473 }
474 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
475 data, &reply);
476 if (result != NO_ERROR) {
477 ALOGE("getHdrCapabilities failed to transact: %d", result);
478 return result;
479 }
480 result = reply.readInt32();
481 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800482 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700483 }
484 return result;
485 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700486
487 virtual status_t enableVSyncInjections(bool enable) {
488 Parcel data, reply;
489 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
490 if (result != NO_ERROR) {
491 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
492 return result;
493 }
494 result = data.writeBool(enable);
495 if (result != NO_ERROR) {
496 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
497 return result;
498 }
499 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
500 data, &reply, TF_ONE_WAY);
501 if (result != NO_ERROR) {
502 ALOGE("enableVSyncInjections failed to transact: %d", result);
503 return result;
504 }
505 return result;
506 }
507
508 virtual status_t injectVSync(nsecs_t when) {
509 Parcel data, reply;
510 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
511 if (result != NO_ERROR) {
512 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
513 return result;
514 }
515 result = data.writeInt64(when);
516 if (result != NO_ERROR) {
517 ALOGE("injectVSync failed to writeInt64: %d", result);
518 return result;
519 }
520 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
521 if (result != NO_ERROR) {
522 ALOGE("injectVSync failed to transact: %d", result);
523 return result;
524 }
525 return result;
526 }
527
Kalle Raitaa099a242017-01-11 11:17:29 -0800528 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
529 {
530 if (!outLayers) {
531 return UNEXPECTED_NULL;
532 }
533
534 Parcel data, reply;
535
536 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
537 if (err != NO_ERROR) {
538 return err;
539 }
540
541 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
542 if (err != NO_ERROR) {
543 return err;
544 }
545
546 int32_t result = 0;
547 err = reply.readInt32(&result);
548 if (err != NO_ERROR) {
549 return err;
550 }
551 if (result != NO_ERROR) {
552 return result;
553 }
554
555 outLayers->clear();
556 return reply.readParcelableVector(outLayers);
557 }
Peiyong Lin0256f722018-08-31 15:45:10 -0700558
Peiyong Linc6780972018-10-28 15:24:08 -0700559 virtual status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
560 ui::PixelFormat* defaultPixelFormat,
561 ui::Dataspace* wideColorGamutDataspace,
562 ui::PixelFormat* wideColorGamutPixelFormat) const {
Peiyong Lin0256f722018-08-31 15:45:10 -0700563 Parcel data, reply;
564 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
565 if (error != NO_ERROR) {
566 return error;
567 }
568 error = remote()->transact(BnSurfaceComposer::GET_COMPOSITION_PREFERENCE, data, &reply);
569 if (error != NO_ERROR) {
570 return error;
571 }
572 error = static_cast<status_t>(reply.readInt32());
573 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -0700574 *defaultDataspace = static_cast<ui::Dataspace>(reply.readInt32());
575 *defaultPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
576 *wideColorGamutDataspace = static_cast<ui::Dataspace>(reply.readInt32());
577 *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(reply.readInt32());
Peiyong Lin0256f722018-08-31 15:45:10 -0700578 }
579 return error;
580 }
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700581
Ady Abraham37965d42018-11-01 13:43:32 -0700582 virtual status_t getColorManagement(bool* outGetColorManagement) const {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700583 Parcel data, reply;
584 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Ady Abraham37965d42018-11-01 13:43:32 -0700585 remote()->transact(BnSurfaceComposer::GET_COLOR_MANAGEMENT, data, &reply);
586 bool result;
587 status_t err = reply.readBool(&result);
588 if (err == NO_ERROR) {
589 *outGetColorManagement = result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700590 }
Ady Abraham37965d42018-11-01 13:43:32 -0700591 return err;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -0700592 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700593
594 virtual status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
595 ui::PixelFormat* outFormat,
596 ui::Dataspace* outDataspace,
597 uint8_t* outComponentMask) const {
598 if (!outFormat || !outDataspace || !outComponentMask) return BAD_VALUE;
599 Parcel data, reply;
600 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
601 data.writeStrongBinder(display);
602
603 status_t error =
604 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
605 data, &reply);
606 if (error != NO_ERROR) {
607 return error;
608 }
609
610 uint32_t value = 0;
611 error = reply.readUint32(&value);
612 if (error != NO_ERROR) {
613 return error;
614 }
615 *outFormat = static_cast<ui::PixelFormat>(value);
616
617 error = reply.readUint32(&value);
618 if (error != NO_ERROR) {
619 return error;
620 }
621 *outDataspace = static_cast<ui::Dataspace>(value);
622
623 error = reply.readUint32(&value);
624 if (error != NO_ERROR) {
625 return error;
626 }
627 *outComponentMask = static_cast<uint8_t>(value);
628 return error;
629 }
Kevin DuBois74e53772018-11-19 10:52:38 -0800630
631 virtual status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
632 uint8_t componentMask,
633 uint64_t maxFrames) const {
634 Parcel data, reply;
635 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
636 data.writeStrongBinder(display);
637 data.writeBool(enable);
638 data.writeByte(static_cast<int8_t>(componentMask));
639 data.writeUint64(maxFrames);
640 status_t result =
641 remote()->transact(BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED, data,
642 &reply);
643 return result;
644 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700645
646 virtual status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
647 uint64_t timestamp,
648 DisplayedFrameStats* outStats) const {
649 if (!outStats) return BAD_VALUE;
650
651 Parcel data, reply;
652 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
653 data.writeStrongBinder(display);
654 data.writeUint64(maxFrames);
655 data.writeUint64(timestamp);
656
657 status_t result =
658 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
659
660 if (result != NO_ERROR) {
661 return result;
662 }
663
664 result = reply.readUint64(&outStats->numFrames);
665 if (result != NO_ERROR) {
666 return result;
667 }
668
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800669 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700670 if (result != NO_ERROR) {
671 return result;
672 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800673 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700674 if (result != NO_ERROR) {
675 return result;
676 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800677 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700678 if (result != NO_ERROR) {
679 return result;
680 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800681 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700682 return result;
683 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800684};
685
Dan Stozad723bd72014-11-18 10:24:03 -0800686// Out-of-line virtual method definition to trigger vtable emission in this
687// translation unit (see clang warning -Wweak-vtables)
688BpSurfaceComposer::~BpSurfaceComposer() {}
689
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800690IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
691
692// ----------------------------------------------------------------------
693
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800694status_t BnSurfaceComposer::onTransact(
695 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
696{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800697 switch(code) {
698 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700699 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800700 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800701 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700702 return NO_ERROR;
703 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700704 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700705 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800706
707 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700708 if (count > data.dataSize()) {
709 return BAD_VALUE;
710 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700711 Vector<ComposerState> state;
712 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800713 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700714 ComposerState s;
Michael Lentine8afa1c42014-10-31 11:10:13 -0700715 if (s.read(data) == BAD_VALUE) {
716 return BAD_VALUE;
717 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700718 state.add(s);
719 }
Dan Stozad723bd72014-11-18 10:24:03 -0800720
721 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700722 if (count > data.dataSize()) {
723 return BAD_VALUE;
724 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700725 DisplayState d;
726 Vector<DisplayState> displays;
727 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800728 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700729 if (d.read(data) == BAD_VALUE) {
730 return BAD_VALUE;
731 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700732 displays.add(d);
733 }
Dan Stozad723bd72014-11-18 10:24:03 -0800734
735 uint32_t stateFlags = data.readUint32();
Marissa Wall713b63f2018-10-17 15:42:43 -0700736 sp<IBinder> applyToken = data.readStrongBinder();
chaviw273171b2018-12-26 11:46:30 -0800737 InputWindowCommands inputWindowCommands;
738 inputWindowCommands.read(data);
739 setTransactionState(state, displays, stateFlags, applyToken, inputWindowCommands);
Jesse Hall6c913be2013-08-08 12:15:49 -0700740 return NO_ERROR;
741 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800742 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700743 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800744 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700745 return NO_ERROR;
746 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800747 case CAPTURE_SCREEN: {
748 CHECK_INTERFACE(ISurfaceComposer, data, reply);
749 sp<IBinder> display = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700750 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
751 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000752 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700753 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700754 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800755 uint32_t reqWidth = data.readUint32();
756 uint32_t reqHeight = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800757 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800758 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800759
Peiyong Lin0e003c92018-09-17 11:09:51 -0700760 status_t res = captureScreen(display, &outBuffer, reqDataspace, reqPixelFormat,
761 sourceCrop, reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000762 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800763 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000764 if (res == NO_ERROR) {
765 reply->write(*outBuffer);
766 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700767 return NO_ERROR;
768 }
chaviwa76b2712017-09-20 12:02:26 -0700769 case CAPTURE_LAYERS: {
770 CHECK_INTERFACE(ISurfaceComposer, data, reply);
771 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Peiyong Lin0e003c92018-09-17 11:09:51 -0700772 ui::Dataspace reqDataspace = static_cast<ui::Dataspace>(data.readInt32());
773 ui::PixelFormat reqPixelFormat = static_cast<ui::PixelFormat>(data.readInt32());
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000774 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800775 Rect sourceCrop(Rect::EMPTY_RECT);
776 data.read(sourceCrop);
777 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800778 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700779
Peiyong Lin0e003c92018-09-17 11:09:51 -0700780 status_t res = captureLayers(layerHandleBinder, &outBuffer, reqDataspace,
781 reqPixelFormat, sourceCrop, frameScale, childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700782 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000783 if (res == NO_ERROR) {
784 reply->write(*outBuffer);
785 }
chaviwa76b2712017-09-20 12:02:26 -0700786 return NO_ERROR;
787 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800788 case AUTHENTICATE_SURFACE: {
789 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800790 sp<IGraphicBufferProducer> bufferProducer =
791 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
792 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800793 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700794 return NO_ERROR;
795 }
Brian Anderson6b376712017-04-04 10:51:39 -0700796 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
797 CHECK_INTERFACE(ISurfaceComposer, data, reply);
798 std::vector<FrameEvent> supportedTimestamps;
799 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
800 status_t err = reply->writeInt32(result);
801 if (err != NO_ERROR) {
802 return err;
803 }
804 if (result != NO_ERROR) {
805 return result;
806 }
807
808 std::vector<int32_t> supported;
809 supported.reserve(supportedTimestamps.size());
810 for (FrameEvent s : supportedTimestamps) {
811 supported.push_back(static_cast<int32_t>(s));
812 }
813 return reply->writeInt32Vector(supported);
814 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800815 case CREATE_DISPLAY_EVENT_CONNECTION: {
816 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700817 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
818 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800819 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800820 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700821 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700822 case CREATE_DISPLAY: {
823 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700824 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700825 bool secure = bool(data.readInt32());
826 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700827 reply->writeStrongBinder(display);
828 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700829 }
830 case DESTROY_DISPLAY: {
831 CHECK_INTERFACE(ISurfaceComposer, data, reply);
832 sp<IBinder> display = data.readStrongBinder();
833 destroyDisplay(display);
834 return NO_ERROR;
835 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700836 case GET_BUILT_IN_DISPLAY: {
837 CHECK_INTERFACE(ISurfaceComposer, data, reply);
838 int32_t id = data.readInt32();
839 sp<IBinder> display(getBuiltInDisplay(id));
840 reply->writeStrongBinder(display);
841 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700842 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700843 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700844 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700845 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700846 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700847 status_t result = getDisplayConfigs(display, &configs);
848 reply->writeInt32(result);
849 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800850 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700851 for (size_t c = 0; c < configs.size(); ++c) {
852 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
853 &configs[c], sizeof(DisplayInfo));
854 }
855 }
856 return NO_ERROR;
857 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700858 case GET_DISPLAY_STATS: {
859 CHECK_INTERFACE(ISurfaceComposer, data, reply);
860 DisplayStatInfo stats;
861 sp<IBinder> display = data.readStrongBinder();
862 status_t result = getDisplayStats(display, &stats);
863 reply->writeInt32(result);
864 if (result == NO_ERROR) {
865 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
866 &stats, sizeof(DisplayStatInfo));
867 }
868 return NO_ERROR;
869 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700870 case GET_ACTIVE_CONFIG: {
871 CHECK_INTERFACE(ISurfaceComposer, data, reply);
872 sp<IBinder> display = data.readStrongBinder();
873 int id = getActiveConfig(display);
874 reply->writeInt32(id);
875 return NO_ERROR;
876 }
877 case SET_ACTIVE_CONFIG: {
878 CHECK_INTERFACE(ISurfaceComposer, data, reply);
879 sp<IBinder> display = data.readStrongBinder();
880 int id = data.readInt32();
881 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700882 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700883 return NO_ERROR;
884 }
Michael Wright28f24d02016-07-12 13:30:53 -0700885 case GET_DISPLAY_COLOR_MODES: {
886 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700887 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -0700888 sp<IBinder> display = nullptr;
889 status_t result = data.readStrongBinder(&display);
890 if (result != NO_ERROR) {
891 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
892 return result;
893 }
894 result = getDisplayColorModes(display, &colorModes);
895 reply->writeInt32(result);
896 if (result == NO_ERROR) {
897 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
898 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700899 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -0700900 }
901 }
902 return NO_ERROR;
903 }
904 case GET_ACTIVE_COLOR_MODE: {
905 CHECK_INTERFACE(ISurfaceComposer, data, reply);
906 sp<IBinder> display = nullptr;
907 status_t result = data.readStrongBinder(&display);
908 if (result != NO_ERROR) {
909 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
910 return result;
911 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700912 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -0700913 result = reply->writeInt32(static_cast<int32_t>(colorMode));
914 return result;
915 }
916 case SET_ACTIVE_COLOR_MODE: {
917 CHECK_INTERFACE(ISurfaceComposer, data, reply);
918 sp<IBinder> display = nullptr;
919 status_t result = data.readStrongBinder(&display);
920 if (result != NO_ERROR) {
921 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
922 return result;
923 }
924 int32_t colorModeInt = 0;
925 result = data.readInt32(&colorModeInt);
926 if (result != NO_ERROR) {
927 ALOGE("setActiveColorMode failed to readInt32: %d", result);
928 return result;
929 }
930 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700931 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -0700932 result = reply->writeInt32(result);
933 return result;
934 }
Svetoslavd85084b2014-03-20 10:28:31 -0700935 case CLEAR_ANIMATION_FRAME_STATS: {
936 CHECK_INTERFACE(ISurfaceComposer, data, reply);
937 status_t result = clearAnimationFrameStats();
938 reply->writeInt32(result);
939 return NO_ERROR;
940 }
941 case GET_ANIMATION_FRAME_STATS: {
942 CHECK_INTERFACE(ISurfaceComposer, data, reply);
943 FrameStats stats;
944 status_t result = getAnimationFrameStats(&stats);
945 reply->write(stats);
946 reply->writeInt32(result);
947 return NO_ERROR;
948 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700949 case SET_POWER_MODE: {
950 CHECK_INTERFACE(ISurfaceComposer, data, reply);
951 sp<IBinder> display = data.readStrongBinder();
952 int32_t mode = data.readInt32();
953 setPowerMode(display, mode);
954 return NO_ERROR;
955 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700956 case GET_HDR_CAPABILITIES: {
957 CHECK_INTERFACE(ISurfaceComposer, data, reply);
958 sp<IBinder> display = nullptr;
959 status_t result = data.readStrongBinder(&display);
960 if (result != NO_ERROR) {
961 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
962 result);
963 return result;
964 }
965 HdrCapabilities capabilities;
966 result = getHdrCapabilities(display, &capabilities);
967 reply->writeInt32(result);
968 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800969 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700970 }
971 return NO_ERROR;
972 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700973 case ENABLE_VSYNC_INJECTIONS: {
974 CHECK_INTERFACE(ISurfaceComposer, data, reply);
975 bool enable = false;
976 status_t result = data.readBool(&enable);
977 if (result != NO_ERROR) {
978 ALOGE("enableVSyncInjections failed to readBool: %d", result);
979 return result;
980 }
981 return enableVSyncInjections(enable);
982 }
983 case INJECT_VSYNC: {
984 CHECK_INTERFACE(ISurfaceComposer, data, reply);
985 int64_t when = 0;
986 status_t result = data.readInt64(&when);
987 if (result != NO_ERROR) {
988 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
989 return result;
990 }
991 return injectVSync(when);
992 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800993 case GET_LAYER_DEBUG_INFO: {
994 CHECK_INTERFACE(ISurfaceComposer, data, reply);
995 std::vector<LayerDebugInfo> outLayers;
996 status_t result = getLayerDebugInfo(&outLayers);
997 reply->writeInt32(result);
998 if (result == NO_ERROR)
999 {
1000 result = reply->writeParcelableVector(outLayers);
1001 }
1002 return result;
1003 }
Peiyong Lin0256f722018-08-31 15:45:10 -07001004 case GET_COMPOSITION_PREFERENCE: {
1005 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Linc6780972018-10-28 15:24:08 -07001006 ui::Dataspace defaultDataspace;
1007 ui::PixelFormat defaultPixelFormat;
1008 ui::Dataspace wideColorGamutDataspace;
1009 ui::PixelFormat wideColorGamutPixelFormat;
1010 status_t error =
1011 getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
1012 &wideColorGamutDataspace, &wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001013 reply->writeInt32(error);
1014 if (error == NO_ERROR) {
Peiyong Linc6780972018-10-28 15:24:08 -07001015 reply->writeInt32(static_cast<int32_t>(defaultDataspace));
1016 reply->writeInt32(static_cast<int32_t>(defaultPixelFormat));
1017 reply->writeInt32(static_cast<int32_t>(wideColorGamutDataspace));
Peiyong Linaa3da6a2018-12-12 02:48:43 -08001018 reply->writeInt32(static_cast<int32_t>(wideColorGamutPixelFormat));
Peiyong Lin0256f722018-08-31 15:45:10 -07001019 }
1020 return NO_ERROR;
1021 }
Ady Abraham37965d42018-11-01 13:43:32 -07001022 case GET_COLOR_MANAGEMENT: {
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001023 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham37965d42018-11-01 13:43:32 -07001024 bool result;
1025 status_t error = getColorManagement(&result);
1026 if (error == NO_ERROR) {
1027 reply->writeBool(result);
1028 }
1029 return result;
Ady Abraham2a6ab2a2018-10-26 14:25:30 -07001030 }
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001031 case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: {
1032 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1033
1034 sp<IBinder> display = data.readStrongBinder();
1035 ui::PixelFormat format;
1036 ui::Dataspace dataspace;
1037 uint8_t component = 0;
1038 auto result =
1039 getDisplayedContentSamplingAttributes(display, &format, &dataspace, &component);
1040 if (result == NO_ERROR) {
1041 reply->writeUint32(static_cast<uint32_t>(format));
1042 reply->writeUint32(static_cast<uint32_t>(dataspace));
1043 reply->writeUint32(static_cast<uint32_t>(component));
1044 }
1045 return result;
1046 }
Kevin DuBois74e53772018-11-19 10:52:38 -08001047 case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: {
1048 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1049
1050 sp<IBinder> display = nullptr;
1051 bool enable = false;
1052 int8_t componentMask = 0;
1053 uint64_t maxFrames = 0;
1054 status_t result = data.readStrongBinder(&display);
1055 if (result != NO_ERROR) {
1056 ALOGE("setDisplayContentSamplingEnabled failure in reading Display token: %d",
1057 result);
1058 return result;
1059 }
1060
1061 result = data.readBool(&enable);
1062 if (result != NO_ERROR) {
1063 ALOGE("setDisplayContentSamplingEnabled failure in reading enable: %d", result);
1064 return result;
1065 }
1066
1067 result = data.readByte(static_cast<int8_t*>(&componentMask));
1068 if (result != NO_ERROR) {
1069 ALOGE("setDisplayContentSamplingEnabled failure in reading component mask: %d",
1070 result);
1071 return result;
1072 }
1073
1074 result = data.readUint64(&maxFrames);
1075 if (result != NO_ERROR) {
1076 ALOGE("setDisplayContentSamplingEnabled failure in reading max frames: %d", result);
1077 return result;
1078 }
1079
1080 return setDisplayContentSamplingEnabled(display, enable,
1081 static_cast<uint8_t>(componentMask), maxFrames);
1082 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001083 case GET_DISPLAYED_CONTENT_SAMPLE: {
1084 CHECK_INTERFACE(ISurfaceComposer, data, reply);
1085
1086 sp<IBinder> display = data.readStrongBinder();
1087 uint64_t maxFrames = 0;
1088 uint64_t timestamp = 0;
1089
1090 status_t result = data.readUint64(&maxFrames);
1091 if (result != NO_ERROR) {
1092 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
1093 return result;
1094 }
1095
1096 result = data.readUint64(&timestamp);
1097 if (result != NO_ERROR) {
1098 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
1099 return result;
1100 }
1101
1102 DisplayedFrameStats stats;
1103 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
1104 if (result == NO_ERROR) {
1105 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -08001106 reply->writeUint64Vector(stats.component_0_sample);
1107 reply->writeUint64Vector(stats.component_1_sample);
1108 reply->writeUint64Vector(stats.component_2_sample);
1109 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001110 }
1111 return result;
1112 }
Jesse Hall6c913be2013-08-08 12:15:49 -07001113 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -07001114 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -07001115 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001116 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001117}
1118
1119// ----------------------------------------------------------------------------
1120
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001121};