blob: 4d2692fe6295be5d1362370c0270085ec0b8052e [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>
Chia-I Wu527747d2017-03-13 20:38:48 +000028#include <gui/IGraphicBufferAlloc.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080029#include <gui/IGraphicBufferProducer.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080030#include <gui/ISurfaceComposer.h>
31#include <gui/ISurfaceComposerClient.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080032
33#include <private/gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070038#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070039#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Jamie Gennis134f0422011-03-08 12:18:54 -080041#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
47class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
48{
49public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070050 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 : BpInterface<ISurfaceComposer>(impl)
52 {
53 }
54
Dan Stozad723bd72014-11-18 10:24:03 -080055 virtual ~BpSurfaceComposer();
56
Mathias Agopian7e27f052010-05-28 14:22:23 -070057 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 Parcel data, reply;
60 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
61 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070062 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 }
64
Robert Carr1db73f62016-12-21 12:58:51 -080065 virtual sp<ISurfaceComposerClient> createScopedConnection(
66 const sp<IGraphicBufferProducer>& parent)
67 {
68 Parcel data, reply;
69 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
70 data.writeStrongBinder(IInterface::asBinder(parent));
71 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
72 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
73 }
74
Chia-I Wu527747d2017-03-13 20:38:48 +000075 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
76 {
77 Parcel data, reply;
78 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
79 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
80 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
81 }
82
Mathias Agopian8b33f032012-07-24 20:43:54 -070083 virtual void setTransactionState(
84 const Vector<ComposerState>& state,
85 const Vector<DisplayState>& displays,
86 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087 {
88 Parcel data, reply;
89 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080090
91 data.writeUint32(static_cast<uint32_t>(state.size()));
92 for (const auto& s : state) {
93 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070094 }
Dan Stozad723bd72014-11-18 10:24:03 -080095
96 data.writeUint32(static_cast<uint32_t>(displays.size()));
97 for (const auto& d : displays) {
98 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070099 }
Dan Stozad723bd72014-11-18 10:24:03 -0800100
101 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700102 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 }
104
105 virtual void bootFinished()
106 {
107 Parcel data, reply;
108 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
109 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
110 }
111
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800112 virtual status_t captureScreen(const sp<IBinder>& display,
113 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700114 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800115 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700116 bool useIdentityTransform,
117 ISurfaceComposer::Rotation rotation)
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800118 {
119 Parcel data, reply;
120 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
121 data.writeStrongBinder(display);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800122 data.writeStrongBinder(IInterface::asBinder(producer));
Dan Stozac1879002014-05-22 15:59:05 -0700123 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800124 data.writeUint32(reqWidth);
125 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800126 data.writeInt32(minLayerZ);
127 data.writeInt32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800128 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700129 data.writeInt32(static_cast<int32_t>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800130 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
131 return reply.readInt32();
132 }
133
Jamie Gennis582270d2011-08-17 18:19:00 -0700134 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800135 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800136 {
137 Parcel data, reply;
138 int err = NO_ERROR;
139 err = data.writeInterfaceToken(
140 ISurfaceComposer::getInterfaceDescriptor());
141 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000142 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800143 "interface descriptor: %s (%d)", strerror(-err), -err);
144 return false;
145 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800146 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800147 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000148 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700149 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800150 return false;
151 }
152 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
153 &reply);
154 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000155 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700156 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800157 return false;
158 }
159 int32_t result = 0;
160 err = reply.readInt32(&result);
161 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000162 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700163 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800164 return false;
165 }
166 return result != 0;
167 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800168
Brian Anderson6b376712017-04-04 10:51:39 -0700169 virtual status_t getSupportedFrameTimestamps(
170 std::vector<FrameEvent>* outSupported) const {
171 if (!outSupported) {
172 return UNEXPECTED_NULL;
173 }
174 outSupported->clear();
175
176 Parcel data, reply;
177
178 status_t err = data.writeInterfaceToken(
179 ISurfaceComposer::getInterfaceDescriptor());
180 if (err != NO_ERROR) {
181 return err;
182 }
183
184 err = remote()->transact(
185 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
186 data, &reply);
187 if (err != NO_ERROR) {
188 return err;
189 }
190
191 int32_t result = 0;
192 err = reply.readInt32(&result);
193 if (err != NO_ERROR) {
194 return err;
195 }
196 if (result != NO_ERROR) {
197 return result;
198 }
199
200 std::vector<int32_t> supported;
201 err = reply.readInt32Vector(&supported);
202 if (err != NO_ERROR) {
203 return err;
204 }
205
206 outSupported->reserve(supported.size());
207 for (int32_t s : supported) {
208 outSupported->push_back(static_cast<FrameEvent>(s));
209 }
210 return NO_ERROR;
211 }
212
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800213 virtual sp<IDisplayEventConnection> createDisplayEventConnection()
214 {
215 Parcel data, reply;
216 sp<IDisplayEventConnection> result;
217 int err = data.writeInterfaceToken(
218 ISurfaceComposer::getInterfaceDescriptor());
219 if (err != NO_ERROR) {
220 return result;
221 }
222 err = remote()->transact(
223 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
224 data, &reply);
225 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000226 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800227 "transaction: %s (%d)", strerror(-err), -err);
228 return result;
229 }
230 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
231 return result;
232 }
Colin Cross8e533062012-06-07 13:17:52 -0700233
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700234 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700235 {
236 Parcel data, reply;
237 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700238 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700239 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700240 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
241 return reply.readStrongBinder();
242 }
243
Jesse Hall6c913be2013-08-08 12:15:49 -0700244 virtual void destroyDisplay(const sp<IBinder>& display)
245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
248 data.writeStrongBinder(display);
249 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
250 }
251
Mathias Agopiane57f2922012-08-09 16:29:12 -0700252 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
253 {
254 Parcel data, reply;
255 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
256 data.writeInt32(id);
257 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
258 return reply.readStrongBinder();
259 }
260
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700261 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700265 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700266 data.writeInt32(mode);
267 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700268 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700269
Dan Stoza7f7da322014-05-02 15:26:25 -0700270 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
271 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700275 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700276 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
277 status_t result = reply.readInt32();
278 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800279 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700280 configs->clear();
281 configs->resize(numConfigs);
282 for (size_t c = 0; c < numConfigs; ++c) {
283 memcpy(&(configs->editItemAt(c)),
284 reply.readInplace(sizeof(DisplayInfo)),
285 sizeof(DisplayInfo));
286 }
287 }
288 return result;
289 }
290
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700291 virtual status_t getDisplayStats(const sp<IBinder>& display,
292 DisplayStatInfo* stats)
293 {
294 Parcel data, reply;
295 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
296 data.writeStrongBinder(display);
297 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
298 status_t result = reply.readInt32();
299 if (result == NO_ERROR) {
300 memcpy(stats,
301 reply.readInplace(sizeof(DisplayStatInfo)),
302 sizeof(DisplayStatInfo));
303 }
304 return result;
305 }
306
Dan Stoza7f7da322014-05-02 15:26:25 -0700307 virtual int getActiveConfig(const sp<IBinder>& display)
308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
311 data.writeStrongBinder(display);
312 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
313 return reply.readInt32();
314 }
315
316 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
317 {
318 Parcel data, reply;
319 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
320 data.writeStrongBinder(display);
321 data.writeInt32(id);
322 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700323 return reply.readInt32();
324 }
Svetoslavd85084b2014-03-20 10:28:31 -0700325
Michael Wright28f24d02016-07-12 13:30:53 -0700326 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
327 Vector<android_color_mode_t>* outColorModes) {
328 Parcel data, reply;
329 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
330 if (result != NO_ERROR) {
331 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
332 return result;
333 }
334 result = data.writeStrongBinder(display);
335 if (result != NO_ERROR) {
336 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
337 return result;
338 }
339 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
340 if (result != NO_ERROR) {
341 ALOGE("getDisplayColorModes failed to transact: %d", result);
342 return result;
343 }
344 result = static_cast<status_t>(reply.readInt32());
345 if (result == NO_ERROR) {
346 size_t numModes = reply.readUint32();
347 outColorModes->clear();
348 outColorModes->resize(numModes);
349 for (size_t i = 0; i < numModes; ++i) {
350 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
351 }
352 }
353 return result;
354 }
355
356 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
357 Parcel data, reply;
358 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
359 if (result != NO_ERROR) {
360 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
361 return static_cast<android_color_mode_t>(result);
362 }
363 result = data.writeStrongBinder(display);
364 if (result != NO_ERROR) {
365 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
366 return static_cast<android_color_mode_t>(result);
367 }
368 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
369 if (result != NO_ERROR) {
370 ALOGE("getActiveColorMode failed to transact: %d", result);
371 return static_cast<android_color_mode_t>(result);
372 }
373 return static_cast<android_color_mode_t>(reply.readInt32());
374 }
375
376 virtual status_t setActiveColorMode(const sp<IBinder>& display,
377 android_color_mode_t colorMode) {
378 Parcel data, reply;
379 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
380 if (result != NO_ERROR) {
381 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
382 return result;
383 }
384 result = data.writeStrongBinder(display);
385 if (result != NO_ERROR) {
386 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
387 return result;
388 }
389 result = data.writeInt32(colorMode);
390 if (result != NO_ERROR) {
391 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
392 return result;
393 }
394 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
395 if (result != NO_ERROR) {
396 ALOGE("setActiveColorMode failed to transact: %d", result);
397 return result;
398 }
399 return static_cast<status_t>(reply.readInt32());
400 }
401
Svetoslavd85084b2014-03-20 10:28:31 -0700402 virtual status_t clearAnimationFrameStats() {
403 Parcel data, reply;
404 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
405 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
406 return reply.readInt32();
407 }
408
409 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
410 Parcel data, reply;
411 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
412 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
413 reply.read(*outStats);
414 return reply.readInt32();
415 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700416
417 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
418 HdrCapabilities* outCapabilities) const {
419 Parcel data, reply;
420 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
421 status_t result = data.writeStrongBinder(display);
422 if (result != NO_ERROR) {
423 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
424 return result;
425 }
426 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
427 data, &reply);
428 if (result != NO_ERROR) {
429 ALOGE("getHdrCapabilities failed to transact: %d", result);
430 return result;
431 }
432 result = reply.readInt32();
433 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800434 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700435 }
436 return result;
437 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700438
439 virtual status_t enableVSyncInjections(bool enable) {
440 Parcel data, reply;
441 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
442 if (result != NO_ERROR) {
443 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
444 return result;
445 }
446 result = data.writeBool(enable);
447 if (result != NO_ERROR) {
448 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
449 return result;
450 }
451 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
452 data, &reply, TF_ONE_WAY);
453 if (result != NO_ERROR) {
454 ALOGE("enableVSyncInjections failed to transact: %d", result);
455 return result;
456 }
457 return result;
458 }
459
460 virtual status_t injectVSync(nsecs_t when) {
461 Parcel data, reply;
462 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
463 if (result != NO_ERROR) {
464 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
465 return result;
466 }
467 result = data.writeInt64(when);
468 if (result != NO_ERROR) {
469 ALOGE("injectVSync failed to writeInt64: %d", result);
470 return result;
471 }
472 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
473 if (result != NO_ERROR) {
474 ALOGE("injectVSync failed to transact: %d", result);
475 return result;
476 }
477 return result;
478 }
479
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480};
481
Dan Stozad723bd72014-11-18 10:24:03 -0800482// Out-of-line virtual method definition to trigger vtable emission in this
483// translation unit (see clang warning -Wweak-vtables)
484BpSurfaceComposer::~BpSurfaceComposer() {}
485
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800486IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
487
488// ----------------------------------------------------------------------
489
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490status_t BnSurfaceComposer::onTransact(
491 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
492{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800493 switch(code) {
494 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700495 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800496 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800497 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700498 return NO_ERROR;
499 }
Robert Carr1db73f62016-12-21 12:58:51 -0800500 case CREATE_SCOPED_CONNECTION: {
501 CHECK_INTERFACE(ISurfaceComposer, data, reply);
502 sp<IGraphicBufferProducer> bufferProducer =
503 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
504 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
505 reply->writeStrongBinder(b);
506 return NO_ERROR;
507 }
Chia-I Wu527747d2017-03-13 20:38:48 +0000508 case CREATE_GRAPHIC_BUFFER_ALLOC: {
509 CHECK_INTERFACE(ISurfaceComposer, data, reply);
510 sp<IBinder> b = IInterface::asBinder(createGraphicBufferAlloc());
511 reply->writeStrongBinder(b);
512 return NO_ERROR;
513 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700514 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700515 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800516
517 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700518 if (count > data.dataSize()) {
519 return BAD_VALUE;
520 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700521 ComposerState s;
522 Vector<ComposerState> state;
523 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800524 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700525 if (s.read(data) == BAD_VALUE) {
526 return BAD_VALUE;
527 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700528 state.add(s);
529 }
Dan Stozad723bd72014-11-18 10:24:03 -0800530
531 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700532 if (count > data.dataSize()) {
533 return BAD_VALUE;
534 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700535 DisplayState d;
536 Vector<DisplayState> displays;
537 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800538 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700539 if (d.read(data) == BAD_VALUE) {
540 return BAD_VALUE;
541 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700542 displays.add(d);
543 }
Dan Stozad723bd72014-11-18 10:24:03 -0800544
545 uint32_t stateFlags = data.readUint32();
546 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700547 return NO_ERROR;
548 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700550 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700552 return NO_ERROR;
553 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800554 case CAPTURE_SCREEN: {
555 CHECK_INTERFACE(ISurfaceComposer, data, reply);
556 sp<IBinder> display = data.readStrongBinder();
557 sp<IGraphicBufferProducer> producer =
558 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700559 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700560 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800561 uint32_t reqWidth = data.readUint32();
562 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800563 int32_t minLayerZ = data.readInt32();
564 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800565 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800566 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800567
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800568 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700569 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700570 useIdentityTransform,
571 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800572 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700573 return NO_ERROR;
574 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800575 case AUTHENTICATE_SURFACE: {
576 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800577 sp<IGraphicBufferProducer> bufferProducer =
578 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
579 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800580 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700581 return NO_ERROR;
582 }
Brian Anderson6b376712017-04-04 10:51:39 -0700583 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
584 CHECK_INTERFACE(ISurfaceComposer, data, reply);
585 std::vector<FrameEvent> supportedTimestamps;
586 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
587 status_t err = reply->writeInt32(result);
588 if (err != NO_ERROR) {
589 return err;
590 }
591 if (result != NO_ERROR) {
592 return result;
593 }
594
595 std::vector<int32_t> supported;
596 supported.reserve(supportedTimestamps.size());
597 for (FrameEvent s : supportedTimestamps) {
598 supported.push_back(static_cast<int32_t>(s));
599 }
600 return reply->writeInt32Vector(supported);
601 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800602 case CREATE_DISPLAY_EVENT_CONNECTION: {
603 CHECK_INTERFACE(ISurfaceComposer, data, reply);
604 sp<IDisplayEventConnection> connection(createDisplayEventConnection());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800605 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800606 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700607 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700608 case CREATE_DISPLAY: {
609 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700610 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700611 bool secure = bool(data.readInt32());
612 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700613 reply->writeStrongBinder(display);
614 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700615 }
616 case DESTROY_DISPLAY: {
617 CHECK_INTERFACE(ISurfaceComposer, data, reply);
618 sp<IBinder> display = data.readStrongBinder();
619 destroyDisplay(display);
620 return NO_ERROR;
621 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700622 case GET_BUILT_IN_DISPLAY: {
623 CHECK_INTERFACE(ISurfaceComposer, data, reply);
624 int32_t id = data.readInt32();
625 sp<IBinder> display(getBuiltInDisplay(id));
626 reply->writeStrongBinder(display);
627 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700628 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700629 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700630 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700631 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700632 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700633 status_t result = getDisplayConfigs(display, &configs);
634 reply->writeInt32(result);
635 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800636 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700637 for (size_t c = 0; c < configs.size(); ++c) {
638 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
639 &configs[c], sizeof(DisplayInfo));
640 }
641 }
642 return NO_ERROR;
643 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700644 case GET_DISPLAY_STATS: {
645 CHECK_INTERFACE(ISurfaceComposer, data, reply);
646 DisplayStatInfo stats;
647 sp<IBinder> display = data.readStrongBinder();
648 status_t result = getDisplayStats(display, &stats);
649 reply->writeInt32(result);
650 if (result == NO_ERROR) {
651 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
652 &stats, sizeof(DisplayStatInfo));
653 }
654 return NO_ERROR;
655 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700656 case GET_ACTIVE_CONFIG: {
657 CHECK_INTERFACE(ISurfaceComposer, data, reply);
658 sp<IBinder> display = data.readStrongBinder();
659 int id = getActiveConfig(display);
660 reply->writeInt32(id);
661 return NO_ERROR;
662 }
663 case SET_ACTIVE_CONFIG: {
664 CHECK_INTERFACE(ISurfaceComposer, data, reply);
665 sp<IBinder> display = data.readStrongBinder();
666 int id = data.readInt32();
667 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700668 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700669 return NO_ERROR;
670 }
Michael Wright28f24d02016-07-12 13:30:53 -0700671 case GET_DISPLAY_COLOR_MODES: {
672 CHECK_INTERFACE(ISurfaceComposer, data, reply);
673 Vector<android_color_mode_t> colorModes;
674 sp<IBinder> display = nullptr;
675 status_t result = data.readStrongBinder(&display);
676 if (result != NO_ERROR) {
677 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
678 return result;
679 }
680 result = getDisplayColorModes(display, &colorModes);
681 reply->writeInt32(result);
682 if (result == NO_ERROR) {
683 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
684 for (size_t i = 0; i < colorModes.size(); ++i) {
685 reply->writeInt32(colorModes[i]);
686 }
687 }
688 return NO_ERROR;
689 }
690 case GET_ACTIVE_COLOR_MODE: {
691 CHECK_INTERFACE(ISurfaceComposer, data, reply);
692 sp<IBinder> display = nullptr;
693 status_t result = data.readStrongBinder(&display);
694 if (result != NO_ERROR) {
695 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
696 return result;
697 }
698 android_color_mode_t colorMode = getActiveColorMode(display);
699 result = reply->writeInt32(static_cast<int32_t>(colorMode));
700 return result;
701 }
702 case SET_ACTIVE_COLOR_MODE: {
703 CHECK_INTERFACE(ISurfaceComposer, data, reply);
704 sp<IBinder> display = nullptr;
705 status_t result = data.readStrongBinder(&display);
706 if (result != NO_ERROR) {
707 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
708 return result;
709 }
710 int32_t colorModeInt = 0;
711 result = data.readInt32(&colorModeInt);
712 if (result != NO_ERROR) {
713 ALOGE("setActiveColorMode failed to readInt32: %d", result);
714 return result;
715 }
716 result = setActiveColorMode(display,
717 static_cast<android_color_mode_t>(colorModeInt));
718 result = reply->writeInt32(result);
719 return result;
720 }
Svetoslavd85084b2014-03-20 10:28:31 -0700721 case CLEAR_ANIMATION_FRAME_STATS: {
722 CHECK_INTERFACE(ISurfaceComposer, data, reply);
723 status_t result = clearAnimationFrameStats();
724 reply->writeInt32(result);
725 return NO_ERROR;
726 }
727 case GET_ANIMATION_FRAME_STATS: {
728 CHECK_INTERFACE(ISurfaceComposer, data, reply);
729 FrameStats stats;
730 status_t result = getAnimationFrameStats(&stats);
731 reply->write(stats);
732 reply->writeInt32(result);
733 return NO_ERROR;
734 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700735 case SET_POWER_MODE: {
736 CHECK_INTERFACE(ISurfaceComposer, data, reply);
737 sp<IBinder> display = data.readStrongBinder();
738 int32_t mode = data.readInt32();
739 setPowerMode(display, mode);
740 return NO_ERROR;
741 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700742 case GET_HDR_CAPABILITIES: {
743 CHECK_INTERFACE(ISurfaceComposer, data, reply);
744 sp<IBinder> display = nullptr;
745 status_t result = data.readStrongBinder(&display);
746 if (result != NO_ERROR) {
747 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
748 result);
749 return result;
750 }
751 HdrCapabilities capabilities;
752 result = getHdrCapabilities(display, &capabilities);
753 reply->writeInt32(result);
754 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800755 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700756 }
757 return NO_ERROR;
758 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700759 case ENABLE_VSYNC_INJECTIONS: {
760 CHECK_INTERFACE(ISurfaceComposer, data, reply);
761 bool enable = false;
762 status_t result = data.readBool(&enable);
763 if (result != NO_ERROR) {
764 ALOGE("enableVSyncInjections failed to readBool: %d", result);
765 return result;
766 }
767 return enableVSyncInjections(enable);
768 }
769 case INJECT_VSYNC: {
770 CHECK_INTERFACE(ISurfaceComposer, data, reply);
771 int64_t when = 0;
772 status_t result = data.readInt64(&when);
773 if (result != NO_ERROR) {
774 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
775 return result;
776 }
777 return injectVSync(when);
778 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700779 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700780 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700781 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800782 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800783}
784
785// ----------------------------------------------------------------------------
786
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800787};