blob: 0c5d1b4d2d35874ff494ee1803829c55a2002496 [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
Mathias Agopian7303c6b2009-07-02 18:11:53 -070067 virtual sp<IMemoryHeap> getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 {
69 Parcel data, reply;
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
Mathias Agopian7303c6b2009-07-02 18:11:53 -070072 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 }
74
75 virtual void openGlobalTransaction()
76 {
77 Parcel data, reply;
78 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
79 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
80 }
81
82 virtual void closeGlobalTransaction()
83 {
84 Parcel data, reply;
85 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
86 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
87 }
88
89 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
90 {
91 Parcel data, reply;
92 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
93 data.writeInt32(dpy);
94 data.writeInt32(flags);
95 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
96 return reply.readInt32();
97 }
98
99 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
100 {
101 Parcel data, reply;
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();
107 }
108
Mathias Agopianc08731e2009-03-27 18:11:38 -0700109 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
113 data.writeInt32(dpy);
114 data.writeInt32(orientation);
Mathias Agopianc08731e2009-03-27 18:11:38 -0700115 data.writeInt32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
117 return reply.readInt32();
118 }
119
120 virtual void bootFinished()
121 {
122 Parcel data, reply;
123 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
124 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
125 }
126
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700127 virtual status_t captureScreen(DisplayID dpy,
128 sp<IMemoryHeap>* heap,
Mathias Agopiandf85c452010-09-29 13:02:36 -0700129 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800130 uint32_t reqWidth, uint32_t reqHeight,
131 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700132 {
133 Parcel data, reply;
134 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
135 data.writeInt32(dpy);
Mathias Agopiandf85c452010-09-29 13:02:36 -0700136 data.writeInt32(reqWidth);
137 data.writeInt32(reqHeight);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800138 data.writeInt32(minLayerZ);
139 data.writeInt32(maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700140 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
141 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder());
142 *width = reply.readInt32();
143 *height = reply.readInt32();
144 *format = reply.readInt32();
145 return reply.readInt32();
146 }
147
Mathias Agopian59119e62010-10-11 12:37:43 -0700148 virtual status_t turnElectronBeamOff(int32_t mode)
149 {
150 Parcel data, reply;
151 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
152 data.writeInt32(mode);
153 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
154 return reply.readInt32();
155 }
156
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700157 virtual status_t turnElectronBeamOn(int32_t mode)
158 {
159 Parcel data, reply;
160 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
161 data.writeInt32(mode);
162 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply);
163 return reply.readInt32();
164 }
165
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166 virtual void signal() const
167 {
168 Parcel data, reply;
169 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
170 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
171 }
172};
173
174IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
175
176// ----------------------------------------------------------------------
177
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800178status_t BnSurfaceComposer::onTransact(
179 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
180{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181 switch(code) {
182 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700183 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800184 sp<IBinder> b = createConnection()->asBinder();
185 reply->writeStrongBinder(b);
186 } break;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700187 case CREATE_CLIENT_CONNECTION: {
188 CHECK_INTERFACE(ISurfaceComposer, data, reply);
189 sp<IBinder> b = createClientConnection()->asBinder();
190 reply->writeStrongBinder(b);
191 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192 case OPEN_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700193 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194 openGlobalTransaction();
195 } break;
196 case CLOSE_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700197 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198 closeGlobalTransaction();
199 } break;
200 case SET_ORIENTATION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700201 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202 DisplayID dpy = data.readInt32();
203 int orientation = data.readInt32();
Mathias Agopianc08731e2009-03-27 18:11:38 -0700204 uint32_t flags = data.readInt32();
205 reply->writeInt32( setOrientation(dpy, orientation, flags) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 } break;
207 case FREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700208 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800209 DisplayID dpy = data.readInt32();
210 uint32_t flags = data.readInt32();
211 reply->writeInt32( freezeDisplay(dpy, flags) );
212 } break;
213 case UNFREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700214 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215 DisplayID dpy = data.readInt32();
216 uint32_t flags = data.readInt32();
217 reply->writeInt32( unfreezeDisplay(dpy, flags) );
218 } break;
219 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700220 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800221 bootFinished();
222 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 case SIGNAL: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700224 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800225 signal();
226 } break;
227 case GET_CBLK: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700228 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229 sp<IBinder> b = getCblk()->asBinder();
230 reply->writeStrongBinder(b);
231 } break;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700232 case CAPTURE_SCREEN: {
233 CHECK_INTERFACE(ISurfaceComposer, data, reply);
234 DisplayID dpy = data.readInt32();
Mathias Agopiandf85c452010-09-29 13:02:36 -0700235 uint32_t reqWidth = data.readInt32();
236 uint32_t reqHeight = data.readInt32();
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800237 uint32_t minLayerZ = data.readInt32();
238 uint32_t maxLayerZ = data.readInt32();
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700239 sp<IMemoryHeap> heap;
240 uint32_t w, h;
241 PixelFormat f;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700242 status_t res = captureScreen(dpy, &heap, &w, &h, &f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800243 reqWidth, reqHeight, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -0700244 reply->writeStrongBinder(heap->asBinder());
245 reply->writeInt32(w);
246 reply->writeInt32(h);
247 reply->writeInt32(f);
248 reply->writeInt32(res);
249 } break;
Mathias Agopian59119e62010-10-11 12:37:43 -0700250 case TURN_ELECTRON_BEAM_OFF: {
251 CHECK_INTERFACE(ISurfaceComposer, data, reply);
252 int32_t mode = data.readInt32();
253 status_t res = turnElectronBeamOff(mode);
254 reply->writeInt32(res);
Jamie Gennis151f2f52010-12-20 11:05:18 -0800255 } break;
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700256 case TURN_ELECTRON_BEAM_ON: {
257 CHECK_INTERFACE(ISurfaceComposer, data, reply);
258 int32_t mode = data.readInt32();
259 status_t res = turnElectronBeamOn(mode);
260 reply->writeInt32(res);
Jamie Gennis151f2f52010-12-20 11:05:18 -0800261 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 default:
Mathias Agopian83c04462009-05-22 19:00:22 -0700263 return BBinder::onTransact(code, data, reply, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800264 }
265 return NO_ERROR;
266}
267
268// ----------------------------------------------------------------------------
269
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270};