blob: e22bc708c9ab5e7db759be5bc0dd5af064629384 [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
Mathias Agopian8b33f032012-07-24 20:43:54 -070076 virtual void setTransactionState(
77 const Vector<ComposerState>& state,
78 const Vector<DisplayState>& displays,
79 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 {
81 Parcel data, reply;
82 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080083
84 data.writeUint32(static_cast<uint32_t>(state.size()));
85 for (const auto& s : state) {
86 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070087 }
Dan Stozad723bd72014-11-18 10:24:03 -080088
89 data.writeUint32(static_cast<uint32_t>(displays.size()));
90 for (const auto& d : displays) {
91 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070092 }
Dan Stozad723bd72014-11-18 10:24:03 -080093
94 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070095 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 }
97
98 virtual void bootFinished()
99 {
100 Parcel data, reply;
101 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
102 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
103 }
104
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000105 virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer,
106 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
107 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
108 ISurfaceComposer::Rotation rotation) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800109 Parcel data, reply;
110 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
111 data.writeStrongBinder(display);
Dan Stozac1879002014-05-22 15:59:05 -0700112 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800113 data.writeUint32(reqWidth);
114 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800115 data.writeInt32(minLayerZ);
116 data.writeInt32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800117 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700118 data.writeInt32(static_cast<int32_t>(rotation));
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000119 status_t err = remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
120
121 if (err != NO_ERROR) {
122 return err;
123 }
124
125 err = reply.readInt32();
126 if (err != NO_ERROR) {
127 return err;
128 }
129
130 *outBuffer = new GraphicBuffer();
131 reply.read(**outBuffer);
132 return err;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800133 }
134
chaviwa76b2712017-09-20 12:02:26 -0700135 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000136 sp<GraphicBuffer>* outBuffer, const Rect& sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800137 float frameScale, bool childrenOnly) {
chaviwa76b2712017-09-20 12:02:26 -0700138 Parcel data, reply;
139 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
140 data.writeStrongBinder(layerHandleBinder);
chaviw7206d492017-11-10 16:16:12 -0800141 data.write(sourceCrop);
142 data.writeFloat(frameScale);
Robert Carr578038f2018-03-09 12:25:24 -0800143 data.writeBool(childrenOnly);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000144 status_t err = remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
145
146 if (err != NO_ERROR) {
147 return err;
148 }
149
150 err = reply.readInt32();
151 if (err != NO_ERROR) {
152 return err;
153 }
154
155 *outBuffer = new GraphicBuffer();
156 reply.read(**outBuffer);
157
158 return err;
chaviwa76b2712017-09-20 12:02:26 -0700159 }
160
Jamie Gennis582270d2011-08-17 18:19:00 -0700161 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800162 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800163 {
164 Parcel data, reply;
165 int err = NO_ERROR;
166 err = data.writeInterfaceToken(
167 ISurfaceComposer::getInterfaceDescriptor());
168 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000169 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800170 "interface descriptor: %s (%d)", strerror(-err), -err);
171 return false;
172 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800173 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800174 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000175 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700176 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800177 return false;
178 }
179 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
180 &reply);
181 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000182 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700183 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800184 return false;
185 }
186 int32_t result = 0;
187 err = reply.readInt32(&result);
188 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000189 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700190 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800191 return false;
192 }
193 return result != 0;
194 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800195
Brian Anderson6b376712017-04-04 10:51:39 -0700196 virtual status_t getSupportedFrameTimestamps(
197 std::vector<FrameEvent>* outSupported) const {
198 if (!outSupported) {
199 return UNEXPECTED_NULL;
200 }
201 outSupported->clear();
202
203 Parcel data, reply;
204
205 status_t err = data.writeInterfaceToken(
206 ISurfaceComposer::getInterfaceDescriptor());
207 if (err != NO_ERROR) {
208 return err;
209 }
210
211 err = remote()->transact(
212 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
213 data, &reply);
214 if (err != NO_ERROR) {
215 return err;
216 }
217
218 int32_t result = 0;
219 err = reply.readInt32(&result);
220 if (err != NO_ERROR) {
221 return err;
222 }
223 if (result != NO_ERROR) {
224 return result;
225 }
226
227 std::vector<int32_t> supported;
228 err = reply.readInt32Vector(&supported);
229 if (err != NO_ERROR) {
230 return err;
231 }
232
233 outSupported->reserve(supported.size());
234 for (int32_t s : supported) {
235 outSupported->push_back(static_cast<FrameEvent>(s));
236 }
237 return NO_ERROR;
238 }
239
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700240 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800241 {
242 Parcel data, reply;
243 sp<IDisplayEventConnection> result;
244 int err = data.writeInterfaceToken(
245 ISurfaceComposer::getInterfaceDescriptor());
246 if (err != NO_ERROR) {
247 return result;
248 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700249 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800250 err = remote()->transact(
251 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
252 data, &reply);
253 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000254 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800255 "transaction: %s (%d)", strerror(-err), -err);
256 return result;
257 }
258 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
259 return result;
260 }
Colin Cross8e533062012-06-07 13:17:52 -0700261
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700262 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700263 {
264 Parcel data, reply;
265 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700266 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700267 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700268 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
269 return reply.readStrongBinder();
270 }
271
Jesse Hall6c913be2013-08-08 12:15:49 -0700272 virtual void destroyDisplay(const sp<IBinder>& display)
273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
276 data.writeStrongBinder(display);
277 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
278 }
279
Mathias Agopiane57f2922012-08-09 16:29:12 -0700280 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
284 data.writeInt32(id);
285 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
286 return reply.readStrongBinder();
287 }
288
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700289 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700293 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700294 data.writeInt32(mode);
295 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700296 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700297
Dan Stoza7f7da322014-05-02 15:26:25 -0700298 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
299 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700300 {
301 Parcel data, reply;
302 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700303 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700304 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
305 status_t result = reply.readInt32();
306 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800307 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700308 configs->clear();
309 configs->resize(numConfigs);
310 for (size_t c = 0; c < numConfigs; ++c) {
311 memcpy(&(configs->editItemAt(c)),
312 reply.readInplace(sizeof(DisplayInfo)),
313 sizeof(DisplayInfo));
314 }
315 }
316 return result;
317 }
318
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700319 virtual status_t getDisplayStats(const sp<IBinder>& display,
320 DisplayStatInfo* stats)
321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
324 data.writeStrongBinder(display);
325 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
326 status_t result = reply.readInt32();
327 if (result == NO_ERROR) {
328 memcpy(stats,
329 reply.readInplace(sizeof(DisplayStatInfo)),
330 sizeof(DisplayStatInfo));
331 }
332 return result;
333 }
334
Dan Stoza7f7da322014-05-02 15:26:25 -0700335 virtual int getActiveConfig(const sp<IBinder>& display)
336 {
337 Parcel data, reply;
338 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
339 data.writeStrongBinder(display);
340 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
341 return reply.readInt32();
342 }
343
344 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
345 {
346 Parcel data, reply;
347 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
348 data.writeStrongBinder(display);
349 data.writeInt32(id);
350 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700351 return reply.readInt32();
352 }
Svetoslavd85084b2014-03-20 10:28:31 -0700353
Michael Wright28f24d02016-07-12 13:30:53 -0700354 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700355 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -0700356 Parcel data, reply;
357 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
358 if (result != NO_ERROR) {
359 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
360 return result;
361 }
362 result = data.writeStrongBinder(display);
363 if (result != NO_ERROR) {
364 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
365 return result;
366 }
367 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
368 if (result != NO_ERROR) {
369 ALOGE("getDisplayColorModes failed to transact: %d", result);
370 return result;
371 }
372 result = static_cast<status_t>(reply.readInt32());
373 if (result == NO_ERROR) {
374 size_t numModes = reply.readUint32();
375 outColorModes->clear();
376 outColorModes->resize(numModes);
377 for (size_t i = 0; i < numModes; ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700378 outColorModes->replaceAt(static_cast<ColorMode>(reply.readInt32()), i);
Michael Wright28f24d02016-07-12 13:30:53 -0700379 }
380 }
381 return result;
382 }
383
Peiyong Lina52f0292018-03-14 17:26:31 -0700384 virtual ColorMode getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -0700385 Parcel data, reply;
386 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
387 if (result != NO_ERROR) {
388 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700389 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700390 }
391 result = data.writeStrongBinder(display);
392 if (result != NO_ERROR) {
393 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700394 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700395 }
396 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
397 if (result != NO_ERROR) {
398 ALOGE("getActiveColorMode failed to transact: %d", result);
Peiyong Lina52f0292018-03-14 17:26:31 -0700399 return static_cast<ColorMode>(result);
Michael Wright28f24d02016-07-12 13:30:53 -0700400 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700401 return static_cast<ColorMode>(reply.readInt32());
Michael Wright28f24d02016-07-12 13:30:53 -0700402 }
403
404 virtual status_t setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700405 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700406 Parcel data, reply;
407 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
408 if (result != NO_ERROR) {
409 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
410 return result;
411 }
412 result = data.writeStrongBinder(display);
413 if (result != NO_ERROR) {
414 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
415 return result;
416 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700417 result = data.writeInt32(static_cast<int32_t>(colorMode));
Michael Wright28f24d02016-07-12 13:30:53 -0700418 if (result != NO_ERROR) {
419 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
420 return result;
421 }
422 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
423 if (result != NO_ERROR) {
424 ALOGE("setActiveColorMode failed to transact: %d", result);
425 return result;
426 }
427 return static_cast<status_t>(reply.readInt32());
428 }
429
Svetoslavd85084b2014-03-20 10:28:31 -0700430 virtual status_t clearAnimationFrameStats() {
431 Parcel data, reply;
432 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
433 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
434 return reply.readInt32();
435 }
436
437 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
438 Parcel data, reply;
439 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
440 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
441 reply.read(*outStats);
442 return reply.readInt32();
443 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700444
445 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
446 HdrCapabilities* outCapabilities) const {
447 Parcel data, reply;
448 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
449 status_t result = data.writeStrongBinder(display);
450 if (result != NO_ERROR) {
451 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
452 return result;
453 }
454 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
455 data, &reply);
456 if (result != NO_ERROR) {
457 ALOGE("getHdrCapabilities failed to transact: %d", result);
458 return result;
459 }
460 result = reply.readInt32();
461 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800462 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700463 }
464 return result;
465 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700466
467 virtual status_t enableVSyncInjections(bool enable) {
468 Parcel data, reply;
469 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
470 if (result != NO_ERROR) {
471 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
472 return result;
473 }
474 result = data.writeBool(enable);
475 if (result != NO_ERROR) {
476 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
477 return result;
478 }
479 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
480 data, &reply, TF_ONE_WAY);
481 if (result != NO_ERROR) {
482 ALOGE("enableVSyncInjections failed to transact: %d", result);
483 return result;
484 }
485 return result;
486 }
487
488 virtual status_t injectVSync(nsecs_t when) {
489 Parcel data, reply;
490 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
491 if (result != NO_ERROR) {
492 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
493 return result;
494 }
495 result = data.writeInt64(when);
496 if (result != NO_ERROR) {
497 ALOGE("injectVSync failed to writeInt64: %d", result);
498 return result;
499 }
500 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
501 if (result != NO_ERROR) {
502 ALOGE("injectVSync failed to transact: %d", result);
503 return result;
504 }
505 return result;
506 }
507
Kalle Raitaa099a242017-01-11 11:17:29 -0800508 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
509 {
510 if (!outLayers) {
511 return UNEXPECTED_NULL;
512 }
513
514 Parcel data, reply;
515
516 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
517 if (err != NO_ERROR) {
518 return err;
519 }
520
521 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
522 if (err != NO_ERROR) {
523 return err;
524 }
525
526 int32_t result = 0;
527 err = reply.readInt32(&result);
528 if (err != NO_ERROR) {
529 return err;
530 }
531 if (result != NO_ERROR) {
532 return result;
533 }
534
535 outLayers->clear();
536 return reply.readParcelableVector(outLayers);
537 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800538};
539
Dan Stozad723bd72014-11-18 10:24:03 -0800540// Out-of-line virtual method definition to trigger vtable emission in this
541// translation unit (see clang warning -Wweak-vtables)
542BpSurfaceComposer::~BpSurfaceComposer() {}
543
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
545
546// ----------------------------------------------------------------------
547
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800548status_t BnSurfaceComposer::onTransact(
549 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
550{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 switch(code) {
552 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700553 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800554 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700556 return NO_ERROR;
557 }
Robert Carr1db73f62016-12-21 12:58:51 -0800558 case CREATE_SCOPED_CONNECTION: {
559 CHECK_INTERFACE(ISurfaceComposer, data, reply);
560 sp<IGraphicBufferProducer> bufferProducer =
561 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
562 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
563 reply->writeStrongBinder(b);
564 return NO_ERROR;
565 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700566 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700567 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800568
569 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700570 if (count > data.dataSize()) {
571 return BAD_VALUE;
572 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700573 ComposerState s;
574 Vector<ComposerState> state;
575 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800576 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700577 if (s.read(data) == BAD_VALUE) {
578 return BAD_VALUE;
579 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700580 state.add(s);
581 }
Dan Stozad723bd72014-11-18 10:24:03 -0800582
583 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700584 if (count > data.dataSize()) {
585 return BAD_VALUE;
586 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700587 DisplayState d;
588 Vector<DisplayState> displays;
589 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800590 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700591 if (d.read(data) == BAD_VALUE) {
592 return BAD_VALUE;
593 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700594 displays.add(d);
595 }
Dan Stozad723bd72014-11-18 10:24:03 -0800596
597 uint32_t stateFlags = data.readUint32();
598 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700599 return NO_ERROR;
600 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800601 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700602 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800603 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700604 return NO_ERROR;
605 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800606 case CAPTURE_SCREEN: {
607 CHECK_INTERFACE(ISurfaceComposer, data, reply);
608 sp<IBinder> display = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000609 sp<GraphicBuffer> outBuffer;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700610 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700611 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800612 uint32_t reqWidth = data.readUint32();
613 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800614 int32_t minLayerZ = data.readInt32();
615 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800616 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800617 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800618
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000619 status_t res = captureScreen(display, &outBuffer, sourceCrop, reqWidth, reqHeight,
620 minLayerZ, maxLayerZ, useIdentityTransform,
621 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800622 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000623 if (res == NO_ERROR) {
624 reply->write(*outBuffer);
625 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700626 return NO_ERROR;
627 }
chaviwa76b2712017-09-20 12:02:26 -0700628 case CAPTURE_LAYERS: {
629 CHECK_INTERFACE(ISurfaceComposer, data, reply);
630 sp<IBinder> layerHandleBinder = data.readStrongBinder();
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000631 sp<GraphicBuffer> outBuffer;
chaviw7206d492017-11-10 16:16:12 -0800632 Rect sourceCrop(Rect::EMPTY_RECT);
633 data.read(sourceCrop);
634 float frameScale = data.readFloat();
Robert Carr578038f2018-03-09 12:25:24 -0800635 bool childrenOnly = data.readBool();
chaviwa76b2712017-09-20 12:02:26 -0700636
Robert Carr578038f2018-03-09 12:25:24 -0800637 status_t res = captureLayers(layerHandleBinder, &outBuffer, sourceCrop, frameScale,
638 childrenOnly);
chaviwa76b2712017-09-20 12:02:26 -0700639 reply->writeInt32(res);
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000640 if (res == NO_ERROR) {
641 reply->write(*outBuffer);
642 }
chaviwa76b2712017-09-20 12:02:26 -0700643 return NO_ERROR;
644 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800645 case AUTHENTICATE_SURFACE: {
646 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800647 sp<IGraphicBufferProducer> bufferProducer =
648 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
649 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800650 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700651 return NO_ERROR;
652 }
Brian Anderson6b376712017-04-04 10:51:39 -0700653 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
654 CHECK_INTERFACE(ISurfaceComposer, data, reply);
655 std::vector<FrameEvent> supportedTimestamps;
656 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
657 status_t err = reply->writeInt32(result);
658 if (err != NO_ERROR) {
659 return err;
660 }
661 if (result != NO_ERROR) {
662 return result;
663 }
664
665 std::vector<int32_t> supported;
666 supported.reserve(supportedTimestamps.size());
667 for (FrameEvent s : supportedTimestamps) {
668 supported.push_back(static_cast<int32_t>(s));
669 }
670 return reply->writeInt32Vector(supported);
671 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800672 case CREATE_DISPLAY_EVENT_CONNECTION: {
673 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700674 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
675 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800676 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800677 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700678 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700679 case CREATE_DISPLAY: {
680 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700681 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700682 bool secure = bool(data.readInt32());
683 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700684 reply->writeStrongBinder(display);
685 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700686 }
687 case DESTROY_DISPLAY: {
688 CHECK_INTERFACE(ISurfaceComposer, data, reply);
689 sp<IBinder> display = data.readStrongBinder();
690 destroyDisplay(display);
691 return NO_ERROR;
692 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700693 case GET_BUILT_IN_DISPLAY: {
694 CHECK_INTERFACE(ISurfaceComposer, data, reply);
695 int32_t id = data.readInt32();
696 sp<IBinder> display(getBuiltInDisplay(id));
697 reply->writeStrongBinder(display);
698 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700699 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700700 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700701 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700702 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700703 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700704 status_t result = getDisplayConfigs(display, &configs);
705 reply->writeInt32(result);
706 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800707 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700708 for (size_t c = 0; c < configs.size(); ++c) {
709 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
710 &configs[c], sizeof(DisplayInfo));
711 }
712 }
713 return NO_ERROR;
714 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700715 case GET_DISPLAY_STATS: {
716 CHECK_INTERFACE(ISurfaceComposer, data, reply);
717 DisplayStatInfo stats;
718 sp<IBinder> display = data.readStrongBinder();
719 status_t result = getDisplayStats(display, &stats);
720 reply->writeInt32(result);
721 if (result == NO_ERROR) {
722 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
723 &stats, sizeof(DisplayStatInfo));
724 }
725 return NO_ERROR;
726 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700727 case GET_ACTIVE_CONFIG: {
728 CHECK_INTERFACE(ISurfaceComposer, data, reply);
729 sp<IBinder> display = data.readStrongBinder();
730 int id = getActiveConfig(display);
731 reply->writeInt32(id);
732 return NO_ERROR;
733 }
734 case SET_ACTIVE_CONFIG: {
735 CHECK_INTERFACE(ISurfaceComposer, data, reply);
736 sp<IBinder> display = data.readStrongBinder();
737 int id = data.readInt32();
738 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700739 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700740 return NO_ERROR;
741 }
Michael Wright28f24d02016-07-12 13:30:53 -0700742 case GET_DISPLAY_COLOR_MODES: {
743 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Peiyong Lina52f0292018-03-14 17:26:31 -0700744 Vector<ColorMode> colorModes;
Michael Wright28f24d02016-07-12 13:30:53 -0700745 sp<IBinder> display = nullptr;
746 status_t result = data.readStrongBinder(&display);
747 if (result != NO_ERROR) {
748 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
749 return result;
750 }
751 result = getDisplayColorModes(display, &colorModes);
752 reply->writeInt32(result);
753 if (result == NO_ERROR) {
754 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
755 for (size_t i = 0; i < colorModes.size(); ++i) {
Peiyong Lina52f0292018-03-14 17:26:31 -0700756 reply->writeInt32(static_cast<int32_t>(colorModes[i]));
Michael Wright28f24d02016-07-12 13:30:53 -0700757 }
758 }
759 return NO_ERROR;
760 }
761 case GET_ACTIVE_COLOR_MODE: {
762 CHECK_INTERFACE(ISurfaceComposer, data, reply);
763 sp<IBinder> display = nullptr;
764 status_t result = data.readStrongBinder(&display);
765 if (result != NO_ERROR) {
766 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
767 return result;
768 }
Peiyong Lina52f0292018-03-14 17:26:31 -0700769 ColorMode colorMode = getActiveColorMode(display);
Michael Wright28f24d02016-07-12 13:30:53 -0700770 result = reply->writeInt32(static_cast<int32_t>(colorMode));
771 return result;
772 }
773 case SET_ACTIVE_COLOR_MODE: {
774 CHECK_INTERFACE(ISurfaceComposer, data, reply);
775 sp<IBinder> display = nullptr;
776 status_t result = data.readStrongBinder(&display);
777 if (result != NO_ERROR) {
778 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
779 return result;
780 }
781 int32_t colorModeInt = 0;
782 result = data.readInt32(&colorModeInt);
783 if (result != NO_ERROR) {
784 ALOGE("setActiveColorMode failed to readInt32: %d", result);
785 return result;
786 }
787 result = setActiveColorMode(display,
Peiyong Lina52f0292018-03-14 17:26:31 -0700788 static_cast<ColorMode>(colorModeInt));
Michael Wright28f24d02016-07-12 13:30:53 -0700789 result = reply->writeInt32(result);
790 return result;
791 }
Svetoslavd85084b2014-03-20 10:28:31 -0700792 case CLEAR_ANIMATION_FRAME_STATS: {
793 CHECK_INTERFACE(ISurfaceComposer, data, reply);
794 status_t result = clearAnimationFrameStats();
795 reply->writeInt32(result);
796 return NO_ERROR;
797 }
798 case GET_ANIMATION_FRAME_STATS: {
799 CHECK_INTERFACE(ISurfaceComposer, data, reply);
800 FrameStats stats;
801 status_t result = getAnimationFrameStats(&stats);
802 reply->write(stats);
803 reply->writeInt32(result);
804 return NO_ERROR;
805 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700806 case SET_POWER_MODE: {
807 CHECK_INTERFACE(ISurfaceComposer, data, reply);
808 sp<IBinder> display = data.readStrongBinder();
809 int32_t mode = data.readInt32();
810 setPowerMode(display, mode);
811 return NO_ERROR;
812 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700813 case GET_HDR_CAPABILITIES: {
814 CHECK_INTERFACE(ISurfaceComposer, data, reply);
815 sp<IBinder> display = nullptr;
816 status_t result = data.readStrongBinder(&display);
817 if (result != NO_ERROR) {
818 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
819 result);
820 return result;
821 }
822 HdrCapabilities capabilities;
823 result = getHdrCapabilities(display, &capabilities);
824 reply->writeInt32(result);
825 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800826 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700827 }
828 return NO_ERROR;
829 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700830 case ENABLE_VSYNC_INJECTIONS: {
831 CHECK_INTERFACE(ISurfaceComposer, data, reply);
832 bool enable = false;
833 status_t result = data.readBool(&enable);
834 if (result != NO_ERROR) {
835 ALOGE("enableVSyncInjections failed to readBool: %d", result);
836 return result;
837 }
838 return enableVSyncInjections(enable);
839 }
840 case INJECT_VSYNC: {
841 CHECK_INTERFACE(ISurfaceComposer, data, reply);
842 int64_t when = 0;
843 status_t result = data.readInt64(&when);
844 if (result != NO_ERROR) {
845 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
846 return result;
847 }
848 return injectVSync(when);
849 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800850 case GET_LAYER_DEBUG_INFO: {
851 CHECK_INTERFACE(ISurfaceComposer, data, reply);
852 std::vector<LayerDebugInfo> outLayers;
853 status_t result = getLayerDebugInfo(&outLayers);
854 reply->writeInt32(result);
855 if (result == NO_ERROR)
856 {
857 result = reply->writeParcelableVector(outLayers);
858 }
859 return result;
860 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700861 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700862 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700863 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800864 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800865}
866
867// ----------------------------------------------------------------------------
868
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800869};