blob: b2036dcadbde368cec430be640e04b6cd73cd19d [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
20#include <stdio.h>
21#include <stdint.h>
22#include <sys/types.h>
23
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
25#include <binder/IMemory.h>
26#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <ui/Point.h>
30#include <ui/Rect.h>
31
Mathias Agopian4d9b8222013-03-12 17:11:48 -070032#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080033#include <gui/ISurfaceComposerClient.h>
34#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40enum {
Mathias Agopiana67932f2011-04-20 14:20:59 -070041 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Svetoslavd85084b2014-03-20 10:28:31 -070042 DESTROY_SURFACE,
43 CLEAR_LAYER_FRAME_STATS,
Robert Carr367c5682016-06-20 11:55:28 -070044 GET_LAYER_FRAME_STATS,
45 GET_TRANSFORM_TO_DISPLAY_INVERSE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046};
47
Mathias Agopian7e27f052010-05-28 14:22:23 -070048class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049{
50public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070051 explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
Mathias Agopian4d9b8222013-03-12 17:11:48 -070052 : BpInterface<ISurfaceComposerClient>(impl) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 }
54
Dan Stozad723bd72014-11-18 10:24:03 -080055 virtual ~BpSurfaceComposerClient();
56
57 virtual status_t createSurface(const String8& name, uint32_t width,
58 uint32_t height, PixelFormat format, uint32_t flags,
Robert Carr1f0a16a2016-10-24 16:27:39 -070059 const sp<IBinder>& parent, sp<IBinder>* handle,
Mathias Agopian4d9b8222013-03-12 17:11:48 -070060 sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070062 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080063 data.writeString8(name);
Dan Stozad723bd72014-11-18 10:24:03 -080064 data.writeUint32(width);
65 data.writeUint32(height);
66 data.writeInt32(static_cast<int32_t>(format));
67 data.writeUint32(flags);
Robert Carr1f0a16a2016-10-24 16:27:39 -070068 if (parent != nullptr) {
69 data.writeStrongBinder(parent);
70 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070072 *handle = reply.readStrongBinder();
73 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
74 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070076
Mathias Agopian4d9b8222013-03-12 17:11:48 -070077 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070079 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080080 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 remote()->transact(DESTROY_SURFACE, data, &reply);
82 return reply.readInt32();
83 }
Svetoslavd85084b2014-03-20 10:28:31 -070084
85 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
86 Parcel data, reply;
87 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
88 data.writeStrongBinder(handle);
89 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
90 return reply.readInt32();
91 }
92
93 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
94 Parcel data, reply;
95 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
96 data.writeStrongBinder(handle);
97 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
98 reply.read(*outStats);
99 return reply.readInt32();
100 }
Robert Carr367c5682016-06-20 11:55:28 -0700101
102 virtual status_t getTransformToDisplayInverse(const sp<IBinder>& handle,
103 bool* outTransformToDisplayInverse) const {
104 Parcel data, reply;
105 status_t result =
106 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
107 if (result != NO_ERROR) {
108 return result;
109 }
110 result = data.writeStrongBinder(handle);
111 if (result != NO_ERROR) {
112 return result;
113 }
114 result = remote()->transact(GET_TRANSFORM_TO_DISPLAY_INVERSE, data, &reply);
115 if (result != NO_ERROR) {
116 return result;
117 }
118 int transformInverse;
119 result = reply.readInt32(&transformInverse);
120 if (result != NO_ERROR) {
121 return result;
122 }
123 *outTransformToDisplayInverse = transformInverse != 0 ? true : false;
124 status_t result2 = reply.readInt32(&result);
125 if (result2 != NO_ERROR) {
126 return result2;
127 }
128 return result;
129 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130};
131
Dan Stozad723bd72014-11-18 10:24:03 -0800132// Out-of-line virtual method definition to trigger vtable emission in this
133// translation unit (see clang warning -Wweak-vtables)
134BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
135
Mathias Agopian7e27f052010-05-28 14:22:23 -0700136IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137
138// ----------------------------------------------------------------------
139
Mathias Agopian7e27f052010-05-28 14:22:23 -0700140status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
142{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 switch(code) {
144 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700145 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800146 String8 name = data.readString8();
Dan Stozad723bd72014-11-18 10:24:03 -0800147 uint32_t width = data.readUint32();
148 uint32_t height = data.readUint32();
149 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
150 uint32_t createFlags = data.readUint32();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700151 sp<IBinder> parent = nullptr;
152 if (data.dataAvail() > 0) {
153 parent = data.readStrongBinder();
154 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700155 sp<IBinder> handle;
156 sp<IGraphicBufferProducer> gbp;
Dan Stozad723bd72014-11-18 10:24:03 -0800157 status_t result = createSurface(name, width, height, format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700158 createFlags, parent, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700159 reply->writeStrongBinder(handle);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800160 reply->writeStrongBinder(IInterface::asBinder(gbp));
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700161 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800163 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800164 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700165 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Svetoslavd85084b2014-03-20 10:28:31 -0700166 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
167 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800168 }
Svetoslavd85084b2014-03-20 10:28:31 -0700169 case CLEAR_LAYER_FRAME_STATS: {
170 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
171 sp<IBinder> handle = data.readStrongBinder();
172 status_t result = clearLayerFrameStats(handle);
173 reply->writeInt32(result);
174 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800175 }
Svetoslavd85084b2014-03-20 10:28:31 -0700176 case GET_LAYER_FRAME_STATS: {
177 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
178 sp<IBinder> handle = data.readStrongBinder();
179 FrameStats stats;
180 status_t result = getLayerFrameStats(handle, &stats);
181 reply->write(stats);
182 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800184 }
Robert Carr367c5682016-06-20 11:55:28 -0700185 case GET_TRANSFORM_TO_DISPLAY_INVERSE: {
186 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
187 sp<IBinder> handle;
188 status_t result = data.readStrongBinder(&handle);
189 if (result != NO_ERROR) {
190 return result;
191 }
192 bool transformInverse = false;
193 result = getTransformToDisplayInverse(handle, &transformInverse);
194 if (result != NO_ERROR) {
195 return result;
196 }
197 result = reply->writeInt32(transformInverse ? 1 : 0);
198 if (result != NO_ERROR) {
199 return result;
200 }
201 result = reply->writeInt32(NO_ERROR);
202 return result;
203 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 default:
205 return BBinder::onTransact(code, data, reply, flags);
206 }
207}
208
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800209}; // namespace android