blob: a42b49d9d9375f246b40fff0ca297f899823585d [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>
Jamie Gennis49563342010-12-20 11:21:07 -080029#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
Mathias Agopian9cce3252010-02-09 17:46:37 -080031#include <surfaceflinger/ISurfaceComposer.h>
32
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033// ---------------------------------------------------------------------------
34
35#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
36#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
37
38// ---------------------------------------------------------------------------
39
40namespace android {
41
42class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
43{
44public:
45 BpSurfaceComposer(const sp<IBinder>& impl)
46 : BpInterface<ISurfaceComposer>(impl)
47 {
48 }
49
Mathias Agopian7e27f052010-05-28 14:22:23 -070050 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 {
52 uint32_t n;
53 Parcel data, reply;
54 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
55 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070056 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 }
58
Mathias Agopianb7e930d2010-06-01 15:12:58 -070059 virtual sp<ISurfaceComposerClient> createClientConnection()
60 {
61 uint32_t n;
62 Parcel data, reply;
63 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
64 remote()->transact(BnSurfaceComposer::CREATE_CLIENT_CONNECTION, data, &reply);
65 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
66 }
67
Mathias Agopian7303c6b2009-07-02 18:11:53 -070068 virtual sp<IMemoryHeap> getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 {
70 Parcel data, reply;
71 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
72 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
Mathias Agopian7303c6b2009-07-02 18:11:53 -070073 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 }
75
76 virtual void openGlobalTransaction()
77 {
78 Parcel data, reply;
79 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
80 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
81 }
82
83 virtual void closeGlobalTransaction()
84 {
85 Parcel data, reply;
86 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
87 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
88 }
89
90 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
91 {
92 Parcel data, reply;
93 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
94 data.writeInt32(dpy);
95 data.writeInt32(flags);
96 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
97 return reply.readInt32();
98 }
99
100 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
101 {
102 Parcel data, reply;
103 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
104 data.writeInt32(dpy);
105 data.writeInt32(flags);
106 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
107 return reply.readInt32();
108 }
109
Mathias Agopianc08731e2009-03-27 18:11:38 -0700110 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 {
112 Parcel data, reply;
113 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
114 data.writeInt32(dpy);
115 data.writeInt32(orientation);
Mathias Agopianc08731e2009-03-27 18:11:38 -0700116 data.writeInt32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
118 return reply.readInt32();
119 }
120
121 virtual void bootFinished()
122 {
123 Parcel data, reply;
124 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
125 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
126 }
127
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700128 virtual status_t captureScreen(DisplayID dpy,
129 sp<IMemoryHeap>* heap,
Mathias Agopiandf85c452010-09-29 13:02:36 -0700130 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800131 uint32_t reqWidth, uint32_t reqHeight,
132 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700133 {
134 Parcel data, reply;
135 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
136 data.writeInt32(dpy);
Mathias Agopiandf85c452010-09-29 13:02:36 -0700137 data.writeInt32(reqWidth);
138 data.writeInt32(reqHeight);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800139 data.writeInt32(minLayerZ);
140 data.writeInt32(maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700141 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
142 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
143 *width = reply.readInt32();
144 *height = reply.readInt32();
145 *format = reply.readInt32();
146 return reply.readInt32();
147 }
148
Mathias Agopian59119e62010-10-11 12:37:43 -0700149 virtual status_t turnElectronBeamOff(int32_t mode)
150 {
151 Parcel data, reply;
152 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
153 data.writeInt32(mode);
154 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
155 return reply.readInt32();
156 }
157
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700158 virtual status_t turnElectronBeamOn(int32_t mode)
159 {
160 Parcel data, reply;
161 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
162 data.writeInt32(mode);
163 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply);
164 return reply.readInt32();
165 }
166
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167 virtual void signal() const
168 {
169 Parcel data, reply;
170 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
171 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
172 }
Jamie Gennis49563342010-12-20 11:21:07 -0800173
174 virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
175 PixelFormat format, uint32_t usage) const {
176 Parcel data, reply;
177 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
178 data.writeInt32(w);
179 data.writeInt32(h);
180 data.writeInt32(format);
181 data.writeInt32(usage);
182 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER, data,
183 &reply);
184 sp<GraphicBuffer> graphicBuffer;
185 bool nonNull = (bool)reply.readInt32();
186 if (nonNull) {
187 graphicBuffer = new GraphicBuffer();
188 reply.read(*graphicBuffer);
189 }
190 return graphicBuffer;
191 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192};
193
194IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
195
196// ----------------------------------------------------------------------
197
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198status_t BnSurfaceComposer::onTransact(
199 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
200{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201 switch(code) {
202 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700203 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 sp<IBinder> b = createConnection()->asBinder();
205 reply->writeStrongBinder(b);
206 } break;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700207 case CREATE_CLIENT_CONNECTION: {
208 CHECK_INTERFACE(ISurfaceComposer, data, reply);
209 sp<IBinder> b = createClientConnection()->asBinder();
210 reply->writeStrongBinder(b);
211 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212 case OPEN_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700213 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214 openGlobalTransaction();
215 } break;
216 case CLOSE_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700217 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800218 closeGlobalTransaction();
219 } break;
220 case SET_ORIENTATION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700221 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 DisplayID dpy = data.readInt32();
223 int orientation = data.readInt32();
Mathias Agopianc08731e2009-03-27 18:11:38 -0700224 uint32_t flags = data.readInt32();
225 reply->writeInt32( setOrientation(dpy, orientation, flags) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226 } break;
227 case FREEZE_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( freezeDisplay(dpy, flags) );
232 } break;
233 case UNFREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700234 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 DisplayID dpy = data.readInt32();
236 uint32_t flags = data.readInt32();
237 reply->writeInt32( unfreezeDisplay(dpy, flags) );
238 } break;
239 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700240 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241 bootFinished();
242 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 case SIGNAL: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700244 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245 signal();
246 } break;
247 case GET_CBLK: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700248 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800249 sp<IBinder> b = getCblk()->asBinder();
250 reply->writeStrongBinder(b);
251 } break;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700252 case CAPTURE_SCREEN: {
253 CHECK_INTERFACE(ISurfaceComposer, data, reply);
254 DisplayID dpy = data.readInt32();
Mathias Agopiandf85c452010-09-29 13:02:36 -0700255 uint32_t reqWidth = data.readInt32();
256 uint32_t reqHeight = data.readInt32();
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800257 uint32_t minLayerZ = data.readInt32();
258 uint32_t maxLayerZ = data.readInt32();
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700259 sp<IMemoryHeap> heap;
260 uint32_t w, h;
261 PixelFormat f;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700262 status_t res = captureScreen(dpy, &heap, &w, &h, &f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800263 reqWidth, reqHeight, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700264 reply->writeStrongBinder(heap->asBinder());
265 reply->writeInt32(w);
266 reply->writeInt32(h);
267 reply->writeInt32(f);
268 reply->writeInt32(res);
269 } break;
Jamie Gennis49563342010-12-20 11:21:07 -0800270 case CREATE_GRAPHIC_BUFFER: {
271 CHECK_INTERFACE(ISurfaceComposer, data, reply);
272 uint32_t w = data.readInt32();
273 uint32_t h = data.readInt32();
274 PixelFormat format = data.readInt32();
275 uint32_t usage = data.readInt32();
276 sp<GraphicBuffer> result(createGraphicBuffer(w, h, format, usage));
277 reply->writeInt32(result != 0);
278 if (result != 0) {
279 reply->write(*result);
280 }
281 } break;
Mathias Agopian59119e62010-10-11 12:37:43 -0700282 case TURN_ELECTRON_BEAM_OFF: {
283 CHECK_INTERFACE(ISurfaceComposer, data, reply);
284 int32_t mode = data.readInt32();
285 status_t res = turnElectronBeamOff(mode);
286 reply->writeInt32(res);
287 }
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700288 case TURN_ELECTRON_BEAM_ON: {
289 CHECK_INTERFACE(ISurfaceComposer, data, reply);
290 int32_t mode = data.readInt32();
291 status_t res = turnElectronBeamOn(mode);
292 reply->writeInt32(res);
293 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800294 default:
Mathias Agopian83c04462009-05-22 19:00:22 -0700295 return BBinder::onTransact(code, data, reply, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800296 }
297 return NO_ERROR;
298}
299
300// ----------------------------------------------------------------------------
301
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800302};