blob: c21c5e3eb879f884c49837660578d07684a0d900 [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,
chaviw7206d492017-11-10 16:16:12 -0800127 const Rect& sourceCrop, float frameScale) {
chaviwa76b2712017-09-20 12:02:26 -0700128 Parcel data, reply;
129 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
130 data.writeStrongBinder(layerHandleBinder);
131 data.writeStrongBinder(IInterface::asBinder(producer));
chaviw7206d492017-11-10 16:16:12 -0800132 data.write(sourceCrop);
133 data.writeFloat(frameScale);
chaviwa76b2712017-09-20 12:02:26 -0700134 remote()->transact(BnSurfaceComposer::CAPTURE_LAYERS, data, &reply);
135 return reply.readInt32();
136 }
137
Jamie Gennis582270d2011-08-17 18:19:00 -0700138 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800139 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800140 {
141 Parcel data, reply;
142 int err = NO_ERROR;
143 err = data.writeInterfaceToken(
144 ISurfaceComposer::getInterfaceDescriptor());
145 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000146 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800147 "interface descriptor: %s (%d)", strerror(-err), -err);
148 return false;
149 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800150 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800151 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000152 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700153 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800154 return false;
155 }
156 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
157 &reply);
158 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000159 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700160 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800161 return false;
162 }
163 int32_t result = 0;
164 err = reply.readInt32(&result);
165 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000166 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700167 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800168 return false;
169 }
170 return result != 0;
171 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800172
Brian Anderson6b376712017-04-04 10:51:39 -0700173 virtual status_t getSupportedFrameTimestamps(
174 std::vector<FrameEvent>* outSupported) const {
175 if (!outSupported) {
176 return UNEXPECTED_NULL;
177 }
178 outSupported->clear();
179
180 Parcel data, reply;
181
182 status_t err = data.writeInterfaceToken(
183 ISurfaceComposer::getInterfaceDescriptor());
184 if (err != NO_ERROR) {
185 return err;
186 }
187
188 err = remote()->transact(
189 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
190 data, &reply);
191 if (err != NO_ERROR) {
192 return err;
193 }
194
195 int32_t result = 0;
196 err = reply.readInt32(&result);
197 if (err != NO_ERROR) {
198 return err;
199 }
200 if (result != NO_ERROR) {
201 return result;
202 }
203
204 std::vector<int32_t> supported;
205 err = reply.readInt32Vector(&supported);
206 if (err != NO_ERROR) {
207 return err;
208 }
209
210 outSupported->reserve(supported.size());
211 for (int32_t s : supported) {
212 outSupported->push_back(static_cast<FrameEvent>(s));
213 }
214 return NO_ERROR;
215 }
216
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700217 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800218 {
219 Parcel data, reply;
220 sp<IDisplayEventConnection> result;
221 int err = data.writeInterfaceToken(
222 ISurfaceComposer::getInterfaceDescriptor());
223 if (err != NO_ERROR) {
224 return result;
225 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700226 data.writeInt32(static_cast<int32_t>(vsyncSource));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800227 err = remote()->transact(
228 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
229 data, &reply);
230 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000231 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800232 "transaction: %s (%d)", strerror(-err), -err);
233 return result;
234 }
235 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
236 return result;
237 }
Colin Cross8e533062012-06-07 13:17:52 -0700238
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700239 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700240 {
241 Parcel data, reply;
242 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700243 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700244 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700245 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
246 return reply.readStrongBinder();
247 }
248
Jesse Hall6c913be2013-08-08 12:15:49 -0700249 virtual void destroyDisplay(const sp<IBinder>& display)
250 {
251 Parcel data, reply;
252 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
253 data.writeStrongBinder(display);
254 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
255 }
256
Mathias Agopiane57f2922012-08-09 16:29:12 -0700257 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
261 data.writeInt32(id);
262 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
263 return reply.readStrongBinder();
264 }
265
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700266 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700267 {
268 Parcel data, reply;
269 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700270 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700271 data.writeInt32(mode);
272 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700273 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700274
Dan Stoza7f7da322014-05-02 15:26:25 -0700275 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
276 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700277 {
278 Parcel data, reply;
279 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700280 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700281 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
282 status_t result = reply.readInt32();
283 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800284 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700285 configs->clear();
286 configs->resize(numConfigs);
287 for (size_t c = 0; c < numConfigs; ++c) {
288 memcpy(&(configs->editItemAt(c)),
289 reply.readInplace(sizeof(DisplayInfo)),
290 sizeof(DisplayInfo));
291 }
292 }
293 return result;
294 }
295
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700296 virtual status_t getDisplayStats(const sp<IBinder>& display,
297 DisplayStatInfo* stats)
298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
301 data.writeStrongBinder(display);
302 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
303 status_t result = reply.readInt32();
304 if (result == NO_ERROR) {
305 memcpy(stats,
306 reply.readInplace(sizeof(DisplayStatInfo)),
307 sizeof(DisplayStatInfo));
308 }
309 return result;
310 }
311
Dan Stoza7f7da322014-05-02 15:26:25 -0700312 virtual int getActiveConfig(const sp<IBinder>& display)
313 {
314 Parcel data, reply;
315 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
316 data.writeStrongBinder(display);
317 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
318 return reply.readInt32();
319 }
320
321 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
322 {
323 Parcel data, reply;
324 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
325 data.writeStrongBinder(display);
326 data.writeInt32(id);
327 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700328 return reply.readInt32();
329 }
Svetoslavd85084b2014-03-20 10:28:31 -0700330
Michael Wright28f24d02016-07-12 13:30:53 -0700331 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
332 Vector<android_color_mode_t>* outColorModes) {
333 Parcel data, reply;
334 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
335 if (result != NO_ERROR) {
336 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
337 return result;
338 }
339 result = data.writeStrongBinder(display);
340 if (result != NO_ERROR) {
341 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
342 return result;
343 }
344 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
345 if (result != NO_ERROR) {
346 ALOGE("getDisplayColorModes failed to transact: %d", result);
347 return result;
348 }
349 result = static_cast<status_t>(reply.readInt32());
350 if (result == NO_ERROR) {
351 size_t numModes = reply.readUint32();
352 outColorModes->clear();
353 outColorModes->resize(numModes);
354 for (size_t i = 0; i < numModes; ++i) {
355 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
356 }
357 }
358 return result;
359 }
360
361 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
362 Parcel data, reply;
363 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
364 if (result != NO_ERROR) {
365 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
366 return static_cast<android_color_mode_t>(result);
367 }
368 result = data.writeStrongBinder(display);
369 if (result != NO_ERROR) {
370 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
371 return static_cast<android_color_mode_t>(result);
372 }
373 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
374 if (result != NO_ERROR) {
375 ALOGE("getActiveColorMode failed to transact: %d", result);
376 return static_cast<android_color_mode_t>(result);
377 }
378 return static_cast<android_color_mode_t>(reply.readInt32());
379 }
380
381 virtual status_t setActiveColorMode(const sp<IBinder>& display,
382 android_color_mode_t colorMode) {
383 Parcel data, reply;
384 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
385 if (result != NO_ERROR) {
386 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
387 return result;
388 }
389 result = data.writeStrongBinder(display);
390 if (result != NO_ERROR) {
391 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
392 return result;
393 }
394 result = data.writeInt32(colorMode);
395 if (result != NO_ERROR) {
396 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
397 return result;
398 }
399 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
400 if (result != NO_ERROR) {
401 ALOGE("setActiveColorMode failed to transact: %d", result);
402 return result;
403 }
404 return static_cast<status_t>(reply.readInt32());
405 }
406
Svetoslavd85084b2014-03-20 10:28:31 -0700407 virtual status_t clearAnimationFrameStats() {
408 Parcel data, reply;
409 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
410 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
411 return reply.readInt32();
412 }
413
414 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
415 Parcel data, reply;
416 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
417 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
418 reply.read(*outStats);
419 return reply.readInt32();
420 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700421
422 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
423 HdrCapabilities* outCapabilities) const {
424 Parcel data, reply;
425 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
426 status_t result = data.writeStrongBinder(display);
427 if (result != NO_ERROR) {
428 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
429 return result;
430 }
431 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
432 data, &reply);
433 if (result != NO_ERROR) {
434 ALOGE("getHdrCapabilities failed to transact: %d", result);
435 return result;
436 }
437 result = reply.readInt32();
438 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800439 result = reply.read(*outCapabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700440 }
441 return result;
442 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700443
444 virtual status_t enableVSyncInjections(bool enable) {
445 Parcel data, reply;
446 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
447 if (result != NO_ERROR) {
448 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
449 return result;
450 }
451 result = data.writeBool(enable);
452 if (result != NO_ERROR) {
453 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
454 return result;
455 }
456 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
457 data, &reply, TF_ONE_WAY);
458 if (result != NO_ERROR) {
459 ALOGE("enableVSyncInjections failed to transact: %d", result);
460 return result;
461 }
462 return result;
463 }
464
465 virtual status_t injectVSync(nsecs_t when) {
466 Parcel data, reply;
467 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
468 if (result != NO_ERROR) {
469 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
470 return result;
471 }
472 result = data.writeInt64(when);
473 if (result != NO_ERROR) {
474 ALOGE("injectVSync failed to writeInt64: %d", result);
475 return result;
476 }
477 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
478 if (result != NO_ERROR) {
479 ALOGE("injectVSync failed to transact: %d", result);
480 return result;
481 }
482 return result;
483 }
484
Kalle Raitaa099a242017-01-11 11:17:29 -0800485 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const
486 {
487 if (!outLayers) {
488 return UNEXPECTED_NULL;
489 }
490
491 Parcel data, reply;
492
493 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
494 if (err != NO_ERROR) {
495 return err;
496 }
497
498 err = remote()->transact(BnSurfaceComposer::GET_LAYER_DEBUG_INFO, data, &reply);
499 if (err != NO_ERROR) {
500 return err;
501 }
502
503 int32_t result = 0;
504 err = reply.readInt32(&result);
505 if (err != NO_ERROR) {
506 return err;
507 }
508 if (result != NO_ERROR) {
509 return result;
510 }
511
512 outLayers->clear();
513 return reply.readParcelableVector(outLayers);
514 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515};
516
Dan Stozad723bd72014-11-18 10:24:03 -0800517// Out-of-line virtual method definition to trigger vtable emission in this
518// translation unit (see clang warning -Wweak-vtables)
519BpSurfaceComposer::~BpSurfaceComposer() {}
520
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800521IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
522
523// ----------------------------------------------------------------------
524
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525status_t BnSurfaceComposer::onTransact(
526 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
527{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800528 switch(code) {
529 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700530 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800531 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800532 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700533 return NO_ERROR;
534 }
Robert Carr1db73f62016-12-21 12:58:51 -0800535 case CREATE_SCOPED_CONNECTION: {
536 CHECK_INTERFACE(ISurfaceComposer, data, reply);
537 sp<IGraphicBufferProducer> bufferProducer =
538 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
539 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
540 reply->writeStrongBinder(b);
541 return NO_ERROR;
542 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700543 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700544 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800545
546 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700547 if (count > data.dataSize()) {
548 return BAD_VALUE;
549 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700550 ComposerState s;
551 Vector<ComposerState> state;
552 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800553 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700554 if (s.read(data) == BAD_VALUE) {
555 return BAD_VALUE;
556 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700557 state.add(s);
558 }
Dan Stozad723bd72014-11-18 10:24:03 -0800559
560 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700561 if (count > data.dataSize()) {
562 return BAD_VALUE;
563 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700564 DisplayState d;
565 Vector<DisplayState> displays;
566 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800567 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700568 if (d.read(data) == BAD_VALUE) {
569 return BAD_VALUE;
570 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700571 displays.add(d);
572 }
Dan Stozad723bd72014-11-18 10:24:03 -0800573
574 uint32_t stateFlags = data.readUint32();
575 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700576 return NO_ERROR;
577 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800578 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700579 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800580 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700581 return NO_ERROR;
582 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800583 case CAPTURE_SCREEN: {
584 CHECK_INTERFACE(ISurfaceComposer, data, reply);
585 sp<IBinder> display = data.readStrongBinder();
586 sp<IGraphicBufferProducer> producer =
587 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700588 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700589 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800590 uint32_t reqWidth = data.readUint32();
591 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800592 int32_t minLayerZ = data.readInt32();
593 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800594 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800595 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800596
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800597 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700598 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700599 useIdentityTransform,
600 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800601 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700602 return NO_ERROR;
603 }
chaviwa76b2712017-09-20 12:02:26 -0700604 case CAPTURE_LAYERS: {
605 CHECK_INTERFACE(ISurfaceComposer, data, reply);
606 sp<IBinder> layerHandleBinder = data.readStrongBinder();
607 sp<IGraphicBufferProducer> producer =
608 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
chaviw7206d492017-11-10 16:16:12 -0800609 Rect sourceCrop(Rect::EMPTY_RECT);
610 data.read(sourceCrop);
611 float frameScale = data.readFloat();
chaviwa76b2712017-09-20 12:02:26 -0700612
chaviw7206d492017-11-10 16:16:12 -0800613 status_t res = captureLayers(layerHandleBinder, producer, sourceCrop, frameScale);
chaviwa76b2712017-09-20 12:02:26 -0700614 reply->writeInt32(res);
615 return NO_ERROR;
616 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800617 case AUTHENTICATE_SURFACE: {
618 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800619 sp<IGraphicBufferProducer> bufferProducer =
620 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
621 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800622 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700623 return NO_ERROR;
624 }
Brian Anderson6b376712017-04-04 10:51:39 -0700625 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
626 CHECK_INTERFACE(ISurfaceComposer, data, reply);
627 std::vector<FrameEvent> supportedTimestamps;
628 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
629 status_t err = reply->writeInt32(result);
630 if (err != NO_ERROR) {
631 return err;
632 }
633 if (result != NO_ERROR) {
634 return result;
635 }
636
637 std::vector<int32_t> supported;
638 supported.reserve(supportedTimestamps.size());
639 for (FrameEvent s : supportedTimestamps) {
640 supported.push_back(static_cast<int32_t>(s));
641 }
642 return reply->writeInt32Vector(supported);
643 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800644 case CREATE_DISPLAY_EVENT_CONNECTION: {
645 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700646 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
647 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800648 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800649 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700650 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700651 case CREATE_DISPLAY: {
652 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700653 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700654 bool secure = bool(data.readInt32());
655 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700656 reply->writeStrongBinder(display);
657 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700658 }
659 case DESTROY_DISPLAY: {
660 CHECK_INTERFACE(ISurfaceComposer, data, reply);
661 sp<IBinder> display = data.readStrongBinder();
662 destroyDisplay(display);
663 return NO_ERROR;
664 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700665 case GET_BUILT_IN_DISPLAY: {
666 CHECK_INTERFACE(ISurfaceComposer, data, reply);
667 int32_t id = data.readInt32();
668 sp<IBinder> display(getBuiltInDisplay(id));
669 reply->writeStrongBinder(display);
670 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700671 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700672 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700673 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700674 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700675 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700676 status_t result = getDisplayConfigs(display, &configs);
677 reply->writeInt32(result);
678 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800679 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700680 for (size_t c = 0; c < configs.size(); ++c) {
681 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
682 &configs[c], sizeof(DisplayInfo));
683 }
684 }
685 return NO_ERROR;
686 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700687 case GET_DISPLAY_STATS: {
688 CHECK_INTERFACE(ISurfaceComposer, data, reply);
689 DisplayStatInfo stats;
690 sp<IBinder> display = data.readStrongBinder();
691 status_t result = getDisplayStats(display, &stats);
692 reply->writeInt32(result);
693 if (result == NO_ERROR) {
694 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
695 &stats, sizeof(DisplayStatInfo));
696 }
697 return NO_ERROR;
698 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700699 case GET_ACTIVE_CONFIG: {
700 CHECK_INTERFACE(ISurfaceComposer, data, reply);
701 sp<IBinder> display = data.readStrongBinder();
702 int id = getActiveConfig(display);
703 reply->writeInt32(id);
704 return NO_ERROR;
705 }
706 case SET_ACTIVE_CONFIG: {
707 CHECK_INTERFACE(ISurfaceComposer, data, reply);
708 sp<IBinder> display = data.readStrongBinder();
709 int id = data.readInt32();
710 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700711 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700712 return NO_ERROR;
713 }
Michael Wright28f24d02016-07-12 13:30:53 -0700714 case GET_DISPLAY_COLOR_MODES: {
715 CHECK_INTERFACE(ISurfaceComposer, data, reply);
716 Vector<android_color_mode_t> colorModes;
717 sp<IBinder> display = nullptr;
718 status_t result = data.readStrongBinder(&display);
719 if (result != NO_ERROR) {
720 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
721 return result;
722 }
723 result = getDisplayColorModes(display, &colorModes);
724 reply->writeInt32(result);
725 if (result == NO_ERROR) {
726 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
727 for (size_t i = 0; i < colorModes.size(); ++i) {
728 reply->writeInt32(colorModes[i]);
729 }
730 }
731 return NO_ERROR;
732 }
733 case GET_ACTIVE_COLOR_MODE: {
734 CHECK_INTERFACE(ISurfaceComposer, data, reply);
735 sp<IBinder> display = nullptr;
736 status_t result = data.readStrongBinder(&display);
737 if (result != NO_ERROR) {
738 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
739 return result;
740 }
741 android_color_mode_t colorMode = getActiveColorMode(display);
742 result = reply->writeInt32(static_cast<int32_t>(colorMode));
743 return result;
744 }
745 case SET_ACTIVE_COLOR_MODE: {
746 CHECK_INTERFACE(ISurfaceComposer, data, reply);
747 sp<IBinder> display = nullptr;
748 status_t result = data.readStrongBinder(&display);
749 if (result != NO_ERROR) {
750 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
751 return result;
752 }
753 int32_t colorModeInt = 0;
754 result = data.readInt32(&colorModeInt);
755 if (result != NO_ERROR) {
756 ALOGE("setActiveColorMode failed to readInt32: %d", result);
757 return result;
758 }
759 result = setActiveColorMode(display,
760 static_cast<android_color_mode_t>(colorModeInt));
761 result = reply->writeInt32(result);
762 return result;
763 }
Svetoslavd85084b2014-03-20 10:28:31 -0700764 case CLEAR_ANIMATION_FRAME_STATS: {
765 CHECK_INTERFACE(ISurfaceComposer, data, reply);
766 status_t result = clearAnimationFrameStats();
767 reply->writeInt32(result);
768 return NO_ERROR;
769 }
770 case GET_ANIMATION_FRAME_STATS: {
771 CHECK_INTERFACE(ISurfaceComposer, data, reply);
772 FrameStats stats;
773 status_t result = getAnimationFrameStats(&stats);
774 reply->write(stats);
775 reply->writeInt32(result);
776 return NO_ERROR;
777 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700778 case SET_POWER_MODE: {
779 CHECK_INTERFACE(ISurfaceComposer, data, reply);
780 sp<IBinder> display = data.readStrongBinder();
781 int32_t mode = data.readInt32();
782 setPowerMode(display, mode);
783 return NO_ERROR;
784 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700785 case GET_HDR_CAPABILITIES: {
786 CHECK_INTERFACE(ISurfaceComposer, data, reply);
787 sp<IBinder> display = nullptr;
788 status_t result = data.readStrongBinder(&display);
789 if (result != NO_ERROR) {
790 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
791 result);
792 return result;
793 }
794 HdrCapabilities capabilities;
795 result = getHdrCapabilities(display, &capabilities);
796 reply->writeInt32(result);
797 if (result == NO_ERROR) {
Mathias Agopiane1f5e6f2017-02-06 16:34:41 -0800798 reply->write(capabilities);
Dan Stozac4f471e2016-03-24 09:31:08 -0700799 }
800 return NO_ERROR;
801 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700802 case ENABLE_VSYNC_INJECTIONS: {
803 CHECK_INTERFACE(ISurfaceComposer, data, reply);
804 bool enable = false;
805 status_t result = data.readBool(&enable);
806 if (result != NO_ERROR) {
807 ALOGE("enableVSyncInjections failed to readBool: %d", result);
808 return result;
809 }
810 return enableVSyncInjections(enable);
811 }
812 case INJECT_VSYNC: {
813 CHECK_INTERFACE(ISurfaceComposer, data, reply);
814 int64_t when = 0;
815 status_t result = data.readInt64(&when);
816 if (result != NO_ERROR) {
817 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
818 return result;
819 }
820 return injectVSync(when);
821 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800822 case GET_LAYER_DEBUG_INFO: {
823 CHECK_INTERFACE(ISurfaceComposer, data, reply);
824 std::vector<LayerDebugInfo> outLayers;
825 status_t result = getLayerDebugInfo(&outLayers);
826 reply->writeInt32(result);
827 if (result == NO_ERROR)
828 {
829 result = reply->writeParcelableVector(outLayers);
830 }
831 return result;
832 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700833 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700834 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700835 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800836 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800837}
838
839// ----------------------------------------------------------------------------
840
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800841};