blob: 06d1261feb26e1c3637fb2b2c73b337b7b87d1fc [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>
24#include <binder/IMemory.h>
25#include <binder/IPCThreadState.h>
26#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopiand0566bc2011-11-17 17:49:17 -080028#include <gui/IDisplayEventConnection.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080029#include <gui/IGraphicBufferAlloc.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080030#include <gui/IGraphicBufferProducer.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080031#include <gui/ISurfaceComposer.h>
32#include <gui/ISurfaceComposerClient.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080033
34#include <private/gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080035
Michael Wright28f24d02016-07-12 13:30:53 -070036#include <system/graphics.h>
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070039#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070040#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Jamie Gennis134f0422011-03-08 12:18:54 -080042#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080043
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044// ---------------------------------------------------------------------------
45
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046namespace android {
47
48class 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
Jamie Gennis9a78c902011-01-12 18:30:40 -080076 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
77 {
Jamie Gennis9a78c902011-01-12 18:30:40 -080078 Parcel data, reply;
79 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
80 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
81 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
82 }
83
Mathias Agopian8b33f032012-07-24 20:43:54 -070084 virtual void setTransactionState(
85 const Vector<ComposerState>& state,
86 const Vector<DisplayState>& displays,
87 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 {
89 Parcel data, reply;
90 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080091
92 data.writeUint32(static_cast<uint32_t>(state.size()));
93 for (const auto& s : state) {
94 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070095 }
Dan Stozad723bd72014-11-18 10:24:03 -080096
97 data.writeUint32(static_cast<uint32_t>(displays.size()));
98 for (const auto& d : displays) {
99 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700100 }
Dan Stozad723bd72014-11-18 10:24:03 -0800101
102 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700103 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 }
105
106 virtual void bootFinished()
107 {
108 Parcel data, reply;
109 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
110 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
111 }
112
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800113 virtual status_t captureScreen(const sp<IBinder>& display,
114 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700115 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800116 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700117 bool useIdentityTransform,
118 ISurfaceComposer::Rotation rotation)
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800119 {
120 Parcel data, reply;
121 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
122 data.writeStrongBinder(display);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800123 data.writeStrongBinder(IInterface::asBinder(producer));
Dan Stozac1879002014-05-22 15:59:05 -0700124 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800125 data.writeUint32(reqWidth);
126 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800127 data.writeInt32(minLayerZ);
128 data.writeInt32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800129 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700130 data.writeInt32(static_cast<int32_t>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800131 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
132 return reply.readInt32();
133 }
134
Jamie Gennis582270d2011-08-17 18:19:00 -0700135 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800136 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800137 {
138 Parcel data, reply;
139 int err = NO_ERROR;
140 err = data.writeInterfaceToken(
141 ISurfaceComposer::getInterfaceDescriptor());
142 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000143 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800144 "interface descriptor: %s (%d)", strerror(-err), -err);
145 return false;
146 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800147 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800148 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000149 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700150 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800151 return false;
152 }
153 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
154 &reply);
155 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000156 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700157 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800158 return false;
159 }
160 int32_t result = 0;
161 err = reply.readInt32(&result);
162 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000163 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700164 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800165 return false;
166 }
167 return result != 0;
168 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800169
Brian Anderson069b3652016-07-22 10:32:47 -0700170 virtual status_t getSupportedFrameTimestamps(
Brian Anderson3890c392016-07-25 12:48:08 -0700171 std::vector<FrameEvent>* outSupported) const {
Brian Anderson069b3652016-07-22 10:32:47 -0700172 if (!outSupported) {
173 return UNEXPECTED_NULL;
174 }
175 outSupported->clear();
176
177 Parcel data, reply;
178
179 status_t err = data.writeInterfaceToken(
180 ISurfaceComposer::getInterfaceDescriptor());
181 if (err != NO_ERROR) {
182 return err;
183 }
184
185 err = remote()->transact(
186 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
187 data, &reply);
188 if (err != NO_ERROR) {
189 return err;
190 }
191
192 int32_t result = 0;
193 err = reply.readInt32(&result);
194 if (err != NO_ERROR) {
195 return err;
196 }
197 if (result != NO_ERROR) {
198 return result;
199 }
200
201 std::vector<int32_t> supported;
202 err = reply.readInt32Vector(&supported);
203 if (err != NO_ERROR) {
204 return err;
205 }
206
207 outSupported->reserve(supported.size());
208 for (int32_t s : supported) {
Brian Anderson3890c392016-07-25 12:48:08 -0700209 outSupported->push_back(static_cast<FrameEvent>(s));
Brian Anderson069b3652016-07-22 10:32:47 -0700210 }
211 return NO_ERROR;
212 }
213
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800214 virtual sp<IDisplayEventConnection> createDisplayEventConnection()
215 {
216 Parcel data, reply;
217 sp<IDisplayEventConnection> result;
218 int err = data.writeInterfaceToken(
219 ISurfaceComposer::getInterfaceDescriptor());
220 if (err != NO_ERROR) {
221 return result;
222 }
223 err = remote()->transact(
224 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
225 data, &reply);
226 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000227 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800228 "transaction: %s (%d)", strerror(-err), -err);
229 return result;
230 }
231 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
232 return result;
233 }
Colin Cross8e533062012-06-07 13:17:52 -0700234
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700235 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700236 {
237 Parcel data, reply;
238 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700239 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700240 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700241 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
242 return reply.readStrongBinder();
243 }
244
Jesse Hall6c913be2013-08-08 12:15:49 -0700245 virtual void destroyDisplay(const sp<IBinder>& display)
246 {
247 Parcel data, reply;
248 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
249 data.writeStrongBinder(display);
250 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
251 }
252
Mathias Agopiane57f2922012-08-09 16:29:12 -0700253 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
257 data.writeInt32(id);
258 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
259 return reply.readStrongBinder();
260 }
261
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700262 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700263 {
264 Parcel data, reply;
265 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700266 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700267 data.writeInt32(mode);
268 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700269 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700270
Dan Stoza7f7da322014-05-02 15:26:25 -0700271 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
272 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700276 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700277 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
278 status_t result = reply.readInt32();
279 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800280 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700281 configs->clear();
282 configs->resize(numConfigs);
283 for (size_t c = 0; c < numConfigs; ++c) {
284 memcpy(&(configs->editItemAt(c)),
285 reply.readInplace(sizeof(DisplayInfo)),
286 sizeof(DisplayInfo));
287 }
288 }
289 return result;
290 }
291
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700292 virtual status_t getDisplayStats(const sp<IBinder>& display,
293 DisplayStatInfo* stats)
294 {
295 Parcel data, reply;
296 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
297 data.writeStrongBinder(display);
298 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
299 status_t result = reply.readInt32();
300 if (result == NO_ERROR) {
301 memcpy(stats,
302 reply.readInplace(sizeof(DisplayStatInfo)),
303 sizeof(DisplayStatInfo));
304 }
305 return result;
306 }
307
Dan Stoza7f7da322014-05-02 15:26:25 -0700308 virtual int getActiveConfig(const sp<IBinder>& display)
309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
312 data.writeStrongBinder(display);
313 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
314 return reply.readInt32();
315 }
316
317 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
321 data.writeStrongBinder(display);
322 data.writeInt32(id);
323 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700324 return reply.readInt32();
325 }
Svetoslavd85084b2014-03-20 10:28:31 -0700326
Michael Wright28f24d02016-07-12 13:30:53 -0700327 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
328 Vector<android_color_mode_t>* outColorModes) {
329 Parcel data, reply;
330 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
331 if (result != NO_ERROR) {
332 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
333 return result;
334 }
335 result = data.writeStrongBinder(display);
336 if (result != NO_ERROR) {
337 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
338 return result;
339 }
340 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
341 if (result != NO_ERROR) {
342 ALOGE("getDisplayColorModes failed to transact: %d", result);
343 return result;
344 }
345 result = static_cast<status_t>(reply.readInt32());
346 if (result == NO_ERROR) {
347 size_t numModes = reply.readUint32();
348 outColorModes->clear();
349 outColorModes->resize(numModes);
350 for (size_t i = 0; i < numModes; ++i) {
351 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
352 }
353 }
354 return result;
355 }
356
357 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
358 Parcel data, reply;
359 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
360 if (result != NO_ERROR) {
361 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
362 return static_cast<android_color_mode_t>(result);
363 }
364 result = data.writeStrongBinder(display);
365 if (result != NO_ERROR) {
366 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
367 return static_cast<android_color_mode_t>(result);
368 }
369 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
370 if (result != NO_ERROR) {
371 ALOGE("getActiveColorMode failed to transact: %d", result);
372 return static_cast<android_color_mode_t>(result);
373 }
374 return static_cast<android_color_mode_t>(reply.readInt32());
375 }
376
377 virtual status_t setActiveColorMode(const sp<IBinder>& display,
378 android_color_mode_t colorMode) {
379 Parcel data, reply;
380 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
381 if (result != NO_ERROR) {
382 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
383 return result;
384 }
385 result = data.writeStrongBinder(display);
386 if (result != NO_ERROR) {
387 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
388 return result;
389 }
390 result = data.writeInt32(colorMode);
391 if (result != NO_ERROR) {
392 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
393 return result;
394 }
395 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
396 if (result != NO_ERROR) {
397 ALOGE("setActiveColorMode failed to transact: %d", result);
398 return result;
399 }
400 return static_cast<status_t>(reply.readInt32());
401 }
402
Svetoslavd85084b2014-03-20 10:28:31 -0700403 virtual status_t clearAnimationFrameStats() {
404 Parcel data, reply;
405 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
406 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
407 return reply.readInt32();
408 }
409
410 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
411 Parcel data, reply;
412 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
413 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
414 reply.read(*outStats);
415 return reply.readInt32();
416 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700417
418 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
419 HdrCapabilities* outCapabilities) const {
420 Parcel data, reply;
421 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
422 status_t result = data.writeStrongBinder(display);
423 if (result != NO_ERROR) {
424 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
425 return result;
426 }
427 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
428 data, &reply);
429 if (result != NO_ERROR) {
430 ALOGE("getHdrCapabilities failed to transact: %d", result);
431 return result;
432 }
433 result = reply.readInt32();
434 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800435 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700436 }
437 return result;
438 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700439
440 virtual status_t enableVSyncInjections(bool enable) {
441 Parcel data, reply;
442 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
443 if (result != NO_ERROR) {
444 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
445 return result;
446 }
447 result = data.writeBool(enable);
448 if (result != NO_ERROR) {
449 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
450 return result;
451 }
452 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
453 data, &reply, TF_ONE_WAY);
454 if (result != NO_ERROR) {
455 ALOGE("enableVSyncInjections failed to transact: %d", result);
456 return result;
457 }
458 return result;
459 }
460
461 virtual status_t injectVSync(nsecs_t when) {
462 Parcel data, reply;
463 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
464 if (result != NO_ERROR) {
465 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
466 return result;
467 }
468 result = data.writeInt64(when);
469 if (result != NO_ERROR) {
470 ALOGE("injectVSync failed to writeInt64: %d", result);
471 return result;
472 }
473 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
474 if (result != NO_ERROR) {
475 ALOGE("injectVSync failed to transact: %d", result);
476 return result;
477 }
478 return result;
479 }
480
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800481};
482
Dan Stozad723bd72014-11-18 10:24:03 -0800483// Out-of-line virtual method definition to trigger vtable emission in this
484// translation unit (see clang warning -Wweak-vtables)
485BpSurfaceComposer::~BpSurfaceComposer() {}
486
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
488
489// ----------------------------------------------------------------------
490
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491status_t BnSurfaceComposer::onTransact(
492 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
493{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800494 switch(code) {
495 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700496 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800497 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800498 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700499 return NO_ERROR;
500 }
Robert Carr1db73f62016-12-21 12:58:51 -0800501 case CREATE_SCOPED_CONNECTION: {
502 CHECK_INTERFACE(ISurfaceComposer, data, reply);
503 sp<IGraphicBufferProducer> bufferProducer =
504 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
505 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
506 reply->writeStrongBinder(b);
507 return NO_ERROR;
508 }
Jamie Gennis9a78c902011-01-12 18:30:40 -0800509 case CREATE_GRAPHIC_BUFFER_ALLOC: {
510 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800511 sp<IBinder> b = IInterface::asBinder(createGraphicBufferAlloc());
Jamie Gennis9a78c902011-01-12 18:30:40 -0800512 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700513 return NO_ERROR;
514 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700515 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700516 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800517
518 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700519 if (count > data.dataSize()) {
520 return BAD_VALUE;
521 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700522 ComposerState s;
523 Vector<ComposerState> state;
524 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800525 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700526 if (s.read(data) == BAD_VALUE) {
527 return BAD_VALUE;
528 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700529 state.add(s);
530 }
Dan Stozad723bd72014-11-18 10:24:03 -0800531
532 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700533 if (count > data.dataSize()) {
534 return BAD_VALUE;
535 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700536 DisplayState d;
537 Vector<DisplayState> displays;
538 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800539 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700540 if (d.read(data) == BAD_VALUE) {
541 return BAD_VALUE;
542 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700543 displays.add(d);
544 }
Dan Stozad723bd72014-11-18 10:24:03 -0800545
546 uint32_t stateFlags = data.readUint32();
547 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700548 return NO_ERROR;
549 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800550 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700551 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800552 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700553 return NO_ERROR;
554 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800555 case CAPTURE_SCREEN: {
556 CHECK_INTERFACE(ISurfaceComposer, data, reply);
557 sp<IBinder> display = data.readStrongBinder();
558 sp<IGraphicBufferProducer> producer =
559 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700560 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700561 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800562 uint32_t reqWidth = data.readUint32();
563 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800564 int32_t minLayerZ = data.readInt32();
565 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800566 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800567 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800568
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800569 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700570 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700571 useIdentityTransform,
572 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800573 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700574 return NO_ERROR;
575 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800576 case AUTHENTICATE_SURFACE: {
577 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800578 sp<IGraphicBufferProducer> bufferProducer =
579 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
580 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800581 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700582 return NO_ERROR;
583 }
Brian Anderson069b3652016-07-22 10:32:47 -0700584 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
585 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Brian Anderson3890c392016-07-25 12:48:08 -0700586 std::vector<FrameEvent> supportedTimestamps;
Brian Anderson069b3652016-07-22 10:32:47 -0700587 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
588 status_t err = reply->writeInt32(result);
589 if (err != NO_ERROR) {
590 return err;
591 }
592 if (result != NO_ERROR) {
593 return result;
594 }
595
596 std::vector<int32_t> supported;
597 supported.reserve(supportedTimestamps.size());
Brian Anderson3890c392016-07-25 12:48:08 -0700598 for (FrameEvent s : supportedTimestamps) {
Brian Anderson069b3652016-07-22 10:32:47 -0700599 supported.push_back(static_cast<int32_t>(s));
600 }
601 return reply->writeInt32Vector(supported);
602 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800603 case CREATE_DISPLAY_EVENT_CONNECTION: {
604 CHECK_INTERFACE(ISurfaceComposer, data, reply);
605 sp<IDisplayEventConnection> connection(createDisplayEventConnection());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800606 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800607 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700608 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700609 case CREATE_DISPLAY: {
610 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700611 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700612 bool secure = bool(data.readInt32());
613 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700614 reply->writeStrongBinder(display);
615 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700616 }
617 case DESTROY_DISPLAY: {
618 CHECK_INTERFACE(ISurfaceComposer, data, reply);
619 sp<IBinder> display = data.readStrongBinder();
620 destroyDisplay(display);
621 return NO_ERROR;
622 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700623 case GET_BUILT_IN_DISPLAY: {
624 CHECK_INTERFACE(ISurfaceComposer, data, reply);
625 int32_t id = data.readInt32();
626 sp<IBinder> display(getBuiltInDisplay(id));
627 reply->writeStrongBinder(display);
628 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700629 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700630 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700631 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700632 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700633 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700634 status_t result = getDisplayConfigs(display, &configs);
635 reply->writeInt32(result);
636 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800637 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700638 for (size_t c = 0; c < configs.size(); ++c) {
639 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
640 &configs[c], sizeof(DisplayInfo));
641 }
642 }
643 return NO_ERROR;
644 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700645 case GET_DISPLAY_STATS: {
646 CHECK_INTERFACE(ISurfaceComposer, data, reply);
647 DisplayStatInfo stats;
648 sp<IBinder> display = data.readStrongBinder();
649 status_t result = getDisplayStats(display, &stats);
650 reply->writeInt32(result);
651 if (result == NO_ERROR) {
652 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
653 &stats, sizeof(DisplayStatInfo));
654 }
655 return NO_ERROR;
656 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700657 case GET_ACTIVE_CONFIG: {
658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
659 sp<IBinder> display = data.readStrongBinder();
660 int id = getActiveConfig(display);
661 reply->writeInt32(id);
662 return NO_ERROR;
663 }
664 case SET_ACTIVE_CONFIG: {
665 CHECK_INTERFACE(ISurfaceComposer, data, reply);
666 sp<IBinder> display = data.readStrongBinder();
667 int id = data.readInt32();
668 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700669 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700670 return NO_ERROR;
671 }
Michael Wright28f24d02016-07-12 13:30:53 -0700672 case GET_DISPLAY_COLOR_MODES: {
673 CHECK_INTERFACE(ISurfaceComposer, data, reply);
674 Vector<android_color_mode_t> colorModes;
675 sp<IBinder> display = nullptr;
676 status_t result = data.readStrongBinder(&display);
677 if (result != NO_ERROR) {
678 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
679 return result;
680 }
681 result = getDisplayColorModes(display, &colorModes);
682 reply->writeInt32(result);
683 if (result == NO_ERROR) {
684 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
685 for (size_t i = 0; i < colorModes.size(); ++i) {
686 reply->writeInt32(colorModes[i]);
687 }
688 }
689 return NO_ERROR;
690 }
691 case GET_ACTIVE_COLOR_MODE: {
692 CHECK_INTERFACE(ISurfaceComposer, data, reply);
693 sp<IBinder> display = nullptr;
694 status_t result = data.readStrongBinder(&display);
695 if (result != NO_ERROR) {
696 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
697 return result;
698 }
699 android_color_mode_t colorMode = getActiveColorMode(display);
700 result = reply->writeInt32(static_cast<int32_t>(colorMode));
701 return result;
702 }
703 case SET_ACTIVE_COLOR_MODE: {
704 CHECK_INTERFACE(ISurfaceComposer, data, reply);
705 sp<IBinder> display = nullptr;
706 status_t result = data.readStrongBinder(&display);
707 if (result != NO_ERROR) {
708 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
709 return result;
710 }
711 int32_t colorModeInt = 0;
712 result = data.readInt32(&colorModeInt);
713 if (result != NO_ERROR) {
714 ALOGE("setActiveColorMode failed to readInt32: %d", result);
715 return result;
716 }
717 result = setActiveColorMode(display,
718 static_cast<android_color_mode_t>(colorModeInt));
719 result = reply->writeInt32(result);
720 return result;
721 }
Svetoslavd85084b2014-03-20 10:28:31 -0700722 case CLEAR_ANIMATION_FRAME_STATS: {
723 CHECK_INTERFACE(ISurfaceComposer, data, reply);
724 status_t result = clearAnimationFrameStats();
725 reply->writeInt32(result);
726 return NO_ERROR;
727 }
728 case GET_ANIMATION_FRAME_STATS: {
729 CHECK_INTERFACE(ISurfaceComposer, data, reply);
730 FrameStats stats;
731 status_t result = getAnimationFrameStats(&stats);
732 reply->write(stats);
733 reply->writeInt32(result);
734 return NO_ERROR;
735 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700736 case SET_POWER_MODE: {
737 CHECK_INTERFACE(ISurfaceComposer, data, reply);
738 sp<IBinder> display = data.readStrongBinder();
739 int32_t mode = data.readInt32();
740 setPowerMode(display, mode);
741 return NO_ERROR;
742 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700743 case GET_HDR_CAPABILITIES: {
744 CHECK_INTERFACE(ISurfaceComposer, data, reply);
745 sp<IBinder> display = nullptr;
746 status_t result = data.readStrongBinder(&display);
747 if (result != NO_ERROR) {
748 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
749 result);
750 return result;
751 }
752 HdrCapabilities capabilities;
753 result = getHdrCapabilities(display, &capabilities);
754 reply->writeInt32(result);
755 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800756 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700757 }
758 return NO_ERROR;
759 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700760 case ENABLE_VSYNC_INJECTIONS: {
761 CHECK_INTERFACE(ISurfaceComposer, data, reply);
762 bool enable = false;
763 status_t result = data.readBool(&enable);
764 if (result != NO_ERROR) {
765 ALOGE("enableVSyncInjections failed to readBool: %d", result);
766 return result;
767 }
768 return enableVSyncInjections(enable);
769 }
770 case INJECT_VSYNC: {
771 CHECK_INTERFACE(ISurfaceComposer, data, reply);
772 int64_t when = 0;
773 status_t result = data.readInt64(&when);
774 if (result != NO_ERROR) {
775 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
776 return result;
777 }
778 return injectVSync(when);
779 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700780 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700781 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700782 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800783 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800784}
785
786// ----------------------------------------------------------------------------
787
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800788};