blob: 22168244c853c98b02ffd8c11ebc81dd4e6ceae5 [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 <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
24#include <binder/IMemory.h>
25#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/DisplayInfo.h>
29
Mathias Agopian9cce3252010-02-09 17:46:37 -080030#include <surfaceflinger/ISurfaceComposer.h>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032// ---------------------------------------------------------------------------
33
34#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
35#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
36
37// ---------------------------------------------------------------------------
38
39namespace android {
40
41class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
42{
43public:
44 BpSurfaceComposer(const sp<IBinder>& impl)
45 : BpInterface<ISurfaceComposer>(impl)
46 {
47 }
48
Mathias Agopian7e27f052010-05-28 14:22:23 -070049 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 {
51 uint32_t n;
52 Parcel data, reply;
53 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
54 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070055 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056 }
57
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 virtual sp<ISurfaceComposerClient> createClientConnection()
59 {
60 uint32_t n;
61 Parcel data, reply;
62 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
63 remote()->transact(BnSurfaceComposer::CREATE_CLIENT_CONNECTION, data, &reply);
64 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
65 }
66
Jamie Gennis9a78c902011-01-12 18:30:40 -080067 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
68 {
69 uint32_t n;
70 Parcel data, reply;
71 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
72 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
73 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
74 }
75
Mathias Agopian7303c6b2009-07-02 18:11:53 -070076 virtual sp<IMemoryHeap> getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 {
78 Parcel data, reply;
79 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
80 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
Mathias Agopian7303c6b2009-07-02 18:11:53 -070081 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 }
83
84 virtual void openGlobalTransaction()
85 {
86 Parcel data, reply;
87 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
88 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
89 }
90
91 virtual void closeGlobalTransaction()
92 {
93 Parcel data, reply;
94 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
95 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
96 }
97
98 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
99 {
100 Parcel data, reply;
101 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
102 data.writeInt32(dpy);
103 data.writeInt32(flags);
104 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
105 return reply.readInt32();
106 }
107
108 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
109 {
110 Parcel data, reply;
111 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
112 data.writeInt32(dpy);
113 data.writeInt32(flags);
114 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
115 return reply.readInt32();
116 }
117
Mathias Agopianc08731e2009-03-27 18:11:38 -0700118 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 {
120 Parcel data, reply;
121 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
122 data.writeInt32(dpy);
123 data.writeInt32(orientation);
Mathias Agopianc08731e2009-03-27 18:11:38 -0700124 data.writeInt32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
126 return reply.readInt32();
127 }
128
129 virtual void bootFinished()
130 {
131 Parcel data, reply;
132 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
133 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
134 }
135
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700136 virtual status_t captureScreen(DisplayID dpy,
137 sp<IMemoryHeap>* heap,
Mathias Agopiandf85c452010-09-29 13:02:36 -0700138 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800139 uint32_t reqWidth, uint32_t reqHeight,
140 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700141 {
142 Parcel data, reply;
143 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
144 data.writeInt32(dpy);
Mathias Agopiandf85c452010-09-29 13:02:36 -0700145 data.writeInt32(reqWidth);
146 data.writeInt32(reqHeight);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800147 data.writeInt32(minLayerZ);
148 data.writeInt32(maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700149 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
150 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
151 *width = reply.readInt32();
152 *height = reply.readInt32();
153 *format = reply.readInt32();
154 return reply.readInt32();
155 }
156
Mathias Agopian59119e62010-10-11 12:37:43 -0700157 virtual status_t turnElectronBeamOff(int32_t mode)
158 {
159 Parcel data, reply;
160 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
161 data.writeInt32(mode);
162 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
163 return reply.readInt32();
164 }
165
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700166 virtual status_t turnElectronBeamOn(int32_t mode)
167 {
168 Parcel data, reply;
169 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
170 data.writeInt32(mode);
171 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply);
172 return reply.readInt32();
173 }
174
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175 virtual void signal() const
176 {
177 Parcel data, reply;
178 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
179 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
180 }
181};
182
183IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
184
185// ----------------------------------------------------------------------
186
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187status_t BnSurfaceComposer::onTransact(
188 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
189{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800190 switch(code) {
191 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700192 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193 sp<IBinder> b = createConnection()->asBinder();
194 reply->writeStrongBinder(b);
195 } break;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700196 case CREATE_CLIENT_CONNECTION: {
197 CHECK_INTERFACE(ISurfaceComposer, data, reply);
198 sp<IBinder> b = createClientConnection()->asBinder();
199 reply->writeStrongBinder(b);
200 } break;
Jamie Gennis9a78c902011-01-12 18:30:40 -0800201 case CREATE_GRAPHIC_BUFFER_ALLOC: {
202 CHECK_INTERFACE(ISurfaceComposer, data, reply);
203 sp<IBinder> b = createGraphicBufferAlloc()->asBinder();
204 reply->writeStrongBinder(b);
205 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 case OPEN_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700207 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208 openGlobalTransaction();
209 } break;
210 case CLOSE_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700211 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212 closeGlobalTransaction();
213 } break;
214 case SET_ORIENTATION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700215 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800216 DisplayID dpy = data.readInt32();
217 int orientation = data.readInt32();
Mathias Agopianc08731e2009-03-27 18:11:38 -0700218 uint32_t flags = data.readInt32();
219 reply->writeInt32( setOrientation(dpy, orientation, flags) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 } break;
221 case FREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700222 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 DisplayID dpy = data.readInt32();
224 uint32_t flags = data.readInt32();
225 reply->writeInt32( freezeDisplay(dpy, flags) );
226 } break;
227 case UNFREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700228 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229 DisplayID dpy = data.readInt32();
230 uint32_t flags = data.readInt32();
231 reply->writeInt32( unfreezeDisplay(dpy, flags) );
232 } break;
233 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700234 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 bootFinished();
236 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800237 case SIGNAL: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700238 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800239 signal();
240 } break;
241 case GET_CBLK: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700242 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 sp<IBinder> b = getCblk()->asBinder();
244 reply->writeStrongBinder(b);
245 } break;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700246 case CAPTURE_SCREEN: {
247 CHECK_INTERFACE(ISurfaceComposer, data, reply);
248 DisplayID dpy = data.readInt32();
Mathias Agopiandf85c452010-09-29 13:02:36 -0700249 uint32_t reqWidth = data.readInt32();
250 uint32_t reqHeight = data.readInt32();
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800251 uint32_t minLayerZ = data.readInt32();
252 uint32_t maxLayerZ = data.readInt32();
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700253 sp<IMemoryHeap> heap;
254 uint32_t w, h;
255 PixelFormat f;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700256 status_t res = captureScreen(dpy, &heap, &w, &h, &f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800257 reqWidth, reqHeight, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700258 reply->writeStrongBinder(heap->asBinder());
259 reply->writeInt32(w);
260 reply->writeInt32(h);
261 reply->writeInt32(f);
262 reply->writeInt32(res);
263 } break;
Mathias Agopian59119e62010-10-11 12:37:43 -0700264 case TURN_ELECTRON_BEAM_OFF: {
265 CHECK_INTERFACE(ISurfaceComposer, data, reply);
266 int32_t mode = data.readInt32();
267 status_t res = turnElectronBeamOff(mode);
268 reply->writeInt32(res);
269 }
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700270 case TURN_ELECTRON_BEAM_ON: {
271 CHECK_INTERFACE(ISurfaceComposer, data, reply);
272 int32_t mode = data.readInt32();
273 status_t res = turnElectronBeamOn(mode);
274 reply->writeInt32(res);
275 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800276 default:
Mathias Agopian83c04462009-05-22 19:00:22 -0700277 return BBinder::onTransact(code, data, reply, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278 }
279 return NO_ERROR;
280}
281
282// ----------------------------------------------------------------------------
283
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800284};