• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gui/ISurfaceComposerClient.h>
21 
22 #include <gui/IGraphicBufferProducer.h>
23 
24 #include <binder/SafeInterface.h>
25 
26 #include <ui/FrameStats.h>
27 
28 namespace android {
29 
30 namespace { // Anonymous
31 
32 enum class Tag : uint32_t {
33     CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
34     CREATE_WITH_SURFACE_PARENT,
35     CLEAR_LAYER_FRAME_STATS,
36     GET_LAYER_FRAME_STATS,
37     MIRROR_SURFACE,
38     LAST = MIRROR_SURFACE,
39 };
40 
41 } // Anonymous namespace
42 
43 class BpSurfaceComposerClient : public SafeBpInterface<ISurfaceComposerClient> {
44 public:
BpSurfaceComposerClient(const sp<IBinder> & impl)45     explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
46           : SafeBpInterface<ISurfaceComposerClient>(impl, "BpSurfaceComposerClient") {}
47 
48     ~BpSurfaceComposerClient() override;
49 
createSurface(const String8 & name,uint32_t width,uint32_t height,PixelFormat format,uint32_t flags,const sp<IBinder> & parent,LayerMetadata metadata,sp<IBinder> * handle,sp<IGraphicBufferProducer> * gbp,int32_t * outLayerId,uint32_t * outTransformHint)50     status_t createSurface(const String8& name, uint32_t width, uint32_t height, PixelFormat format,
51                            uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata,
52                            sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp,
53                            int32_t* outLayerId, uint32_t* outTransformHint) override {
54         return callRemote<decltype(&ISurfaceComposerClient::createSurface)>(Tag::CREATE_SURFACE,
55                                                                             name, width, height,
56                                                                             format, flags, parent,
57                                                                             std::move(metadata),
58                                                                             handle, gbp, outLayerId,
59                                                                             outTransformHint);
60     }
61 
createWithSurfaceParent(const String8 & name,uint32_t width,uint32_t height,PixelFormat format,uint32_t flags,const sp<IGraphicBufferProducer> & parent,LayerMetadata metadata,sp<IBinder> * handle,sp<IGraphicBufferProducer> * gbp,int32_t * outLayerId,uint32_t * outTransformHint)62     status_t createWithSurfaceParent(const String8& name, uint32_t width, uint32_t height,
63                                      PixelFormat format, uint32_t flags,
64                                      const sp<IGraphicBufferProducer>& parent,
65                                      LayerMetadata metadata, sp<IBinder>* handle,
66                                      sp<IGraphicBufferProducer>* gbp, int32_t* outLayerId,
67                                      uint32_t* outTransformHint) override {
68         return callRemote<decltype(
69                 &ISurfaceComposerClient::createWithSurfaceParent)>(Tag::CREATE_WITH_SURFACE_PARENT,
70                                                                    name, width, height, format,
71                                                                    flags, parent,
72                                                                    std::move(metadata), handle, gbp,
73                                                                    outLayerId, outTransformHint);
74     }
75 
clearLayerFrameStats(const sp<IBinder> & handle) const76     status_t clearLayerFrameStats(const sp<IBinder>& handle) const override {
77         return callRemote<decltype(
78                 &ISurfaceComposerClient::clearLayerFrameStats)>(Tag::CLEAR_LAYER_FRAME_STATS,
79                                                                 handle);
80     }
81 
getLayerFrameStats(const sp<IBinder> & handle,FrameStats * outStats) const82     status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const override {
83         return callRemote<decltype(
84                 &ISurfaceComposerClient::getLayerFrameStats)>(Tag::GET_LAYER_FRAME_STATS, handle,
85                                                               outStats);
86     }
87 
mirrorSurface(const sp<IBinder> & mirrorFromHandle,sp<IBinder> * outHandle,int32_t * outLayerId)88     status_t mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle,
89                            int32_t* outLayerId) override {
90         return callRemote<decltype(&ISurfaceComposerClient::mirrorSurface)>(Tag::MIRROR_SURFACE,
91                                                                             mirrorFromHandle,
92                                                                             outHandle, outLayerId);
93     }
94 };
95 
96 // Out-of-line virtual method definition to trigger vtable emission in this
97 // translation unit (see clang warning -Wweak-vtables)
~BpSurfaceComposerClient()98 BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
99 
100 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
101 
102 // ----------------------------------------------------------------------
103 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)104 status_t BnSurfaceComposerClient::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
105                                              uint32_t flags) {
106     if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
107         return BBinder::onTransact(code, data, reply, flags);
108     }
109     auto tag = static_cast<Tag>(code);
110     switch (tag) {
111         case Tag::CREATE_SURFACE:
112             return callLocal(data, reply, &ISurfaceComposerClient::createSurface);
113         case Tag::CREATE_WITH_SURFACE_PARENT:
114             return callLocal(data, reply, &ISurfaceComposerClient::createWithSurfaceParent);
115         case Tag::CLEAR_LAYER_FRAME_STATS:
116             return callLocal(data, reply, &ISurfaceComposerClient::clearLayerFrameStats);
117         case Tag::GET_LAYER_FRAME_STATS:
118             return callLocal(data, reply, &ISurfaceComposerClient::getLayerFrameStats);
119         case Tag::MIRROR_SURFACE:
120             return callLocal(data, reply, &ISurfaceComposerClient::mirrorSurface);
121     }
122 }
123 
124 } // namespace android
125