blob: 40450a3d0750f3264aa848b7f5a1d1a60b233892 [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
Jamie Gennis134f0422011-03-08 12:18:54 -080028#include <surfaceflinger/ISurfaceComposer.h>
29
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030#include <ui/DisplayInfo.h>
31
Jamie Gennis134f0422011-03-08 12:18:54 -080032#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080033
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034// ---------------------------------------------------------------------------
35
36#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
37#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
38
39// ---------------------------------------------------------------------------
40
41namespace android {
42
43class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
44{
45public:
46 BpSurfaceComposer(const sp<IBinder>& impl)
47 : BpInterface<ISurfaceComposer>(impl)
48 {
49 }
50
Mathias Agopian7e27f052010-05-28 14:22:23 -070051 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 {
53 uint32_t n;
54 Parcel data, reply;
55 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
56 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070057 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 }
59
Jamie Gennis9a78c902011-01-12 18:30:40 -080060 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc()
61 {
62 uint32_t n;
63 Parcel data, reply;
64 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
65 remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply);
66 return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
67 }
68
Mathias Agopian7303c6b2009-07-02 18:11:53 -070069 virtual sp<IMemoryHeap> getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 {
71 Parcel data, reply;
72 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
73 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
Mathias Agopian7303c6b2009-07-02 18:11:53 -070074 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 }
76
77 virtual void openGlobalTransaction()
78 {
79 Parcel data, reply;
80 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
81 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
82 }
83
84 virtual void closeGlobalTransaction()
85 {
86 Parcel data, reply;
87 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
88 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
89 }
90
91 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
92 {
93 Parcel data, reply;
94 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
95 data.writeInt32(dpy);
96 data.writeInt32(flags);
97 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
98 return reply.readInt32();
99 }
100
101 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
102 {
103 Parcel data, reply;
104 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
105 data.writeInt32(dpy);
106 data.writeInt32(flags);
107 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
108 return reply.readInt32();
109 }
110
Mathias Agopianc08731e2009-03-27 18:11:38 -0700111 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 {
113 Parcel data, reply;
114 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
115 data.writeInt32(dpy);
116 data.writeInt32(orientation);
Mathias Agopianc08731e2009-03-27 18:11:38 -0700117 data.writeInt32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
119 return reply.readInt32();
120 }
121
122 virtual void bootFinished()
123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
126 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
127 }
128
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700129 virtual status_t captureScreen(DisplayID dpy,
130 sp<IMemoryHeap>* heap,
Mathias Agopiandf85c452010-09-29 13:02:36 -0700131 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800132 uint32_t reqWidth, uint32_t reqHeight,
133 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
137 data.writeInt32(dpy);
Mathias Agopiandf85c452010-09-29 13:02:36 -0700138 data.writeInt32(reqWidth);
139 data.writeInt32(reqHeight);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800140 data.writeInt32(minLayerZ);
141 data.writeInt32(maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700142 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
143 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
144 *width = reply.readInt32();
145 *height = reply.readInt32();
146 *format = reply.readInt32();
147 return reply.readInt32();
148 }
149
Mathias Agopian59119e62010-10-11 12:37:43 -0700150 virtual status_t turnElectronBeamOff(int32_t mode)
151 {
152 Parcel data, reply;
153 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
154 data.writeInt32(mode);
155 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
156 return reply.readInt32();
157 }
158
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700159 virtual status_t turnElectronBeamOn(int32_t mode)
160 {
161 Parcel data, reply;
162 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
163 data.writeInt32(mode);
164 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply);
165 return reply.readInt32();
166 }
167
Jamie Gennis134f0422011-03-08 12:18:54 -0800168 virtual bool authenticateSurface(const sp<ISurface>& surface) const
169 {
170 Parcel data, reply;
171 int err = NO_ERROR;
172 err = data.writeInterfaceToken(
173 ISurfaceComposer::getInterfaceDescriptor());
174 if (err != NO_ERROR) {
175 LOGE("ISurfaceComposer::authenticateSurface: error writing "
176 "interface descriptor: %s (%d)", strerror(-err), -err);
177 return false;
178 }
179 err = data.writeStrongBinder(surface->asBinder());
180 if (err != NO_ERROR) {
181 LOGE("ISurfaceComposer::authenticateSurface: error writing strong "
182 "binder to parcel: %s (%d)", strerror(-err), -err);
183 return false;
184 }
185 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
186 &reply);
187 if (err != NO_ERROR) {
188 LOGE("ISurfaceComposer::authenticateSurface: error performing "
189 "transaction: %s (%d)", strerror(-err), -err);
190 return false;
191 }
192 int32_t result = 0;
193 err = reply.readInt32(&result);
194 if (err != NO_ERROR) {
195 LOGE("ISurfaceComposer::authenticateSurface: error retrieving "
196 "result: %s (%d)", strerror(-err), -err);
197 return false;
198 }
199 return result != 0;
200 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201};
202
203IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
204
205// ----------------------------------------------------------------------
206
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207status_t BnSurfaceComposer::onTransact(
208 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
209{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210 switch(code) {
211 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700212 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213 sp<IBinder> b = createConnection()->asBinder();
214 reply->writeStrongBinder(b);
215 } break;
Jamie Gennis9a78c902011-01-12 18:30:40 -0800216 case CREATE_GRAPHIC_BUFFER_ALLOC: {
217 CHECK_INTERFACE(ISurfaceComposer, data, reply);
218 sp<IBinder> b = createGraphicBufferAlloc()->asBinder();
219 reply->writeStrongBinder(b);
220 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800221 case OPEN_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700222 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 openGlobalTransaction();
224 } break;
225 case CLOSE_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700226 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800227 closeGlobalTransaction();
228 } break;
229 case SET_ORIENTATION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700230 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231 DisplayID dpy = data.readInt32();
232 int orientation = data.readInt32();
Mathias Agopianc08731e2009-03-27 18:11:38 -0700233 uint32_t flags = data.readInt32();
234 reply->writeInt32( setOrientation(dpy, orientation, flags) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 } break;
236 case FREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700237 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238 DisplayID dpy = data.readInt32();
239 uint32_t flags = data.readInt32();
240 reply->writeInt32( freezeDisplay(dpy, flags) );
241 } break;
242 case UNFREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700243 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800244 DisplayID dpy = data.readInt32();
245 uint32_t flags = data.readInt32();
246 reply->writeInt32( unfreezeDisplay(dpy, flags) );
247 } break;
248 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700249 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800250 bootFinished();
251 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800252 case GET_CBLK: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700253 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254 sp<IBinder> b = getCblk()->asBinder();
255 reply->writeStrongBinder(b);
256 } break;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700257 case CAPTURE_SCREEN: {
258 CHECK_INTERFACE(ISurfaceComposer, data, reply);
259 DisplayID dpy = data.readInt32();
Mathias Agopiandf85c452010-09-29 13:02:36 -0700260 uint32_t reqWidth = data.readInt32();
261 uint32_t reqHeight = data.readInt32();
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800262 uint32_t minLayerZ = data.readInt32();
263 uint32_t maxLayerZ = data.readInt32();
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700264 sp<IMemoryHeap> heap;
265 uint32_t w, h;
266 PixelFormat f;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700267 status_t res = captureScreen(dpy, &heap, &w, &h, &f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800268 reqWidth, reqHeight, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700269 reply->writeStrongBinder(heap->asBinder());
270 reply->writeInt32(w);
271 reply->writeInt32(h);
272 reply->writeInt32(f);
273 reply->writeInt32(res);
274 } break;
Mathias Agopian59119e62010-10-11 12:37:43 -0700275 case TURN_ELECTRON_BEAM_OFF: {
276 CHECK_INTERFACE(ISurfaceComposer, data, reply);
277 int32_t mode = data.readInt32();
278 status_t res = turnElectronBeamOff(mode);
279 reply->writeInt32(res);
Jamie Gennis151f2f52010-12-20 11:05:18 -0800280 } break;
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700281 case TURN_ELECTRON_BEAM_ON: {
282 CHECK_INTERFACE(ISurfaceComposer, data, reply);
283 int32_t mode = data.readInt32();
284 status_t res = turnElectronBeamOn(mode);
285 reply->writeInt32(res);
Jamie Gennis151f2f52010-12-20 11:05:18 -0800286 } break;
Jamie Gennis134f0422011-03-08 12:18:54 -0800287 case AUTHENTICATE_SURFACE: {
288 CHECK_INTERFACE(ISurfaceComposer, data, reply);
289 sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder());
290 int32_t result = authenticateSurface(surface) ? 1 : 0;
291 reply->writeInt32(result);
292 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800293 default:
Mathias Agopian83c04462009-05-22 19:00:22 -0700294 return BBinder::onTransact(code, data, reply, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800295 }
296 return NO_ERROR;
297}
298
299// ----------------------------------------------------------------------------
300
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301};