blob: db8a517d4d0e6e27919ee5ff5f64dd108566ea13 [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>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070025#include <binder/IPCThreadState.h>
26#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <ui/Point.h>
29#include <ui/Rect.h>
30
Mathias Agopian4d9b8222013-03-12 17:11:48 -070031#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080032#include <gui/ISurfaceComposerClient.h>
33#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
35// ---------------------------------------------------------------------------
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
39enum {
Mathias Agopiana67932f2011-04-20 14:20:59 -070040 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Svetoslavd85084b2014-03-20 10:28:31 -070041 DESTROY_SURFACE,
42 CLEAR_LAYER_FRAME_STATS,
Robert Carr367c5682016-06-20 11:55:28 -070043 GET_LAYER_FRAME_STATS,
44 GET_TRANSFORM_TO_DISPLAY_INVERSE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045};
46
Mathias Agopian7e27f052010-05-28 14:22:23 -070047class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048{
49public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070050 explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
Mathias Agopian4d9b8222013-03-12 17:11:48 -070051 : BpInterface<ISurfaceComposerClient>(impl) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 }
53
Dan Stozad723bd72014-11-18 10:24:03 -080054 virtual ~BpSurfaceComposerClient();
55
56 virtual status_t createSurface(const String8& name, uint32_t width,
57 uint32_t height, PixelFormat format, uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -050058 const sp<IBinder>& parent, uint32_t windowType, uint32_t ownerUid,
59 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080062 data.writeString8(name);
Dan Stozad723bd72014-11-18 10:24:03 -080063 data.writeUint32(width);
64 data.writeUint32(height);
65 data.writeInt32(static_cast<int32_t>(format));
66 data.writeUint32(flags);
Albert Chaulk479c60c2017-01-27 14:21:34 -050067 data.writeUint32(windowType);
68 data.writeUint32(ownerUid);
Robert Carr1f0a16a2016-10-24 16:27:39 -070069 if (parent != nullptr) {
70 data.writeStrongBinder(parent);
71 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070073 *handle = reply.readStrongBinder();
74 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
75 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070077
Mathias Agopian4d9b8222013-03-12 17:11:48 -070078 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070080 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080081 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 remote()->transact(DESTROY_SURFACE, data, &reply);
83 return reply.readInt32();
84 }
Svetoslavd85084b2014-03-20 10:28:31 -070085
86 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
87 Parcel data, reply;
88 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
89 data.writeStrongBinder(handle);
90 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
91 return reply.readInt32();
92 }
93
94 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
95 Parcel data, reply;
96 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
97 data.writeStrongBinder(handle);
98 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
99 reply.read(*outStats);
100 return reply.readInt32();
101 }
Robert Carr367c5682016-06-20 11:55:28 -0700102
103 virtual status_t getTransformToDisplayInverse(const sp<IBinder>& handle,
104 bool* outTransformToDisplayInverse) const {
105 Parcel data, reply;
106 status_t result =
107 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
108 if (result != NO_ERROR) {
109 return result;
110 }
111 result = data.writeStrongBinder(handle);
112 if (result != NO_ERROR) {
113 return result;
114 }
115 result = remote()->transact(GET_TRANSFORM_TO_DISPLAY_INVERSE, data, &reply);
116 if (result != NO_ERROR) {
117 return result;
118 }
119 int transformInverse;
120 result = reply.readInt32(&transformInverse);
121 if (result != NO_ERROR) {
122 return result;
123 }
124 *outTransformToDisplayInverse = transformInverse != 0 ? true : false;
125 status_t result2 = reply.readInt32(&result);
126 if (result2 != NO_ERROR) {
127 return result2;
128 }
129 return result;
130 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131};
132
Dan Stozad723bd72014-11-18 10:24:03 -0800133// Out-of-line virtual method definition to trigger vtable emission in this
134// translation unit (see clang warning -Wweak-vtables)
135BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
136
Mathias Agopian7e27f052010-05-28 14:22:23 -0700137IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138
139// ----------------------------------------------------------------------
140
Mathias Agopian7e27f052010-05-28 14:22:23 -0700141status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
143{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 switch(code) {
145 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700146 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800147 String8 name = data.readString8();
Dan Stozad723bd72014-11-18 10:24:03 -0800148 uint32_t width = data.readUint32();
149 uint32_t height = data.readUint32();
150 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
151 uint32_t createFlags = data.readUint32();
Albert Chaulk479c60c2017-01-27 14:21:34 -0500152 uint32_t windowType = data.readUint32();
153 uint32_t ownerUid = data.readUint32();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700154 sp<IBinder> parent = nullptr;
155 if (data.dataAvail() > 0) {
156 parent = data.readStrongBinder();
157 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700158 sp<IBinder> handle;
159 sp<IGraphicBufferProducer> gbp;
Dan Stozad723bd72014-11-18 10:24:03 -0800160 status_t result = createSurface(name, width, height, format,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500161 createFlags, parent, windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700162 reply->writeStrongBinder(handle);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800163 reply->writeStrongBinder(IInterface::asBinder(gbp));
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700164 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800166 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700168 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Svetoslavd85084b2014-03-20 10:28:31 -0700169 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
170 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800171 }
Svetoslavd85084b2014-03-20 10:28:31 -0700172 case CLEAR_LAYER_FRAME_STATS: {
173 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
174 sp<IBinder> handle = data.readStrongBinder();
175 status_t result = clearLayerFrameStats(handle);
176 reply->writeInt32(result);
177 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800178 }
Svetoslavd85084b2014-03-20 10:28:31 -0700179 case GET_LAYER_FRAME_STATS: {
180 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
181 sp<IBinder> handle = data.readStrongBinder();
182 FrameStats stats;
183 status_t result = getLayerFrameStats(handle, &stats);
184 reply->write(stats);
185 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800187 }
Robert Carr367c5682016-06-20 11:55:28 -0700188 case GET_TRANSFORM_TO_DISPLAY_INVERSE: {
189 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
190 sp<IBinder> handle;
191 status_t result = data.readStrongBinder(&handle);
192 if (result != NO_ERROR) {
193 return result;
194 }
195 bool transformInverse = false;
196 result = getTransformToDisplayInverse(handle, &transformInverse);
197 if (result != NO_ERROR) {
198 return result;
199 }
200 result = reply->writeInt32(transformInverse ? 1 : 0);
201 if (result != NO_ERROR) {
202 return result;
203 }
204 result = reply->writeInt32(NO_ERROR);
205 return result;
206 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207 default:
208 return BBinder::onTransact(code, data, reply, flags);
209 }
210}
211
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212}; // namespace android