2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 // tag as surfaceflinger
18 #define LOG_TAG "SurfaceFlinger"
22 #include <sys/types.h>
24 #include <binder/Parcel.h>
25 #include <binder/IMemory.h>
26 #include <binder/IPCThreadState.h>
27 #include <binder/IServiceManager.h>
32 #include <gui/IGraphicBufferProducer.h>
33 #include <gui/ISurfaceComposerClient.h>
34 #include <private/gui/LayerState.h>
36 // ---------------------------------------------------------------------------
41 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
43 CLEAR_LAYER_FRAME_STATS,
44 GET_LAYER_FRAME_STATS,
45 GET_TRANSFORM_TO_DISPLAY_INVERSE
48 class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
51 BpSurfaceComposerClient(const sp<IBinder>& impl)
52 : BpInterface<ISurfaceComposerClient>(impl) {
55 virtual ~BpSurfaceComposerClient();
57 virtual status_t createSurface(const String8& name, uint32_t width,
58 uint32_t height, PixelFormat format, uint32_t flags,
60 sp<IGraphicBufferProducer>* gbp) {
62 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
63 data.writeString8(name);
64 data.writeUint32(width);
65 data.writeUint32(height);
66 data.writeInt32(static_cast<int32_t>(format));
67 data.writeUint32(flags);
68 remote()->transact(CREATE_SURFACE, data, &reply);
69 *handle = reply.readStrongBinder();
70 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
71 return reply.readInt32();
74 virtual status_t destroySurface(const sp<IBinder>& handle) {
76 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
77 data.writeStrongBinder(handle);
78 remote()->transact(DESTROY_SURFACE, data, &reply);
79 return reply.readInt32();
82 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
84 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
85 data.writeStrongBinder(handle);
86 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
87 return reply.readInt32();
90 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
92 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
93 data.writeStrongBinder(handle);
94 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
95 reply.read(*outStats);
96 return reply.readInt32();
99 virtual status_t getTransformToDisplayInverse(const sp<IBinder>& handle,
100 bool* outTransformToDisplayInverse) const {
103 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
104 if (result != NO_ERROR) {
107 result = data.writeStrongBinder(handle);
108 if (result != NO_ERROR) {
111 result = remote()->transact(GET_TRANSFORM_TO_DISPLAY_INVERSE, data, &reply);
112 if (result != NO_ERROR) {
115 int transformInverse;
116 result = reply.readInt32(&transformInverse);
117 if (result != NO_ERROR) {
120 *outTransformToDisplayInverse = transformInverse != 0 ? true : false;
121 status_t result2 = reply.readInt32(&result);
122 if (result2 != NO_ERROR) {
129 // Out-of-line virtual method definition to trigger vtable emission in this
130 // translation unit (see clang warning -Wweak-vtables)
131 BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
133 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
135 // ----------------------------------------------------------------------
137 status_t BnSurfaceComposerClient::onTransact(
138 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
141 case CREATE_SURFACE: {
142 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
143 String8 name = data.readString8();
144 uint32_t width = data.readUint32();
145 uint32_t height = data.readUint32();
146 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
147 uint32_t createFlags = data.readUint32();
149 sp<IGraphicBufferProducer> gbp;
150 status_t result = createSurface(name, width, height, format,
151 createFlags, &handle, &gbp);
152 reply->writeStrongBinder(handle);
153 reply->writeStrongBinder(IInterface::asBinder(gbp));
154 reply->writeInt32(result);
157 case DESTROY_SURFACE: {
158 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
159 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
162 case CLEAR_LAYER_FRAME_STATS: {
163 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
164 sp<IBinder> handle = data.readStrongBinder();
165 status_t result = clearLayerFrameStats(handle);
166 reply->writeInt32(result);
169 case GET_LAYER_FRAME_STATS: {
170 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
171 sp<IBinder> handle = data.readStrongBinder();
173 status_t result = getLayerFrameStats(handle, &stats);
175 reply->writeInt32(result);
178 case GET_TRANSFORM_TO_DISPLAY_INVERSE: {
179 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
181 status_t result = data.readStrongBinder(&handle);
182 if (result != NO_ERROR) {
185 bool transformInverse = false;
186 result = getTransformToDisplayInverse(handle, &transformInverse);
187 if (result != NO_ERROR) {
190 result = reply->writeInt32(transformInverse ? 1 : 0);
191 if (result != NO_ERROR) {
194 result = reply->writeInt32(NO_ERROR);
198 return BBinder::onTransact(code, data, reply, flags);
202 }; // namespace android