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,
47 class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
50 BpSurfaceComposerClient(const sp<IBinder>& impl)
51 : BpInterface<ISurfaceComposerClient>(impl) {
54 virtual status_t createSurface(const String8& name, uint32_t w,
55 uint32_t h, PixelFormat format, uint32_t flags,
57 sp<IGraphicBufferProducer>* gbp) {
59 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
60 data.writeString8(name);
63 data.writeInt32(format);
64 data.writeInt32(flags);
65 remote()->transact(CREATE_SURFACE, data, &reply);
66 *handle = reply.readStrongBinder();
67 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
68 return reply.readInt32();
71 virtual status_t destroySurface(const sp<IBinder>& handle) {
73 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
74 data.writeStrongBinder(handle);
75 remote()->transact(DESTROY_SURFACE, data, &reply);
76 return reply.readInt32();
79 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
81 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
82 data.writeStrongBinder(handle);
83 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
84 return reply.readInt32();
87 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
89 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
90 data.writeStrongBinder(handle);
91 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
92 reply.read(*outStats);
93 return reply.readInt32();
97 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
99 // ----------------------------------------------------------------------
101 status_t BnSurfaceComposerClient::onTransact(
102 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
105 case CREATE_SURFACE: {
106 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
107 String8 name = data.readString8();
108 uint32_t w = data.readInt32();
109 uint32_t h = data.readInt32();
110 PixelFormat format = data.readInt32();
111 uint32_t flags = data.readInt32();
113 sp<IGraphicBufferProducer> gbp;
114 status_t result = createSurface(name, w, h, format, flags,
116 reply->writeStrongBinder(handle);
117 reply->writeStrongBinder(gbp->asBinder());
118 reply->writeInt32(result);
121 case DESTROY_SURFACE: {
122 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
123 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
126 case CLEAR_LAYER_FRAME_STATS: {
127 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
128 sp<IBinder> handle = data.readStrongBinder();
129 status_t result = clearLayerFrameStats(handle);
130 reply->writeInt32(result);
133 case GET_LAYER_FRAME_STATS: {
134 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
135 sp<IBinder> handle = data.readStrongBinder();
137 status_t result = getLayerFrameStats(handle, &stats);
139 reply->writeInt32(result);
143 return BBinder::onTransact(code, data, reply, flags);
147 }; // namespace android