blob: b98e48b52a8a6aabbcfdcc52ea0764fd5a3ef427 [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
Dan Stoza0fe41e52017-04-03 15:16:27 -070020#include <gui/ISurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
Dan Stoza0fe41e52017-04-03 15:16:27 -070022#include <gui/IGraphicBufferProducer.h>
23
Dan Stozaa615e472017-03-23 14:41:55 -070024#include <binder/SafeInterface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
Dan Stozaa615e472017-03-23 14:41:55 -070026#include <ui/FrameStats.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028namespace android {
29
Dan Stoza0fe41e52017-04-03 15:16:27 -070030namespace { // Anonymous
31
32enum class Tag : uint32_t {
33 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Marissa Wall35187b32019-01-08 10:08:52 -080034 CREATE_WITH_SURFACE_PARENT,
Dan Stoza0fe41e52017-04-03 15:16:27 -070035 CLEAR_LAYER_FRAME_STATS,
36 GET_LAYER_FRAME_STATS,
chaviwfe94a222019-08-21 13:52:59 -070037 MIRROR_SURFACE,
38 LAST = MIRROR_SURFACE,
Dan Stoza0fe41e52017-04-03 15:16:27 -070039};
40
41} // Anonymous namespace
42
Dan Stozaa615e472017-03-23 14:41:55 -070043class BpSurfaceComposerClient : public SafeBpInterface<ISurfaceComposerClient> {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070045 explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
Dan Stozaa615e472017-03-23 14:41:55 -070046 : 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 Rosky1f6d6d52018-12-06 10:47:26 -080051 uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata,
52 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) override {
Dan Stoza0fe41e52017-04-03 15:16:27 -070053 return callRemote<decltype(&ISurfaceComposerClient::createSurface)>(Tag::CREATE_SURFACE,
Dan Stozaa615e472017-03-23 14:41:55 -070054 name, width, height,
55 format, flags, parent,
Evan Rosky1f6d6d52018-12-06 10:47:26 -080056 std::move(metadata),
Dan Stozaa615e472017-03-23 14:41:55 -070057 handle, gbp);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 }
59
Marissa Wall35187b32019-01-08 10:08:52 -080060 status_t createWithSurfaceParent(const String8& name, uint32_t width, uint32_t height,
61 PixelFormat format, uint32_t flags,
Evan Rosky1f6d6d52018-12-06 10:47:26 -080062 const sp<IGraphicBufferProducer>& parent,
63 LayerMetadata metadata, sp<IBinder>* handle,
Marissa Wall35187b32019-01-08 10:08:52 -080064 sp<IGraphicBufferProducer>* gbp) override {
65 return callRemote<decltype(
66 &ISurfaceComposerClient::createWithSurfaceParent)>(Tag::CREATE_WITH_SURFACE_PARENT,
67 name, width, height, format,
Evan Rosky1f6d6d52018-12-06 10:47:26 -080068 flags, parent,
69 std::move(metadata), handle,
70 gbp);
Marissa Wall35187b32019-01-08 10:08:52 -080071 }
72
Dan Stozaa615e472017-03-23 14:41:55 -070073 status_t clearLayerFrameStats(const sp<IBinder>& handle) const override {
74 return callRemote<decltype(
Dan Stoza0fe41e52017-04-03 15:16:27 -070075 &ISurfaceComposerClient::clearLayerFrameStats)>(Tag::CLEAR_LAYER_FRAME_STATS,
76 handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 }
Svetoslavd85084b2014-03-20 10:28:31 -070078
Dan Stozaa615e472017-03-23 14:41:55 -070079 status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const override {
80 return callRemote<decltype(
Dan Stoza0fe41e52017-04-03 15:16:27 -070081 &ISurfaceComposerClient::getLayerFrameStats)>(Tag::GET_LAYER_FRAME_STATS, handle,
Dan Stozaa615e472017-03-23 14:41:55 -070082 outStats);
Svetoslavd85084b2014-03-20 10:28:31 -070083 }
chaviwfe94a222019-08-21 13:52:59 -070084
85 status_t mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle) override {
86 return callRemote<decltype(&ISurfaceComposerClient::mirrorSurface)>(Tag::MIRROR_SURFACE,
87 mirrorFromHandle,
88 outHandle);
89 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090};
91
Dan Stozad723bd72014-11-18 10:24:03 -080092// Out-of-line virtual method definition to trigger vtable emission in this
93// translation unit (see clang warning -Wweak-vtables)
94BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
95
Mathias Agopian7e27f052010-05-28 14:22:23 -070096IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097
98// ----------------------------------------------------------------------
99
Dan Stozaa615e472017-03-23 14:41:55 -0700100status_t BnSurfaceComposerClient::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
101 uint32_t flags) {
Dan Stoza0fe41e52017-04-03 15:16:27 -0700102 if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
Dan Stozaa615e472017-03-23 14:41:55 -0700103 return BBinder::onTransact(code, data, reply, flags);
104 }
105 auto tag = static_cast<Tag>(code);
106 switch (tag) {
Dan Stoza0fe41e52017-04-03 15:16:27 -0700107 case Tag::CREATE_SURFACE:
Dan Stozaa615e472017-03-23 14:41:55 -0700108 return callLocal(data, reply, &ISurfaceComposerClient::createSurface);
Marissa Wall35187b32019-01-08 10:08:52 -0800109 case Tag::CREATE_WITH_SURFACE_PARENT:
110 return callLocal(data, reply, &ISurfaceComposerClient::createWithSurfaceParent);
Dan Stoza0fe41e52017-04-03 15:16:27 -0700111 case Tag::CLEAR_LAYER_FRAME_STATS:
Dan Stozaa615e472017-03-23 14:41:55 -0700112 return callLocal(data, reply, &ISurfaceComposerClient::clearLayerFrameStats);
Dan Stoza0fe41e52017-04-03 15:16:27 -0700113 case Tag::GET_LAYER_FRAME_STATS:
Dan Stozaa615e472017-03-23 14:41:55 -0700114 return callLocal(data, reply, &ISurfaceComposerClient::getLayerFrameStats);
chaviwfe94a222019-08-21 13:52:59 -0700115 case Tag::MIRROR_SURFACE:
116 return callLocal(data, reply, &ISurfaceComposerClient::mirrorSurface);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 }
118}
119
Dan Stozaa615e472017-03-23 14:41:55 -0700120} // namespace android