blob: 6c1662c00da907e10f9bc50f46b8989d1bc929e6 [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
Jamie Gennis9a78c902011-01-12 18:30:40 -080067 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
68 {
Jamie Gennis9a78c902011-01-12 18:30:40 -080069 Parcel data, reply;
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
72 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
73 }
74
Mathias Agopian8b33f032012-07-24 20:43:54 -070075 virtual void setTransactionState(
76 const Vector<ComposerState>& state,
77 const Vector<DisplayState>& displays,
78 uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 {
80 Parcel data, reply;
81 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080082
83 data.writeUint32(static_cast<uint32_t>(state.size()));
84 for (const auto& s : state) {
85 s.write(data);
Mathias Agopian698c0872011-06-28 19:09:31 -070086 }
Dan Stozad723bd72014-11-18 10:24:03 -080087
88 data.writeUint32(static_cast<uint32_t>(displays.size()));
89 for (const auto& d : displays) {
90 d.write(data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070091 }
Dan Stozad723bd72014-11-18 10:24:03 -080092
93 data.writeUint32(flags);
Jamie Gennisb8d69a52011-10-10 15:48:06 -070094 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 }
96
97 virtual void bootFinished()
98 {
99 Parcel data, reply;
100 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
101 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
102 }
103
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800104 virtual status_t captureScreen(const sp<IBinder>& display,
105 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700106 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800107 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700108 bool useIdentityTransform,
109 ISurfaceComposer::Rotation rotation)
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
113 data.writeStrongBinder(display);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800114 data.writeStrongBinder(IInterface::asBinder(producer));
Dan Stozac1879002014-05-22 15:59:05 -0700115 data.write(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800116 data.writeUint32(reqWidth);
117 data.writeUint32(reqHeight);
118 data.writeUint32(minLayerZ);
119 data.writeUint32(maxLayerZ);
Dan Stozac7014012014-02-14 15:03:43 -0800120 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700121 data.writeInt32(static_cast<int32_t>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800122 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
123 return reply.readInt32();
124 }
125
Jamie Gennis582270d2011-08-17 18:19:00 -0700126 virtual bool authenticateSurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -0800127 const sp<IGraphicBufferProducer>& bufferProducer) const
Jamie Gennis134f0422011-03-08 12:18:54 -0800128 {
129 Parcel data, reply;
130 int err = NO_ERROR;
131 err = data.writeInterfaceToken(
132 ISurfaceComposer::getInterfaceDescriptor());
133 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000134 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800135 "interface descriptor: %s (%d)", strerror(-err), -err);
136 return false;
137 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800138 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800139 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000140 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700141 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800142 return false;
143 }
144 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
145 &reply);
146 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000147 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700148 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800149 return false;
150 }
151 int32_t result = 0;
152 err = reply.readInt32(&result);
153 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000154 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700155 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800156 return false;
157 }
158 return result != 0;
159 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800160
161 virtual sp<IDisplayEventConnection> createDisplayEventConnection()
162 {
163 Parcel data, reply;
164 sp<IDisplayEventConnection> result;
165 int err = data.writeInterfaceToken(
166 ISurfaceComposer::getInterfaceDescriptor());
167 if (err != NO_ERROR) {
168 return result;
169 }
170 err = remote()->transact(
171 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
172 data, &reply);
173 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000174 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800175 "transaction: %s (%d)", strerror(-err), -err);
176 return result;
177 }
178 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
179 return result;
180 }
Colin Cross8e533062012-06-07 13:17:52 -0700181
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700182 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700183 {
184 Parcel data, reply;
185 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700186 data.writeString8(displayName);
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700187 data.writeInt32(secure ? 1 : 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700188 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
189 return reply.readStrongBinder();
190 }
191
Jesse Hall6c913be2013-08-08 12:15:49 -0700192 virtual void destroyDisplay(const sp<IBinder>& display)
193 {
194 Parcel data, reply;
195 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
196 data.writeStrongBinder(display);
197 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
198 }
199
Mathias Agopiane57f2922012-08-09 16:29:12 -0700200 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
201 {
202 Parcel data, reply;
203 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
204 data.writeInt32(id);
205 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
206 return reply.readStrongBinder();
207 }
208
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700209 virtual void setPowerMode(const sp<IBinder>& display, int mode)
Colin Cross8e533062012-06-07 13:17:52 -0700210 {
211 Parcel data, reply;
212 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700213 data.writeStrongBinder(display);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700214 data.writeInt32(mode);
215 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
Colin Cross8e533062012-06-07 13:17:52 -0700216 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700217
Dan Stoza7f7da322014-05-02 15:26:25 -0700218 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
219 Vector<DisplayInfo>* configs)
Mathias Agopianc666cae2012-07-25 18:56:13 -0700220 {
221 Parcel data, reply;
222 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700223 data.writeStrongBinder(display);
Dan Stoza7f7da322014-05-02 15:26:25 -0700224 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
225 status_t result = reply.readInt32();
226 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800227 size_t numConfigs = reply.readUint32();
Dan Stoza7f7da322014-05-02 15:26:25 -0700228 configs->clear();
229 configs->resize(numConfigs);
230 for (size_t c = 0; c < numConfigs; ++c) {
231 memcpy(&(configs->editItemAt(c)),
232 reply.readInplace(sizeof(DisplayInfo)),
233 sizeof(DisplayInfo));
234 }
235 }
236 return result;
237 }
238
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700239 virtual status_t getDisplayStats(const sp<IBinder>& display,
240 DisplayStatInfo* stats)
241 {
242 Parcel data, reply;
243 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
244 data.writeStrongBinder(display);
245 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
246 status_t result = reply.readInt32();
247 if (result == NO_ERROR) {
248 memcpy(stats,
249 reply.readInplace(sizeof(DisplayStatInfo)),
250 sizeof(DisplayStatInfo));
251 }
252 return result;
253 }
254
Dan Stoza7f7da322014-05-02 15:26:25 -0700255 virtual int getActiveConfig(const sp<IBinder>& display)
256 {
257 Parcel data, reply;
258 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
259 data.writeStrongBinder(display);
260 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
261 return reply.readInt32();
262 }
263
264 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
265 {
266 Parcel data, reply;
267 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
268 data.writeStrongBinder(display);
269 data.writeInt32(id);
270 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700271 return reply.readInt32();
272 }
Svetoslavd85084b2014-03-20 10:28:31 -0700273
Michael Wright28f24d02016-07-12 13:30:53 -0700274 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
275 Vector<android_color_mode_t>* outColorModes) {
276 Parcel data, reply;
277 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
278 if (result != NO_ERROR) {
279 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
280 return result;
281 }
282 result = data.writeStrongBinder(display);
283 if (result != NO_ERROR) {
284 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
285 return result;
286 }
287 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
288 if (result != NO_ERROR) {
289 ALOGE("getDisplayColorModes failed to transact: %d", result);
290 return result;
291 }
292 result = static_cast<status_t>(reply.readInt32());
293 if (result == NO_ERROR) {
294 size_t numModes = reply.readUint32();
295 outColorModes->clear();
296 outColorModes->resize(numModes);
297 for (size_t i = 0; i < numModes; ++i) {
298 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
299 }
300 }
301 return result;
302 }
303
304 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
305 Parcel data, reply;
306 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
307 if (result != NO_ERROR) {
308 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
309 return static_cast<android_color_mode_t>(result);
310 }
311 result = data.writeStrongBinder(display);
312 if (result != NO_ERROR) {
313 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
314 return static_cast<android_color_mode_t>(result);
315 }
316 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
317 if (result != NO_ERROR) {
318 ALOGE("getActiveColorMode failed to transact: %d", result);
319 return static_cast<android_color_mode_t>(result);
320 }
321 return static_cast<android_color_mode_t>(reply.readInt32());
322 }
323
324 virtual status_t setActiveColorMode(const sp<IBinder>& display,
325 android_color_mode_t colorMode) {
326 Parcel data, reply;
327 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
328 if (result != NO_ERROR) {
329 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
330 return result;
331 }
332 result = data.writeStrongBinder(display);
333 if (result != NO_ERROR) {
334 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
335 return result;
336 }
337 result = data.writeInt32(colorMode);
338 if (result != NO_ERROR) {
339 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
340 return result;
341 }
342 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
343 if (result != NO_ERROR) {
344 ALOGE("setActiveColorMode failed to transact: %d", result);
345 return result;
346 }
347 return static_cast<status_t>(reply.readInt32());
348 }
349
Svetoslavd85084b2014-03-20 10:28:31 -0700350 virtual status_t clearAnimationFrameStats() {
351 Parcel data, reply;
352 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
353 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
354 return reply.readInt32();
355 }
356
357 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
358 Parcel data, reply;
359 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
360 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
361 reply.read(*outStats);
362 return reply.readInt32();
363 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700364
365 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
366 HdrCapabilities* outCapabilities) const {
367 Parcel data, reply;
368 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
369 status_t result = data.writeStrongBinder(display);
370 if (result != NO_ERROR) {
371 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
372 return result;
373 }
374 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
375 data, &reply);
376 if (result != NO_ERROR) {
377 ALOGE("getHdrCapabilities failed to transact: %d", result);
378 return result;
379 }
380 result = reply.readInt32();
381 if (result == NO_ERROR) {
382 result = reply.readParcelable(outCapabilities);
383 }
384 return result;
385 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700386
387 virtual status_t enableVSyncInjections(bool enable) {
388 Parcel data, reply;
389 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
390 if (result != NO_ERROR) {
391 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
392 return result;
393 }
394 result = data.writeBool(enable);
395 if (result != NO_ERROR) {
396 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
397 return result;
398 }
399 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
400 data, &reply, TF_ONE_WAY);
401 if (result != NO_ERROR) {
402 ALOGE("enableVSyncInjections failed to transact: %d", result);
403 return result;
404 }
405 return result;
406 }
407
408 virtual status_t injectVSync(nsecs_t when) {
409 Parcel data, reply;
410 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
411 if (result != NO_ERROR) {
412 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
413 return result;
414 }
415 result = data.writeInt64(when);
416 if (result != NO_ERROR) {
417 ALOGE("injectVSync failed to writeInt64: %d", result);
418 return result;
419 }
420 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
421 if (result != NO_ERROR) {
422 ALOGE("injectVSync failed to transact: %d", result);
423 return result;
424 }
425 return result;
426 }
427
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800428};
429
Dan Stozad723bd72014-11-18 10:24:03 -0800430// Out-of-line virtual method definition to trigger vtable emission in this
431// translation unit (see clang warning -Wweak-vtables)
432BpSurfaceComposer::~BpSurfaceComposer() {}
433
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
435
436// ----------------------------------------------------------------------
437
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438status_t BnSurfaceComposer::onTransact(
439 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
440{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441 switch(code) {
442 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700443 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800444 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800445 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700446 return NO_ERROR;
447 }
Jamie Gennis9a78c902011-01-12 18:30:40 -0800448 case CREATE_GRAPHIC_BUFFER_ALLOC: {
449 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800450 sp<IBinder> b = IInterface::asBinder(createGraphicBufferAlloc());
Jamie Gennis9a78c902011-01-12 18:30:40 -0800451 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700452 return NO_ERROR;
453 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700454 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700455 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800456
457 size_t count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700458 if (count > data.dataSize()) {
459 return BAD_VALUE;
460 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700461 ComposerState s;
462 Vector<ComposerState> state;
463 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800464 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700465 if (s.read(data) == BAD_VALUE) {
466 return BAD_VALUE;
467 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700468 state.add(s);
469 }
Dan Stozad723bd72014-11-18 10:24:03 -0800470
471 count = data.readUint32();
Michael Lentine8afa1c42014-10-31 11:10:13 -0700472 if (count > data.dataSize()) {
473 return BAD_VALUE;
474 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700475 DisplayState d;
476 Vector<DisplayState> displays;
477 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800478 for (size_t i = 0; i < count; i++) {
Michael Lentine8afa1c42014-10-31 11:10:13 -0700479 if (d.read(data) == BAD_VALUE) {
480 return BAD_VALUE;
481 }
Mathias Agopian8b33f032012-07-24 20:43:54 -0700482 displays.add(d);
483 }
Dan Stozad723bd72014-11-18 10:24:03 -0800484
485 uint32_t stateFlags = data.readUint32();
486 setTransactionState(state, displays, stateFlags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700487 return NO_ERROR;
488 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800489 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700490 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700492 return NO_ERROR;
493 }
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800494 case CAPTURE_SCREEN: {
495 CHECK_INTERFACE(ISurfaceComposer, data, reply);
496 sp<IBinder> display = data.readStrongBinder();
497 sp<IGraphicBufferProducer> producer =
498 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
Pablo Ceballos60d69222015-08-07 14:47:20 -0700499 Rect sourceCrop(Rect::EMPTY_RECT);
Dan Stozac1879002014-05-22 15:59:05 -0700500 data.read(sourceCrop);
Dan Stozad723bd72014-11-18 10:24:03 -0800501 uint32_t reqWidth = data.readUint32();
502 uint32_t reqHeight = data.readUint32();
503 uint32_t minLayerZ = data.readUint32();
504 uint32_t maxLayerZ = data.readUint32();
Dan Stozac7014012014-02-14 15:03:43 -0800505 bool useIdentityTransform = static_cast<bool>(data.readInt32());
Dan Stozad723bd72014-11-18 10:24:03 -0800506 int32_t rotation = data.readInt32();
Dan Stozac7014012014-02-14 15:03:43 -0800507
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800508 status_t res = captureScreen(display, producer,
Dan Stozac1879002014-05-22 15:59:05 -0700509 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700510 useIdentityTransform,
511 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800512 reply->writeInt32(res);
Jesse Hall6c913be2013-08-08 12:15:49 -0700513 return NO_ERROR;
514 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800515 case AUTHENTICATE_SURFACE: {
516 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800517 sp<IGraphicBufferProducer> bufferProducer =
518 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
519 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800520 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700521 return NO_ERROR;
522 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800523 case CREATE_DISPLAY_EVENT_CONNECTION: {
524 CHECK_INTERFACE(ISurfaceComposer, data, reply);
525 sp<IDisplayEventConnection> connection(createDisplayEventConnection());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800526 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800527 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700528 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700529 case CREATE_DISPLAY: {
530 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700531 String8 displayName = data.readString8();
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700532 bool secure = bool(data.readInt32());
533 sp<IBinder> display(createDisplay(displayName, secure));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700534 reply->writeStrongBinder(display);
535 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700536 }
537 case DESTROY_DISPLAY: {
538 CHECK_INTERFACE(ISurfaceComposer, data, reply);
539 sp<IBinder> display = data.readStrongBinder();
540 destroyDisplay(display);
541 return NO_ERROR;
542 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700543 case GET_BUILT_IN_DISPLAY: {
544 CHECK_INTERFACE(ISurfaceComposer, data, reply);
545 int32_t id = data.readInt32();
546 sp<IBinder> display(getBuiltInDisplay(id));
547 reply->writeStrongBinder(display);
548 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700549 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700550 case GET_DISPLAY_CONFIGS: {
Mathias Agopianc666cae2012-07-25 18:56:13 -0700551 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stoza7f7da322014-05-02 15:26:25 -0700552 Vector<DisplayInfo> configs;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700553 sp<IBinder> display = data.readStrongBinder();
Dan Stoza7f7da322014-05-02 15:26:25 -0700554 status_t result = getDisplayConfigs(display, &configs);
555 reply->writeInt32(result);
556 if (result == NO_ERROR) {
Dan Stozad723bd72014-11-18 10:24:03 -0800557 reply->writeUint32(static_cast<uint32_t>(configs.size()));
Dan Stoza7f7da322014-05-02 15:26:25 -0700558 for (size_t c = 0; c < configs.size(); ++c) {
559 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
560 &configs[c], sizeof(DisplayInfo));
561 }
562 }
563 return NO_ERROR;
564 }
Lajos Molnar67d8bd62014-09-11 14:58:45 -0700565 case GET_DISPLAY_STATS: {
566 CHECK_INTERFACE(ISurfaceComposer, data, reply);
567 DisplayStatInfo stats;
568 sp<IBinder> display = data.readStrongBinder();
569 status_t result = getDisplayStats(display, &stats);
570 reply->writeInt32(result);
571 if (result == NO_ERROR) {
572 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
573 &stats, sizeof(DisplayStatInfo));
574 }
575 return NO_ERROR;
576 }
Dan Stoza7f7da322014-05-02 15:26:25 -0700577 case GET_ACTIVE_CONFIG: {
578 CHECK_INTERFACE(ISurfaceComposer, data, reply);
579 sp<IBinder> display = data.readStrongBinder();
580 int id = getActiveConfig(display);
581 reply->writeInt32(id);
582 return NO_ERROR;
583 }
584 case SET_ACTIVE_CONFIG: {
585 CHECK_INTERFACE(ISurfaceComposer, data, reply);
586 sp<IBinder> display = data.readStrongBinder();
587 int id = data.readInt32();
588 status_t result = setActiveConfig(display, id);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700589 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700590 return NO_ERROR;
591 }
Michael Wright28f24d02016-07-12 13:30:53 -0700592 case GET_DISPLAY_COLOR_MODES: {
593 CHECK_INTERFACE(ISurfaceComposer, data, reply);
594 Vector<android_color_mode_t> colorModes;
595 sp<IBinder> display = nullptr;
596 status_t result = data.readStrongBinder(&display);
597 if (result != NO_ERROR) {
598 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
599 return result;
600 }
601 result = getDisplayColorModes(display, &colorModes);
602 reply->writeInt32(result);
603 if (result == NO_ERROR) {
604 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
605 for (size_t i = 0; i < colorModes.size(); ++i) {
606 reply->writeInt32(colorModes[i]);
607 }
608 }
609 return NO_ERROR;
610 }
611 case GET_ACTIVE_COLOR_MODE: {
612 CHECK_INTERFACE(ISurfaceComposer, data, reply);
613 sp<IBinder> display = nullptr;
614 status_t result = data.readStrongBinder(&display);
615 if (result != NO_ERROR) {
616 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
617 return result;
618 }
619 android_color_mode_t colorMode = getActiveColorMode(display);
620 result = reply->writeInt32(static_cast<int32_t>(colorMode));
621 return result;
622 }
623 case SET_ACTIVE_COLOR_MODE: {
624 CHECK_INTERFACE(ISurfaceComposer, data, reply);
625 sp<IBinder> display = nullptr;
626 status_t result = data.readStrongBinder(&display);
627 if (result != NO_ERROR) {
628 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
629 return result;
630 }
631 int32_t colorModeInt = 0;
632 result = data.readInt32(&colorModeInt);
633 if (result != NO_ERROR) {
634 ALOGE("setActiveColorMode failed to readInt32: %d", result);
635 return result;
636 }
637 result = setActiveColorMode(display,
638 static_cast<android_color_mode_t>(colorModeInt));
639 result = reply->writeInt32(result);
640 return result;
641 }
Svetoslavd85084b2014-03-20 10:28:31 -0700642 case CLEAR_ANIMATION_FRAME_STATS: {
643 CHECK_INTERFACE(ISurfaceComposer, data, reply);
644 status_t result = clearAnimationFrameStats();
645 reply->writeInt32(result);
646 return NO_ERROR;
647 }
648 case GET_ANIMATION_FRAME_STATS: {
649 CHECK_INTERFACE(ISurfaceComposer, data, reply);
650 FrameStats stats;
651 status_t result = getAnimationFrameStats(&stats);
652 reply->write(stats);
653 reply->writeInt32(result);
654 return NO_ERROR;
655 }
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700656 case SET_POWER_MODE: {
657 CHECK_INTERFACE(ISurfaceComposer, data, reply);
658 sp<IBinder> display = data.readStrongBinder();
659 int32_t mode = data.readInt32();
660 setPowerMode(display, mode);
661 return NO_ERROR;
662 }
Dan Stozac4f471e2016-03-24 09:31:08 -0700663 case GET_HDR_CAPABILITIES: {
664 CHECK_INTERFACE(ISurfaceComposer, data, reply);
665 sp<IBinder> display = nullptr;
666 status_t result = data.readStrongBinder(&display);
667 if (result != NO_ERROR) {
668 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
669 result);
670 return result;
671 }
672 HdrCapabilities capabilities;
673 result = getHdrCapabilities(display, &capabilities);
674 reply->writeInt32(result);
675 if (result == NO_ERROR) {
676 reply->writeParcelable(capabilities);
677 }
678 return NO_ERROR;
679 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700680 case ENABLE_VSYNC_INJECTIONS: {
681 CHECK_INTERFACE(ISurfaceComposer, data, reply);
682 bool enable = false;
683 status_t result = data.readBool(&enable);
684 if (result != NO_ERROR) {
685 ALOGE("enableVSyncInjections failed to readBool: %d", result);
686 return result;
687 }
688 return enableVSyncInjections(enable);
689 }
690 case INJECT_VSYNC: {
691 CHECK_INTERFACE(ISurfaceComposer, data, reply);
692 int64_t when = 0;
693 status_t result = data.readInt64(&when);
694 if (result != NO_ERROR) {
695 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
696 return result;
697 }
698 return injectVSync(when);
699 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700700 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700701 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700702 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800703 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800704}
705
706// ----------------------------------------------------------------------------
707
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800708};