blob: 96771257c1cff0e2608ab443de3158b29077adcc [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
46class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
47{
48public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070049 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 : BpInterface<ISurfaceComposer>(impl)
51 {
52 }
53
Dan Stozad723bd72014-11-18 10:24:03 -080054 virtual ~BpSurfaceComposer();
55
Mathias Agopian7e27f052010-05-28 14:22:23 -070056 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 Parcel data, reply;
59 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
60 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 }
63
Robert Carr1db73f62016-12-21 12:58:51 -080064 virtual sp<ISurfaceComposerClient> createScopedConnection(
65 const sp<IGraphicBufferProducer>& parent)
66 {
67 Parcel data, reply;
68 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
69 data.writeStrongBinder(IInterface::asBinder(parent));
70 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
71 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
72 }
73
Mathias Agopian8b33f032012-07-24 20:43:54 -070074 virtual void setTransactionState(
75 const Vector<ComposerState>& state,
76 const Vector<DisplayState>& displays,
77 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 {
79 Parcel data, reply;
80 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080081
82 data.writeUint32(static_cast<uint32_t>(state.size()));
83 for (const auto& s : state) {
84 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070085 }
Dan Stozad723bd72014-11-18 10:24:03 -080086
87 data.writeUint32(static_cast<uint32_t>(displays.size()));
88 for (const auto& d : displays) {
89 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070090 }
Dan Stozad723bd72014-11-18 10:24:03 -080091
92 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070093 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 }
95
96 virtual void bootFinished()
97 {
98 Parcel data, reply;
99 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
100 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
101 }
102
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800103 virtual status_t captureScreen(const sp<IBinder>& display,
104 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700105 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800106 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700107 bool useIdentityTransform,
108 ISurfaceComposer::Rotation rotation)
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800109 {
110 Parcel data, reply;
111 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
112 data.writeStrongBinder(display);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800113 data.writeStrongBinder(IInterface::asBinder(producer));
Dan Stozac1879002014-05-22 15:59:05 -0700114 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800115 data.writeUint32(reqWidth);
116 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800117 data.writeInt32(minLayerZ);
118 data.writeInt32(maxLayerZ);
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));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800121 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
122 return reply.readInt32();
123 }
124
Jamie Gennis582270d2011-08-17 18:19:00 -0700125 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800126 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800127 {
128 Parcel data, reply;
129 int err = NO_ERROR;
130 err = data.writeInterfaceToken(
131 ISurfaceComposer::getInterfaceDescriptor());
132 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000133 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800134 "interface descriptor: %s (%d)", strerror(-err), -err);
135 return false;
136 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800137 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800138 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000139 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700140 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800141 return false;
142 }
143 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
144 &reply);
145 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000146 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700147 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800148 return false;
149 }
150 int32_t result = 0;
151 err = reply.readInt32(&result);
152 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000153 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700154 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800155 return false;
156 }
157 return result != 0;
158 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800159
Brian Anderson6b376712017-04-04 10:51:39 -0700160 virtual status_t getSupportedFrameTimestamps(
161 std::vector<FrameEvent>* outSupported) const {
162 if (!outSupported) {
163 return UNEXPECTED_NULL;
164 }
165 outSupported->clear();
166
167 Parcel data, reply;
168
169 status_t err = data.writeInterfaceToken(
170 ISurfaceComposer::getInterfaceDescriptor());
171 if (err != NO_ERROR) {
172 return err;
173 }
174
175 err = remote()->transact(
176 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
177 data, &reply);
178 if (err != NO_ERROR) {
179 return err;
180 }
181
182 int32_t result = 0;
183 err = reply.readInt32(&result);
184 if (err != NO_ERROR) {
185 return err;
186 }
187 if (result != NO_ERROR) {
188 return result;
189 }
190
191 std::vector<int32_t> supported;
192 err = reply.readInt32Vector(&supported);
193 if (err != NO_ERROR) {
194 return err;
195 }
196
197 outSupported->reserve(supported.size());
198 for (int32_t s : supported) {
199 outSupported->push_back(static_cast<FrameEvent>(s));
200 }
201 return NO_ERROR;
202 }
203
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700204 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800205 {
206 Parcel data, reply;
207 sp<IDisplayEventConnection> result;
208 int err = data.writeInterfaceToken(
209 ISurfaceComposer::getInterfaceDescriptor());
210 if (err != NO_ERROR) {
211 return result;
212 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700213 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800214 err = remote()->transact(
215 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
216 data, &reply);
217 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000218 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800219 "transaction: %s (%d)", strerror(-err), -err);
220 return result;
221 }
222 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
223 return result;
224 }
Colin Cross8e533062012-06-07 13:17:52 -0700225
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700226 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700227 {
228 Parcel data, reply;
229 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700230 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700231 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700232 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
233 return reply.readStrongBinder();
234 }
235
Jesse Hall6c913be2013-08-08 12:15:49 -0700236 virtual void destroyDisplay(const sp<IBinder>& display)
237 {
238 Parcel data, reply;
239 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
240 data.writeStrongBinder(display);
241 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
242 }
243
Mathias Agopiane57f2922012-08-09 16:29:12 -0700244 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
248 data.writeInt32(id);
249 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
250 return reply.readStrongBinder();
251 }
252
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700253 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700257 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700258 data.writeInt32(mode);
259 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700260 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700261
Dan Stoza7f7da322014-05-02 15:26:25 -0700262 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
263 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700267 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700268 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
269 status_t result = reply.readInt32();
270 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800271 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700272 configs->clear();
273 configs->resize(numConfigs);
274 for (size_t c = 0; c < numConfigs; ++c) {
275 memcpy(&(configs->editItemAt(c)),
276 reply.readInplace(sizeof(DisplayInfo)),
277 sizeof(DisplayInfo));
278 }
279 }
280 return result;
281 }
282
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700283 virtual status_t getDisplayStats(const sp<IBinder>& display,
284 DisplayStatInfo* stats)
285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
288 data.writeStrongBinder(display);
289 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
290 status_t result = reply.readInt32();
291 if (result == NO_ERROR) {
292 memcpy(stats,
293 reply.readInplace(sizeof(DisplayStatInfo)),
294 sizeof(DisplayStatInfo));
295 }
296 return result;
297 }
298
Dan Stoza7f7da322014-05-02 15:26:25 -0700299 virtual int getActiveConfig(const sp<IBinder>& display)
300 {
301 Parcel data, reply;
302 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
303 data.writeStrongBinder(display);
304 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
305 return reply.readInt32();
306 }
307
308 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
312 data.writeStrongBinder(display);
313 data.writeInt32(id);
314 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700315 return reply.readInt32();
316 }
Svetoslavd85084b2014-03-20 10:28:31 -0700317
Michael Wright28f24d02016-07-12 13:30:53 -0700318 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
319 Vector<android_color_mode_t>* outColorModes) {
320 Parcel data, reply;
321 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
322 if (result != NO_ERROR) {
323 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
324 return result;
325 }
326 result = data.writeStrongBinder(display);
327 if (result != NO_ERROR) {
328 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
329 return result;
330 }
331 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
332 if (result != NO_ERROR) {
333 ALOGE("getDisplayColorModes failed to transact: %d", result);
334 return result;
335 }
336 result = static_cast<status_t>(reply.readInt32());
337 if (result == NO_ERROR) {
338 size_t numModes = reply.readUint32();
339 outColorModes->clear();
340 outColorModes->resize(numModes);
341 for (size_t i = 0; i < numModes; ++i) {
342 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
343 }
344 }
345 return result;
346 }
347
348 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
349 Parcel data, reply;
350 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
351 if (result != NO_ERROR) {
352 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
353 return static_cast<android_color_mode_t>(result);
354 }
355 result = data.writeStrongBinder(display);
356 if (result != NO_ERROR) {
357 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
358 return static_cast<android_color_mode_t>(result);
359 }
360 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
361 if (result != NO_ERROR) {
362 ALOGE("getActiveColorMode failed to transact: %d", result);
363 return static_cast<android_color_mode_t>(result);
364 }
365 return static_cast<android_color_mode_t>(reply.readInt32());
366 }
367
368 virtual status_t setActiveColorMode(const sp<IBinder>& display,
369 android_color_mode_t colorMode) {
370 Parcel data, reply;
371 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
372 if (result != NO_ERROR) {
373 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
374 return result;
375 }
376 result = data.writeStrongBinder(display);
377 if (result != NO_ERROR) {
378 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
379 return result;
380 }
381 result = data.writeInt32(colorMode);
382 if (result != NO_ERROR) {
383 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
384 return result;
385 }
386 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
387 if (result != NO_ERROR) {
388 ALOGE("setActiveColorMode failed to transact: %d", result);
389 return result;
390 }
391 return static_cast<status_t>(reply.readInt32());
392 }
393
Svetoslavd85084b2014-03-20 10:28:31 -0700394 virtual status_t clearAnimationFrameStats() {
395 Parcel data, reply;
396 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
397 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
398 return reply.readInt32();
399 }
400
401 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
402 Parcel data, reply;
403 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
404 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
405 reply.read(*outStats);
406 return reply.readInt32();
407 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700408
409 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
410 HdrCapabilities* outCapabilities) const {
411 Parcel data, reply;
412 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
413 status_t result = data.writeStrongBinder(display);
414 if (result != NO_ERROR) {
415 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
416 return result;
417 }
418 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
419 data, &reply);
420 if (result != NO_ERROR) {
421 ALOGE("getHdrCapabilities failed to transact: %d", result);
422 return result;
423 }
424 result = reply.readInt32();
425 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800426 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700427 }
428 return result;
429 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700430
431 virtual status_t enableVSyncInjections(bool enable) {
432 Parcel data, reply;
433 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
434 if (result != NO_ERROR) {
435 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
436 return result;
437 }
438 result = data.writeBool(enable);
439 if (result != NO_ERROR) {
440 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
441 return result;
442 }
443 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
444 data, &reply, TF_ONE_WAY);
445 if (result != NO_ERROR) {
446 ALOGE("enableVSyncInjections failed to transact: %d", result);
447 return result;
448 }
449 return result;
450 }
451
452 virtual status_t injectVSync(nsecs_t when) {
453 Parcel data, reply;
454 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
455 if (result != NO_ERROR) {
456 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
457 return result;
458 }
459 result = data.writeInt64(when);
460 if (result != NO_ERROR) {
461 ALOGE("injectVSync failed to writeInt64: %d", result);
462 return result;
463 }
464 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
465 if (result != NO_ERROR) {
466 ALOGE("injectVSync failed to transact: %d", result);
467 return result;
468 }
469 return result;
470 }
471
Kalle Raitaa099a242017-01-11 11:17:29 -0800472 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
473 {
474 if (!outLayers) {
475 return UNEXPECTED_NULL;
476 }
477
478 Parcel data, reply;
479
480 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
481 if (err != NO_ERROR) {
482 return err;
483 }
484
485 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
486 if (err != NO_ERROR) {
487 return err;
488 }
489
490 int32_t result = 0;
491 err = reply.readInt32(&result);
492 if (err != NO_ERROR) {
493 return err;
494 }
495 if (result != NO_ERROR) {
496 return result;
497 }
498
499 outLayers->clear();
500 return reply.readParcelableVector(outLayers);
501 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800502};
503
Dan Stozad723bd72014-11-18 10:24:03 -0800504// Out-of-line virtual method definition to trigger vtable emission in this
505// translation unit (see clang warning -Wweak-vtables)
506BpSurfaceComposer::~BpSurfaceComposer() {}
507
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
509
510// ----------------------------------------------------------------------
511
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800512status_t BnSurfaceComposer::onTransact(
513 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
514{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515 switch(code) {
516 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700517 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800518 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800519 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700520 return NO_ERROR;
521 }
Robert Carr1db73f62016-12-21 12:58:51 -0800522 case CREATE_SCOPED_CONNECTION: {
523 CHECK_INTERFACE(ISurfaceComposer, data, reply);
524 sp<IGraphicBufferProducer> bufferProducer =
525 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
526 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
527 reply->writeStrongBinder(b);
528 return NO_ERROR;
529 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700530 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700531 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800532
533 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700534 if (count > data.dataSize()) {
535 return BAD_VALUE;
536 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700537 ComposerState s;
538 Vector<ComposerState> state;
539 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800540 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700541 if (s.read(data) == BAD_VALUE) {
542 return BAD_VALUE;
543 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700544 state.add(s);
545 }
Dan Stozad723bd72014-11-18 10:24:03 -0800546
547 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700548 if (count > data.dataSize()) {
549 return BAD_VALUE;
550 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700551 DisplayState d;
552 Vector<DisplayState> displays;
553 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800554 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700555 if (d.read(data) == BAD_VALUE) {
556 return BAD_VALUE;
557 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700558 displays.add(d);
559 }
Dan Stozad723bd72014-11-18 10:24:03 -0800560
561 uint32_t stateFlags = data.readUint32();
562 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700563 return NO_ERROR;
564 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800565 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700566 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800567 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700568 return NO_ERROR;
569 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800570 case CAPTURE_SCREEN: {
571 CHECK_INTERFACE(ISurfaceComposer, data, reply);
572 sp<IBinder> display = data.readStrongBinder();
573 sp<IGraphicBufferProducer> producer =
574 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700575 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700576 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800577 uint32_t reqWidth = data.readUint32();
578 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800579 int32_t minLayerZ = data.readInt32();
580 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800581 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800582 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800583
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800584 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700585 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700586 useIdentityTransform,
587 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800588 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700589 return NO_ERROR;
590 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800591 case AUTHENTICATE_SURFACE: {
592 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800593 sp<IGraphicBufferProducer> bufferProducer =
594 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
595 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800596 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700597 return NO_ERROR;
598 }
Brian Anderson6b376712017-04-04 10:51:39 -0700599 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
600 CHECK_INTERFACE(ISurfaceComposer, data, reply);
601 std::vector<FrameEvent> supportedTimestamps;
602 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
603 status_t err = reply->writeInt32(result);
604 if (err != NO_ERROR) {
605 return err;
606 }
607 if (result != NO_ERROR) {
608 return result;
609 }
610
611 std::vector<int32_t> supported;
612 supported.reserve(supportedTimestamps.size());
613 for (FrameEvent s : supportedTimestamps) {
614 supported.push_back(static_cast<int32_t>(s));
615 }
616 return reply->writeInt32Vector(supported);
617 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800618 case CREATE_DISPLAY_EVENT_CONNECTION: {
619 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700620 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
621 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800622 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800623 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700624 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700625 case CREATE_DISPLAY: {
626 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700627 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700628 bool secure = bool(data.readInt32());
629 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700630 reply->writeStrongBinder(display);
631 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700632 }
633 case DESTROY_DISPLAY: {
634 CHECK_INTERFACE(ISurfaceComposer, data, reply);
635 sp<IBinder> display = data.readStrongBinder();
636 destroyDisplay(display);
637 return NO_ERROR;
638 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700639 case GET_BUILT_IN_DISPLAY: {
640 CHECK_INTERFACE(ISurfaceComposer, data, reply);
641 int32_t id = data.readInt32();
642 sp<IBinder> display(getBuiltInDisplay(id));
643 reply->writeStrongBinder(display);
644 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700645 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700646 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700647 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700648 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700649 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700650 status_t result = getDisplayConfigs(display, &configs);
651 reply->writeInt32(result);
652 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800653 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700654 for (size_t c = 0; c < configs.size(); ++c) {
655 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
656 &configs[c], sizeof(DisplayInfo));
657 }
658 }
659 return NO_ERROR;
660 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700661 case GET_DISPLAY_STATS: {
662 CHECK_INTERFACE(ISurfaceComposer, data, reply);
663 DisplayStatInfo stats;
664 sp<IBinder> display = data.readStrongBinder();
665 status_t result = getDisplayStats(display, &stats);
666 reply->writeInt32(result);
667 if (result == NO_ERROR) {
668 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
669 &stats, sizeof(DisplayStatInfo));
670 }
671 return NO_ERROR;
672 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700673 case GET_ACTIVE_CONFIG: {
674 CHECK_INTERFACE(ISurfaceComposer, data, reply);
675 sp<IBinder> display = data.readStrongBinder();
676 int id = getActiveConfig(display);
677 reply->writeInt32(id);
678 return NO_ERROR;
679 }
680 case SET_ACTIVE_CONFIG: {
681 CHECK_INTERFACE(ISurfaceComposer, data, reply);
682 sp<IBinder> display = data.readStrongBinder();
683 int id = data.readInt32();
684 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700685 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700686 return NO_ERROR;
687 }
Michael Wright28f24d02016-07-12 13:30:53 -0700688 case GET_DISPLAY_COLOR_MODES: {
689 CHECK_INTERFACE(ISurfaceComposer, data, reply);
690 Vector<android_color_mode_t> colorModes;
691 sp<IBinder> display = nullptr;
692 status_t result = data.readStrongBinder(&display);
693 if (result != NO_ERROR) {
694 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
695 return result;
696 }
697 result = getDisplayColorModes(display, &colorModes);
698 reply->writeInt32(result);
699 if (result == NO_ERROR) {
700 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
701 for (size_t i = 0; i < colorModes.size(); ++i) {
702 reply->writeInt32(colorModes[i]);
703 }
704 }
705 return NO_ERROR;
706 }
707 case GET_ACTIVE_COLOR_MODE: {
708 CHECK_INTERFACE(ISurfaceComposer, data, reply);
709 sp<IBinder> display = nullptr;
710 status_t result = data.readStrongBinder(&display);
711 if (result != NO_ERROR) {
712 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
713 return result;
714 }
715 android_color_mode_t colorMode = getActiveColorMode(display);
716 result = reply->writeInt32(static_cast<int32_t>(colorMode));
717 return result;
718 }
719 case SET_ACTIVE_COLOR_MODE: {
720 CHECK_INTERFACE(ISurfaceComposer, data, reply);
721 sp<IBinder> display = nullptr;
722 status_t result = data.readStrongBinder(&display);
723 if (result != NO_ERROR) {
724 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
725 return result;
726 }
727 int32_t colorModeInt = 0;
728 result = data.readInt32(&colorModeInt);
729 if (result != NO_ERROR) {
730 ALOGE("setActiveColorMode failed to readInt32: %d", result);
731 return result;
732 }
733 result = setActiveColorMode(display,
734 static_cast<android_color_mode_t>(colorModeInt));
735 result = reply->writeInt32(result);
736 return result;
737 }
Svetoslavd85084b2014-03-20 10:28:31 -0700738 case CLEAR_ANIMATION_FRAME_STATS: {
739 CHECK_INTERFACE(ISurfaceComposer, data, reply);
740 status_t result = clearAnimationFrameStats();
741 reply->writeInt32(result);
742 return NO_ERROR;
743 }
744 case GET_ANIMATION_FRAME_STATS: {
745 CHECK_INTERFACE(ISurfaceComposer, data, reply);
746 FrameStats stats;
747 status_t result = getAnimationFrameStats(&stats);
748 reply->write(stats);
749 reply->writeInt32(result);
750 return NO_ERROR;
751 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700752 case SET_POWER_MODE: {
753 CHECK_INTERFACE(ISurfaceComposer, data, reply);
754 sp<IBinder> display = data.readStrongBinder();
755 int32_t mode = data.readInt32();
756 setPowerMode(display, mode);
757 return NO_ERROR;
758 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700759 case GET_HDR_CAPABILITIES: {
760 CHECK_INTERFACE(ISurfaceComposer, data, reply);
761 sp<IBinder> display = nullptr;
762 status_t result = data.readStrongBinder(&display);
763 if (result != NO_ERROR) {
764 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
765 result);
766 return result;
767 }
768 HdrCapabilities capabilities;
769 result = getHdrCapabilities(display, &capabilities);
770 reply->writeInt32(result);
771 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800772 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700773 }
774 return NO_ERROR;
775 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700776 case ENABLE_VSYNC_INJECTIONS: {
777 CHECK_INTERFACE(ISurfaceComposer, data, reply);
778 bool enable = false;
779 status_t result = data.readBool(&enable);
780 if (result != NO_ERROR) {
781 ALOGE("enableVSyncInjections failed to readBool: %d", result);
782 return result;
783 }
784 return enableVSyncInjections(enable);
785 }
786 case INJECT_VSYNC: {
787 CHECK_INTERFACE(ISurfaceComposer, data, reply);
788 int64_t when = 0;
789 status_t result = data.readInt64(&when);
790 if (result != NO_ERROR) {
791 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
792 return result;
793 }
794 return injectVSync(when);
795 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800796 case GET_LAYER_DEBUG_INFO: {
797 CHECK_INTERFACE(ISurfaceComposer, data, reply);
798 std::vector<LayerDebugInfo> outLayers;
799 status_t result = getLayerDebugInfo(&outLayers);
800 reply->writeInt32(result);
801 if (result == NO_ERROR)
802 {
803 result = reply->writeParcelableVector(outLayers);
804 }
805 return result;
806 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700807 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700808 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700809 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800810 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800811}
812
813// ----------------------------------------------------------------------------
814
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800815};