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 ~BpSurfaceComposerClient();
56 virtual status_t createSurface(const String8& name, uint32_t width,
57 uint32_t height, PixelFormat format, uint32_t flags,
59 sp<IGraphicBufferProducer>* gbp) {
61 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
62 data.writeString8(name);
63 data.writeUint32(width);
64 data.writeUint32(height);
65 data.writeInt32(static_cast<int32_t>(format));
66 data.writeUint32(flags);
67 remote()->transact(CREATE_SURFACE, data, &reply);
68 *handle = reply.readStrongBinder();
69 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
70 return reply.readInt32();
73 virtual status_t destroySurface(const sp<IBinder>& handle) {
75 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
76 data.writeStrongBinder(handle);
77 remote()->transact(DESTROY_SURFACE, data, &reply);
78 return reply.readInt32();
81 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
83 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
84 data.writeStrongBinder(handle);
85 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
86 return reply.readInt32();
89 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
91 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
92 data.writeStrongBinder(handle);
93 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
94 reply.read(*outStats);
95 return reply.readInt32();
99 // Out-of-line virtual method definition to trigger vtable emission in this
100 // translation unit (see clang warning -Wweak-vtables)
101 BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
103 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
105 // ----------------------------------------------------------------------
107 status_t BnSurfaceComposerClient::onTransact(
108 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
111 case CREATE_SURFACE: {
112 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
113 String8 name = data.readString8();
114 uint32_t width = data.readUint32();
115 uint32_t height = data.readUint32();
116 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
117 uint32_t createFlags = data.readUint32();
119 sp<IGraphicBufferProducer> gbp;
120 status_t result = createSurface(name, width, height, format,
121 createFlags, &handle, &gbp);
122 reply->writeStrongBinder(handle);
123 reply->writeStrongBinder(IInterface::asBinder(gbp));
124 reply->writeInt32(result);
127 case DESTROY_SURFACE: {
128 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
129 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
132 case CLEAR_LAYER_FRAME_STATS: {
133 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
134 sp<IBinder> handle = data.readStrongBinder();
135 status_t result = clearLayerFrameStats(handle);
136 reply->writeInt32(result);
139 case GET_LAYER_FRAME_STATS: {
140 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
141 sp<IBinder> handle = data.readStrongBinder();
143 status_t result = getLayerFrameStats(handle, &stats);
145 reply->writeInt32(result);
149 return BBinder::onTransact(code, data, reply, flags);
153 }; // namespace android