blob: 2a327da07d12532bcda1b56bae20256507460866 [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/BitTube.h>
29#include <gui/IDisplayEventConnection.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080030#include <gui/ISurfaceComposer.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080031#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080032
33#include <private/gui/LayerState.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034
Michael Wright28f24d02016-07-12 13:30:53 -070035#include <system/graphics.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/DisplayInfo.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070038#include <ui/DisplayStatInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070039#include <ui/HdrCapabilities.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Jamie Gennis134f0422011-03-08 12:18:54 -080041#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043// ---------------------------------------------------------------------------
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Mathias Agopiand0566bc2011-11-17 17:49:17 -080047class IDisplayEventConnection;
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
50{
51public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070052 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 : BpInterface<ISurfaceComposer>(impl)
54 {
55 }
56
Dan Stozad723bd72014-11-18 10:24:03 -080057 virtual ~BpSurfaceComposer();
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 }
66
Robert Carr1db73f62016-12-21 12:58:51 -080067 virtual sp<ISurfaceComposerClient> createScopedConnection(
68 const sp<IGraphicBufferProducer>& parent)
69 {
70 Parcel data, reply;
71 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
72 data.writeStrongBinder(IInterface::asBinder(parent));
73 remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply);
74 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
75 }
76
Jamie Gennis9a78c902011-01-12 18:30:40 -080077 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
78 {
Jamie Gennis9a78c902011-01-12 18:30:40 -080079 Parcel data, reply;
80 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
81 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
82 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
83 }
84
Mathias Agopian8b33f032012-07-24 20:43:54 -070085 virtual void setTransactionState(
86 const Vector<ComposerState>& state,
87 const Vector<DisplayState>& displays,
88 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 {
90 Parcel data, reply;
91 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080092
93 data.writeUint32(static_cast<uint32_t>(state.size()));
94 for (const auto& s : state) {
95 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070096 }
Dan Stozad723bd72014-11-18 10:24:03 -080097
98 data.writeUint32(static_cast<uint32_t>(displays.size()));
99 for (const auto& d : displays) {
100 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700101 }
Dan Stozad723bd72014-11-18 10:24:03 -0800102
103 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700104 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 }
106
107 virtual void bootFinished()
108 {
109 Parcel data, reply;
110 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
111 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
112 }
113
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800114 virtual status_t captureScreen(const sp<IBinder>& display,
115 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700116 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800117 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700118 bool useIdentityTransform,
119 ISurfaceComposer::Rotation rotation)
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800120 {
121 Parcel data, reply;
122 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
123 data.writeStrongBinder(display);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800124 data.writeStrongBinder(IInterface::asBinder(producer));
Dan Stozac1879002014-05-22 15:59:05 -0700125 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800126 data.writeUint32(reqWidth);
127 data.writeUint32(reqHeight);
Robert Carrae060832016-11-28 10:51:00 -0800128 data.writeInt32(minLayerZ);
129 data.writeInt32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800130 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700131 data.writeInt32(static_cast<int32_t>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800132 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
133 return reply.readInt32();
134 }
135
Jamie Gennis582270d2011-08-17 18:19:00 -0700136 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800137 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800138 {
139 Parcel data, reply;
140 int err = NO_ERROR;
141 err = data.writeInterfaceToken(
142 ISurfaceComposer::getInterfaceDescriptor());
143 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000144 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800145 "interface descriptor: %s (%d)", strerror(-err), -err);
146 return false;
147 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800148 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800149 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000150 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700151 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800152 return false;
153 }
154 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
155 &reply);
156 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000157 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700158 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800159 return false;
160 }
161 int32_t result = 0;
162 err = reply.readInt32(&result);
163 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000164 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700165 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800166 return false;
167 }
168 return result != 0;
169 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800170
Brian Anderson069b3652016-07-22 10:32:47 -0700171 virtual status_t getSupportedFrameTimestamps(
Brian Anderson3890c392016-07-25 12:48:08 -0700172 std::vector<FrameEvent>* outSupported) const {
Brian Anderson069b3652016-07-22 10:32:47 -0700173 if (!outSupported) {
174 return UNEXPECTED_NULL;
175 }
176 outSupported->clear();
177
178 Parcel data, reply;
179
180 status_t err = data.writeInterfaceToken(
181 ISurfaceComposer::getInterfaceDescriptor());
182 if (err != NO_ERROR) {
183 return err;
184 }
185
186 err = remote()->transact(
187 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
188 data, &reply);
189 if (err != NO_ERROR) {
190 return err;
191 }
192
193 int32_t result = 0;
194 err = reply.readInt32(&result);
195 if (err != NO_ERROR) {
196 return err;
197 }
198 if (result != NO_ERROR) {
199 return result;
200 }
201
202 std::vector<int32_t> supported;
203 err = reply.readInt32Vector(&supported);
204 if (err != NO_ERROR) {
205 return err;
206 }
207
208 outSupported->reserve(supported.size());
209 for (int32_t s : supported) {
Brian Anderson3890c392016-07-25 12:48:08 -0700210 outSupported->push_back(static_cast<FrameEvent>(s));
Brian Anderson069b3652016-07-22 10:32:47 -0700211 }
212 return NO_ERROR;
213 }
214
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800215 virtual sp<IDisplayEventConnection> createDisplayEventConnection()
216 {
217 Parcel data, reply;
218 sp<IDisplayEventConnection> result;
219 int err = data.writeInterfaceToken(
220 ISurfaceComposer::getInterfaceDescriptor());
221 if (err != NO_ERROR) {
222 return result;
223 }
224 err = remote()->transact(
225 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
226 data, &reply);
227 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000228 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800229 "transaction: %s (%d)", strerror(-err), -err);
230 return result;
231 }
232 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
233 return result;
234 }
Colin Cross8e533062012-06-07 13:17:52 -0700235
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700236 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700237 {
238 Parcel data, reply;
239 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700240 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700241 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700242 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
243 return reply.readStrongBinder();
244 }
245
Jesse Hall6c913be2013-08-08 12:15:49 -0700246 virtual void destroyDisplay(const sp<IBinder>& display)
247 {
248 Parcel data, reply;
249 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
250 data.writeStrongBinder(display);
251 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
252 }
253
Mathias Agopiane57f2922012-08-09 16:29:12 -0700254 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
258 data.writeInt32(id);
259 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
260 return reply.readStrongBinder();
261 }
262
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700263 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700267 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700268 data.writeInt32(mode);
269 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700270 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700271
Dan Stoza7f7da322014-05-02 15:26:25 -0700272 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
273 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700277 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700278 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
279 status_t result = reply.readInt32();
280 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800281 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700282 configs->clear();
283 configs->resize(numConfigs);
284 for (size_t c = 0; c < numConfigs; ++c) {
285 memcpy(&(configs->editItemAt(c)),
286 reply.readInplace(sizeof(DisplayInfo)),
287 sizeof(DisplayInfo));
288 }
289 }
290 return result;
291 }
292
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700293 virtual status_t getDisplayStats(const sp<IBinder>& display,
294 DisplayStatInfo* stats)
295 {
296 Parcel data, reply;
297 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
298 data.writeStrongBinder(display);
299 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
300 status_t result = reply.readInt32();
301 if (result == NO_ERROR) {
302 memcpy(stats,
303 reply.readInplace(sizeof(DisplayStatInfo)),
304 sizeof(DisplayStatInfo));
305 }
306 return result;
307 }
308
Dan Stoza7f7da322014-05-02 15:26:25 -0700309 virtual int getActiveConfig(const sp<IBinder>& display)
310 {
311 Parcel data, reply;
312 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
313 data.writeStrongBinder(display);
314 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
315 return reply.readInt32();
316 }
317
318 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
322 data.writeStrongBinder(display);
323 data.writeInt32(id);
324 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700325 return reply.readInt32();
326 }
Svetoslavd85084b2014-03-20 10:28:31 -0700327
Michael Wright28f24d02016-07-12 13:30:53 -0700328 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
329 Vector<android_color_mode_t>* outColorModes) {
330 Parcel data, reply;
331 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
332 if (result != NO_ERROR) {
333 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
334 return result;
335 }
336 result = data.writeStrongBinder(display);
337 if (result != NO_ERROR) {
338 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
339 return result;
340 }
341 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
342 if (result != NO_ERROR) {
343 ALOGE("getDisplayColorModes failed to transact: %d", result);
344 return result;
345 }
346 result = static_cast<status_t>(reply.readInt32());
347 if (result == NO_ERROR) {
348 size_t numModes = reply.readUint32();
349 outColorModes->clear();
350 outColorModes->resize(numModes);
351 for (size_t i = 0; i < numModes; ++i) {
352 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
353 }
354 }
355 return result;
356 }
357
358 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
359 Parcel data, reply;
360 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
361 if (result != NO_ERROR) {
362 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
363 return static_cast<android_color_mode_t>(result);
364 }
365 result = data.writeStrongBinder(display);
366 if (result != NO_ERROR) {
367 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
368 return static_cast<android_color_mode_t>(result);
369 }
370 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
371 if (result != NO_ERROR) {
372 ALOGE("getActiveColorMode failed to transact: %d", result);
373 return static_cast<android_color_mode_t>(result);
374 }
375 return static_cast<android_color_mode_t>(reply.readInt32());
376 }
377
378 virtual status_t setActiveColorMode(const sp<IBinder>& display,
379 android_color_mode_t colorMode) {
380 Parcel data, reply;
381 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
382 if (result != NO_ERROR) {
383 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
384 return result;
385 }
386 result = data.writeStrongBinder(display);
387 if (result != NO_ERROR) {
388 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
389 return result;
390 }
391 result = data.writeInt32(colorMode);
392 if (result != NO_ERROR) {
393 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
394 return result;
395 }
396 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
397 if (result != NO_ERROR) {
398 ALOGE("setActiveColorMode failed to transact: %d", result);
399 return result;
400 }
401 return static_cast<status_t>(reply.readInt32());
402 }
403
Svetoslavd85084b2014-03-20 10:28:31 -0700404 virtual status_t clearAnimationFrameStats() {
405 Parcel data, reply;
406 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
407 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
408 return reply.readInt32();
409 }
410
411 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
412 Parcel data, reply;
413 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
414 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
415 reply.read(*outStats);
416 return reply.readInt32();
417 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700418
419 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
420 HdrCapabilities* outCapabilities) const {
421 Parcel data, reply;
422 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
423 status_t result = data.writeStrongBinder(display);
424 if (result != NO_ERROR) {
425 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
426 return result;
427 }
428 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
429 data, &reply);
430 if (result != NO_ERROR) {
431 ALOGE("getHdrCapabilities failed to transact: %d", result);
432 return result;
433 }
434 result = reply.readInt32();
435 if (result == NO_ERROR) {
436 result = reply.readParcelable(outCapabilities);
437 }
438 return result;
439 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700440
441 virtual status_t enableVSyncInjections(bool enable) {
442 Parcel data, reply;
443 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
444 if (result != NO_ERROR) {
445 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
446 return result;
447 }
448 result = data.writeBool(enable);
449 if (result != NO_ERROR) {
450 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
451 return result;
452 }
453 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
454 data, &reply, TF_ONE_WAY);
455 if (result != NO_ERROR) {
456 ALOGE("enableVSyncInjections failed to transact: %d", result);
457 return result;
458 }
459 return result;
460 }
461
462 virtual status_t injectVSync(nsecs_t when) {
463 Parcel data, reply;
464 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
465 if (result != NO_ERROR) {
466 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
467 return result;
468 }
469 result = data.writeInt64(when);
470 if (result != NO_ERROR) {
471 ALOGE("injectVSync failed to writeInt64: %d", result);
472 return result;
473 }
474 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
475 if (result != NO_ERROR) {
476 ALOGE("injectVSync failed to transact: %d", result);
477 return result;
478 }
479 return result;
480 }
481
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482};
483
Dan Stozad723bd72014-11-18 10:24:03 -0800484// Out-of-line virtual method definition to trigger vtable emission in this
485// translation unit (see clang warning -Wweak-vtables)
486BpSurfaceComposer::~BpSurfaceComposer() {}
487
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800488IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
489
490// ----------------------------------------------------------------------
491
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492status_t BnSurfaceComposer::onTransact(
493 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
494{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495 switch(code) {
496 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700497 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800498 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700500 return NO_ERROR;
501 }
Robert Carr1db73f62016-12-21 12:58:51 -0800502 case CREATE_SCOPED_CONNECTION: {
503 CHECK_INTERFACE(ISurfaceComposer, data, reply);
504 sp<IGraphicBufferProducer> bufferProducer =
505 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
506 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
507 reply->writeStrongBinder(b);
508 return NO_ERROR;
509 }
Jamie Gennis9a78c902011-01-12 18:30:40 -0800510 case CREATE_GRAPHIC_BUFFER_ALLOC: {
511 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800512 sp<IBinder> b = IInterface::asBinder(createGraphicBufferAlloc());
Jamie Gennis9a78c902011-01-12 18:30:40 -0800513 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700514 return NO_ERROR;
515 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700516 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700517 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800518
519 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700520 if (count > data.dataSize()) {
521 return BAD_VALUE;
522 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700523 ComposerState s;
524 Vector<ComposerState> state;
525 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800526 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700527 if (s.read(data) == BAD_VALUE) {
528 return BAD_VALUE;
529 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700530 state.add(s);
531 }
Dan Stozad723bd72014-11-18 10:24:03 -0800532
533 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700534 if (count > data.dataSize()) {
535 return BAD_VALUE;
536 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700537 DisplayState d;
538 Vector<DisplayState> displays;
539 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800540 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700541 if (d.read(data) == BAD_VALUE) {
542 return BAD_VALUE;
543 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700544 displays.add(d);
545 }
Dan Stozad723bd72014-11-18 10:24:03 -0800546
547 uint32_t stateFlags = data.readUint32();
548 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700549 return NO_ERROR;
550 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700552 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800553 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700554 return NO_ERROR;
555 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800556 case CAPTURE_SCREEN: {
557 CHECK_INTERFACE(ISurfaceComposer, data, reply);
558 sp<IBinder> display = data.readStrongBinder();
559 sp<IGraphicBufferProducer> producer =
560 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700561 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700562 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800563 uint32_t reqWidth = data.readUint32();
564 uint32_t reqHeight = data.readUint32();
Robert Carrae060832016-11-28 10:51:00 -0800565 int32_t minLayerZ = data.readInt32();
566 int32_t maxLayerZ = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800567 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800568 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800569
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800570 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700571 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700572 useIdentityTransform,
573 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800574 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700575 return NO_ERROR;
576 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800577 case AUTHENTICATE_SURFACE: {
578 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800579 sp<IGraphicBufferProducer> bufferProducer =
580 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
581 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800582 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700583 return NO_ERROR;
584 }
Brian Anderson069b3652016-07-22 10:32:47 -0700585 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
586 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Brian Anderson3890c392016-07-25 12:48:08 -0700587 std::vector<FrameEvent> supportedTimestamps;
Brian Anderson069b3652016-07-22 10:32:47 -0700588 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
589 status_t err = reply->writeInt32(result);
590 if (err != NO_ERROR) {
591 return err;
592 }
593 if (result != NO_ERROR) {
594 return result;
595 }
596
597 std::vector<int32_t> supported;
598 supported.reserve(supportedTimestamps.size());
Brian Anderson3890c392016-07-25 12:48:08 -0700599 for (FrameEvent s : supportedTimestamps) {
Brian Anderson069b3652016-07-22 10:32:47 -0700600 supported.push_back(static_cast<int32_t>(s));
601 }
602 return reply->writeInt32Vector(supported);
603 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800604 case CREATE_DISPLAY_EVENT_CONNECTION: {
605 CHECK_INTERFACE(ISurfaceComposer, data, reply);
606 sp<IDisplayEventConnection> connection(createDisplayEventConnection());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800607 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800608 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700609 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700610 case CREATE_DISPLAY: {
611 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700612 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700613 bool secure = bool(data.readInt32());
614 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700615 reply->writeStrongBinder(display);
616 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700617 }
618 case DESTROY_DISPLAY: {
619 CHECK_INTERFACE(ISurfaceComposer, data, reply);
620 sp<IBinder> display = data.readStrongBinder();
621 destroyDisplay(display);
622 return NO_ERROR;
623 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700624 case GET_BUILT_IN_DISPLAY: {
625 CHECK_INTERFACE(ISurfaceComposer, data, reply);
626 int32_t id = data.readInt32();
627 sp<IBinder> display(getBuiltInDisplay(id));
628 reply->writeStrongBinder(display);
629 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700630 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700631 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700632 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700633 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700634 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700635 status_t result = getDisplayConfigs(display, &configs);
636 reply->writeInt32(result);
637 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800638 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700639 for (size_t c = 0; c < configs.size(); ++c) {
640 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
641 &configs[c], sizeof(DisplayInfo));
642 }
643 }
644 return NO_ERROR;
645 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700646 case GET_DISPLAY_STATS: {
647 CHECK_INTERFACE(ISurfaceComposer, data, reply);
648 DisplayStatInfo stats;
649 sp<IBinder> display = data.readStrongBinder();
650 status_t result = getDisplayStats(display, &stats);
651 reply->writeInt32(result);
652 if (result == NO_ERROR) {
653 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
654 &stats, sizeof(DisplayStatInfo));
655 }
656 return NO_ERROR;
657 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700658 case GET_ACTIVE_CONFIG: {
659 CHECK_INTERFACE(ISurfaceComposer, data, reply);
660 sp<IBinder> display = data.readStrongBinder();
661 int id = getActiveConfig(display);
662 reply->writeInt32(id);
663 return NO_ERROR;
664 }
665 case SET_ACTIVE_CONFIG: {
666 CHECK_INTERFACE(ISurfaceComposer, data, reply);
667 sp<IBinder> display = data.readStrongBinder();
668 int id = data.readInt32();
669 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700670 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700671 return NO_ERROR;
672 }
Michael Wright28f24d02016-07-12 13:30:53 -0700673 case GET_DISPLAY_COLOR_MODES: {
674 CHECK_INTERFACE(ISurfaceComposer, data, reply);
675 Vector<android_color_mode_t> colorModes;
676 sp<IBinder> display = nullptr;
677 status_t result = data.readStrongBinder(&display);
678 if (result != NO_ERROR) {
679 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
680 return result;
681 }
682 result = getDisplayColorModes(display, &colorModes);
683 reply->writeInt32(result);
684 if (result == NO_ERROR) {
685 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
686 for (size_t i = 0; i < colorModes.size(); ++i) {
687 reply->writeInt32(colorModes[i]);
688 }
689 }
690 return NO_ERROR;
691 }
692 case GET_ACTIVE_COLOR_MODE: {
693 CHECK_INTERFACE(ISurfaceComposer, data, reply);
694 sp<IBinder> display = nullptr;
695 status_t result = data.readStrongBinder(&display);
696 if (result != NO_ERROR) {
697 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
698 return result;
699 }
700 android_color_mode_t colorMode = getActiveColorMode(display);
701 result = reply->writeInt32(static_cast<int32_t>(colorMode));
702 return result;
703 }
704 case SET_ACTIVE_COLOR_MODE: {
705 CHECK_INTERFACE(ISurfaceComposer, data, reply);
706 sp<IBinder> display = nullptr;
707 status_t result = data.readStrongBinder(&display);
708 if (result != NO_ERROR) {
709 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
710 return result;
711 }
712 int32_t colorModeInt = 0;
713 result = data.readInt32(&colorModeInt);
714 if (result != NO_ERROR) {
715 ALOGE("setActiveColorMode failed to readInt32: %d", result);
716 return result;
717 }
718 result = setActiveColorMode(display,
719 static_cast<android_color_mode_t>(colorModeInt));
720 result = reply->writeInt32(result);
721 return result;
722 }
Svetoslavd85084b2014-03-20 10:28:31 -0700723 case CLEAR_ANIMATION_FRAME_STATS: {
724 CHECK_INTERFACE(ISurfaceComposer, data, reply);
725 status_t result = clearAnimationFrameStats();
726 reply->writeInt32(result);
727 return NO_ERROR;
728 }
729 case GET_ANIMATION_FRAME_STATS: {
730 CHECK_INTERFACE(ISurfaceComposer, data, reply);
731 FrameStats stats;
732 status_t result = getAnimationFrameStats(&stats);
733 reply->write(stats);
734 reply->writeInt32(result);
735 return NO_ERROR;
736 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700737 case SET_POWER_MODE: {
738 CHECK_INTERFACE(ISurfaceComposer, data, reply);
739 sp<IBinder> display = data.readStrongBinder();
740 int32_t mode = data.readInt32();
741 setPowerMode(display, mode);
742 return NO_ERROR;
743 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700744 case GET_HDR_CAPABILITIES: {
745 CHECK_INTERFACE(ISurfaceComposer, data, reply);
746 sp<IBinder> display = nullptr;
747 status_t result = data.readStrongBinder(&display);
748 if (result != NO_ERROR) {
749 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
750 result);
751 return result;
752 }
753 HdrCapabilities capabilities;
754 result = getHdrCapabilities(display, &capabilities);
755 reply->writeInt32(result);
756 if (result == NO_ERROR) {
757 reply->writeParcelable(capabilities);
758 }
759 return NO_ERROR;
760 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700761 case ENABLE_VSYNC_INJECTIONS: {
762 CHECK_INTERFACE(ISurfaceComposer, data, reply);
763 bool enable = false;
764 status_t result = data.readBool(&enable);
765 if (result != NO_ERROR) {
766 ALOGE("enableVSyncInjections failed to readBool: %d", result);
767 return result;
768 }
769 return enableVSyncInjections(enable);
770 }
771 case INJECT_VSYNC: {
772 CHECK_INTERFACE(ISurfaceComposer, data, reply);
773 int64_t when = 0;
774 status_t result = data.readInt64(&when);
775 if (result != NO_ERROR) {
776 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
777 return result;
778 }
779 return injectVSync(when);
780 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700781 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700782 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700783 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800784 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800785}
786
787// ----------------------------------------------------------------------------
788
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800789};