The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 20 | #include <gui/ISurfaceComposerClient.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 22 | #include <gui/IGraphicBufferProducer.h> |
| 23 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 24 | #include <binder/SafeInterface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 26 | #include <ui/FrameStats.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 30 | namespace { // Anonymous |
| 31 | |
| 32 | enum class Tag : uint32_t { |
| 33 | CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION, |
Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 34 | CREATE_WITH_SURFACE_PARENT, |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 35 | CLEAR_LAYER_FRAME_STATS, |
| 36 | GET_LAYER_FRAME_STATS, |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 37 | MIRROR_SURFACE, |
| 38 | LAST = MIRROR_SURFACE, |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // Anonymous namespace |
| 42 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 43 | class BpSurfaceComposerClient : public SafeBpInterface<ISurfaceComposerClient> { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 45 | explicit BpSurfaceComposerClient(const sp<IBinder>& impl) |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 46 | : SafeBpInterface<ISurfaceComposerClient>(impl, "BpSurfaceComposerClient") {} |
| 47 | |
| 48 | ~BpSurfaceComposerClient() override; |
| 49 | |
| 50 | status_t createSurface(const String8& name, uint32_t width, uint32_t height, PixelFormat format, |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 51 | uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata, |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 52 | sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, |
| 53 | uint32_t* outTransformHint) override { |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 54 | return callRemote<decltype(&ISurfaceComposerClient::createSurface)>(Tag::CREATE_SURFACE, |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 55 | name, width, height, |
| 56 | format, flags, parent, |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 57 | std::move(metadata), |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 58 | handle, gbp, |
| 59 | outTransformHint); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 62 | status_t createWithSurfaceParent(const String8& name, uint32_t width, uint32_t height, |
| 63 | PixelFormat format, uint32_t flags, |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 64 | const sp<IGraphicBufferProducer>& parent, |
| 65 | LayerMetadata metadata, sp<IBinder>* handle, |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 66 | sp<IGraphicBufferProducer>* gbp, |
| 67 | uint32_t* outTransformHint) override { |
Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 68 | return callRemote<decltype( |
| 69 | &ISurfaceComposerClient::createWithSurfaceParent)>(Tag::CREATE_WITH_SURFACE_PARENT, |
| 70 | name, width, height, format, |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 71 | flags, parent, |
Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 72 | std::move(metadata), handle, gbp, |
| 73 | outTransformHint); |
Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 76 | status_t clearLayerFrameStats(const sp<IBinder>& handle) const override { |
| 77 | return callRemote<decltype( |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 78 | &ISurfaceComposerClient::clearLayerFrameStats)>(Tag::CLEAR_LAYER_FRAME_STATS, |
| 79 | handle); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 81 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 82 | status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const override { |
| 83 | return callRemote<decltype( |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 84 | &ISurfaceComposerClient::getLayerFrameStats)>(Tag::GET_LAYER_FRAME_STATS, handle, |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 85 | outStats); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 86 | } |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 87 | |
| 88 | status_t mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle) override { |
| 89 | return callRemote<decltype(&ISurfaceComposerClient::mirrorSurface)>(Tag::MIRROR_SURFACE, |
| 90 | mirrorFromHandle, |
| 91 | outHandle); |
| 92 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 95 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 96 | // translation unit (see clang warning -Wweak-vtables) |
| 97 | BpSurfaceComposerClient::~BpSurfaceComposerClient() {} |
| 98 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 99 | IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | // ---------------------------------------------------------------------- |
| 102 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 103 | status_t BnSurfaceComposerClient::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 104 | uint32_t flags) { |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 105 | if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 106 | return BBinder::onTransact(code, data, reply, flags); |
| 107 | } |
| 108 | auto tag = static_cast<Tag>(code); |
| 109 | switch (tag) { |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 110 | case Tag::CREATE_SURFACE: |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 111 | return callLocal(data, reply, &ISurfaceComposerClient::createSurface); |
Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 112 | case Tag::CREATE_WITH_SURFACE_PARENT: |
| 113 | return callLocal(data, reply, &ISurfaceComposerClient::createWithSurfaceParent); |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 114 | case Tag::CLEAR_LAYER_FRAME_STATS: |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 115 | return callLocal(data, reply, &ISurfaceComposerClient::clearLayerFrameStats); |
Dan Stoza | 0fe41e5 | 2017-04-03 15:16:27 -0700 | [diff] [blame] | 116 | case Tag::GET_LAYER_FRAME_STATS: |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 117 | return callLocal(data, reply, &ISurfaceComposerClient::getLayerFrameStats); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 118 | case Tag::MIRROR_SURFACE: |
| 119 | return callLocal(data, reply, &ISurfaceComposerClient::mirrorSurface); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Dan Stoza | a615e47 | 2017-03-23 14:41:55 -0700 | [diff] [blame] | 123 | } // namespace android |