Home | History | Annotate | Download | only in gui
      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     LAST = GET_LAYER_FRAME_STATS,
     38 };
     39 
     40 } // Anonymous namespace
     41 
     42 class BpSurfaceComposerClient : public SafeBpInterface<ISurfaceComposerClient> {
     43 public:
     44     explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
     45           : SafeBpInterface<ISurfaceComposerClient>(impl, "BpSurfaceComposerClient") {}
     46 
     47     ~BpSurfaceComposerClient() override;
     48 
     49     status_t createSurface(const String8& name, uint32_t width, uint32_t height, PixelFormat format,
     50                            uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata,
     51                            sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) override {
     52         return callRemote<decltype(&ISurfaceComposerClient::createSurface)>(Tag::CREATE_SURFACE,
     53                                                                             name, width, height,
     54                                                                             format, flags, parent,
     55                                                                             std::move(metadata),
     56                                                                             handle, gbp);
     57     }
     58 
     59     status_t createWithSurfaceParent(const String8& name, uint32_t width, uint32_t height,
     60                                      PixelFormat format, uint32_t flags,
     61                                      const sp<IGraphicBufferProducer>& parent,
     62                                      LayerMetadata metadata, sp<IBinder>* handle,
     63                                      sp<IGraphicBufferProducer>* gbp) override {
     64         return callRemote<decltype(
     65                 &ISurfaceComposerClient::createWithSurfaceParent)>(Tag::CREATE_WITH_SURFACE_PARENT,
     66                                                                    name, width, height, format,
     67                                                                    flags, parent,
     68                                                                    std::move(metadata), handle,
     69                                                                    gbp);
     70     }
     71 
     72     status_t clearLayerFrameStats(const sp<IBinder>& handle) const override {
     73         return callRemote<decltype(
     74                 &ISurfaceComposerClient::clearLayerFrameStats)>(Tag::CLEAR_LAYER_FRAME_STATS,
     75                                                                 handle);
     76     }
     77 
     78     status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const override {
     79         return callRemote<decltype(
     80                 &ISurfaceComposerClient::getLayerFrameStats)>(Tag::GET_LAYER_FRAME_STATS, handle,
     81                                                               outStats);
     82     }
     83 };
     84 
     85 // Out-of-line virtual method definition to trigger vtable emission in this
     86 // translation unit (see clang warning -Wweak-vtables)
     87 BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
     88 
     89 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
     90 
     91 // ----------------------------------------------------------------------
     92 
     93 status_t BnSurfaceComposerClient::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
     94                                              uint32_t flags) {
     95     if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
     96         return BBinder::onTransact(code, data, reply, flags);
     97     }
     98     auto tag = static_cast<Tag>(code);
     99     switch (tag) {
    100         case Tag::CREATE_SURFACE:
    101             return callLocal(data, reply, &ISurfaceComposerClient::createSurface);
    102         case Tag::CREATE_WITH_SURFACE_PARENT:
    103             return callLocal(data, reply, &ISurfaceComposerClient::createWithSurfaceParent);
    104         case Tag::CLEAR_LAYER_FRAME_STATS:
    105             return callLocal(data, reply, &ISurfaceComposerClient::clearLayerFrameStats);
    106         case Tag::GET_LAYER_FRAME_STATS:
    107             return callLocal(data, reply, &ISurfaceComposerClient::getLayerFrameStats);
    108     }
    109 }
    110 
    111 } // namespace android
    112