1 /*
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
23 #include <binder/Parcel.h>
24 #include <binder/IPCThreadState.h>
25 #include <binder/IServiceManager.h>
26
27 #include <gui/IDisplayEventConnection.h>
28 #include <gui/IGraphicBufferProducer.h>
29 #include <gui/ISurfaceComposer.h>
30 #include <gui/ISurfaceComposerClient.h>
31
32 #include <private/gui/LayerState.h>
33
34 #include <system/graphics.h>
35
36 #include <ui/DisplayInfo.h>
37 #include <ui/DisplayStatInfo.h>
38 #include <ui/HdrCapabilities.h>
39
40 #include <utils/Log.h>
41
42 // ---------------------------------------------------------------------------
43
44 namespace android {
45
46 class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
47 {
48 public:
BpSurfaceComposer(const sp<IBinder> & impl)49 explicit BpSurfaceComposer(const sp<IBinder>& impl)
50 : BpInterface<ISurfaceComposer>(impl)
51 {
52 }
53
54 virtual ~BpSurfaceComposer();
55
createConnection()56 virtual sp<ISurfaceComposerClient> createConnection()
57 {
58 Parcel data, reply;
59 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
60 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
61 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
62 }
63
createScopedConnection(const sp<IGraphicBufferProducer> & parent)64 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
setTransactionState(const Vector<ComposerState> & state,const Vector<DisplayState> & displays,uint32_t flags)74 virtual void setTransactionState(
75 const Vector<ComposerState>& state,
76 const Vector<DisplayState>& displays,
77 uint32_t flags)
78 {
79 Parcel data, reply;
80 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
81
82 data.writeUint32(static_cast<uint32_t>(state.size()));
83 for (const auto& s : state) {
84 s.write(data);
85 }
86
87 data.writeUint32(static_cast<uint32_t>(displays.size()));
88 for (const auto& d : displays) {
89 d.write(data);
90 }
91
92 data.writeUint32(flags);
93 remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
94 }
95
bootFinished()96 virtual void bootFinished()
97 {
98 Parcel data, reply;
99 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
100 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
101 }
102
captureScreen(const sp<IBinder> & display,const sp<IGraphicBufferProducer> & producer,Rect sourceCrop,uint32_t reqWidth,uint32_t reqHeight,int32_t minLayerZ,int32_t maxLayerZ,bool useIdentityTransform,ISurfaceComposer::Rotation rotation)103 virtual status_t captureScreen(const sp<IBinder>& display,
104 const sp<IGraphicBufferProducer>& producer,
105 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
106 int32_t minLayerZ, int32_t maxLayerZ,
107 bool useIdentityTransform,
108 ISurfaceComposer::Rotation rotation)
109 {
110 Parcel data, reply;
111 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
112 data.writeStrongBinder(display);
113 data.writeStrongBinder(IInterface::asBinder(producer));
114 data.write(sourceCrop);
115 data.writeUint32(reqWidth);
116 data.writeUint32(reqHeight);
117 data.writeInt32(minLayerZ);
118 data.writeInt32(maxLayerZ);
119 data.writeInt32(static_cast<int32_t>(useIdentityTransform));
120 data.writeInt32(static_cast<int32_t>(rotation));
121 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
122 return reply.readInt32();
123 }
124
authenticateSurfaceTexture(const sp<IGraphicBufferProducer> & bufferProducer) const125 virtual bool authenticateSurfaceTexture(
126 const sp<IGraphicBufferProducer>& bufferProducer) const
127 {
128 Parcel data, reply;
129 int err = NO_ERROR;
130 err = data.writeInterfaceToken(
131 ISurfaceComposer::getInterfaceDescriptor());
132 if (err != NO_ERROR) {
133 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
134 "interface descriptor: %s (%d)", strerror(-err), -err);
135 return false;
136 }
137 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
138 if (err != NO_ERROR) {
139 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
140 "strong binder to parcel: %s (%d)", strerror(-err), -err);
141 return false;
142 }
143 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
144 &reply);
145 if (err != NO_ERROR) {
146 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
147 "performing transaction: %s (%d)", strerror(-err), -err);
148 return false;
149 }
150 int32_t result = 0;
151 err = reply.readInt32(&result);
152 if (err != NO_ERROR) {
153 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
154 "retrieving result: %s (%d)", strerror(-err), -err);
155 return false;
156 }
157 return result != 0;
158 }
159
getSupportedFrameTimestamps(std::vector<FrameEvent> * outSupported) const160 virtual status_t getSupportedFrameTimestamps(
161 std::vector<FrameEvent>* outSupported) const {
162 if (!outSupported) {
163 return UNEXPECTED_NULL;
164 }
165 outSupported->clear();
166
167 Parcel data, reply;
168
169 status_t err = data.writeInterfaceToken(
170 ISurfaceComposer::getInterfaceDescriptor());
171 if (err != NO_ERROR) {
172 return err;
173 }
174
175 err = remote()->transact(
176 BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
177 data, &reply);
178 if (err != NO_ERROR) {
179 return err;
180 }
181
182 int32_t result = 0;
183 err = reply.readInt32(&result);
184 if (err != NO_ERROR) {
185 return err;
186 }
187 if (result != NO_ERROR) {
188 return result;
189 }
190
191 std::vector<int32_t> supported;
192 err = reply.readInt32Vector(&supported);
193 if (err != NO_ERROR) {
194 return err;
195 }
196
197 outSupported->reserve(supported.size());
198 for (int32_t s : supported) {
199 outSupported->push_back(static_cast<FrameEvent>(s));
200 }
201 return NO_ERROR;
202 }
203
createDisplayEventConnection(VsyncSource vsyncSource)204 virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource)
205 {
206 Parcel data, reply;
207 sp<IDisplayEventConnection> result;
208 int err = data.writeInterfaceToken(
209 ISurfaceComposer::getInterfaceDescriptor());
210 if (err != NO_ERROR) {
211 return result;
212 }
213 data.writeInt32(static_cast<int32_t>(vsyncSource));
214 err = remote()->transact(
215 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
216 data, &reply);
217 if (err != NO_ERROR) {
218 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
219 "transaction: %s (%d)", strerror(-err), -err);
220 return result;
221 }
222 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
223 return result;
224 }
225
createDisplay(const String8 & displayName,bool secure)226 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure)
227 {
228 Parcel data, reply;
229 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
230 data.writeString8(displayName);
231 data.writeInt32(secure ? 1 : 0);
232 remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply);
233 return reply.readStrongBinder();
234 }
235
destroyDisplay(const sp<IBinder> & display)236 virtual void destroyDisplay(const sp<IBinder>& display)
237 {
238 Parcel data, reply;
239 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
240 data.writeStrongBinder(display);
241 remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply);
242 }
243
getBuiltInDisplay(int32_t id)244 virtual sp<IBinder> getBuiltInDisplay(int32_t id)
245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
248 data.writeInt32(id);
249 remote()->transact(BnSurfaceComposer::GET_BUILT_IN_DISPLAY, data, &reply);
250 return reply.readStrongBinder();
251 }
252
setPowerMode(const sp<IBinder> & display,int mode)253 virtual void setPowerMode(const sp<IBinder>& display, int mode)
254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
257 data.writeStrongBinder(display);
258 data.writeInt32(mode);
259 remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
260 }
261
getDisplayConfigs(const sp<IBinder> & display,Vector<DisplayInfo> * configs)262 virtual status_t getDisplayConfigs(const sp<IBinder>& display,
263 Vector<DisplayInfo>* configs)
264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
267 data.writeStrongBinder(display);
268 remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
269 status_t result = reply.readInt32();
270 if (result == NO_ERROR) {
271 size_t numConfigs = reply.readUint32();
272 configs->clear();
273 configs->resize(numConfigs);
274 for (size_t c = 0; c < numConfigs; ++c) {
275 memcpy(&(configs->editItemAt(c)),
276 reply.readInplace(sizeof(DisplayInfo)),
277 sizeof(DisplayInfo));
278 }
279 }
280 return result;
281 }
282
getDisplayStats(const sp<IBinder> & display,DisplayStatInfo * stats)283 virtual status_t getDisplayStats(const sp<IBinder>& display,
284 DisplayStatInfo* stats)
285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
288 data.writeStrongBinder(display);
289 remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATS, data, &reply);
290 status_t result = reply.readInt32();
291 if (result == NO_ERROR) {
292 memcpy(stats,
293 reply.readInplace(sizeof(DisplayStatInfo)),
294 sizeof(DisplayStatInfo));
295 }
296 return result;
297 }
298
getActiveConfig(const sp<IBinder> & display)299 virtual int getActiveConfig(const sp<IBinder>& display)
300 {
301 Parcel data, reply;
302 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
303 data.writeStrongBinder(display);
304 remote()->transact(BnSurfaceComposer::GET_ACTIVE_CONFIG, data, &reply);
305 return reply.readInt32();
306 }
307
setActiveConfig(const sp<IBinder> & display,int id)308 virtual status_t setActiveConfig(const sp<IBinder>& display, int id)
309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
312 data.writeStrongBinder(display);
313 data.writeInt32(id);
314 remote()->transact(BnSurfaceComposer::SET_ACTIVE_CONFIG, data, &reply);
315 return reply.readInt32();
316 }
317
getDisplayColorModes(const sp<IBinder> & display,Vector<android_color_mode_t> * outColorModes)318 virtual status_t getDisplayColorModes(const sp<IBinder>& display,
319 Vector<android_color_mode_t>* outColorModes) {
320 Parcel data, reply;
321 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
322 if (result != NO_ERROR) {
323 ALOGE("getDisplayColorModes failed to writeInterfaceToken: %d", result);
324 return result;
325 }
326 result = data.writeStrongBinder(display);
327 if (result != NO_ERROR) {
328 ALOGE("getDisplayColorModes failed to writeStrongBinder: %d", result);
329 return result;
330 }
331 result = remote()->transact(BnSurfaceComposer::GET_DISPLAY_COLOR_MODES, data, &reply);
332 if (result != NO_ERROR) {
333 ALOGE("getDisplayColorModes failed to transact: %d", result);
334 return result;
335 }
336 result = static_cast<status_t>(reply.readInt32());
337 if (result == NO_ERROR) {
338 size_t numModes = reply.readUint32();
339 outColorModes->clear();
340 outColorModes->resize(numModes);
341 for (size_t i = 0; i < numModes; ++i) {
342 outColorModes->replaceAt(static_cast<android_color_mode_t>(reply.readInt32()), i);
343 }
344 }
345 return result;
346 }
347
getActiveColorMode(const sp<IBinder> & display)348 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) {
349 Parcel data, reply;
350 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
351 if (result != NO_ERROR) {
352 ALOGE("getActiveColorMode failed to writeInterfaceToken: %d", result);
353 return static_cast<android_color_mode_t>(result);
354 }
355 result = data.writeStrongBinder(display);
356 if (result != NO_ERROR) {
357 ALOGE("getActiveColorMode failed to writeStrongBinder: %d", result);
358 return static_cast<android_color_mode_t>(result);
359 }
360 result = remote()->transact(BnSurfaceComposer::GET_ACTIVE_COLOR_MODE, data, &reply);
361 if (result != NO_ERROR) {
362 ALOGE("getActiveColorMode failed to transact: %d", result);
363 return static_cast<android_color_mode_t>(result);
364 }
365 return static_cast<android_color_mode_t>(reply.readInt32());
366 }
367
setActiveColorMode(const sp<IBinder> & display,android_color_mode_t colorMode)368 virtual status_t setActiveColorMode(const sp<IBinder>& display,
369 android_color_mode_t colorMode) {
370 Parcel data, reply;
371 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
372 if (result != NO_ERROR) {
373 ALOGE("setActiveColorMode failed to writeInterfaceToken: %d", result);
374 return result;
375 }
376 result = data.writeStrongBinder(display);
377 if (result != NO_ERROR) {
378 ALOGE("setActiveColorMode failed to writeStrongBinder: %d", result);
379 return result;
380 }
381 result = data.writeInt32(colorMode);
382 if (result != NO_ERROR) {
383 ALOGE("setActiveColorMode failed to writeInt32: %d", result);
384 return result;
385 }
386 result = remote()->transact(BnSurfaceComposer::SET_ACTIVE_COLOR_MODE, data, &reply);
387 if (result != NO_ERROR) {
388 ALOGE("setActiveColorMode failed to transact: %d", result);
389 return result;
390 }
391 return static_cast<status_t>(reply.readInt32());
392 }
393
clearAnimationFrameStats()394 virtual status_t clearAnimationFrameStats() {
395 Parcel data, reply;
396 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
397 remote()->transact(BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS, data, &reply);
398 return reply.readInt32();
399 }
400
getAnimationFrameStats(FrameStats * outStats) const401 virtual status_t getAnimationFrameStats(FrameStats* outStats) const {
402 Parcel data, reply;
403 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
404 remote()->transact(BnSurfaceComposer::GET_ANIMATION_FRAME_STATS, data, &reply);
405 reply.read(*outStats);
406 return reply.readInt32();
407 }
408
getHdrCapabilities(const sp<IBinder> & display,HdrCapabilities * outCapabilities) const409 virtual status_t getHdrCapabilities(const sp<IBinder>& display,
410 HdrCapabilities* outCapabilities) const {
411 Parcel data, reply;
412 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
413 status_t result = data.writeStrongBinder(display);
414 if (result != NO_ERROR) {
415 ALOGE("getHdrCapabilities failed to writeStrongBinder: %d", result);
416 return result;
417 }
418 result = remote()->transact(BnSurfaceComposer::GET_HDR_CAPABILITIES,
419 data, &reply);
420 if (result != NO_ERROR) {
421 ALOGE("getHdrCapabilities failed to transact: %d", result);
422 return result;
423 }
424 result = reply.readInt32();
425 if (result == NO_ERROR) {
426 result = reply.read(*outCapabilities);
427 }
428 return result;
429 }
430
enableVSyncInjections(bool enable)431 virtual status_t enableVSyncInjections(bool enable) {
432 Parcel data, reply;
433 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
434 if (result != NO_ERROR) {
435 ALOGE("enableVSyncInjections failed to writeInterfaceToken: %d", result);
436 return result;
437 }
438 result = data.writeBool(enable);
439 if (result != NO_ERROR) {
440 ALOGE("enableVSyncInjections failed to writeBool: %d", result);
441 return result;
442 }
443 result = remote()->transact(BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
444 data, &reply, TF_ONE_WAY);
445 if (result != NO_ERROR) {
446 ALOGE("enableVSyncInjections failed to transact: %d", result);
447 return result;
448 }
449 return result;
450 }
451
injectVSync(nsecs_t when)452 virtual status_t injectVSync(nsecs_t when) {
453 Parcel data, reply;
454 status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
455 if (result != NO_ERROR) {
456 ALOGE("injectVSync failed to writeInterfaceToken: %d", result);
457 return result;
458 }
459 result = data.writeInt64(when);
460 if (result != NO_ERROR) {
461 ALOGE("injectVSync failed to writeInt64: %d", result);
462 return result;
463 }
464 result = remote()->transact(BnSurfaceComposer::INJECT_VSYNC, data, &reply, TF_ONE_WAY);
465 if (result != NO_ERROR) {
466 ALOGE("injectVSync failed to transact: %d", result);
467 return result;
468 }
469 return result;
470 }
471
472 };
473
474 // Out-of-line virtual method definition to trigger vtable emission in this
475 // translation unit (see clang warning -Wweak-vtables)
~BpSurfaceComposer()476 BpSurfaceComposer::~BpSurfaceComposer() {}
477
478 IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
479
480 // ----------------------------------------------------------------------
481
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)482 status_t BnSurfaceComposer::onTransact(
483 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
484 {
485 switch(code) {
486 case CREATE_CONNECTION: {
487 CHECK_INTERFACE(ISurfaceComposer, data, reply);
488 sp<IBinder> b = IInterface::asBinder(createConnection());
489 reply->writeStrongBinder(b);
490 return NO_ERROR;
491 }
492 case CREATE_SCOPED_CONNECTION: {
493 CHECK_INTERFACE(ISurfaceComposer, data, reply);
494 sp<IGraphicBufferProducer> bufferProducer =
495 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
496 sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer));
497 reply->writeStrongBinder(b);
498 return NO_ERROR;
499 }
500 case SET_TRANSACTION_STATE: {
501 CHECK_INTERFACE(ISurfaceComposer, data, reply);
502
503 size_t count = data.readUint32();
504 if (count > data.dataSize()) {
505 return BAD_VALUE;
506 }
507 ComposerState s;
508 Vector<ComposerState> state;
509 state.setCapacity(count);
510 for (size_t i = 0; i < count; i++) {
511 if (s.read(data) == BAD_VALUE) {
512 return BAD_VALUE;
513 }
514 state.add(s);
515 }
516
517 count = data.readUint32();
518 if (count > data.dataSize()) {
519 return BAD_VALUE;
520 }
521 DisplayState d;
522 Vector<DisplayState> displays;
523 displays.setCapacity(count);
524 for (size_t i = 0; i < count; i++) {
525 if (d.read(data) == BAD_VALUE) {
526 return BAD_VALUE;
527 }
528 displays.add(d);
529 }
530
531 uint32_t stateFlags = data.readUint32();
532 setTransactionState(state, displays, stateFlags);
533 return NO_ERROR;
534 }
535 case BOOT_FINISHED: {
536 CHECK_INTERFACE(ISurfaceComposer, data, reply);
537 bootFinished();
538 return NO_ERROR;
539 }
540 case CAPTURE_SCREEN: {
541 CHECK_INTERFACE(ISurfaceComposer, data, reply);
542 sp<IBinder> display = data.readStrongBinder();
543 sp<IGraphicBufferProducer> producer =
544 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
545 Rect sourceCrop(Rect::EMPTY_RECT);
546 data.read(sourceCrop);
547 uint32_t reqWidth = data.readUint32();
548 uint32_t reqHeight = data.readUint32();
549 int32_t minLayerZ = data.readInt32();
550 int32_t maxLayerZ = data.readInt32();
551 bool useIdentityTransform = static_cast<bool>(data.readInt32());
552 int32_t rotation = data.readInt32();
553
554 status_t res = captureScreen(display, producer,
555 sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ,
556 useIdentityTransform,
557 static_cast<ISurfaceComposer::Rotation>(rotation));
558 reply->writeInt32(res);
559 return NO_ERROR;
560 }
561 case AUTHENTICATE_SURFACE: {
562 CHECK_INTERFACE(ISurfaceComposer, data, reply);
563 sp<IGraphicBufferProducer> bufferProducer =
564 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
565 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
566 reply->writeInt32(result);
567 return NO_ERROR;
568 }
569 case GET_SUPPORTED_FRAME_TIMESTAMPS: {
570 CHECK_INTERFACE(ISurfaceComposer, data, reply);
571 std::vector<FrameEvent> supportedTimestamps;
572 status_t result = getSupportedFrameTimestamps(&supportedTimestamps);
573 status_t err = reply->writeInt32(result);
574 if (err != NO_ERROR) {
575 return err;
576 }
577 if (result != NO_ERROR) {
578 return result;
579 }
580
581 std::vector<int32_t> supported;
582 supported.reserve(supportedTimestamps.size());
583 for (FrameEvent s : supportedTimestamps) {
584 supported.push_back(static_cast<int32_t>(s));
585 }
586 return reply->writeInt32Vector(supported);
587 }
588 case CREATE_DISPLAY_EVENT_CONNECTION: {
589 CHECK_INTERFACE(ISurfaceComposer, data, reply);
590 sp<IDisplayEventConnection> connection(createDisplayEventConnection(
591 static_cast<ISurfaceComposer::VsyncSource>(data.readInt32())));
592 reply->writeStrongBinder(IInterface::asBinder(connection));
593 return NO_ERROR;
594 }
595 case CREATE_DISPLAY: {
596 CHECK_INTERFACE(ISurfaceComposer, data, reply);
597 String8 displayName = data.readString8();
598 bool secure = bool(data.readInt32());
599 sp<IBinder> display(createDisplay(displayName, secure));
600 reply->writeStrongBinder(display);
601 return NO_ERROR;
602 }
603 case DESTROY_DISPLAY: {
604 CHECK_INTERFACE(ISurfaceComposer, data, reply);
605 sp<IBinder> display = data.readStrongBinder();
606 destroyDisplay(display);
607 return NO_ERROR;
608 }
609 case GET_BUILT_IN_DISPLAY: {
610 CHECK_INTERFACE(ISurfaceComposer, data, reply);
611 int32_t id = data.readInt32();
612 sp<IBinder> display(getBuiltInDisplay(id));
613 reply->writeStrongBinder(display);
614 return NO_ERROR;
615 }
616 case GET_DISPLAY_CONFIGS: {
617 CHECK_INTERFACE(ISurfaceComposer, data, reply);
618 Vector<DisplayInfo> configs;
619 sp<IBinder> display = data.readStrongBinder();
620 status_t result = getDisplayConfigs(display, &configs);
621 reply->writeInt32(result);
622 if (result == NO_ERROR) {
623 reply->writeUint32(static_cast<uint32_t>(configs.size()));
624 for (size_t c = 0; c < configs.size(); ++c) {
625 memcpy(reply->writeInplace(sizeof(DisplayInfo)),
626 &configs[c], sizeof(DisplayInfo));
627 }
628 }
629 return NO_ERROR;
630 }
631 case GET_DISPLAY_STATS: {
632 CHECK_INTERFACE(ISurfaceComposer, data, reply);
633 DisplayStatInfo stats;
634 sp<IBinder> display = data.readStrongBinder();
635 status_t result = getDisplayStats(display, &stats);
636 reply->writeInt32(result);
637 if (result == NO_ERROR) {
638 memcpy(reply->writeInplace(sizeof(DisplayStatInfo)),
639 &stats, sizeof(DisplayStatInfo));
640 }
641 return NO_ERROR;
642 }
643 case GET_ACTIVE_CONFIG: {
644 CHECK_INTERFACE(ISurfaceComposer, data, reply);
645 sp<IBinder> display = data.readStrongBinder();
646 int id = getActiveConfig(display);
647 reply->writeInt32(id);
648 return NO_ERROR;
649 }
650 case SET_ACTIVE_CONFIG: {
651 CHECK_INTERFACE(ISurfaceComposer, data, reply);
652 sp<IBinder> display = data.readStrongBinder();
653 int id = data.readInt32();
654 status_t result = setActiveConfig(display, id);
655 reply->writeInt32(result);
656 return NO_ERROR;
657 }
658 case GET_DISPLAY_COLOR_MODES: {
659 CHECK_INTERFACE(ISurfaceComposer, data, reply);
660 Vector<android_color_mode_t> colorModes;
661 sp<IBinder> display = nullptr;
662 status_t result = data.readStrongBinder(&display);
663 if (result != NO_ERROR) {
664 ALOGE("getDisplayColorModes failed to readStrongBinder: %d", result);
665 return result;
666 }
667 result = getDisplayColorModes(display, &colorModes);
668 reply->writeInt32(result);
669 if (result == NO_ERROR) {
670 reply->writeUint32(static_cast<uint32_t>(colorModes.size()));
671 for (size_t i = 0; i < colorModes.size(); ++i) {
672 reply->writeInt32(colorModes[i]);
673 }
674 }
675 return NO_ERROR;
676 }
677 case GET_ACTIVE_COLOR_MODE: {
678 CHECK_INTERFACE(ISurfaceComposer, data, reply);
679 sp<IBinder> display = nullptr;
680 status_t result = data.readStrongBinder(&display);
681 if (result != NO_ERROR) {
682 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
683 return result;
684 }
685 android_color_mode_t colorMode = getActiveColorMode(display);
686 result = reply->writeInt32(static_cast<int32_t>(colorMode));
687 return result;
688 }
689 case SET_ACTIVE_COLOR_MODE: {
690 CHECK_INTERFACE(ISurfaceComposer, data, reply);
691 sp<IBinder> display = nullptr;
692 status_t result = data.readStrongBinder(&display);
693 if (result != NO_ERROR) {
694 ALOGE("getActiveColorMode failed to readStrongBinder: %d", result);
695 return result;
696 }
697 int32_t colorModeInt = 0;
698 result = data.readInt32(&colorModeInt);
699 if (result != NO_ERROR) {
700 ALOGE("setActiveColorMode failed to readInt32: %d", result);
701 return result;
702 }
703 result = setActiveColorMode(display,
704 static_cast<android_color_mode_t>(colorModeInt));
705 result = reply->writeInt32(result);
706 return result;
707 }
708 case CLEAR_ANIMATION_FRAME_STATS: {
709 CHECK_INTERFACE(ISurfaceComposer, data, reply);
710 status_t result = clearAnimationFrameStats();
711 reply->writeInt32(result);
712 return NO_ERROR;
713 }
714 case GET_ANIMATION_FRAME_STATS: {
715 CHECK_INTERFACE(ISurfaceComposer, data, reply);
716 FrameStats stats;
717 status_t result = getAnimationFrameStats(&stats);
718 reply->write(stats);
719 reply->writeInt32(result);
720 return NO_ERROR;
721 }
722 case SET_POWER_MODE: {
723 CHECK_INTERFACE(ISurfaceComposer, data, reply);
724 sp<IBinder> display = data.readStrongBinder();
725 int32_t mode = data.readInt32();
726 setPowerMode(display, mode);
727 return NO_ERROR;
728 }
729 case GET_HDR_CAPABILITIES: {
730 CHECK_INTERFACE(ISurfaceComposer, data, reply);
731 sp<IBinder> display = nullptr;
732 status_t result = data.readStrongBinder(&display);
733 if (result != NO_ERROR) {
734 ALOGE("getHdrCapabilities failed to readStrongBinder: %d",
735 result);
736 return result;
737 }
738 HdrCapabilities capabilities;
739 result = getHdrCapabilities(display, &capabilities);
740 reply->writeInt32(result);
741 if (result == NO_ERROR) {
742 reply->write(capabilities);
743 }
744 return NO_ERROR;
745 }
746 case ENABLE_VSYNC_INJECTIONS: {
747 CHECK_INTERFACE(ISurfaceComposer, data, reply);
748 bool enable = false;
749 status_t result = data.readBool(&enable);
750 if (result != NO_ERROR) {
751 ALOGE("enableVSyncInjections failed to readBool: %d", result);
752 return result;
753 }
754 return enableVSyncInjections(enable);
755 }
756 case INJECT_VSYNC: {
757 CHECK_INTERFACE(ISurfaceComposer, data, reply);
758 int64_t when = 0;
759 status_t result = data.readInt64(&when);
760 if (result != NO_ERROR) {
761 ALOGE("enableVSyncInjections failed to readInt64: %d", result);
762 return result;
763 }
764 return injectVSync(when);
765 }
766 default: {
767 return BBinder::onTransact(code, data, reply, flags);
768 }
769 }
770 }
771
772 // ----------------------------------------------------------------------------
773
774 };
775