blob: 973302c2265249aa25e071f4d7309749b7a4f2b3 [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
chaviwa76b2712017-09-20 12:02:26 -0700125 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder,
126 const sp<IGraphicBufferProducer>& producer,
127 ISurfaceComposer::Rotation rotation) {
128 Parcel data, reply;
129 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
130 data.writeStrongBinder(layerHandleBinder);
131 data.writeStrongBinder(IInterface::asBinder(producer));
132 data.writeInt32(static_cast<int32_t>(rotation));
133 remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
134 return reply.readInt32();
135 }
136
Jamie Gennis582270d2011-08-17 18:19:00 -0700137 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800138 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800139 {
140 Parcel data, reply;
141 int err = NO_ERROR;
142 err = data.writeInterfaceToken(
143 ISurfaceComposer::getInterfaceDescriptor());
144 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000145 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800146 "interface descriptor: %s (%d)", strerror(-err), -err);
147 return false;
148 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800149 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800150 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000151 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700152 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800153 return false;
154 }
155 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
156 &reply);
157 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000158 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700159 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800160 return false;
161 }
162 int32_t result = 0;
163 err = reply.readInt32(&result);
164 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000165 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700166 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800167 return false;
168 }
169 return result != 0;
170 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800171
Brian Anderson6b376712017-04-04 10:51:39 -0700172 virtual status_t getSupportedFrameTimestamps(
173 std::vector<FrameEvent>* outSupported) const {
174 if (!outSupported) {
175 return UNEXPECTED_NULL;
176 }
177 outSupported->clear();
178
179 Parcel data, reply;
180
181 status_t err = data.writeInterfaceToken(
182 ISurfaceComposer::getInterfaceDescriptor());
183 if (err != NO_ERROR) {
184 return err;
185 }
186
187 err = remote()->transact(
188 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
189 data, &reply);
190 if (err != NO_ERROR) {
191 return err;
192 }
193
194 int32_t result = 0;
195 err = reply.readInt32(&result);
196 if (err != NO_ERROR) {
197 return err;
198 }
199 if (result != NO_ERROR) {
200 return result;
201 }
202
203 std::vector<int32_t> supported;
204 err = reply.readInt32Vector(&supported);
205 if (err != NO_ERROR) {
206 return err;
207 }
208
209 outSupported->reserve(supported.size());
210 for (int32_t s : supported) {
211 outSupported->push_back(static_cast<FrameEvent>(s));
212 }
213 return NO_ERROR;
214 }
215
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700216 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800217 {
218 Parcel data, reply;
219 sp<IDisplayEventConnection> result;
220 int err = data.writeInterfaceToken(
221 ISurfaceComposer::getInterfaceDescriptor());
222 if (err != NO_ERROR) {
223 return result;
224 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700225 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800226 err = remote()->transact(
227 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
228 data, &reply);
229 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000230 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800231 "transaction: %s (%d)", strerror(-err), -err);
232 return result;
233 }
234 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
235 return result;
236 }
Colin Cross8e533062012-06-07 13:17:52 -0700237
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700238 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700239 {
240 Parcel data, reply;
241 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700242 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700243 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700244 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
245 return reply.readStrongBinder();
246 }
247
Jesse Hall6c913be2013-08-08 12:15:49 -0700248 virtual void destroyDisplay(const sp<IBinder>& display)
249 {
250 Parcel data, reply;
251 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
252 data.writeStrongBinder(display);
253 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
254 }
255
Mathias Agopiane57f2922012-08-09 16:29:12 -0700256 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
257 {
258 Parcel data, reply;
259 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
260 data.writeInt32(id);
261 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
262 return reply.readStrongBinder();
263 }
264
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700265 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700266 {
267 Parcel data, reply;
268 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700269 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700270 data.writeInt32(mode);
271 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700272 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700273
Dan Stoza7f7da322014-05-02 15:26:25 -0700274 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
275 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700279 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700280 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
281 status_t result = reply.readInt32();
282 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800283 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700284 configs->clear();
285 configs->resize(numConfigs);
286 for (size_t c = 0; c < numConfigs; ++c) {
287 memcpy(&(configs->editItemAt(c)),
288 reply.readInplace(sizeof(DisplayInfo)),
289 sizeof(DisplayInfo));
290 }
291 }
292 return result;
293 }
294
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700295 virtual status_t getDisplayStats(const sp<IBinder>& display,
296 DisplayStatInfo* stats)
297 {
298 Parcel data, reply;
299 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
300 data.writeStrongBinder(display);
301 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
302 status_t result = reply.readInt32();
303 if (result == NO_ERROR) {
304 memcpy(stats,
305 reply.readInplace(sizeof(DisplayStatInfo)),
306 sizeof(DisplayStatInfo));
307 }
308 return result;
309 }
310
Dan Stoza7f7da322014-05-02 15:26:25 -0700311 virtual int getActiveConfig(const sp<IBinder>& display)
312 {
313 Parcel data, reply;
314 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
315 data.writeStrongBinder(display);
316 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
317 return reply.readInt32();
318 }
319
320 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
324 data.writeStrongBinder(display);
325 data.writeInt32(id);
326 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700327 return reply.readInt32();
328 }
Svetoslavd85084b2014-03-20 10:28:31 -0700329
Michael Wright28f24d02016-07-12 13:30:53 -0700330 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
331 Vector<android_color_mode_t>* outColorModes) {
332 Parcel data, reply;
333 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
334 if (result != NO_ERROR) {
335 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
336 return result;
337 }
338 result = data.writeStrongBinder(display);
339 if (result != NO_ERROR) {
340 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
341 return result;
342 }
343 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
344 if (result != NO_ERROR) {
345 ALOGE("getDisplayColorModes failed to transact: %d", result);
346 return result;
347 }
348 result = static_cast<status_t>(reply.readInt32());
349 if (result == NO_ERROR) {
350 size_t numModes = reply.readUint32();
351 outColorModes->clear();
352 outColorModes->resize(numModes);
353 for (size_t i = 0; i < numModes; ++i) {
354 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
355 }
356 }
357 return result;
358 }
359
360 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
361 Parcel data, reply;
362 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
363 if (result != NO_ERROR) {
364 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
365 return static_cast<android_color_mode_t>(result);
366 }
367 result = data.writeStrongBinder(display);
368 if (result != NO_ERROR) {
369 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
370 return static_cast<android_color_mode_t>(result);
371 }
372 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
373 if (result != NO_ERROR) {
374 ALOGE("getActiveColorMode failed to transact: %d", result);
375 return static_cast<android_color_mode_t>(result);
376 }
377 return static_cast<android_color_mode_t>(reply.readInt32());
378 }
379
380 virtual status_t setActiveColorMode(const sp<IBinder>& display,
381 android_color_mode_t colorMode) {
382 Parcel data, reply;
383 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
384 if (result != NO_ERROR) {
385 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
386 return result;
387 }
388 result = data.writeStrongBinder(display);
389 if (result != NO_ERROR) {
390 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
391 return result;
392 }
393 result = data.writeInt32(colorMode);
394 if (result != NO_ERROR) {
395 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
396 return result;
397 }
398 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
399 if (result != NO_ERROR) {
400 ALOGE("setActiveColorMode failed to transact: %d", result);
401 return result;
402 }
403 return static_cast<status_t>(reply.readInt32());
404 }
405
Svetoslavd85084b2014-03-20 10:28:31 -0700406 virtual status_t clearAnimationFrameStats() {
407 Parcel data, reply;
408 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
409 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
410 return reply.readInt32();
411 }
412
413 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
414 Parcel data, reply;
415 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
416 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
417 reply.read(*outStats);
418 return reply.readInt32();
419 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700420
421 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
422 HdrCapabilities* outCapabilities) const {
423 Parcel data, reply;
424 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
425 status_t result = data.writeStrongBinder(display);
426 if (result != NO_ERROR) {
427 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
428 return result;
429 }
430 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
431 data, &reply);
432 if (result != NO_ERROR) {
433 ALOGE("getHdrCapabilities failed to transact: %d", result);
434 return result;
435 }
436 result = reply.readInt32();
437 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800438 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700439 }
440 return result;
441 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700442
443 virtual status_t enableVSyncInjections(bool enable) {
444 Parcel data, reply;
445 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
446 if (result != NO_ERROR) {
447 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
448 return result;
449 }
450 result = data.writeBool(enable);
451 if (result != NO_ERROR) {
452 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
453 return result;
454 }
455 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
456 data, &reply, TF_ONE_WAY);
457 if (result != NO_ERROR) {
458 ALOGE("enableVSyncInjections failed to transact: %d", result);
459 return result;
460 }
461 return result;
462 }
463
464 virtual status_t injectVSync(nsecs_t when) {
465 Parcel data, reply;
466 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
467 if (result != NO_ERROR) {
468 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
469 return result;
470 }
471 result = data.writeInt64(when);
472 if (result != NO_ERROR) {
473 ALOGE("injectVSync failed to writeInt64: %d", result);
474 return result;
475 }
476 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
477 if (result != NO_ERROR) {
478 ALOGE("injectVSync failed to transact: %d", result);
479 return result;
480 }
481 return result;
482 }
483
Kalle Raitaa099a242017-01-11 11:17:29 -0800484 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
485 {
486 if (!outLayers) {
487 return UNEXPECTED_NULL;
488 }
489
490 Parcel data, reply;
491
492 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
493 if (err != NO_ERROR) {
494 return err;
495 }
496
497 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
498 if (err != NO_ERROR) {
499 return err;
500 }
501
502 int32_t result = 0;
503 err = reply.readInt32(&result);
504 if (err != NO_ERROR) {
505 return err;
506 }
507 if (result != NO_ERROR) {
508 return result;
509 }
510
511 outLayers->clear();
512 return reply.readParcelableVector(outLayers);
513 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514};
515
Dan Stozad723bd72014-11-18 10:24:03 -0800516// Out-of-line virtual method definition to trigger vtable emission in this
517// translation unit (see clang warning -Wweak-vtables)
518BpSurfaceComposer::~BpSurfaceComposer() {}
519
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
521
522// ----------------------------------------------------------------------
523
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800524status_t BnSurfaceComposer::onTransact(
525 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
526{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800527 switch(code) {
528 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700529 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800530 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800531 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700532 return NO_ERROR;
533 }
Robert Carr1db73f62016-12-21 12:58:51 -0800534 case CREATE_SCOPED_CONNECTION: {
535 CHECK_INTERFACE(ISurfaceComposer, data, reply);
536 sp<IGraphicBufferProducer> bufferProducer =
537 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
538 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
539 reply->writeStrongBinder(b);
540 return NO_ERROR;
541 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700542 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700543 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800544
545 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700546 if (count > data.dataSize()) {
547 return BAD_VALUE;
548 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700549 ComposerState s;
550 Vector<ComposerState> state;
551 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800552 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700553 if (s.read(data) == BAD_VALUE) {
554 return BAD_VALUE;
555 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700556 state.add(s);
557 }
Dan Stozad723bd72014-11-18 10:24:03 -0800558
559 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700560 if (count > data.dataSize()) {
561 return BAD_VALUE;
562 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700563 DisplayState d;
564 Vector<DisplayState> displays;
565 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800566 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700567 if (d.read(data) == BAD_VALUE) {
568 return BAD_VALUE;
569 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700570 displays.add(d);
571 }
Dan Stozad723bd72014-11-18 10:24:03 -0800572
573 uint32_t stateFlags = data.readUint32();
574 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700575 return NO_ERROR;
576 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800577 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700578 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800579 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700580 return NO_ERROR;
581 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800582 case CAPTURE_SCREEN: {
583 CHECK_INTERFACE(ISurfaceComposer, data, reply);
584 sp<IBinder> display = data.readStrongBinder();
585 sp<IGraphicBufferProducer> producer =
586 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700587 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700588 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800589 uint32_t reqWidth = data.readUint32();
590 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800591 int32_t minLayerZ = data.readInt32();
592 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800593 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800594 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800595
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800596 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700597 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700598 useIdentityTransform,
599 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800600 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700601 return NO_ERROR;
602 }
chaviwa76b2712017-09-20 12:02:26 -0700603 case CAPTURE_LAYERS: {
604 CHECK_INTERFACE(ISurfaceComposer, data, reply);
605 sp<IBinder> layerHandleBinder = data.readStrongBinder();
606 sp<IGraphicBufferProducer> producer =
607 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
608 int32_t rotation = data.readInt32();
609
610 status_t res = captureLayers(layerHandleBinder, producer,
611 static_cast<ISurfaceComposer::Rotation>(rotation));
612 reply->writeInt32(res);
613 return NO_ERROR;
614 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800615 case AUTHENTICATE_SURFACE: {
616 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800617 sp<IGraphicBufferProducer> bufferProducer =
618 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
619 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800620 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700621 return NO_ERROR;
622 }
Brian Anderson6b376712017-04-04 10:51:39 -0700623 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
624 CHECK_INTERFACE(ISurfaceComposer, data, reply);
625 std::vector<FrameEvent> supportedTimestamps;
626 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
627 status_t err = reply->writeInt32(result);
628 if (err != NO_ERROR) {
629 return err;
630 }
631 if (result != NO_ERROR) {
632 return result;
633 }
634
635 std::vector<int32_t> supported;
636 supported.reserve(supportedTimestamps.size());
637 for (FrameEvent s : supportedTimestamps) {
638 supported.push_back(static_cast<int32_t>(s));
639 }
640 return reply->writeInt32Vector(supported);
641 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800642 case CREATE_DISPLAY_EVENT_CONNECTION: {
643 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700644 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
645 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800646 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800647 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700648 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700649 case CREATE_DISPLAY: {
650 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700651 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700652 bool secure = bool(data.readInt32());
653 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700654 reply->writeStrongBinder(display);
655 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700656 }
657 case DESTROY_DISPLAY: {
658 CHECK_INTERFACE(ISurfaceComposer, data, reply);
659 sp<IBinder> display = data.readStrongBinder();
660 destroyDisplay(display);
661 return NO_ERROR;
662 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700663 case GET_BUILT_IN_DISPLAY: {
664 CHECK_INTERFACE(ISurfaceComposer, data, reply);
665 int32_t id = data.readInt32();
666 sp<IBinder> display(getBuiltInDisplay(id));
667 reply->writeStrongBinder(display);
668 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700669 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700670 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700671 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700672 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700673 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700674 status_t result = getDisplayConfigs(display, &configs);
675 reply->writeInt32(result);
676 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800677 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700678 for (size_t c = 0; c < configs.size(); ++c) {
679 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
680 &configs[c], sizeof(DisplayInfo));
681 }
682 }
683 return NO_ERROR;
684 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700685 case GET_DISPLAY_STATS: {
686 CHECK_INTERFACE(ISurfaceComposer, data, reply);
687 DisplayStatInfo stats;
688 sp<IBinder> display = data.readStrongBinder();
689 status_t result = getDisplayStats(display, &stats);
690 reply->writeInt32(result);
691 if (result == NO_ERROR) {
692 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
693 &stats, sizeof(DisplayStatInfo));
694 }
695 return NO_ERROR;
696 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700697 case GET_ACTIVE_CONFIG: {
698 CHECK_INTERFACE(ISurfaceComposer, data, reply);
699 sp<IBinder> display = data.readStrongBinder();
700 int id = getActiveConfig(display);
701 reply->writeInt32(id);
702 return NO_ERROR;
703 }
704 case SET_ACTIVE_CONFIG: {
705 CHECK_INTERFACE(ISurfaceComposer, data, reply);
706 sp<IBinder> display = data.readStrongBinder();
707 int id = data.readInt32();
708 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700709 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700710 return NO_ERROR;
711 }
Michael Wright28f24d02016-07-12 13:30:53 -0700712 case GET_DISPLAY_COLOR_MODES: {
713 CHECK_INTERFACE(ISurfaceComposer, data, reply);
714 Vector<android_color_mode_t> colorModes;
715 sp<IBinder> display = nullptr;
716 status_t result = data.readStrongBinder(&display);
717 if (result != NO_ERROR) {
718 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
719 return result;
720 }
721 result = getDisplayColorModes(display, &colorModes);
722 reply->writeInt32(result);
723 if (result == NO_ERROR) {
724 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
725 for (size_t i = 0; i < colorModes.size(); ++i) {
726 reply->writeInt32(colorModes[i]);
727 }
728 }
729 return NO_ERROR;
730 }
731 case GET_ACTIVE_COLOR_MODE: {
732 CHECK_INTERFACE(ISurfaceComposer, data, reply);
733 sp<IBinder> display = nullptr;
734 status_t result = data.readStrongBinder(&display);
735 if (result != NO_ERROR) {
736 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
737 return result;
738 }
739 android_color_mode_t colorMode = getActiveColorMode(display);
740 result = reply->writeInt32(static_cast<int32_t>(colorMode));
741 return result;
742 }
743 case SET_ACTIVE_COLOR_MODE: {
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("getActiveColorMode failed to readStrongBinder: %d", result);
749 return result;
750 }
751 int32_t colorModeInt = 0;
752 result = data.readInt32(&colorModeInt);
753 if (result != NO_ERROR) {
754 ALOGE("setActiveColorMode failed to readInt32: %d", result);
755 return result;
756 }
757 result = setActiveColorMode(display,
758 static_cast<android_color_mode_t>(colorModeInt));
759 result = reply->writeInt32(result);
760 return result;
761 }
Svetoslavd85084b2014-03-20 10:28:31 -0700762 case CLEAR_ANIMATION_FRAME_STATS: {
763 CHECK_INTERFACE(ISurfaceComposer, data, reply);
764 status_t result = clearAnimationFrameStats();
765 reply->writeInt32(result);
766 return NO_ERROR;
767 }
768 case GET_ANIMATION_FRAME_STATS: {
769 CHECK_INTERFACE(ISurfaceComposer, data, reply);
770 FrameStats stats;
771 status_t result = getAnimationFrameStats(&stats);
772 reply->write(stats);
773 reply->writeInt32(result);
774 return NO_ERROR;
775 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700776 case SET_POWER_MODE: {
777 CHECK_INTERFACE(ISurfaceComposer, data, reply);
778 sp<IBinder> display = data.readStrongBinder();
779 int32_t mode = data.readInt32();
780 setPowerMode(display, mode);
781 return NO_ERROR;
782 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700783 case GET_HDR_CAPABILITIES: {
784 CHECK_INTERFACE(ISurfaceComposer, data, reply);
785 sp<IBinder> display = nullptr;
786 status_t result = data.readStrongBinder(&display);
787 if (result != NO_ERROR) {
788 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
789 result);
790 return result;
791 }
792 HdrCapabilities capabilities;
793 result = getHdrCapabilities(display, &capabilities);
794 reply->writeInt32(result);
795 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800796 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700797 }
798 return NO_ERROR;
799 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700800 case ENABLE_VSYNC_INJECTIONS: {
801 CHECK_INTERFACE(ISurfaceComposer, data, reply);
802 bool enable = false;
803 status_t result = data.readBool(&enable);
804 if (result != NO_ERROR) {
805 ALOGE("enableVSyncInjections failed to readBool: %d", result);
806 return result;
807 }
808 return enableVSyncInjections(enable);
809 }
810 case INJECT_VSYNC: {
811 CHECK_INTERFACE(ISurfaceComposer, data, reply);
812 int64_t when = 0;
813 status_t result = data.readInt64(&when);
814 if (result != NO_ERROR) {
815 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
816 return result;
817 }
818 return injectVSync(when);
819 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800820 case GET_LAYER_DEBUG_INFO: {
821 CHECK_INTERFACE(ISurfaceComposer, data, reply);
822 std::vector<LayerDebugInfo> outLayers;
823 status_t result = getLayerDebugInfo(&outLayers);
824 reply->writeInt32(result);
825 if (result == NO_ERROR)
826 {
827 result = reply->writeParcelableVector(outLayers);
828 }
829 return result;
830 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700831 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700832 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700833 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800834 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800835}
836
837// ----------------------------------------------------------------------------
838
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800839};