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"
21 #include <sys/types.h>
23 #include <binder/Parcel.h>
24 #include <binder/IMemory.h>
25 #include <binder/IPCThreadState.h>
26 #include <binder/IServiceManager.h>
28 #include <ui/DisplayInfo.h>
30 #include <surfaceflinger/ISurfaceComposer.h>
32 // ---------------------------------------------------------------------------
34 #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
35 #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
37 // ---------------------------------------------------------------------------
41 class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
44 BpSurfaceComposer(const sp<IBinder>& impl)
45 : BpInterface<ISurfaceComposer>(impl)
49 virtual sp<ISurfaceComposerClient> createConnection()
53 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
54 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
55 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
58 virtual sp<ISurfaceComposerClient> createClientConnection()
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CLIENT_CONNECTION, data, &reply);
64 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
67 virtual sp<IMemoryHeap> getCblk() const
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
72 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
75 virtual void openGlobalTransaction()
78 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
79 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
82 virtual void closeGlobalTransaction()
85 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
86 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
89 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
92 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
94 data.writeInt32(flags);
95 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
96 return reply.readInt32();
99 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
102 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
103 data.writeInt32(dpy);
104 data.writeInt32(flags);
105 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
106 return reply.readInt32();
109 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
112 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
113 data.writeInt32(dpy);
114 data.writeInt32(orientation);
115 data.writeInt32(flags);
116 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
117 return reply.readInt32();
120 virtual void bootFinished()
123 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
124 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
127 virtual status_t captureScreen(DisplayID dpy,
128 sp<IMemoryHeap>* heap,
129 uint32_t* width, uint32_t* height, PixelFormat* format,
130 uint32_t reqWidth, uint32_t reqHeight)
133 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
134 data.writeInt32(dpy);
135 data.writeInt32(reqWidth);
136 data.writeInt32(reqHeight);
137 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
138 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
139 *width = reply.readInt32();
140 *height = reply.readInt32();
141 *format = reply.readInt32();
142 return reply.readInt32();
145 virtual status_t turnElectronBeamOff(int32_t mode)
148 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
149 data.writeInt32(mode);
150 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
151 return reply.readInt32();
154 virtual status_t turnElectronBeamOn(int32_t mode)
157 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
158 data.writeInt32(mode);
159 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply);
160 return reply.readInt32();
163 virtual void signal() const
166 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
167 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
171 IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
173 // ----------------------------------------------------------------------
175 status_t BnSurfaceComposer::onTransact(
176 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
179 case CREATE_CONNECTION: {
180 CHECK_INTERFACE(ISurfaceComposer, data, reply);
181 sp<IBinder> b = createConnection()->asBinder();
182 reply->writeStrongBinder(b);
184 case CREATE_CLIENT_CONNECTION: {
185 CHECK_INTERFACE(ISurfaceComposer, data, reply);
186 sp<IBinder> b = createClientConnection()->asBinder();
187 reply->writeStrongBinder(b);
189 case OPEN_GLOBAL_TRANSACTION: {
190 CHECK_INTERFACE(ISurfaceComposer, data, reply);
191 openGlobalTransaction();
193 case CLOSE_GLOBAL_TRANSACTION: {
194 CHECK_INTERFACE(ISurfaceComposer, data, reply);
195 closeGlobalTransaction();
197 case SET_ORIENTATION: {
198 CHECK_INTERFACE(ISurfaceComposer, data, reply);
199 DisplayID dpy = data.readInt32();
200 int orientation = data.readInt32();
201 uint32_t flags = data.readInt32();
202 reply->writeInt32( setOrientation(dpy, orientation, flags) );
204 case FREEZE_DISPLAY: {
205 CHECK_INTERFACE(ISurfaceComposer, data, reply);
206 DisplayID dpy = data.readInt32();
207 uint32_t flags = data.readInt32();
208 reply->writeInt32( freezeDisplay(dpy, flags) );
210 case UNFREEZE_DISPLAY: {
211 CHECK_INTERFACE(ISurfaceComposer, data, reply);
212 DisplayID dpy = data.readInt32();
213 uint32_t flags = data.readInt32();
214 reply->writeInt32( unfreezeDisplay(dpy, flags) );
216 case BOOT_FINISHED: {
217 CHECK_INTERFACE(ISurfaceComposer, data, reply);
221 CHECK_INTERFACE(ISurfaceComposer, data, reply);
225 CHECK_INTERFACE(ISurfaceComposer, data, reply);
226 sp<IBinder> b = getCblk()->asBinder();
227 reply->writeStrongBinder(b);
229 case CAPTURE_SCREEN: {
230 CHECK_INTERFACE(ISurfaceComposer, data, reply);
231 DisplayID dpy = data.readInt32();
232 uint32_t reqWidth = data.readInt32();
233 uint32_t reqHeight = data.readInt32();
234 sp<IMemoryHeap> heap;
237 status_t res = captureScreen(dpy, &heap, &w, &h, &f,
238 reqWidth, reqHeight);
239 reply->writeStrongBinder(heap->asBinder());
240 reply->writeInt32(w);
241 reply->writeInt32(h);
242 reply->writeInt32(f);
243 reply->writeInt32(res);
245 case TURN_ELECTRON_BEAM_OFF: {
246 CHECK_INTERFACE(ISurfaceComposer, data, reply);
247 int32_t mode = data.readInt32();
248 status_t res = turnElectronBeamOff(mode);
249 reply->writeInt32(res);
251 case TURN_ELECTRON_BEAM_ON: {
252 CHECK_INTERFACE(ISurfaceComposer, data, reply);
253 int32_t mode = data.readInt32();
254 status_t res = turnElectronBeamOn(mode);
255 reply->writeInt32(res);
258 return BBinder::onTransact(code, data, reply, flags);
263 // ----------------------------------------------------------------------------