blob: 8cfaa31a63d5ffabdda28824239fddf31d0e992e [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
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019#include <stdint.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <errno.h>
22#include <math.h>
Keun young Park63f165f2012-08-31 10:53:36 -070023#include <dlfcn.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070024
25#include <EGL/egl.h>
26#include <GLES/gl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
28#include <cutils/log.h>
29#include <cutils/properties.h>
30
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070031#include <binder/IPCThreadState.h>
32#include <binder/IServiceManager.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070033#include <binder/MemoryHeapBase.h>
Mathias Agopian99b49842011-06-27 16:05:52 -070034#include <binder/PermissionCache.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070035
Mathias Agopianc666cae2012-07-25 18:56:13 -070036#include <ui/DisplayInfo.h>
37
Mathias Agopian921e6ac2012-07-23 23:11:29 -070038#include <gui/BitTube.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070039#include <gui/BufferQueue.h>
Andy McFadden4803b742012-09-24 19:07:20 -070040#include <gui/GuiConfig.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070041#include <gui/IDisplayEventConnection.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070042#include <gui/SurfaceTextureClient.h>
43
44#include <ui/GraphicBufferAllocator.h>
45#include <ui/PixelFormat.h>
Andy McFadden4803b742012-09-24 19:07:20 -070046#include <ui/UiConfig.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080047
Mathias Agopiancde87a32012-09-13 14:09:01 -070048#include <utils/misc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049#include <utils/String8.h>
50#include <utils/String16.h>
51#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080052#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053
Mathias Agopian921e6ac2012-07-23 23:11:29 -070054#include <private/android_filesystem_config.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
56#include "clz.h"
Mathias Agopian90ac7992012-02-25 18:48:35 -080057#include "DdmConnection.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070058#include "DisplayDevice.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070059#include "Client.h"
Mathias Agopiand0566bc2011-11-17 17:49:17 -080060#include "EventThread.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070061#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063#include "LayerDim.h"
Mathias Agopian118d0242011-10-13 16:02:48 -070064#include "LayerScreenshot.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066
Mathias Agopiana4912602012-07-12 14:25:33 -070067#include "DisplayHardware/FramebufferSurface.h"
Mathias Agopianf33e4b62012-09-20 16:54:14 -070068#include "DisplayHardware/GraphicBufferAlloc.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070069#include "DisplayHardware/HWComposer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070
Mathias Agopiana67932f2011-04-20 14:20:59 -070071
Mathias Agopianbc2d79e2011-11-29 17:55:46 -080072#define EGL_VERSION_HW_ANDROID 0x3143
73
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074#define DISPLAY_COUNT 1
75
76namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077// ---------------------------------------------------------------------------
78
Mathias Agopian99b49842011-06-27 16:05:52 -070079const String16 sHardwareTest("android.permission.HARDWARE_TEST");
80const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
81const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER");
82const String16 sDump("android.permission.DUMP");
83
84// ---------------------------------------------------------------------------
85
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086SurfaceFlinger::SurfaceFlinger()
87 : BnSurfaceComposer(), Thread(false),
88 mTransactionFlags(0),
Jamie Gennis28378392011-10-12 17:39:00 -070089 mTransationPending(false),
Mathias Agopian076b1cc2009-04-10 14:24:30 -070090 mLayersRemoved(false),
Mathias Agopian52bbb1a2012-07-31 19:01:53 -070091 mRepaintEverything(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092 mBootTime(systemTime()),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 mVisibleRegionsDirty(false),
Mathias Agopiana350ff92010-08-10 17:14:02 -070094 mHwWorkListDirty(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 mDebugRegion(0),
Mathias Agopian8afb7e32011-08-15 20:44:40 -070096 mDebugDDMS(0),
Mathias Agopian73d3ba92010-09-22 18:58:01 -070097 mDebugDisableHWC(0),
Mathias Agopiana4583642011-08-23 18:03:18 -070098 mDebugDisableTransformHint(0),
Mathias Agopian9795c422009-08-26 16:36:26 -070099 mDebugInSwapBuffers(0),
100 mLastSwapBufferTime(0),
101 mDebugInTransaction(0),
102 mLastTransactionTime(0),
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700103 mBootFinished(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104{
Steve Blocka19954a2012-01-04 20:05:49 +0000105 ALOGI("SurfaceFlinger is starting");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106
107 // debugging stuff...
108 char value[PROPERTY_VALUE_MAX];
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700109
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 property_get("debug.sf.showupdates", value, "0");
111 mDebugRegion = atoi(value);
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700112
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700113 property_get("debug.sf.ddms", value, "0");
114 mDebugDDMS = atoi(value);
115 if (mDebugDDMS) {
Keun young Park63f165f2012-08-31 10:53:36 -0700116 if (!startDdmConnection()) {
117 // start failed, and DDMS debugging not enabled
118 mDebugDDMS = 0;
119 }
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700120 }
Mathias Agopianc1d359d2012-08-04 20:09:03 -0700121 ALOGI_IF(mDebugRegion, "showupdates enabled");
122 ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123}
124
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800125void SurfaceFlinger::onFirstRef()
126{
127 mEventQueue.init(this);
128
129 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
130
131 // Wait for the main thread to be done with its initialization
132 mReadyToRunBarrier.wait();
133}
134
135
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136SurfaceFlinger::~SurfaceFlinger()
137{
Mathias Agopiana4912602012-07-12 14:25:33 -0700138 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
139 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
140 eglTerminate(display);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141}
142
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800143void SurfaceFlinger::binderDied(const wp<IBinder>& who)
144{
145 // the window manager died on us. prepare its eulogy.
146
Andy McFadden13a082e2012-08-24 10:16:42 -0700147 // restore initial conditions (default device unblank, etc)
148 initializeDisplays();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800149
150 // restart the boot-animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700151 startBootAnim();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800152}
153
Mathias Agopian7e27f052010-05-28 14:22:23 -0700154sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155{
Mathias Agopian96f08192010-06-02 23:28:45 -0700156 sp<ISurfaceComposerClient> bclient;
157 sp<Client> client(new Client(this));
158 status_t err = client->initCheck();
159 if (err == NO_ERROR) {
160 bclient = client;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 return bclient;
163}
164
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700165sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName)
Mathias Agopiane57f2922012-08-09 16:29:12 -0700166{
167 class DisplayToken : public BBinder {
168 sp<SurfaceFlinger> flinger;
169 virtual ~DisplayToken() {
170 // no more references, this display must be terminated
171 Mutex::Autolock _l(flinger->mStateLock);
172 flinger->mCurrentState.displays.removeItem(this);
173 flinger->setTransactionFlags(eDisplayTransactionNeeded);
174 }
175 public:
176 DisplayToken(const sp<SurfaceFlinger>& flinger)
177 : flinger(flinger) {
178 }
179 };
180
181 sp<BBinder> token = new DisplayToken(this);
182
183 Mutex::Autolock _l(mStateLock);
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700184 DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700185 info.displayName = displayName;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700186 mCurrentState.displays.add(token, info);
187
188 return token;
189}
190
191sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700192 if (uint32_t(id) >= DisplayDevice::NUM_DISPLAY_TYPES) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700193 ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id);
194 return NULL;
195 }
196 return mDefaultDisplays[id];
197}
198
Jamie Gennis9a78c902011-01-12 18:30:40 -0800199sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
200{
201 sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
202 return gba;
203}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700204
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800205void SurfaceFlinger::bootFinished()
206{
207 const nsecs_t now = systemTime();
208 const nsecs_t duration = now - mBootTime;
Steve Blocka19954a2012-01-04 20:05:49 +0000209 ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
Mathias Agopian3330b202009-10-05 17:07:12 -0700210 mBootFinished = true;
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700211
212 // wait patiently for the window manager death
213 const String16 name("window");
214 sp<IBinder> window(defaultServiceManager()->getService(name));
215 if (window != 0) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700216 window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this));
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700217 }
218
219 // stop boot animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700220 // formerly we would just kill the process, but we now ask it to exit so it
221 // can choose where to stop the animation.
222 property_set("service.bootanim.exit", "1");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223}
224
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700225void SurfaceFlinger::deleteTextureAsync(GLuint texture) {
226 class MessageDestroyGLTexture : public MessageBase {
227 GLuint texture;
228 public:
229 MessageDestroyGLTexture(GLuint texture)
230 : texture(texture) {
231 }
232 virtual bool handler() {
233 glDeleteTextures(1, &texture);
234 return true;
235 }
236 };
237 postMessageAsync(new MessageDestroyGLTexture(texture));
238}
239
Mathias Agopian722b98f2012-09-25 18:24:31 -0700240status_t SurfaceFlinger::selectConfigForAttribute(
Mathias Agopiana4912602012-07-12 14:25:33 -0700241 EGLDisplay dpy,
242 EGLint const* attrs,
Mathias Agopian722b98f2012-09-25 18:24:31 -0700243 EGLint attribute, EGLint wanted,
Mathias Agopiana4912602012-07-12 14:25:33 -0700244 EGLConfig* outConfig)
245{
246 EGLConfig config = NULL;
247 EGLint numConfigs = -1, n=0;
248 eglGetConfigs(dpy, NULL, 0, &numConfigs);
249 EGLConfig* const configs = new EGLConfig[numConfigs];
250 eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
Mathias Agopiancde87a32012-09-13 14:09:01 -0700251
Mathias Agopian722b98f2012-09-25 18:24:31 -0700252 if (n) {
253 if (attribute != EGL_NONE) {
254 for (int i=0 ; i<n ; i++) {
255 EGLint value = 0;
256 eglGetConfigAttrib(dpy, configs[i], attribute, &value);
257 if (wanted == value) {
258 *outConfig = configs[i];
259 delete [] configs;
260 return NO_ERROR;
261 }
262 }
263 } else {
264 // just pick the first one
265 *outConfig = configs[0];
Mathias Agopiana4912602012-07-12 14:25:33 -0700266 delete [] configs;
267 return NO_ERROR;
268 }
269 }
270 delete [] configs;
271 return NAME_NOT_FOUND;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272}
273
Mathias Agopian722b98f2012-09-25 18:24:31 -0700274class EGLAttributeVector {
275 struct Attribute;
276 class Adder;
277 friend class Adder;
278 KeyedVector<Attribute, EGLint> mList;
279 struct Attribute {
280 Attribute() {};
281 Attribute(EGLint v) : v(v) { }
282 EGLint v;
283 bool operator < (const Attribute& other) const {
284 // this places EGL_NONE at the end
285 EGLint lhs(v);
286 EGLint rhs(other.v);
287 if (lhs == EGL_NONE) lhs = 0x7FFFFFFF;
288 if (rhs == EGL_NONE) rhs = 0x7FFFFFFF;
289 return lhs < rhs;
290 }
291 };
292 class Adder {
293 friend class EGLAttributeVector;
294 EGLAttributeVector& v;
295 EGLint attribute;
296 Adder(EGLAttributeVector& v, EGLint attribute)
297 : v(v), attribute(attribute) {
298 }
299 public:
300 void operator = (EGLint value) {
301 if (attribute != EGL_NONE) {
302 v.mList.add(attribute, value);
303 }
304 }
305 operator EGLint () const { return v.mList[attribute]; }
306 };
307public:
308 EGLAttributeVector() {
309 mList.add(EGL_NONE, EGL_NONE);
310 }
311 void remove(EGLint attribute) {
312 if (attribute != EGL_NONE) {
313 mList.removeItem(attribute);
314 }
315 }
316 Adder operator [] (EGLint attribute) {
317 return Adder(*this, attribute);
318 }
319 EGLint operator [] (EGLint attribute) const {
320 return mList[attribute];
321 }
322 // cast-operator to (EGLint const*)
323 operator EGLint const* () const { return &mList.keyAt(0).v; }
324};
325
Mathias Agopiana4912602012-07-12 14:25:33 -0700326EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
327 // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
328 // it is to be used with WIFI displays
329 EGLConfig config;
330 EGLint dummy;
331 status_t err;
Mathias Agopianda27af92012-09-13 18:17:13 -0700332
Mathias Agopian722b98f2012-09-25 18:24:31 -0700333 EGLAttributeVector attribs;
334 attribs[EGL_SURFACE_TYPE] = EGL_WINDOW_BIT;
335 attribs[EGL_RECORDABLE_ANDROID] = EGL_TRUE;
336 attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
337 attribs[EGL_RED_SIZE] = 8;
338 attribs[EGL_GREEN_SIZE] = 8;
339 attribs[EGL_BLUE_SIZE] = 8;
340
341 err = selectConfigForAttribute(display, attribs, EGL_NONE, EGL_NONE, &config);
342 if (!err)
343 goto success;
344
345 // maybe we failed because of EGL_FRAMEBUFFER_TARGET_ANDROID
346 ALOGW("no suitable EGLConfig found, trying without EGL_FRAMEBUFFER_TARGET_ANDROID");
347 attribs.remove(EGL_FRAMEBUFFER_TARGET_ANDROID);
348 err = selectConfigForAttribute(display, attribs,
349 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
Jesse Hallf21cffa2012-09-19 21:00:49 -0700350 if (!err)
351 goto success;
352
353 // maybe we failed because of EGL_RECORDABLE_ANDROID
354 ALOGW("no suitable EGLConfig found, trying without EGL_RECORDABLE_ANDROID");
Mathias Agopian722b98f2012-09-25 18:24:31 -0700355 attribs.remove(EGL_RECORDABLE_ANDROID);
356 err = selectConfigForAttribute(display, attribs,
357 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
Jesse Hallf21cffa2012-09-19 21:00:49 -0700358 if (!err)
359 goto success;
360
361 // allow less than 24-bit color; the non-gpu-accelerated emulator only
362 // supports 16-bit color
363 ALOGW("no suitable EGLConfig found, trying with 16-bit color allowed");
Mathias Agopian722b98f2012-09-25 18:24:31 -0700364 attribs.remove(EGL_RED_SIZE);
365 attribs.remove(EGL_GREEN_SIZE);
366 attribs.remove(EGL_BLUE_SIZE);
367 err = selectConfigForAttribute(display, attribs,
368 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
Jesse Hallf21cffa2012-09-19 21:00:49 -0700369 if (!err)
370 goto success;
371
372 // this EGL is too lame for Android
373 ALOGE("no suitable EGLConfig found, giving up");
374
375 return 0;
376
377success:
378 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy))
Mathias Agopiana4912602012-07-12 14:25:33 -0700379 ALOGW_IF(dummy == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
Mathias Agopiana4912602012-07-12 14:25:33 -0700380 return config;
381}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382
Mathias Agopiana4912602012-07-12 14:25:33 -0700383EGLContext SurfaceFlinger::createGLContext(EGLDisplay display, EGLConfig config) {
384 // Also create our EGLContext
385 EGLint contextAttributes[] = {
386#ifdef EGL_IMG_context_priority
387#ifdef HAS_CONTEXT_PRIORITY
388#warning "using EGL_IMG_context_priority"
389 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
390#endif
391#endif
392 EGL_NONE, EGL_NONE
393 };
394 EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
395 ALOGE_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
396 return ctxt;
397}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800398
Mathias Agopiancde87a32012-09-13 14:09:01 -0700399void SurfaceFlinger::initializeGL(EGLDisplay display) {
Mathias Agopiana4912602012-07-12 14:25:33 -0700400 GLExtensions& extensions(GLExtensions::getInstance());
401 extensions.initWithGLStrings(
402 glGetString(GL_VENDOR),
403 glGetString(GL_RENDERER),
404 glGetString(GL_VERSION),
405 glGetString(GL_EXTENSIONS),
406 eglQueryString(display, EGL_VENDOR),
407 eglQueryString(display, EGL_VERSION),
408 eglQueryString(display, EGL_EXTENSIONS));
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700409
Mathias Agopiana4912602012-07-12 14:25:33 -0700410 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
411 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700412
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700414 glPixelStorei(GL_PACK_ALIGNMENT, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415 glEnableClientState(GL_VERTEX_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 glShadeModel(GL_FLAT);
417 glDisable(GL_DITHER);
418 glDisable(GL_CULL_FACE);
419
Mathias Agopiana4912602012-07-12 14:25:33 -0700420 struct pack565 {
421 inline uint16_t operator() (int r, int g, int b) const {
422 return (r<<11)|(g<<5)|b;
423 }
424 } pack565;
425
Jamie Gennis9575f602011-10-07 14:51:16 -0700426 const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) };
427 glGenTextures(1, &mProtectedTexName);
428 glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
429 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
430 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
431 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
432 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
433 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
434 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800435
Mathias Agopiana4912602012-07-12 14:25:33 -0700436 // print some debugging info
437 EGLint r,g,b,a;
438 eglGetConfigAttrib(display, mEGLConfig, EGL_RED_SIZE, &r);
439 eglGetConfigAttrib(display, mEGLConfig, EGL_GREEN_SIZE, &g);
440 eglGetConfigAttrib(display, mEGLConfig, EGL_BLUE_SIZE, &b);
441 eglGetConfigAttrib(display, mEGLConfig, EGL_ALPHA_SIZE, &a);
442 ALOGI("EGL informations:");
443 ALOGI("vendor : %s", extensions.getEglVendor());
444 ALOGI("version : %s", extensions.getEglVersion());
445 ALOGI("extensions: %s", extensions.getEglExtension());
446 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
447 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, mEGLConfig);
448 ALOGI("OpenGL ES informations:");
449 ALOGI("vendor : %s", extensions.getVendor());
450 ALOGI("renderer : %s", extensions.getRenderer());
451 ALOGI("version : %s", extensions.getVersion());
452 ALOGI("extensions: %s", extensions.getExtension());
453 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
454 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
455}
456
Mathias Agopiana4912602012-07-12 14:25:33 -0700457status_t SurfaceFlinger::readyToRun()
458{
459 ALOGI( "SurfaceFlinger's main thread ready to run. "
460 "Initializing graphics H/W...");
461
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700462 // initialize EGL for the default display
Jesse Hall34a09ba2012-07-29 22:35:34 -0700463 mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
464 eglInitialize(mEGLDisplay, NULL, NULL);
Mathias Agopiana4912602012-07-12 14:25:33 -0700465
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700466 // Initialize the H/W composer object. There may or may not be an
467 // actual hardware composer underneath.
468 mHwc = new HWComposer(this,
469 *static_cast<HWComposer::EventHandler *>(this));
470
Mathias Agopiana4912602012-07-12 14:25:33 -0700471 // initialize the config and context
Mathias Agopiancde87a32012-09-13 14:09:01 -0700472 EGLint format = mHwc->getVisualID();
Jesse Hall34a09ba2012-07-29 22:35:34 -0700473 mEGLConfig = selectEGLConfig(mEGLDisplay, format);
474 mEGLContext = createGLContext(mEGLDisplay, mEGLConfig);
Mathias Agopiana4912602012-07-12 14:25:33 -0700475
Mathias Agopianda27af92012-09-13 18:17:13 -0700476 LOG_ALWAYS_FATAL_IF(mEGLContext == EGL_NO_CONTEXT,
477 "couldn't create EGLContext");
478
Mathias Agopiancde87a32012-09-13 14:09:01 -0700479 // initialize our non-virtual displays
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700480 for (size_t i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) {
Mathias Agopianf5a33922012-09-19 18:16:22 -0700481 DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700482 mDefaultDisplays[i] = new BBinder();
Mathias Agopianf5a33922012-09-19 18:16:22 -0700483 wp<IBinder> token = mDefaultDisplays[i];
Mathias Agopianf5a33922012-09-19 18:16:22 -0700484
485 // set-up the displays that are already connected
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700486 if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) {
487 mCurrentState.displays.add(token, DisplayDeviceState(type));
Mathias Agopianf5a33922012-09-19 18:16:22 -0700488 sp<FramebufferSurface> fbs = new FramebufferSurface(*mHwc, i);
489 sp<SurfaceTextureClient> stc = new SurfaceTextureClient(
490 static_cast< sp<ISurfaceTexture> >(fbs->getBufferQueue()));
491 sp<DisplayDevice> hw = new DisplayDevice(this,
492 type, token, stc, fbs, mEGLConfig);
Mathias Agopianf5a33922012-09-19 18:16:22 -0700493 if (i > DisplayDevice::DISPLAY_PRIMARY) {
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700494 // FIXME: currently we don't get blank/unblank requests
Mathias Agopianf5a33922012-09-19 18:16:22 -0700495 // for displays other than the main display, so we always
496 // assume a connected display is unblanked.
Andy McFaddenc01a79d2012-09-27 16:02:06 -0700497 ALOGD("marking display %d as acquired/unblanked", i);
Mathias Agopianf5a33922012-09-19 18:16:22 -0700498 hw->acquireScreen();
499 }
500 mDisplays.add(token, hw);
501 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700502 }
Mathias Agopiancde87a32012-09-13 14:09:01 -0700503
Mathias Agopianf5a33922012-09-19 18:16:22 -0700504 // we need a GL context current in a few places, when initializing
505 // OpenGL ES (see below), or creating a layer,
506 // or when a texture is (asynchronously) destroyed, and for that
507 // we need a valid surface, so it's convenient to use the main display
508 // for that.
509 sp<const DisplayDevice> hw = getDefaultDisplayDevice();
Mathias Agopiancde87a32012-09-13 14:09:01 -0700510
Mathias Agopiana4912602012-07-12 14:25:33 -0700511 // initialize OpenGL ES
Mathias Agopiancde87a32012-09-13 14:09:01 -0700512 DisplayDevice::makeCurrent(mEGLDisplay, hw, mEGLContext);
513 initializeGL(mEGLDisplay);
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800514
Mathias Agopian028508c2012-07-25 21:12:12 -0700515 // start the EventThread
516 mEventThread = new EventThread(this);
517 mEventQueue.setEventThread(mEventThread);
518
Mathias Agopian92a979a2012-08-02 18:32:23 -0700519 // initialize our drawing state
520 mDrawingState = mCurrentState;
Mathias Agopian86303202012-07-24 22:46:10 -0700521
Mathias Agopiancde87a32012-09-13 14:09:01 -0700522
Mathias Agopiana4912602012-07-12 14:25:33 -0700523 // We're now ready to accept clients...
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800524 mReadyToRunBarrier.open();
525
Andy McFadden13a082e2012-08-24 10:16:42 -0700526 // set initial conditions (e.g. unblank default device)
527 initializeDisplays();
528
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700529 // start boot animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700530 startBootAnim();
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700531
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800532 return NO_ERROR;
533}
534
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700535int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) {
536 return (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) ?
537 type : mHwc->allocateDisplayId();
538}
539
Mathias Agopiana67e4182012-06-19 17:26:12 -0700540void SurfaceFlinger::startBootAnim() {
541 // start boot animation
542 property_set("service.bootanim.exit", "0");
543 property_set("ctl.start", "bootanim");
544}
545
Mathias Agopiana4912602012-07-12 14:25:33 -0700546uint32_t SurfaceFlinger::getMaxTextureSize() const {
547 return mMaxTextureSize;
548}
549
550uint32_t SurfaceFlinger::getMaxViewportDims() const {
551 return mMaxViewportDims[0] < mMaxViewportDims[1] ?
552 mMaxViewportDims[0] : mMaxViewportDims[1];
553}
554
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555// ----------------------------------------------------------------------------
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800556
Jamie Gennis582270d2011-08-17 18:19:00 -0700557bool SurfaceFlinger::authenticateSurfaceTexture(
558 const sp<ISurfaceTexture>& surfaceTexture) const {
Jamie Gennis134f0422011-03-08 12:18:54 -0800559 Mutex::Autolock _l(mStateLock);
Jamie Gennis582270d2011-08-17 18:19:00 -0700560 sp<IBinder> surfaceTextureBinder(surfaceTexture->asBinder());
Jamie Gennis134f0422011-03-08 12:18:54 -0800561
562 // Check the visible layer list for the ISurface
563 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
564 size_t count = currentLayers.size();
565 for (size_t i=0 ; i<count ; i++) {
566 const sp<LayerBase>& layer(currentLayers[i]);
567 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
Jamie Gennis582270d2011-08-17 18:19:00 -0700568 if (lbc != NULL) {
569 wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
570 if (lbcBinder == surfaceTextureBinder) {
571 return true;
572 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800573 }
574 }
575
576 // Check the layers in the purgatory. This check is here so that if a
Jamie Gennis582270d2011-08-17 18:19:00 -0700577 // SurfaceTexture gets destroyed before all the clients are done using it,
578 // the error will not be reported as "surface XYZ is not authenticated", but
Jamie Gennis134f0422011-03-08 12:18:54 -0800579 // will instead fail later on when the client tries to use the surface,
580 // which should be reported as "surface XYZ returned an -ENODEV". The
581 // purgatorized layers are no less authentic than the visible ones, so this
582 // should not cause any harm.
583 size_t purgatorySize = mLayerPurgatory.size();
584 for (size_t i=0 ; i<purgatorySize ; i++) {
585 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
586 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
Jamie Gennis582270d2011-08-17 18:19:00 -0700587 if (lbc != NULL) {
588 wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
589 if (lbcBinder == surfaceTextureBinder) {
590 return true;
591 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800592 }
593 }
594
595 return false;
596}
597
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700598status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
Mathias Agopian1604f772012-09-18 21:54:42 -0700599 int32_t type = BAD_VALUE;
600 for (int i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) {
601 if (display == mDefaultDisplays[i]) {
602 type = i;
603 break;
604 }
605 }
606
607 if (type < 0) {
608 return type;
Mathias Agopianc666cae2012-07-25 18:56:13 -0700609 }
Mathias Agopian8b736f12012-08-13 17:54:26 -0700610
611 const HWComposer& hwc(getHwComposer());
Mathias Agopian4c0751a2012-09-20 21:28:12 -0700612 if (!hwc.isConnected(type)) {
613 return NAME_NOT_FOUND;
614 }
615
Mathias Agopian1604f772012-09-18 21:54:42 -0700616 float xdpi = hwc.getDpiX(type);
617 float ydpi = hwc.getDpiY(type);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700618
619 // TODO: Not sure if display density should handled by SF any longer
620 class Density {
621 static int getDensityFromProperty(char const* propName) {
622 char property[PROPERTY_VALUE_MAX];
623 int density = 0;
624 if (property_get(propName, property, NULL) > 0) {
625 density = atoi(property);
626 }
627 return density;
628 }
629 public:
630 static int getEmuDensity() {
631 return getDensityFromProperty("qemu.sf.lcd_density"); }
632 static int getBuildDensity() {
633 return getDensityFromProperty("ro.sf.lcd_density"); }
634 };
Mathias Agopian1604f772012-09-18 21:54:42 -0700635
636 if (type == DisplayDevice::DISPLAY_PRIMARY) {
637 // The density of the device is provided by a build property
638 float density = Density::getBuildDensity() / 160.0f;
639 if (density == 0) {
640 // the build doesn't provide a density -- this is wrong!
641 // use xdpi instead
642 ALOGE("ro.sf.lcd_density must be defined as a build property");
643 density = xdpi / 160.0f;
644 }
645 if (Density::getEmuDensity()) {
646 // if "qemu.sf.lcd_density" is specified, it overrides everything
647 xdpi = ydpi = density = Density::getEmuDensity();
648 density /= 160.0f;
649 }
650 info->density = density;
651
652 // TODO: this needs to go away (currently needed only by webkit)
653 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
654 info->orientation = hw->getOrientation();
655 getPixelFormatInfo(hw->getFormat(), &info->pixelFormatInfo);
656 } else {
657 // TODO: where should this value come from?
658 static const int TV_DENSITY = 213;
659 info->density = TV_DENSITY / 160.0f;
660 info->orientation = 0;
Mathias Agopian8b736f12012-08-13 17:54:26 -0700661 }
662
Mathias Agopian1604f772012-09-18 21:54:42 -0700663 info->w = hwc.getWidth(type);
664 info->h = hwc.getHeight(type);
Mathias Agopian8b736f12012-08-13 17:54:26 -0700665 info->xdpi = xdpi;
666 info->ydpi = ydpi;
Mathias Agopian1604f772012-09-18 21:54:42 -0700667 info->fps = float(1e9 / hwc.getRefreshPeriod(type));
Mathias Agopian888c8222012-08-04 21:10:38 -0700668 return NO_ERROR;
Mathias Agopianc666cae2012-07-25 18:56:13 -0700669}
670
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800671// ----------------------------------------------------------------------------
672
673sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {
Mathias Agopian8aedd472012-01-24 16:39:14 -0800674 return mEventThread->createEventConnection();
Mathias Agopianbb641242010-05-18 17:06:55 -0700675}
676
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700677void SurfaceFlinger::connectDisplay(const sp<ISurfaceTexture>& surface) {
Mathias Agopian3094df32012-06-18 18:06:45 -0700678
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700679 sp<IBinder> token;
680 { // scope for the lock
681 Mutex::Autolock _l(mStateLock);
682 token = mExtDisplayToken;
683 }
684
685 if (token == 0) {
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700686 token = createDisplay(String8("Display from connectDisplay"));
Mathias Agopian3094df32012-06-18 18:06:45 -0700687 }
688
689 { // scope for the lock
690 Mutex::Autolock _l(mStateLock);
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700691 if (surface == 0) {
692 // release our current display. we're guarantee to have
693 // a reference to it (token), while we hold the lock
694 mExtDisplayToken = 0;
695 } else {
696 mExtDisplayToken = token;
697 }
Mathias Agopian3094df32012-06-18 18:06:45 -0700698
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700699 DisplayDeviceState& info(mCurrentState.displays.editValueFor(token));
700 info.surface = surface;
701 setTransactionFlags(eDisplayTransactionNeeded);
Mathias Agopian3094df32012-06-18 18:06:45 -0700702 }
703}
704
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800705// ----------------------------------------------------------------------------
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800706
707void SurfaceFlinger::waitForEvent() {
708 mEventQueue.waitMessage();
709}
710
711void SurfaceFlinger::signalTransaction() {
712 mEventQueue.invalidate();
713}
714
715void SurfaceFlinger::signalLayerUpdate() {
716 mEventQueue.invalidate();
717}
718
719void SurfaceFlinger::signalRefresh() {
720 mEventQueue.refresh();
721}
722
723status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
724 nsecs_t reltime, uint32_t flags) {
725 return mEventQueue.postMessage(msg, reltime);
726}
727
728status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
729 nsecs_t reltime, uint32_t flags) {
730 status_t res = mEventQueue.postMessage(msg, reltime);
731 if (res == NO_ERROR) {
732 msg->wait();
733 }
734 return res;
735}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800736
Mathias Agopian4fec8732012-06-29 14:12:52 -0700737bool SurfaceFlinger::threadLoop() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800738 waitForEvent();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800739 return true;
740}
741
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700742void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) {
Andy McFadden43601a22012-09-11 15:15:13 -0700743 if (mEventThread == NULL) {
744 // This is a temporary workaround for b/7145521. A non-null pointer
745 // does not mean EventThread has finished initializing, so this
746 // is not a correct fix.
747 ALOGW("WARNING: EventThread not started, ignoring vsync");
748 return;
749 }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700750 if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) {
751 // we should only receive DisplayDevice::DisplayType from the vsync callback
Mathias Agopian148994e2012-09-19 17:31:36 -0700752 mEventThread->onVSyncReceived(type, timestamp);
753 }
754}
755
756void SurfaceFlinger::onHotplugReceived(int type, bool connected) {
757 if (mEventThread == NULL) {
758 // This is a temporary workaround for b/7145521. A non-null pointer
759 // does not mean EventThread has finished initializing, so this
760 // is not a correct fix.
761 ALOGW("WARNING: EventThread not started, ignoring hotplug");
762 return;
763 }
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700764
Mathias Agopian148994e2012-09-19 17:31:36 -0700765 if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700766 Mutex::Autolock _l(mStateLock);
767 if (connected == false) {
768 mCurrentState.displays.removeItem(mDefaultDisplays[type]);
769 } else {
770 DisplayDeviceState info((DisplayDevice::DisplayType)type);
771 mCurrentState.displays.add(mDefaultDisplays[type], info);
772 }
773 setTransactionFlags(eDisplayTransactionNeeded);
774
Mathias Agopian148994e2012-09-19 17:31:36 -0700775 // we should only receive DisplayDevice::DisplayType from the vsync callback
776 mEventThread->onHotplugReceived(type, connected);
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700777 }
Mathias Agopian86303202012-07-24 22:46:10 -0700778}
779
780void SurfaceFlinger::eventControl(int event, int enabled) {
781 getHwComposer().eventControl(event, enabled);
782}
783
Mathias Agopian4fec8732012-06-29 14:12:52 -0700784void SurfaceFlinger::onMessageReceived(int32_t what) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800785 ATRACE_CALL();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800786 switch (what) {
Mathias Agopian4fec8732012-06-29 14:12:52 -0700787 case MessageQueue::INVALIDATE:
788 handleMessageTransaction();
789 handleMessageInvalidate();
790 signalRefresh();
791 break;
792 case MessageQueue::REFRESH:
793 handleMessageRefresh();
794 break;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800795 }
796}
797
Mathias Agopian4fec8732012-06-29 14:12:52 -0700798void SurfaceFlinger::handleMessageTransaction() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700799 uint32_t transactionFlags = peekTransactionFlags(eTransactionMask);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700800 if (transactionFlags) {
Mathias Agopian87baae12012-07-31 12:38:26 -0700801 handleTransaction(transactionFlags);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700802 }
803}
804
805void SurfaceFlinger::handleMessageInvalidate() {
Mathias Agopiancd60f992012-08-16 16:28:27 -0700806 ATRACE_CALL();
Mathias Agopian87baae12012-07-31 12:38:26 -0700807 handlePageFlip();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700808}
809
810void SurfaceFlinger::handleMessageRefresh() {
Mathias Agopiancd60f992012-08-16 16:28:27 -0700811 ATRACE_CALL();
812 preComposition();
813 rebuildLayerStacks();
814 setUpHWComposer();
815 doDebugFlashRegions();
816 doComposition();
817 postComposition();
818}
Mathias Agopian4fec8732012-06-29 14:12:52 -0700819
Mathias Agopiancd60f992012-08-16 16:28:27 -0700820void SurfaceFlinger::doDebugFlashRegions()
821{
822 // is debugging enabled
823 if (CC_LIKELY(!mDebugRegion))
824 return;
825
826 const bool repaintEverything = mRepaintEverything;
827 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
828 const sp<DisplayDevice>& hw(mDisplays[dpy]);
829 if (hw->canDraw()) {
830 // transform the dirty region into this screen's coordinate space
831 const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
832 if (!dirtyRegion.isEmpty()) {
833 // redraw the whole screen
834 doComposeSurfaces(hw, Region(hw->bounds()));
835
836 // and draw the dirty region
837 glDisable(GL_TEXTURE_EXTERNAL_OES);
838 glDisable(GL_TEXTURE_2D);
839 glDisable(GL_BLEND);
840 glColor4f(1, 0, 1, 1);
841 const int32_t height = hw->getHeight();
842 Region::const_iterator it = dirtyRegion.begin();
843 Region::const_iterator const end = dirtyRegion.end();
844 while (it != end) {
845 const Rect& r = *it++;
846 GLfloat vertices[][2] = {
847 { r.left, height - r.top },
848 { r.left, height - r.bottom },
849 { r.right, height - r.bottom },
850 { r.right, height - r.top }
851 };
852 glVertexPointer(2, GL_FLOAT, 0, vertices);
853 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
854 }
855 hw->compositionComplete();
Mathias Agopianda27af92012-09-13 18:17:13 -0700856 hw->swapBuffers(getHwComposer());
Mathias Agopiancd60f992012-08-16 16:28:27 -0700857 }
858 }
859 }
860
861 postFramebuffer();
862
863 if (mDebugRegion > 1) {
864 usleep(mDebugRegion * 1000);
865 }
Mathias Agopianbb53b0e2012-09-24 21:27:29 -0700866
867 HWComposer& hwc(getHwComposer());
868 if (hwc.initCheck() == NO_ERROR) {
869 status_t err = hwc.prepare();
870 ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
871 }
Mathias Agopiancd60f992012-08-16 16:28:27 -0700872}
873
874void SurfaceFlinger::preComposition()
875{
876 bool needExtraInvalidate = false;
877 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
878 const size_t count = currentLayers.size();
879 for (size_t i=0 ; i<count ; i++) {
880 if (currentLayers[i]->onPreComposition()) {
881 needExtraInvalidate = true;
882 }
883 }
884 if (needExtraInvalidate) {
885 signalLayerUpdate();
886 }
887}
888
889void SurfaceFlinger::postComposition()
890{
891 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
892 const size_t count = currentLayers.size();
893 for (size_t i=0 ; i<count ; i++) {
894 currentLayers[i]->onPostComposition();
895 }
896}
897
898void SurfaceFlinger::rebuildLayerStacks() {
899 // rebuild the visible layer list per screen
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700900 if (CC_UNLIKELY(mVisibleRegionsDirty)) {
Mathias Agopiancd60f992012-08-16 16:28:27 -0700901 ATRACE_CALL();
Mathias Agopian87baae12012-07-31 12:38:26 -0700902 mVisibleRegionsDirty = false;
903 invalidateHwcGeometry();
Mathias Agopiance3a0a52012-09-12 15:34:57 -0700904
Mathias Agopian87baae12012-07-31 12:38:26 -0700905 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
Mathias Agopian92a979a2012-08-02 18:32:23 -0700906 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
Mathias Agopiance3a0a52012-09-12 15:34:57 -0700907 Region opaqueRegion;
908 Region dirtyRegion;
909 Vector< sp<LayerBase> > layersSortedByZ;
Mathias Agopian42977342012-08-05 00:40:46 -0700910 const sp<DisplayDevice>& hw(mDisplays[dpy]);
Mathias Agopian7e7ed7f2012-08-28 14:20:00 -0700911 const Transform& tr(hw->getTransform());
912 const Rect bounds(hw->getBounds());
Mathias Agopiance3a0a52012-09-12 15:34:57 -0700913 if (hw->canDraw()) {
914 SurfaceFlinger::computeVisibleRegions(currentLayers,
915 hw->getLayerStack(), dirtyRegion, opaqueRegion);
Mathias Agopian7e7ed7f2012-08-28 14:20:00 -0700916
Mathias Agopiance3a0a52012-09-12 15:34:57 -0700917 const size_t count = currentLayers.size();
918 for (size_t i=0 ; i<count ; i++) {
919 const sp<LayerBase>& layer(currentLayers[i]);
920 const Layer::State& s(layer->drawingState());
921 if (s.layerStack == hw->getLayerStack()) {
Jesse Halla8026d22012-09-25 13:25:04 -0700922 Region drawRegion(tr.transform(
923 layer->visibleNonTransparentRegion));
924 drawRegion.andSelf(bounds);
925 if (!drawRegion.isEmpty()) {
Mathias Agopiance3a0a52012-09-12 15:34:57 -0700926 layersSortedByZ.add(layer);
927 }
Mathias Agopian87baae12012-07-31 12:38:26 -0700928 }
929 }
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700930 }
Mathias Agopian42977342012-08-05 00:40:46 -0700931 hw->setVisibleLayersSortedByZ(layersSortedByZ);
Mathias Agopian7e7ed7f2012-08-28 14:20:00 -0700932 hw->undefinedRegion.set(bounds);
933 hw->undefinedRegion.subtractSelf(tr.transform(opaqueRegion));
934 hw->dirtyRegion.orSelf(dirtyRegion);
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700935 }
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700936 }
Mathias Agopiancd60f992012-08-16 16:28:27 -0700937}
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700938
Mathias Agopiancd60f992012-08-16 16:28:27 -0700939void SurfaceFlinger::setUpHWComposer() {
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700940 HWComposer& hwc(getHwComposer());
941 if (hwc.initCheck() == NO_ERROR) {
942 // build the h/w work list
Jamie Gennisa4310c82012-09-25 20:26:00 -0700943 if (CC_UNLIKELY(mHwWorkListDirty)) {
944 mHwWorkListDirty = false;
945 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
946 sp<const DisplayDevice> hw(mDisplays[dpy]);
947 const int32_t id = hw->getHwcDisplayId();
948 if (id >= 0) {
949 const Vector< sp<LayerBase> >& currentLayers(
950 hw->getVisibleLayersSortedByZ());
951 const size_t count = currentLayers.size();
952 if (hwc.createWorkList(id, count) == NO_ERROR) {
953 HWComposer::LayerListIterator cur = hwc.begin(id);
954 const HWComposer::LayerListIterator end = hwc.end(id);
955 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
956 const sp<LayerBase>& layer(currentLayers[i]);
957 layer->setGeometry(hw, *cur);
958 if (mDebugDisableHWC || mDebugRegion) {
959 cur->setSkip(true);
960 }
961 }
962 }
963 }
964 }
965 }
966
967 // set the per-frame data
Mathias Agopian92a979a2012-08-02 18:32:23 -0700968 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
Mathias Agopian42977342012-08-05 00:40:46 -0700969 sp<const DisplayDevice> hw(mDisplays[dpy]);
Mathias Agopiane60b0682012-08-21 23:34:09 -0700970 const int32_t id = hw->getHwcDisplayId();
971 if (id >= 0) {
972 const Vector< sp<LayerBase> >& currentLayers(
Mathias Agopiancd60f992012-08-16 16:28:27 -0700973 hw->getVisibleLayersSortedByZ());
Mathias Agopiane60b0682012-08-21 23:34:09 -0700974 const size_t count = currentLayers.size();
Jamie Gennisa4310c82012-09-25 20:26:00 -0700975 HWComposer::LayerListIterator cur = hwc.begin(id);
976 const HWComposer::LayerListIterator end = hwc.end(id);
977 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
978 /*
979 * update the per-frame h/w composer data for each layer
980 * and build the transparent region of the FB
981 */
982 const sp<LayerBase>& layer(currentLayers[i]);
983 layer->setPerFrameData(hw, *cur);
Mathias Agopian1e260872012-08-08 18:35:12 -0700984 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700985 }
Mathias Agopian87baae12012-07-31 12:38:26 -0700986 }
Jamie Gennisa4310c82012-09-25 20:26:00 -0700987
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700988 status_t err = hwc.prepare();
989 ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
990 }
Mathias Agopiancd60f992012-08-16 16:28:27 -0700991}
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700992
Mathias Agopiancd60f992012-08-16 16:28:27 -0700993void SurfaceFlinger::doComposition() {
994 ATRACE_CALL();
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700995 const bool repaintEverything = android_atomic_and(0, &mRepaintEverything);
Mathias Agopian92a979a2012-08-02 18:32:23 -0700996 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
Mathias Agopian42977342012-08-05 00:40:46 -0700997 const sp<DisplayDevice>& hw(mDisplays[dpy]);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700998 if (hw->canDraw()) {
999 // transform the dirty region into this screen's coordinate space
1000 const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
1001 if (!dirtyRegion.isEmpty()) {
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001002 // repaint the framebuffer (if needed)
Mathias Agopiancd60f992012-08-16 16:28:27 -07001003 doDisplayComposition(hw, dirtyRegion);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001004 }
Mathias Agopiancd60f992012-08-16 16:28:27 -07001005 hw->dirtyRegion.clear();
1006 hw->flip(hw->swapRegion);
1007 hw->swapRegion.clear();
Mathias Agopian87baae12012-07-31 12:38:26 -07001008 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001009 // inform the h/w that we're done compositing
Mathias Agopian42977342012-08-05 00:40:46 -07001010 hw->compositionComplete();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001011 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001012 postFramebuffer();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001013}
1014
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001015void SurfaceFlinger::postFramebuffer()
1016{
Mathias Agopian841cde52012-03-01 15:44:37 -08001017 ATRACE_CALL();
Mathias Agopianb048cef2012-02-04 15:44:04 -08001018
Mathias Agopiana44b0412011-10-16 18:46:35 -07001019 const nsecs_t now = systemTime();
1020 mDebugInSwapBuffers = now;
Jesse Hallc5c5a142012-07-02 16:49:28 -07001021
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001022 HWComposer& hwc(getHwComposer());
Jesse Hallef194142012-06-14 14:45:17 -07001023 if (hwc.initCheck() == NO_ERROR) {
Mathias Agopian2a231842012-09-24 18:12:35 -07001024 if (!hwc.supportsFramebufferTarget()) {
1025 // EGL spec says:
1026 // "surface must be bound to the calling thread's current context,
1027 // for the current rendering API."
1028 DisplayDevice::makeCurrent(mEGLDisplay,
1029 getDefaultDisplayDevice(), mEGLContext);
1030 }
Mathias Agopiane60b0682012-08-21 23:34:09 -07001031 hwc.commit();
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001032 }
1033
Mathias Agopian92a979a2012-08-02 18:32:23 -07001034 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
Mathias Agopian42977342012-08-05 00:40:46 -07001035 sp<const DisplayDevice> hw(mDisplays[dpy]);
1036 const Vector< sp<LayerBase> >& currentLayers(hw->getVisibleLayersSortedByZ());
Mathias Agopianda27af92012-09-13 18:17:13 -07001037 hw->onSwapBuffersCompleted(hwc);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001038 const size_t count = currentLayers.size();
Mathias Agopiane60b0682012-08-21 23:34:09 -07001039 int32_t id = hw->getHwcDisplayId();
1040 if (id >=0 && hwc.initCheck() == NO_ERROR) {
Mathias Agopian1e260872012-08-08 18:35:12 -07001041 HWComposer::LayerListIterator cur = hwc.begin(id);
1042 const HWComposer::LayerListIterator end = hwc.end(id);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001043 for (size_t i = 0; cur != end && i < count; ++i, ++cur) {
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001044 currentLayers[i]->onLayerDisplayed(hw, &*cur);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001045 }
Mathias Agopiancd60f992012-08-16 16:28:27 -07001046 } else {
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001047 for (size_t i = 0; i < count; i++) {
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001048 currentLayers[i]->onLayerDisplayed(hw, NULL);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001049 }
Jesse Hallef194142012-06-14 14:45:17 -07001050 }
Jamie Gennise8696a42012-01-15 18:54:57 -08001051 }
1052
Mathias Agopiana44b0412011-10-16 18:46:35 -07001053 mLastSwapBufferTime = systemTime() - now;
1054 mDebugInSwapBuffers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001055}
1056
Mathias Agopian87baae12012-07-31 12:38:26 -07001057void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001058{
Mathias Agopian841cde52012-03-01 15:44:37 -08001059 ATRACE_CALL();
1060
Mathias Agopianca4d3602011-05-19 15:38:14 -07001061 Mutex::Autolock _l(mStateLock);
1062 const nsecs_t now = systemTime();
1063 mDebugInTransaction = now;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001064
Mathias Agopianca4d3602011-05-19 15:38:14 -07001065 // Here we're guaranteed that some transaction flags are set
1066 // so we can call handleTransactionLocked() unconditionally.
1067 // We call getTransactionFlags(), which will also clear the flags,
1068 // with mStateLock held to guarantee that mCurrentState won't change
1069 // until the transaction is committed.
Mathias Agopian4da75192010-08-10 17:19:56 -07001070
Mathias Agopiane57f2922012-08-09 16:29:12 -07001071 transactionFlags = getTransactionFlags(eTransactionMask);
Mathias Agopian87baae12012-07-31 12:38:26 -07001072 handleTransactionLocked(transactionFlags);
Mathias Agopiandea20b12011-05-03 17:04:02 -07001073
Mathias Agopianca4d3602011-05-19 15:38:14 -07001074 mLastTransactionTime = systemTime() - now;
1075 mDebugInTransaction = 0;
1076 invalidateHwcGeometry();
1077 // here the transaction has been committed
Mathias Agopian3d579642009-06-04 18:46:21 -07001078}
1079
Mathias Agopian87baae12012-07-31 12:38:26 -07001080void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
Mathias Agopian3d579642009-06-04 18:46:21 -07001081{
1082 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001083 const size_t count = currentLayers.size();
1084
1085 /*
1086 * Traversal of the children
1087 * (perform the transaction for each of them if needed)
1088 */
1089
Mathias Agopian3559b072012-08-15 13:46:03 -07001090 if (transactionFlags & eTraversalNeeded) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001091 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001092 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001093 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
1094 if (!trFlags) continue;
1095
1096 const uint32_t flags = layer->doTransaction(0);
1097 if (flags & Layer::eVisibleRegion)
1098 mVisibleRegionsDirty = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001099 }
1100 }
1101
1102 /*
Mathias Agopian3559b072012-08-15 13:46:03 -07001103 * Perform display own transactions if needed
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001104 */
1105
Mathias Agopiane57f2922012-08-09 16:29:12 -07001106 if (transactionFlags & eDisplayTransactionNeeded) {
Mathias Agopian92a979a2012-08-02 18:32:23 -07001107 // here we take advantage of Vector's copy-on-write semantics to
1108 // improve performance by skipping the transaction entirely when
1109 // know that the lists are identical
Mathias Agopiane57f2922012-08-09 16:29:12 -07001110 const KeyedVector< wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays);
1111 const KeyedVector< wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays);
Mathias Agopian92a979a2012-08-02 18:32:23 -07001112 if (!curr.isIdenticalTo(draw)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001113 mVisibleRegionsDirty = true;
Mathias Agopian92a979a2012-08-02 18:32:23 -07001114 const size_t cc = curr.size();
Mathias Agopian93997a82012-08-29 17:30:36 -07001115 size_t dc = draw.size();
Mathias Agopian92a979a2012-08-02 18:32:23 -07001116
1117 // find the displays that were removed
1118 // (ie: in drawing state but not in current state)
1119 // also handle displays that changed
1120 // (ie: displays that are in both lists)
1121 for (size_t i=0 ; i<dc ; i++) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001122 const ssize_t j = curr.indexOfKey(draw.keyAt(i));
1123 if (j < 0) {
Mathias Agopian92a979a2012-08-02 18:32:23 -07001124 // in drawing state but not in current state
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001125 if (!draw[i].isMainDisplay()) {
1126 mDisplays.removeItem(draw.keyAt(i));
Mathias Agopian92a979a2012-08-02 18:32:23 -07001127 } else {
1128 ALOGW("trying to remove the main display");
1129 }
1130 } else {
1131 // this display is in both lists. see if something changed.
Mathias Agopiane57f2922012-08-09 16:29:12 -07001132 const DisplayDeviceState& state(curr[j]);
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001133 const wp<IBinder>& display(curr.keyAt(j));
Mathias Agopian111b2d82012-08-16 20:52:17 -07001134 if (state.surface->asBinder() != draw[i].surface->asBinder()) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001135 // changing the surface is like destroying and
Mathias Agopian93997a82012-08-29 17:30:36 -07001136 // recreating the DisplayDevice, so we just remove it
1137 // from the drawing state, so that it get re-added
1138 // below.
1139 mDisplays.removeItem(display);
1140 mDrawingState.displays.removeItemsAt(i);
1141 dc--; i--;
1142 // at this point we must loop to the next item
1143 continue;
1144 }
Mathias Agopiane57f2922012-08-09 16:29:12 -07001145
Mathias Agopian93997a82012-08-29 17:30:36 -07001146 const sp<DisplayDevice>& disp(getDisplayDevice(display));
1147 if (disp != NULL) {
1148 if (state.layerStack != draw[i].layerStack) {
1149 disp->setLayerStack(state.layerStack);
1150 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001151 if ((state.orientation != draw[i].orientation)
1152 || (state.viewport != draw[i].viewport)
1153 || (state.frame != draw[i].frame))
1154 {
1155 disp->setProjection(state.orientation,
Jeff Brown4fb39992012-09-07 12:55:10 -07001156 state.viewport, state.frame);
Mathias Agopian93997a82012-08-29 17:30:36 -07001157 }
Andy McFadden69052052012-09-14 16:10:11 -07001158
1159 // Walk through all the layers in currentLayers,
1160 // and update their transform hint.
1161 //
1162 // TODO: we could be much more clever about which
1163 // layers we touch and how often we do these updates
1164 // (e.g. only touch the layers associated with this
1165 // display, and only on a rotation).
1166 for (size_t i = 0; i < count; i++) {
1167 const sp<LayerBase>& layerBase = currentLayers[i];
1168 layerBase->updateTransformHint();
1169 }
Mathias Agopian92a979a2012-08-02 18:32:23 -07001170 }
1171 }
1172 }
1173
1174 // find displays that were added
1175 // (ie: in current state but not in drawing state)
1176 for (size_t i=0 ; i<cc ; i++) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001177 if (draw.indexOfKey(curr.keyAt(i)) < 0) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001178 const DisplayDeviceState& state(curr[i]);
Mathias Agopiancde87a32012-09-13 14:09:01 -07001179
1180 sp<FramebufferSurface> fbs;
1181 sp<SurfaceTextureClient> stc;
1182 if (!state.isVirtualDisplay()) {
1183
1184 ALOGE_IF(state.surface!=NULL,
1185 "adding a supported display, but rendering "
1186 "surface is provided (%p), ignoring it",
1187 state.surface.get());
1188
1189 // for supported (by hwc) displays we provide our
1190 // own rendering surface
Mathias Agopianf5a33922012-09-19 18:16:22 -07001191 fbs = new FramebufferSurface(*mHwc, state.type);
Mathias Agopiancde87a32012-09-13 14:09:01 -07001192 stc = new SurfaceTextureClient(
1193 static_cast< sp<ISurfaceTexture> >(fbs->getBufferQueue()));
1194 } else {
1195 if (state.surface != NULL) {
1196 stc = new SurfaceTextureClient(state.surface);
1197 }
1198 }
1199
1200 const wp<IBinder>& display(curr.keyAt(i));
1201 if (stc != NULL) {
1202 sp<DisplayDevice> hw = new DisplayDevice(this,
1203 state.type, display, stc, fbs, mEGLConfig);
1204 hw->setLayerStack(state.layerStack);
1205 hw->setProjection(state.orientation,
Jeff Brown4fb39992012-09-07 12:55:10 -07001206 state.viewport, state.frame);
Andy McFadden8dfa92f2012-09-17 18:27:17 -07001207 hw->setDisplayName(state.displayName);
Mathias Agopiancde87a32012-09-13 14:09:01 -07001208 mDisplays.add(display, hw);
1209 if (hw->getDisplayType() < DisplayDevice::NUM_DISPLAY_TYPES) {
1210 // notify the system that this display is now up
1211 // (note onScreenAcquired() is safe to call from
1212 // here because we're in the main thread)
1213 onScreenAcquired(hw);
1214 }
Mathias Agopian93997a82012-08-29 17:30:36 -07001215 }
Mathias Agopian92a979a2012-08-02 18:32:23 -07001216 }
1217 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001218 }
Mathias Agopian3559b072012-08-15 13:46:03 -07001219 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001220
Mathias Agopian3559b072012-08-15 13:46:03 -07001221 /*
1222 * Perform our own transaction if needed
1223 */
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001224
Mathias Agopiancd60f992012-08-16 16:28:27 -07001225 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
1226 if (currentLayers.size() > previousLayers.size()) {
Mathias Agopian3559b072012-08-15 13:46:03 -07001227 // layers have been added
1228 mVisibleRegionsDirty = true;
1229 }
1230
1231 // some layers might have been removed, so
1232 // we need to update the regions they're exposing.
1233 if (mLayersRemoved) {
1234 mLayersRemoved = false;
1235 mVisibleRegionsDirty = true;
Mathias Agopian3559b072012-08-15 13:46:03 -07001236 const size_t count = previousLayers.size();
1237 for (size_t i=0 ; i<count ; i++) {
1238 const sp<LayerBase>& layer(previousLayers[i]);
1239 if (currentLayers.indexOf(layer) < 0) {
1240 // this layer is not visible anymore
1241 // TODO: we could traverse the tree from front to back and
1242 // compute the actual visible region
1243 // TODO: we could cache the transformed region
Mathias Agopian1501d542012-09-04 21:04:09 -07001244 const Layer::State& s(layer->drawingState());
1245 Region visibleReg = s.transform.transform(
1246 Region(Rect(s.active.w, s.active.h)));
1247 invalidateLayerStack(s.layerStack, visibleReg);
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001248 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001249 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001250 }
1251
1252 commitTransaction();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001253}
1254
1255void SurfaceFlinger::commitTransaction()
1256{
1257 if (!mLayersPendingRemoval.isEmpty()) {
1258 // Notify removed layers now that they can't be drawn from
1259 for (size_t i = 0; i < mLayersPendingRemoval.size(); i++) {
1260 mLayersPendingRemoval[i]->onRemoved();
1261 }
1262 mLayersPendingRemoval.clear();
1263 }
1264
1265 mDrawingState = mCurrentState;
1266 mTransationPending = false;
1267 mTransactionCV.broadcast();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001268}
1269
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001270void SurfaceFlinger::computeVisibleRegions(
Mathias Agopian87baae12012-07-31 12:38:26 -07001271 const LayerVector& currentLayers, uint32_t layerStack,
1272 Region& outDirtyRegion, Region& outOpaqueRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001273{
Mathias Agopian841cde52012-03-01 15:44:37 -08001274 ATRACE_CALL();
1275
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001276 Region aboveOpaqueLayers;
1277 Region aboveCoveredLayers;
1278 Region dirty;
1279
Mathias Agopian87baae12012-07-31 12:38:26 -07001280 outDirtyRegion.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001281
1282 size_t i = currentLayers.size();
1283 while (i--) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001284 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001285
1286 // start with the whole surface at its current location
Mathias Agopian97011222009-07-28 10:57:27 -07001287 const Layer::State& s(layer->drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001288
Mathias Agopian87baae12012-07-31 12:38:26 -07001289 // only consider the layers on the given later stack
1290 if (s.layerStack != layerStack)
1291 continue;
1292
Mathias Agopianab028732010-03-16 16:41:46 -07001293 /*
1294 * opaqueRegion: area of a surface that is fully opaque.
1295 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001296 Region opaqueRegion;
Mathias Agopianab028732010-03-16 16:41:46 -07001297
1298 /*
1299 * visibleRegion: area of a surface that is visible on screen
1300 * and not fully transparent. This is essentially the layer's
1301 * footprint minus the opaque regions above it.
1302 * Areas covered by a translucent surface are considered visible.
1303 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001304 Region visibleRegion;
Mathias Agopianab028732010-03-16 16:41:46 -07001305
1306 /*
1307 * coveredRegion: area of a surface that is covered by all
1308 * visible regions above it (which includes the translucent areas).
1309 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001310 Region coveredRegion;
Mathias Agopianab028732010-03-16 16:41:46 -07001311
Jesse Halla8026d22012-09-25 13:25:04 -07001312 /*
1313 * transparentRegion: area of a surface that is hinted to be completely
1314 * transparent. This is only used to tell when the layer has no visible
1315 * non-transparent regions and can be removed from the layer list. It
1316 * does not affect the visibleRegion of this layer or any layers
1317 * beneath it. The hint may not be correct if apps don't respect the
1318 * SurfaceView restrictions (which, sadly, some don't).
1319 */
1320 Region transparentRegion;
1321
Mathias Agopianab028732010-03-16 16:41:46 -07001322
1323 // handle hidden surfaces by setting the visible region to empty
Mathias Agopianda27af92012-09-13 18:17:13 -07001324 if (CC_LIKELY(layer->isVisible())) {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001325 const bool translucent = !layer->isOpaque();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001326 Rect bounds(layer->computeBounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001327 visibleRegion.set(bounds);
Mathias Agopianab028732010-03-16 16:41:46 -07001328 if (!visibleRegion.isEmpty()) {
1329 // Remove the transparent area from the visible region
1330 if (translucent) {
Mathias Agopian4fec8732012-06-29 14:12:52 -07001331 const Transform tr(s.transform);
1332 if (tr.transformed()) {
1333 if (tr.preserveRects()) {
1334 // transform the transparent region
Jesse Halla8026d22012-09-25 13:25:04 -07001335 transparentRegion = tr.transform(s.transparentRegion);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001336 } else {
1337 // transformation too complex, can't do the
1338 // transparent region optimization.
Jesse Halla8026d22012-09-25 13:25:04 -07001339 transparentRegion.clear();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001340 }
1341 } else {
Jesse Halla8026d22012-09-25 13:25:04 -07001342 transparentRegion = s.transparentRegion;
Mathias Agopian4fec8732012-06-29 14:12:52 -07001343 }
Mathias Agopianab028732010-03-16 16:41:46 -07001344 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001345
Mathias Agopianab028732010-03-16 16:41:46 -07001346 // compute the opaque region
Mathias Agopian4fec8732012-06-29 14:12:52 -07001347 const int32_t layerOrientation = s.transform.getOrientation();
Mathias Agopianab028732010-03-16 16:41:46 -07001348 if (s.alpha==255 && !translucent &&
1349 ((layerOrientation & Transform::ROT_INVALID) == false)) {
1350 // the opaque region is the layer's footprint
1351 opaqueRegion = visibleRegion;
1352 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001353 }
1354 }
1355
Mathias Agopianab028732010-03-16 16:41:46 -07001356 // Clip the covered region to the visible region
1357 coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
1358
1359 // Update aboveCoveredLayers for next (lower) layer
1360 aboveCoveredLayers.orSelf(visibleRegion);
1361
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001362 // subtract the opaque region covered by the layers above us
1363 visibleRegion.subtractSelf(aboveOpaqueLayers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001364
1365 // compute this layer's dirty region
1366 if (layer->contentDirty) {
1367 // we need to invalidate the whole region
1368 dirty = visibleRegion;
1369 // as well, as the old visible region
Mathias Agopian4fec8732012-06-29 14:12:52 -07001370 dirty.orSelf(layer->visibleRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001371 layer->contentDirty = false;
1372 } else {
Mathias Agopiana8d44f72009-06-28 02:54:16 -07001373 /* compute the exposed region:
Mathias Agopianab028732010-03-16 16:41:46 -07001374 * the exposed region consists of two components:
1375 * 1) what's VISIBLE now and was COVERED before
1376 * 2) what's EXPOSED now less what was EXPOSED before
1377 *
1378 * note that (1) is conservative, we start with the whole
1379 * visible region but only keep what used to be covered by
1380 * something -- which mean it may have been exposed.
1381 *
1382 * (2) handles areas that were not covered by anything but got
1383 * exposed because of a resize.
Mathias Agopiana8d44f72009-06-28 02:54:16 -07001384 */
Mathias Agopianab028732010-03-16 16:41:46 -07001385 const Region newExposed = visibleRegion - coveredRegion;
Mathias Agopian4fec8732012-06-29 14:12:52 -07001386 const Region oldVisibleRegion = layer->visibleRegion;
1387 const Region oldCoveredRegion = layer->coveredRegion;
Mathias Agopianab028732010-03-16 16:41:46 -07001388 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
1389 dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001390 }
1391 dirty.subtractSelf(aboveOpaqueLayers);
1392
1393 // accumulate to the screen dirty region
Mathias Agopian87baae12012-07-31 12:38:26 -07001394 outDirtyRegion.orSelf(dirty);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001395
Mathias Agopianab028732010-03-16 16:41:46 -07001396 // Update aboveOpaqueLayers for next (lower) layer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001397 aboveOpaqueLayers.orSelf(opaqueRegion);
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001398
Jesse Halla8026d22012-09-25 13:25:04 -07001399 // Store the visible region in screen space
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001400 layer->setVisibleRegion(visibleRegion);
1401 layer->setCoveredRegion(coveredRegion);
Jesse Halla8026d22012-09-25 13:25:04 -07001402 layer->setVisibleNonTransparentRegion(
1403 visibleRegion.subtract(transparentRegion));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001404 }
1405
Mathias Agopian87baae12012-07-31 12:38:26 -07001406 outOpaqueRegion = aboveOpaqueLayers;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001407}
1408
Mathias Agopian87baae12012-07-31 12:38:26 -07001409void SurfaceFlinger::invalidateLayerStack(uint32_t layerStack,
1410 const Region& dirty) {
Mathias Agopian92a979a2012-08-02 18:32:23 -07001411 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
Mathias Agopian42977342012-08-05 00:40:46 -07001412 const sp<DisplayDevice>& hw(mDisplays[dpy]);
1413 if (hw->getLayerStack() == layerStack) {
1414 hw->dirtyRegion.orSelf(dirty);
Mathias Agopian92a979a2012-08-02 18:32:23 -07001415 }
1416 }
Mathias Agopian87baae12012-07-31 12:38:26 -07001417}
1418
1419void SurfaceFlinger::handlePageFlip()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001420{
Mathias Agopian4fec8732012-06-29 14:12:52 -07001421 Region dirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001422
Mathias Agopian4fec8732012-06-29 14:12:52 -07001423 bool visibleRegions = false;
Mathias Agopiancd60f992012-08-16 16:28:27 -07001424 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001425 const size_t count = currentLayers.size();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001426 for (size_t i=0 ; i<count ; i++) {
Mathias Agopiancd60f992012-08-16 16:28:27 -07001427 const sp<LayerBase>& layer(currentLayers[i]);
Mathias Agopian87baae12012-07-31 12:38:26 -07001428 const Region dirty(layer->latchBuffer(visibleRegions));
Mathias Agopian1501d542012-09-04 21:04:09 -07001429 const Layer::State& s(layer->drawingState());
Mathias Agopian87baae12012-07-31 12:38:26 -07001430 invalidateLayerStack(s.layerStack, dirty);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001431 }
Mathias Agopian4da75192010-08-10 17:19:56 -07001432
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001433 mVisibleRegionsDirty |= visibleRegions;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001434}
1435
Mathias Agopianad456f92011-01-13 17:53:01 -08001436void SurfaceFlinger::invalidateHwcGeometry()
1437{
1438 mHwWorkListDirty = true;
1439}
1440
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001441
Mathias Agopiancd60f992012-08-16 16:28:27 -07001442void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
Mathias Agopian87baae12012-07-31 12:38:26 -07001443 const Region& inDirtyRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001444{
Mathias Agopian87baae12012-07-31 12:38:26 -07001445 Region dirtyRegion(inDirtyRegion);
1446
Mathias Agopianb8a55602009-06-26 19:06:36 -07001447 // compute the invalid region
Mathias Agopian42977342012-08-05 00:40:46 -07001448 hw->swapRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001449
Mathias Agopian42977342012-08-05 00:40:46 -07001450 uint32_t flags = hw->getFlags();
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -07001451 if (flags & DisplayDevice::SWAP_RECTANGLE) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001452 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
1453 // takes a rectangle, we must make sure to update that whole
1454 // rectangle in that case
Mathias Agopian42977342012-08-05 00:40:46 -07001455 dirtyRegion.set(hw->swapRegion.bounds());
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001456 } else {
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -07001457 if (flags & DisplayDevice::PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001458 // We need to redraw the rectangle that will be updated
1459 // (pushed to the framebuffer).
Mathias Agopian95a666b2009-09-24 14:57:26 -07001460 // This is needed because PARTIAL_UPDATES only takes one
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -07001461 // rectangle instead of a region (see DisplayDevice::flip())
Mathias Agopian42977342012-08-05 00:40:46 -07001462 dirtyRegion.set(hw->swapRegion.bounds());
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001463 } else {
1464 // we need to redraw everything (the whole screen)
Mathias Agopian42977342012-08-05 00:40:46 -07001465 dirtyRegion.set(hw->bounds());
1466 hw->swapRegion = dirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001467 }
1468 }
1469
Mathias Agopiancd60f992012-08-16 16:28:27 -07001470 doComposeSurfaces(hw, dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001471
Mathias Agopian9c6e2972011-09-20 17:21:56 -07001472 // update the swap region and clear the dirty region
Mathias Agopian42977342012-08-05 00:40:46 -07001473 hw->swapRegion.orSelf(dirtyRegion);
Mathias Agopianda27af92012-09-13 18:17:13 -07001474
1475 // swap buffers (presentation)
1476 hw->swapBuffers(getHwComposer());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001477}
1478
Mathias Agopiancd60f992012-08-16 16:28:27 -07001479void SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty)
Mathias Agopianf384cc32011-09-08 18:31:55 -07001480{
Mathias Agopian85d751c2012-08-29 16:59:24 -07001481 const int32_t id = hw->getHwcDisplayId();
Mathias Agopian86303202012-07-24 22:46:10 -07001482 HWComposer& hwc(getHwComposer());
Mathias Agopian1e260872012-08-08 18:35:12 -07001483 HWComposer::LayerListIterator cur = hwc.begin(id);
1484 const HWComposer::LayerListIterator end = hwc.end(id);
Mathias Agopiancd20eb02011-09-22 20:57:04 -07001485
Mathias Agopian85d751c2012-08-29 16:59:24 -07001486 const bool hasGlesComposition = hwc.hasGlesComposition(id) || (cur==end);
1487 if (hasGlesComposition) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -07001488 DisplayDevice::makeCurrent(mEGLDisplay, hw, mEGLContext);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -07001489
1490 // set the frame buffer
1491 glMatrixMode(GL_MODELVIEW);
1492 glLoadIdentity();
1493
1494 // Never touch the framebuffer if we don't have any framebuffer layers
Mathias Agopian85d751c2012-08-29 16:59:24 -07001495 const bool hasHwcComposition = hwc.hasHwcComposition(id);
Mathias Agopiane60b0682012-08-21 23:34:09 -07001496 if (hasHwcComposition) {
Mathias Agopianb9494d52012-04-18 02:28:45 -07001497 // when using overlays, we assume a fully transparent framebuffer
1498 // NOTE: we could reduce how much we need to clear, for instance
1499 // remove where there are opaque FB layers. however, on some
1500 // GPUs doing a "clean slate" glClear might be more efficient.
1501 // We'll revisit later if needed.
1502 glClearColor(0, 0, 0, 0);
1503 glClear(GL_COLOR_BUFFER_BIT);
1504 } else {
Mathias Agopian42977342012-08-05 00:40:46 -07001505 const Region region(hw->undefinedRegion.intersect(dirty));
Mathias Agopianb9494d52012-04-18 02:28:45 -07001506 // screen is already cleared here
Mathias Agopian87baae12012-07-31 12:38:26 -07001507 if (!region.isEmpty()) {
Mathias Agopianb9494d52012-04-18 02:28:45 -07001508 // can happen with SurfaceView
Mathias Agopian55801e42012-08-27 18:54:24 -07001509 drawWormhole(hw, region);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001510 }
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001511 }
Mathias Agopian85d751c2012-08-29 16:59:24 -07001512 }
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001513
Mathias Agopian85d751c2012-08-29 16:59:24 -07001514 /*
1515 * and then, render the layers targeted at the framebuffer
1516 */
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001517
Mathias Agopian85d751c2012-08-29 16:59:24 -07001518 const Vector< sp<LayerBase> >& layers(hw->getVisibleLayersSortedByZ());
1519 const size_t count = layers.size();
1520 const Transform& tr = hw->getTransform();
1521 if (cur != end) {
1522 // we're using h/w composer
1523 for (size_t i=0 ; i<count && cur!=end ; ++i, ++cur) {
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001524 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001525 const Region clip(dirty.intersect(tr.transform(layer->visibleRegion)));
Mathias Agopian85d751c2012-08-29 16:59:24 -07001526 if (!clip.isEmpty()) {
1527 switch (cur->getCompositionType()) {
1528 case HWC_OVERLAY: {
1529 if ((cur->getHints() & HWC_HINT_CLEAR_FB)
1530 && i
1531 && layer->isOpaque()
1532 && hasGlesComposition) {
Mathias Agopiancd60f992012-08-16 16:28:27 -07001533 // never clear the very first layer since we're
1534 // guaranteed the FB is already cleared
1535 layer->clearWithOpenGL(hw, clip);
1536 }
Mathias Agopian85d751c2012-08-29 16:59:24 -07001537 break;
Mathias Agopiancd60f992012-08-16 16:28:27 -07001538 }
Mathias Agopian85d751c2012-08-29 16:59:24 -07001539 case HWC_FRAMEBUFFER: {
1540 layer->draw(hw, clip);
1541 break;
1542 }
Mathias Agopianda27af92012-09-13 18:17:13 -07001543 case HWC_FRAMEBUFFER_TARGET: {
1544 // this should not happen as the iterator shouldn't
1545 // let us get there.
1546 ALOGW("HWC_FRAMEBUFFER_TARGET found in hwc list (index=%d)", i);
1547 break;
1548 }
Mathias Agopiancd60f992012-08-16 16:28:27 -07001549 }
Mathias Agopian85d751c2012-08-29 16:59:24 -07001550 }
1551 layer->setAcquireFence(hw, *cur);
1552 }
1553 } else {
1554 // we're not using h/w composer
1555 for (size_t i=0 ; i<count ; ++i) {
1556 const sp<LayerBase>& layer(layers[i]);
1557 const Region clip(dirty.intersect(
1558 tr.transform(layer->visibleRegion)));
1559 if (!clip.isEmpty()) {
1560 layer->draw(hw, clip);
Jesse Halla6b32db2012-07-19 16:44:38 -07001561 }
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001562 }
1563 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001564}
1565
Mathias Agopian55801e42012-08-27 18:54:24 -07001566void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw,
1567 const Region& region) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001568{
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001569 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001570 glDisable(GL_TEXTURE_2D);
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001571 glDisable(GL_BLEND);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001572 glColor4f(0,0,0,0);
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001573
Mathias Agopian55801e42012-08-27 18:54:24 -07001574 const int32_t height = hw->getHeight();
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001575 Region::const_iterator it = region.begin();
1576 Region::const_iterator const end = region.end();
1577 while (it != end) {
1578 const Rect& r = *it++;
Mathias Agopian55801e42012-08-27 18:54:24 -07001579 GLfloat vertices[][2] = {
1580 { r.left, height - r.top },
1581 { r.left, height - r.bottom },
1582 { r.right, height - r.bottom },
1583 { r.right, height - r.top }
1584 };
1585 glVertexPointer(2, GL_FLOAT, 0, vertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001586 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1587 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001588}
1589
Mathias Agopian96f08192010-06-02 23:28:45 -07001590ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
1591 const sp<LayerBaseClient>& lbc)
1592{
Mathias Agopian96f08192010-06-02 23:28:45 -07001593 // attach this layer to the client
Mathias Agopian4f113742011-05-03 16:21:41 -07001594 size_t name = client->attachLayer(lbc);
1595
Mathias Agopian96f08192010-06-02 23:28:45 -07001596 // add this layer to the current state list
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001597 Mutex::Autolock _l(mStateLock);
1598 mCurrentState.layersSortedByZ.add(lbc);
Mathias Agopian96f08192010-06-02 23:28:45 -07001599
Mathias Agopian4f113742011-05-03 16:21:41 -07001600 return ssize_t(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001601}
1602
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001603status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001604{
1605 Mutex::Autolock _l(mStateLock);
Mathias Agopian3d579642009-06-04 18:46:21 -07001606 status_t err = purgatorizeLayer_l(layer);
1607 if (err == NO_ERROR)
Mathias Agopian3559b072012-08-15 13:46:03 -07001608 setTransactionFlags(eTransactionNeeded);
Mathias Agopian3d579642009-06-04 18:46:21 -07001609 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001610}
1611
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001612status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001613{
1614 ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase);
1615 if (index >= 0) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001616 mLayersRemoved = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001617 return NO_ERROR;
1618 }
Mathias Agopian3d579642009-06-04 18:46:21 -07001619 return status_t(index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001620}
1621
Mathias Agopian9a112062009-04-17 19:36:26 -07001622status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase)
1623{
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001624 // First add the layer to the purgatory list, which makes sure it won't
1625 // go away, then remove it from the main list (through a transaction).
Mathias Agopian9a112062009-04-17 19:36:26 -07001626 ssize_t err = removeLayer_l(layerBase);
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001627 if (err >= 0) {
1628 mLayerPurgatory.add(layerBase);
1629 }
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001630
Jesse Hall2f4b68d2011-12-02 10:00:00 -08001631 mLayersPendingRemoval.push(layerBase);
Mathias Agopian0b3ad462009-10-02 18:12:30 -07001632
Mathias Agopian3d579642009-06-04 18:46:21 -07001633 // it's possible that we don't find a layer, because it might
1634 // have been destroyed already -- this is not technically an error
Mathias Agopian96f08192010-06-02 23:28:45 -07001635 // from the user because there is a race between Client::destroySurface(),
1636 // ~Client() and ~ISurface().
Mathias Agopian9a112062009-04-17 19:36:26 -07001637 return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err;
1638}
1639
Mathias Agopiandea20b12011-05-03 17:04:02 -07001640uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
1641{
1642 return android_atomic_release_load(&mTransactionFlags);
1643}
1644
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001645uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1646{
1647 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1648}
1649
Mathias Agopianbb641242010-05-18 17:06:55 -07001650uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001651{
1652 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1653 if ((old & flags)==0) { // wake the server up
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001654 signalTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001655 }
1656 return old;
1657}
1658
Mathias Agopian8b33f032012-07-24 20:43:54 -07001659void SurfaceFlinger::setTransactionState(
1660 const Vector<ComposerState>& state,
1661 const Vector<DisplayState>& displays,
1662 uint32_t flags)
1663{
Mathias Agopian698c0872011-06-28 19:09:31 -07001664 Mutex::Autolock _l(mStateLock);
Jamie Gennis28378392011-10-12 17:39:00 -07001665 uint32_t transactionFlags = 0;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001666
1667 size_t count = displays.size();
1668 for (size_t i=0 ; i<count ; i++) {
1669 const DisplayState& s(displays[i]);
1670 transactionFlags |= setDisplayStateLocked(s);
Jamie Gennisb8d69a52011-10-10 15:48:06 -07001671 }
1672
Mathias Agopiane57f2922012-08-09 16:29:12 -07001673 count = state.size();
Mathias Agopian698c0872011-06-28 19:09:31 -07001674 for (size_t i=0 ; i<count ; i++) {
1675 const ComposerState& s(state[i]);
1676 sp<Client> client( static_cast<Client *>(s.client.get()) );
Jamie Gennis28378392011-10-12 17:39:00 -07001677 transactionFlags |= setClientStateLocked(client, s.state);
Mathias Agopian698c0872011-06-28 19:09:31 -07001678 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001679
Mathias Agopian386aa982011-11-07 21:58:03 -08001680 if (transactionFlags) {
1681 // this triggers the transaction
1682 setTransactionFlags(transactionFlags);
1683
1684 // if this is a synchronous transaction, wait for it to take effect
1685 // before returning.
1686 if (flags & eSynchronous) {
1687 mTransationPending = true;
1688 }
1689 while (mTransationPending) {
1690 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1691 if (CC_UNLIKELY(err != NO_ERROR)) {
1692 // just in case something goes wrong in SF, return to the
1693 // called after a few seconds.
Steve Block32397c12012-01-05 23:22:43 +00001694 ALOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!");
Mathias Agopian386aa982011-11-07 21:58:03 -08001695 mTransationPending = false;
1696 break;
1697 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001698 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001699 }
1700}
1701
Mathias Agopiane57f2922012-08-09 16:29:12 -07001702uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s)
1703{
1704 uint32_t flags = 0;
1705 DisplayDeviceState& disp(mCurrentState.displays.editValueFor(s.token));
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001706 if (disp.isValid()) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001707 const uint32_t what = s.what;
1708 if (what & DisplayState::eSurfaceChanged) {
1709 if (disp.surface->asBinder() != s.surface->asBinder()) {
1710 disp.surface = s.surface;
1711 flags |= eDisplayTransactionNeeded;
1712 }
1713 }
1714 if (what & DisplayState::eLayerStackChanged) {
1715 if (disp.layerStack != s.layerStack) {
1716 disp.layerStack = s.layerStack;
1717 flags |= eDisplayTransactionNeeded;
1718 }
1719 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001720 if (what & DisplayState::eDisplayProjectionChanged) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001721 if (disp.orientation != s.orientation) {
1722 disp.orientation = s.orientation;
1723 flags |= eDisplayTransactionNeeded;
1724 }
1725 if (disp.frame != s.frame) {
1726 disp.frame = s.frame;
1727 flags |= eDisplayTransactionNeeded;
1728 }
1729 if (disp.viewport != s.viewport) {
1730 disp.viewport = s.viewport;
1731 flags |= eDisplayTransactionNeeded;
1732 }
1733 }
1734 }
1735 return flags;
1736}
1737
1738uint32_t SurfaceFlinger::setClientStateLocked(
1739 const sp<Client>& client,
1740 const layer_state_t& s)
1741{
1742 uint32_t flags = 0;
1743 sp<LayerBaseClient> layer(client->getLayerUser(s.surface));
1744 if (layer != 0) {
1745 const uint32_t what = s.what;
1746 if (what & layer_state_t::ePositionChanged) {
1747 if (layer->setPosition(s.x, s.y))
1748 flags |= eTraversalNeeded;
1749 }
1750 if (what & layer_state_t::eLayerChanged) {
1751 // NOTE: index needs to be calculated before we update the state
1752 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1753 if (layer->setLayer(s.z)) {
1754 mCurrentState.layersSortedByZ.removeAt(idx);
1755 mCurrentState.layersSortedByZ.add(layer);
1756 // we need traversal (state changed)
1757 // AND transaction (list changed)
1758 flags |= eTransactionNeeded|eTraversalNeeded;
1759 }
1760 }
1761 if (what & layer_state_t::eSizeChanged) {
1762 if (layer->setSize(s.w, s.h)) {
1763 flags |= eTraversalNeeded;
1764 }
1765 }
1766 if (what & layer_state_t::eAlphaChanged) {
1767 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1768 flags |= eTraversalNeeded;
1769 }
1770 if (what & layer_state_t::eMatrixChanged) {
1771 if (layer->setMatrix(s.matrix))
1772 flags |= eTraversalNeeded;
1773 }
1774 if (what & layer_state_t::eTransparentRegionChanged) {
1775 if (layer->setTransparentRegionHint(s.transparentRegion))
1776 flags |= eTraversalNeeded;
1777 }
1778 if (what & layer_state_t::eVisibilityChanged) {
1779 if (layer->setFlags(s.flags, s.mask))
1780 flags |= eTraversalNeeded;
1781 }
1782 if (what & layer_state_t::eCropChanged) {
1783 if (layer->setCrop(s.crop))
1784 flags |= eTraversalNeeded;
1785 }
1786 if (what & layer_state_t::eLayerStackChanged) {
1787 // NOTE: index needs to be calculated before we update the state
1788 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1789 if (layer->setLayerStack(s.layerStack)) {
1790 mCurrentState.layersSortedByZ.removeAt(idx);
1791 mCurrentState.layersSortedByZ.add(layer);
1792 // we need traversal (state changed)
1793 // AND transaction (list changed)
1794 flags |= eTransactionNeeded|eTraversalNeeded;
1795 }
1796 }
1797 }
1798 return flags;
1799}
1800
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001801sp<ISurface> SurfaceFlinger::createLayer(
Mathias Agopian0ef4e152011-04-20 14:19:32 -07001802 ISurfaceComposerClient::surface_data_t* params,
1803 const String8& name,
1804 const sp<Client>& client,
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001805 uint32_t w, uint32_t h, PixelFormat format,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001806 uint32_t flags)
1807{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001808 sp<LayerBaseClient> layer;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001809 sp<ISurface> surfaceHandle;
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001810
1811 if (int32_t(w|h) < 0) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001812 ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)",
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001813 int(w), int(h));
1814 return surfaceHandle;
1815 }
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001816
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001817 //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string());
Mathias Agopian3165cc22012-08-08 19:42:09 -07001818 switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
1819 case ISurfaceComposerClient::eFXSurfaceNormal:
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001820 layer = createNormalLayer(client, w, h, flags, format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001821 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -07001822 case ISurfaceComposerClient::eFXSurfaceBlur:
1823 case ISurfaceComposerClient::eFXSurfaceDim:
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001824 layer = createDimLayer(client, w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001825 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -07001826 case ISurfaceComposerClient::eFXSurfaceScreenshot:
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001827 layer = createScreenshotLayer(client, w, h, flags);
Mathias Agopian118d0242011-10-13 16:02:48 -07001828 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001829 }
1830
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001831 if (layer != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001832 layer->initStates(w, h, flags);
Mathias Agopian285dbde2010-03-01 16:09:43 -08001833 layer->setName(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001834 ssize_t token = addClientLayer(client, layer);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001835 surfaceHandle = layer->getSurface();
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001836 if (surfaceHandle != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001837 params->token = token;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001838 params->identity = layer->getIdentity();
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001839 }
Mathias Agopian96f08192010-06-02 23:28:45 -07001840 setTransactionFlags(eTransactionNeeded);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001841 }
1842
1843 return surfaceHandle;
1844}
1845
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001846sp<Layer> SurfaceFlinger::createNormalLayer(
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001847 const sp<Client>& client,
Mathias Agopian96f08192010-06-02 23:28:45 -07001848 uint32_t w, uint32_t h, uint32_t flags,
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001849 PixelFormat& format)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001850{
1851 // initialize the surfaces
Mathias Agopian92a979a2012-08-02 18:32:23 -07001852 switch (format) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001853 case PIXEL_FORMAT_TRANSPARENT:
1854 case PIXEL_FORMAT_TRANSLUCENT:
1855 format = PIXEL_FORMAT_RGBA_8888;
1856 break;
1857 case PIXEL_FORMAT_OPAQUE:
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001858#ifdef NO_RGBX_8888
1859 format = PIXEL_FORMAT_RGB_565;
1860#else
Mathias Agopian8f105402010-04-05 18:01:24 -07001861 format = PIXEL_FORMAT_RGBX_8888;
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001862#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001863 break;
1864 }
1865
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001866#ifdef NO_RGBX_8888
1867 if (format == PIXEL_FORMAT_RGBX_8888)
1868 format = PIXEL_FORMAT_RGBA_8888;
1869#endif
1870
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001871 sp<Layer> layer = new Layer(this, client);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001872 status_t err = layer->setBuffers(w, h, format, flags);
Glenn Kasten99ed2242011-12-15 09:51:17 -08001873 if (CC_LIKELY(err != NO_ERROR)) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001874 ALOGE("createNormalLayer() failed (%s)", strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001875 layer.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001876 }
1877 return layer;
1878}
1879
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001880sp<LayerDim> SurfaceFlinger::createDimLayer(
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001881 const sp<Client>& client,
Mathias Agopian96f08192010-06-02 23:28:45 -07001882 uint32_t w, uint32_t h, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001883{
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001884 sp<LayerDim> layer = new LayerDim(this, client);
Mathias Agopian118d0242011-10-13 16:02:48 -07001885 return layer;
1886}
1887
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001888sp<LayerScreenshot> SurfaceFlinger::createScreenshotLayer(
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001889 const sp<Client>& client,
Mathias Agopian118d0242011-10-13 16:02:48 -07001890 uint32_t w, uint32_t h, uint32_t flags)
1891{
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001892 sp<LayerScreenshot> layer = new LayerScreenshot(this, client);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001893 return layer;
1894}
1895
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001896status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, SurfaceID sid)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001897{
Mathias Agopian9a112062009-04-17 19:36:26 -07001898 /*
1899 * called by the window manager, when a surface should be marked for
1900 * destruction.
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001901 *
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001902 * The surface is removed from the current and drawing lists, but placed
1903 * in the purgatory queue, so it's not destroyed right-away (we need
1904 * to wait for all client's references to go away first).
Mathias Agopian9a112062009-04-17 19:36:26 -07001905 */
Mathias Agopian9a112062009-04-17 19:36:26 -07001906
Mathias Agopian48d819a2009-09-10 19:41:18 -07001907 status_t err = NAME_NOT_FOUND;
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001908 Mutex::Autolock _l(mStateLock);
Mathias Agopian96f08192010-06-02 23:28:45 -07001909 sp<LayerBaseClient> layer = client->getLayerUser(sid);
Daniel Lamb2675792012-02-23 14:35:13 -08001910
Mathias Agopian48d819a2009-09-10 19:41:18 -07001911 if (layer != 0) {
1912 err = purgatorizeLayer_l(layer);
1913 if (err == NO_ERROR) {
Mathias Agopian13233e02012-08-15 16:14:33 -07001914 setTransactionFlags(eTransactionNeeded);
Mathias Agopian48d819a2009-09-10 19:41:18 -07001915 }
Mathias Agopian9a112062009-04-17 19:36:26 -07001916 }
1917 return err;
1918}
1919
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001920status_t SurfaceFlinger::onLayerDestroyed(const wp<LayerBaseClient>& layer)
Mathias Agopian9a112062009-04-17 19:36:26 -07001921{
Mathias Agopian759fdb22009-07-02 17:33:40 -07001922 // called by ~ISurface() when all references are gone
Mathias Agopianca4d3602011-05-19 15:38:14 -07001923 status_t err = NO_ERROR;
1924 sp<LayerBaseClient> l(layer.promote());
1925 if (l != NULL) {
1926 Mutex::Autolock _l(mStateLock);
1927 err = removeLayer_l(l);
1928 if (err == NAME_NOT_FOUND) {
1929 // The surface wasn't in the current list, which means it was
1930 // removed already, which means it is in the purgatory,
1931 // and need to be removed from there.
1932 ssize_t idx = mLayerPurgatory.remove(l);
Steve Blocke6f43dd2012-01-06 19:20:56 +00001933 ALOGE_IF(idx < 0,
Mathias Agopianca4d3602011-05-19 15:38:14 -07001934 "layer=%p is not in the purgatory list", l.get());
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001935 }
Steve Blocke6f43dd2012-01-06 19:20:56 +00001936 ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
Mathias Agopianca4d3602011-05-19 15:38:14 -07001937 "error removing layer=%p (%s)", l.get(), strerror(-err));
1938 }
1939 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001940}
1941
Mathias Agopianb60314a2012-04-10 22:09:54 -07001942// ---------------------------------------------------------------------------
1943
Andy McFadden13a082e2012-08-24 10:16:42 -07001944void SurfaceFlinger::onInitializeDisplays() {
1945 // reset screen orientation
1946 Vector<ComposerState> state;
1947 Vector<DisplayState> displays;
1948 DisplayState d;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001949 d.what = DisplayState::eDisplayProjectionChanged;
Mathias Agopian3ee454a2012-08-27 16:28:24 -07001950 d.token = mDefaultDisplays[DisplayDevice::DISPLAY_PRIMARY];
Andy McFadden13a082e2012-08-24 10:16:42 -07001951 d.orientation = DisplayState::eOrientationDefault;
Jeff Brown4c05dd12012-09-09 00:07:17 -07001952 d.frame.makeInvalid();
1953 d.viewport.makeInvalid();
Andy McFadden13a082e2012-08-24 10:16:42 -07001954 displays.add(d);
1955 setTransactionState(state, displays, 0);
Mathias Agopiancde87a32012-09-13 14:09:01 -07001956 onScreenAcquired(getDefaultDisplayDevice());
Andy McFadden13a082e2012-08-24 10:16:42 -07001957}
1958
1959void SurfaceFlinger::initializeDisplays() {
1960 class MessageScreenInitialized : public MessageBase {
1961 SurfaceFlinger* flinger;
1962 public:
1963 MessageScreenInitialized(SurfaceFlinger* flinger) : flinger(flinger) { }
1964 virtual bool handler() {
1965 flinger->onInitializeDisplays();
1966 return true;
1967 }
1968 };
1969 sp<MessageBase> msg = new MessageScreenInitialized(this);
1970 postMessageAsync(msg); // we may be called from main thread, use async message
1971}
1972
1973
Mathias Agopiancde87a32012-09-13 14:09:01 -07001974void SurfaceFlinger::onScreenAcquired(const sp<const DisplayDevice>& hw) {
Andy McFaddenc01a79d2012-09-27 16:02:06 -07001975 ALOGD("Screen acquired, type=%d flinger=%p", hw->getDisplayType(), this);
1976 if (hw->isScreenAcquired()) {
1977 // this is expected, e.g. when power manager wakes up during boot
1978 ALOGD(" screen was previously acquired");
1979 return;
1980 }
1981
Mathias Agopian42977342012-08-05 00:40:46 -07001982 hw->acquireScreen();
Andy McFaddenc01a79d2012-09-27 16:02:06 -07001983 int32_t type = hw->getDisplayType();
1984 if (type < DisplayDevice::NUM_DISPLAY_TYPES) {
1985 // built-in display, tell the HWC
1986 getHwComposer().acquire(type);
1987
1988 if (type == DisplayDevice::DISPLAY_PRIMARY) {
1989 // FIXME: eventthread only knows about the main display right now
1990 mEventThread->onScreenAcquired();
1991 }
Mathias Agopiancde87a32012-09-13 14:09:01 -07001992 }
Mathias Agopian20128302012-08-13 18:32:13 -07001993 mVisibleRegionsDirty = true;
1994 repaintEverything();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001995}
1996
Mathias Agopiancde87a32012-09-13 14:09:01 -07001997void SurfaceFlinger::onScreenReleased(const sp<const DisplayDevice>& hw) {
Andy McFaddenc01a79d2012-09-27 16:02:06 -07001998 ALOGD("Screen released, type=%d flinger=%p", hw->getDisplayType(), this);
1999 if (!hw->isScreenAcquired()) {
2000 ALOGD(" screen was previously released");
2001 return;
2002 }
2003
2004 hw->releaseScreen();
2005 int32_t type = hw->getDisplayType();
2006 if (type < DisplayDevice::NUM_DISPLAY_TYPES) {
2007 if (type == DisplayDevice::DISPLAY_PRIMARY) {
Mathias Agopiancde87a32012-09-13 14:09:01 -07002008 // FIXME: eventthread only knows about the main display right now
2009 mEventThread->onScreenReleased();
2010 }
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002011
2012 // built-in display, tell the HWC
2013 getHwComposer().release(type);
2014 }
2015 mVisibleRegionsDirty = true;
2016 // from this point on, SF will stop drawing on this display
2017}
2018
2019void SurfaceFlinger::unblank(const sp<IBinder>& display) {
2020 class MessageScreenAcquired : public MessageBase {
2021 SurfaceFlinger* mFlinger;
2022 const sp<DisplayDevice>& mHw;
2023 public:
2024 MessageScreenAcquired(SurfaceFlinger* flinger,
2025 const sp<DisplayDevice>& hw) : mFlinger(flinger), mHw(hw) { }
2026 virtual bool handler() {
2027 mFlinger->onScreenAcquired(mHw);
2028 return true;
2029 }
2030 };
2031 const sp<DisplayDevice>& hw = getDisplayDevice(display);
2032 if (hw == NULL) {
2033 ALOGE("Attempt to unblank null display %p", display.get());
2034 } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) {
2035 ALOGW("Attempt to unblank virtual display");
2036 } else {
2037 sp<MessageBase> msg = new MessageScreenAcquired(this, hw);
2038 postMessageSync(msg);
Mathias Agopianb60314a2012-04-10 22:09:54 -07002039 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002040}
2041
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002042void SurfaceFlinger::blank(const sp<IBinder>& display) {
Mathias Agopianb60314a2012-04-10 22:09:54 -07002043 class MessageScreenReleased : public MessageBase {
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002044 SurfaceFlinger* mFlinger;
2045 const sp<DisplayDevice>& mHw;
Mathias Agopianb60314a2012-04-10 22:09:54 -07002046 public:
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002047 MessageScreenReleased(SurfaceFlinger* flinger,
2048 const sp<DisplayDevice>& hw) : mFlinger(flinger), mHw(hw) { }
Mathias Agopianb60314a2012-04-10 22:09:54 -07002049 virtual bool handler() {
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002050 mFlinger->onScreenReleased(mHw);
Mathias Agopianb60314a2012-04-10 22:09:54 -07002051 return true;
2052 }
2053 };
Andy McFaddenc01a79d2012-09-27 16:02:06 -07002054 const sp<DisplayDevice>& hw = getDisplayDevice(display);
2055 if (hw == NULL) {
2056 ALOGE("Attempt to blank null display %p", display.get());
2057 } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) {
2058 ALOGW("Attempt to blank virtual display");
2059 } else {
2060 sp<MessageBase> msg = new MessageScreenReleased(this, hw);
2061 postMessageSync(msg);
2062 }
Mathias Agopianb60314a2012-04-10 22:09:54 -07002063}
2064
2065// ---------------------------------------------------------------------------
2066
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002067status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
2068{
Erik Gilling1d21a9c2010-12-01 16:38:01 -08002069 const size_t SIZE = 4096;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002070 char buffer[SIZE];
2071 String8 result;
Mathias Agopian99b49842011-06-27 16:05:52 -07002072
2073 if (!PermissionCache::checkCallingPermission(sDump)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002074 snprintf(buffer, SIZE, "Permission Denial: "
2075 "can't dump SurfaceFlinger from pid=%d, uid=%d\n",
2076 IPCThreadState::self()->getCallingPid(),
2077 IPCThreadState::self()->getCallingUid());
2078 result.append(buffer);
2079 } else {
Mathias Agopian9795c422009-08-26 16:36:26 -07002080 // Try to get the main lock, but don't insist if we can't
2081 // (this would indicate SF is stuck, but we want to be able to
2082 // print something in dumpsys).
2083 int retry = 3;
2084 while (mStateLock.tryLock()<0 && --retry>=0) {
2085 usleep(1000000);
2086 }
2087 const bool locked(retry >= 0);
2088 if (!locked) {
Andreas Huber8b42e8a2010-08-16 08:49:37 -07002089 snprintf(buffer, SIZE,
Mathias Agopian9795c422009-08-26 16:36:26 -07002090 "SurfaceFlinger appears to be unresponsive, "
2091 "dumping anyways (no locks held)\n");
2092 result.append(buffer);
2093 }
2094
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002095 bool dumpAll = true;
2096 size_t index = 0;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002097 size_t numArgs = args.size();
2098 if (numArgs) {
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002099 if ((index < numArgs) &&
2100 (args[index] == String16("--list"))) {
2101 index++;
2102 listLayersLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08002103 dumpAll = false;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002104 }
2105
2106 if ((index < numArgs) &&
2107 (args[index] == String16("--latency"))) {
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002108 index++;
2109 dumpStatsLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08002110 dumpAll = false;
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002111 }
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002112
2113 if ((index < numArgs) &&
2114 (args[index] == String16("--latency-clear"))) {
2115 index++;
2116 clearStatsLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08002117 dumpAll = false;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002118 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002119 }
Mathias Agopian1b5e1022010-04-20 17:55:49 -07002120
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002121 if (dumpAll) {
2122 dumpAllLocked(result, buffer, SIZE);
Mathias Agopian48b888a2011-01-19 16:15:53 -08002123 }
2124
Mathias Agopian9795c422009-08-26 16:36:26 -07002125 if (locked) {
2126 mStateLock.unlock();
2127 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002128 }
2129 write(fd, result.string(), result.size());
2130 return NO_ERROR;
2131}
2132
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002133void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index,
2134 String8& result, char* buffer, size_t SIZE) const
2135{
2136 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2137 const size_t count = currentLayers.size();
2138 for (size_t i=0 ; i<count ; i++) {
2139 const sp<LayerBase>& layer(currentLayers[i]);
2140 snprintf(buffer, SIZE, "%s\n", layer->getName().string());
2141 result.append(buffer);
2142 }
2143}
2144
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002145void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index,
2146 String8& result, char* buffer, size_t SIZE) const
2147{
2148 String8 name;
2149 if (index < args.size()) {
2150 name = String8(args[index]);
2151 index++;
2152 }
2153
2154 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2155 const size_t count = currentLayers.size();
2156 for (size_t i=0 ; i<count ; i++) {
2157 const sp<LayerBase>& layer(currentLayers[i]);
2158 if (name.isEmpty()) {
2159 snprintf(buffer, SIZE, "%s\n", layer->getName().string());
2160 result.append(buffer);
2161 }
2162 if (name.isEmpty() || (name == layer->getName())) {
2163 layer->dumpStats(result, buffer, SIZE);
2164 }
2165 }
2166}
2167
Mathias Agopian25e66fc2012-01-28 22:31:55 -08002168void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
2169 String8& result, char* buffer, size_t SIZE) const
2170{
2171 String8 name;
2172 if (index < args.size()) {
2173 name = String8(args[index]);
2174 index++;
2175 }
2176
2177 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2178 const size_t count = currentLayers.size();
2179 for (size_t i=0 ; i<count ; i++) {
2180 const sp<LayerBase>& layer(currentLayers[i]);
2181 if (name.isEmpty() || (name == layer->getName())) {
2182 layer->clearStats();
2183 }
2184 }
2185}
2186
Andy McFadden4803b742012-09-24 19:07:20 -07002187/*static*/ void SurfaceFlinger::appendSfConfigString(String8& result)
2188{
2189 static const char* config =
2190 " [sf"
2191#ifdef NO_RGBX_8888
2192 " NO_RGBX_8888"
2193#endif
2194#ifdef HAS_CONTEXT_PRIORITY
2195 " HAS_CONTEXT_PRIORITY"
2196#endif
2197#ifdef NEVER_DEFAULT_TO_ASYNC_MODE
2198 " NEVER_DEFAULT_TO_ASYNC_MODE"
2199#endif
2200#ifdef TARGET_DISABLE_TRIPLE_BUFFERING
2201 " TARGET_DISABLE_TRIPLE_BUFFERING"
2202#endif
2203 "]";
2204 result.append(config);
2205}
2206
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002207void SurfaceFlinger::dumpAllLocked(
2208 String8& result, char* buffer, size_t SIZE) const
2209{
2210 // figure out if we're stuck somewhere
2211 const nsecs_t now = systemTime();
2212 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
2213 const nsecs_t inTransaction(mDebugInTransaction);
2214 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
2215 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
2216
2217 /*
Andy McFadden4803b742012-09-24 19:07:20 -07002218 * Dump library configuration.
2219 */
2220 result.append("Build configuration:");
2221 appendSfConfigString(result);
2222 appendUiConfigString(result);
2223 appendGuiConfigString(result);
2224 result.append("\n");
2225
2226 /*
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002227 * Dump the visible layer list
2228 */
2229 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2230 const size_t count = currentLayers.size();
2231 snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count);
2232 result.append(buffer);
2233 for (size_t i=0 ; i<count ; i++) {
2234 const sp<LayerBase>& layer(currentLayers[i]);
2235 layer->dump(result, buffer, SIZE);
2236 }
2237
2238 /*
2239 * Dump the layers in the purgatory
2240 */
2241
2242 const size_t purgatorySize = mLayerPurgatory.size();
2243 snprintf(buffer, SIZE, "Purgatory state (%d entries)\n", purgatorySize);
2244 result.append(buffer);
2245 for (size_t i=0 ; i<purgatorySize ; i++) {
2246 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
2247 layer->shortDump(result, buffer, SIZE);
2248 }
2249
2250 /*
Mathias Agopian5f20e2d2012-08-10 18:50:38 -07002251 * Dump Display state
2252 */
2253
Andy McFadden8dfa92f2012-09-17 18:27:17 -07002254 snprintf(buffer, SIZE, "Displays (%d entries)\n", mDisplays.size());
2255 result.append(buffer);
Mathias Agopian5f20e2d2012-08-10 18:50:38 -07002256 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
2257 const sp<const DisplayDevice>& hw(mDisplays[dpy]);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -07002258 hw->dump(result, buffer, SIZE);
Mathias Agopian5f20e2d2012-08-10 18:50:38 -07002259 }
2260
2261 /*
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002262 * Dump SurfaceFlinger global state
2263 */
2264
2265 snprintf(buffer, SIZE, "SurfaceFlinger global state:\n");
2266 result.append(buffer);
2267
Mathias Agopian888c8222012-08-04 21:10:38 -07002268 HWComposer& hwc(getHwComposer());
Mathias Agopian42977342012-08-05 00:40:46 -07002269 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002270 const GLExtensions& extensions(GLExtensions::getInstance());
2271 snprintf(buffer, SIZE, "GLES: %s, %s, %s\n",
2272 extensions.getVendor(),
2273 extensions.getRenderer(),
2274 extensions.getVersion());
2275 result.append(buffer);
2276
2277 snprintf(buffer, SIZE, "EGL : %s\n",
Mathias Agopiand3ee2312012-08-02 14:01:42 -07002278 eglQueryString(mEGLDisplay, EGL_VERSION_HW_ANDROID));
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002279 result.append(buffer);
2280
2281 snprintf(buffer, SIZE, "EXTS: %s\n", extensions.getExtension());
2282 result.append(buffer);
2283
Mathias Agopian42977342012-08-05 00:40:46 -07002284 hw->undefinedRegion.dump(result, "undefinedRegion");
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002285 snprintf(buffer, SIZE,
2286 " orientation=%d, canDraw=%d\n",
Mathias Agopian42977342012-08-05 00:40:46 -07002287 hw->getOrientation(), hw->canDraw());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002288 result.append(buffer);
2289 snprintf(buffer, SIZE,
2290 " last eglSwapBuffers() time: %f us\n"
2291 " last transaction time : %f us\n"
Mathias Agopianc95dbdc2012-02-05 00:19:27 -08002292 " transaction-flags : %08x\n"
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002293 " refresh-rate : %f fps\n"
2294 " x-dpi : %f\n"
Mathias Agopian8b736f12012-08-13 17:54:26 -07002295 " y-dpi : %f\n",
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002296 mLastSwapBufferTime/1000.0,
2297 mLastTransactionTime/1000.0,
Mathias Agopianc95dbdc2012-02-05 00:19:27 -08002298 mTransactionFlags,
Andy McFaddenb0d1dd32012-09-10 14:08:09 -07002299 1e9 / hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY),
2300 hwc.getDpiX(HWC_DISPLAY_PRIMARY),
2301 hwc.getDpiY(HWC_DISPLAY_PRIMARY));
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002302 result.append(buffer);
2303
2304 snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
2305 inSwapBuffersDuration/1000.0);
2306 result.append(buffer);
2307
2308 snprintf(buffer, SIZE, " transaction time: %f us\n",
2309 inTransactionDuration/1000.0);
2310 result.append(buffer);
2311
2312 /*
2313 * VSYNC state
2314 */
2315 mEventThread->dump(result, buffer, SIZE);
2316
2317 /*
2318 * Dump HWComposer state
2319 */
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002320 snprintf(buffer, SIZE, "h/w composer state:\n");
2321 result.append(buffer);
2322 snprintf(buffer, SIZE, " h/w composer %s and %s\n",
2323 hwc.initCheck()==NO_ERROR ? "present" : "not present",
2324 (mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled");
2325 result.append(buffer);
Mathias Agopian42977342012-08-05 00:40:46 -07002326 hwc.dump(result, buffer, SIZE, hw->getVisibleLayersSortedByZ());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002327
2328 /*
2329 * Dump gralloc state
2330 */
2331 const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
2332 alloc.dump(result);
Mathias Agopian82d7ab62012-01-19 18:34:40 -08002333}
2334
Keun young Park63f165f2012-08-31 10:53:36 -07002335bool SurfaceFlinger::startDdmConnection()
2336{
2337 void* libddmconnection_dso =
2338 dlopen("libsurfaceflinger_ddmconnection.so", RTLD_NOW);
2339 if (!libddmconnection_dso) {
2340 return false;
2341 }
2342 void (*DdmConnection_start)(const char* name);
2343 DdmConnection_start =
2344 (typeof DdmConnection_start)dlsym(libddmconnection_dso, "DdmConnection_start");
2345 if (!DdmConnection_start) {
2346 dlclose(libddmconnection_dso);
2347 return false;
2348 }
2349 (*DdmConnection_start)(getServiceName());
2350 return true;
2351}
2352
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002353status_t SurfaceFlinger::onTransact(
2354 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
2355{
2356 switch (code) {
2357 case CREATE_CONNECTION:
Mathias Agopian698c0872011-06-28 19:09:31 -07002358 case SET_TRANSACTION_STATE:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002359 case BOOT_FINISHED:
Colin Cross8e533062012-06-07 13:17:52 -07002360 case BLANK:
2361 case UNBLANK:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002362 {
2363 // codes that require permission check
2364 IPCThreadState* ipc = IPCThreadState::self();
2365 const int pid = ipc->getCallingPid();
Mathias Agopiana1ecca92009-05-21 19:21:59 -07002366 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07002367 if ((uid != AID_GRAPHICS) &&
2368 !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
Steve Blocke6f43dd2012-01-06 19:20:56 +00002369 ALOGE("Permission Denial: "
Mathias Agopian375f5632009-06-15 18:24:59 -07002370 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
2371 return PERMISSION_DENIED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002372 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002373 break;
2374 }
2375 case CAPTURE_SCREEN:
2376 {
2377 // codes that require permission check
2378 IPCThreadState* ipc = IPCThreadState::self();
2379 const int pid = ipc->getCallingPid();
2380 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07002381 if ((uid != AID_GRAPHICS) &&
2382 !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
Steve Blocke6f43dd2012-01-06 19:20:56 +00002383 ALOGE("Permission Denial: "
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002384 "can't read framebuffer pid=%d, uid=%d", pid, uid);
2385 return PERMISSION_DENIED;
2386 }
2387 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002388 }
2389 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002390
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002391 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
2392 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
Mathias Agopianb8a55602009-06-26 19:06:36 -07002393 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Glenn Kasten99ed2242011-12-15 09:51:17 -08002394 if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
Mathias Agopian375f5632009-06-15 18:24:59 -07002395 IPCThreadState* ipc = IPCThreadState::self();
2396 const int pid = ipc->getCallingPid();
2397 const int uid = ipc->getCallingUid();
Steve Blocke6f43dd2012-01-06 19:20:56 +00002398 ALOGE("Permission Denial: "
Mathias Agopian375f5632009-06-15 18:24:59 -07002399 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002400 return PERMISSION_DENIED;
2401 }
2402 int n;
2403 switch (code) {
Mathias Agopian01b76682009-04-16 20:04:08 -07002404 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
Mathias Agopian35b48d12010-09-13 22:57:58 -07002405 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002406 return NO_ERROR;
2407 case 1002: // SHOW_UPDATES
2408 n = data.readInt32();
2409 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
Mathias Agopian53331da2011-08-22 21:44:41 -07002410 invalidateHwcGeometry();
2411 repaintEverything();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002412 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002413 case 1004:{ // repaint everything
Mathias Agopian53331da2011-08-22 21:44:41 -07002414 repaintEverything();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07002415 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002416 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07002417 case 1005:{ // force transaction
Mathias Agopiane57f2922012-08-09 16:29:12 -07002418 setTransactionFlags(
2419 eTransactionNeeded|
2420 eDisplayTransactionNeeded|
2421 eTraversalNeeded);
Mathias Agopiancbb288b2009-09-07 16:32:45 -07002422 return NO_ERROR;
2423 }
Mathias Agopian4d143ee2012-02-23 20:05:39 -08002424 case 1006:{ // send empty update
2425 signalRefresh();
2426 return NO_ERROR;
2427 }
Mathias Agopian53331da2011-08-22 21:44:41 -07002428 case 1008: // toggle use of hw composer
2429 n = data.readInt32();
2430 mDebugDisableHWC = n ? 1 : 0;
2431 invalidateHwcGeometry();
2432 repaintEverything();
2433 return NO_ERROR;
Mathias Agopiana4583642011-08-23 18:03:18 -07002434 case 1009: // toggle use of transform hint
2435 n = data.readInt32();
2436 mDebugDisableTransformHint = n ? 1 : 0;
2437 invalidateHwcGeometry();
2438 repaintEverything();
2439 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002440 case 1010: // interrogate.
Mathias Agopian01b76682009-04-16 20:04:08 -07002441 reply->writeInt32(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002442 reply->writeInt32(0);
2443 reply->writeInt32(mDebugRegion);
Mathias Agopianb9494d52012-04-18 02:28:45 -07002444 reply->writeInt32(0);
Dianne Hackborn12839be2012-02-06 21:21:05 -08002445 reply->writeInt32(mDebugDisableHWC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002446 return NO_ERROR;
2447 case 1013: {
2448 Mutex::Autolock _l(mStateLock);
Mathias Agopian42977342012-08-05 00:40:46 -07002449 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
2450 reply->writeInt32(hw->getPageFlipCount());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002451 }
2452 return NO_ERROR;
2453 }
2454 }
2455 return err;
2456}
2457
Mathias Agopian53331da2011-08-22 21:44:41 -07002458void SurfaceFlinger::repaintEverything() {
Mathias Agopian87baae12012-07-31 12:38:26 -07002459 android_atomic_or(1, &mRepaintEverything);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08002460 signalTransaction();
Mathias Agopian53331da2011-08-22 21:44:41 -07002461}
2462
Mathias Agopian59119e62010-10-11 12:37:43 -07002463// ---------------------------------------------------------------------------
2464
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002465status_t SurfaceFlinger::renderScreenToTexture(uint32_t layerStack,
Mathias Agopian118d0242011-10-13 16:02:48 -07002466 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
2467{
2468 Mutex::Autolock _l(mStateLock);
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002469 return renderScreenToTextureLocked(layerStack, textureName, uOut, vOut);
Mathias Agopian118d0242011-10-13 16:02:48 -07002470}
2471
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002472status_t SurfaceFlinger::renderScreenToTextureLocked(uint32_t layerStack,
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002473 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
Mathias Agopian59119e62010-10-11 12:37:43 -07002474{
Mathias Agopian22ffb112012-04-10 21:04:02 -07002475 ATRACE_CALL();
2476
Mathias Agopian59119e62010-10-11 12:37:43 -07002477 if (!GLExtensions::getInstance().haveFramebufferObject())
2478 return INVALID_OPERATION;
2479
2480 // get screen geometry
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002481 // FIXME: figure out what it means to have a screenshot texture w/ multi-display
2482 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
Mathias Agopian42977342012-08-05 00:40:46 -07002483 const uint32_t hw_w = hw->getWidth();
2484 const uint32_t hw_h = hw->getHeight();
Mathias Agopian59119e62010-10-11 12:37:43 -07002485 GLfloat u = 1;
2486 GLfloat v = 1;
2487
2488 // make sure to clear all GL error flags
2489 while ( glGetError() != GL_NO_ERROR ) ;
2490
2491 // create a FBO
2492 GLuint name, tname;
2493 glGenTextures(1, &tname);
2494 glBindTexture(GL_TEXTURE_2D, tname);
Mathias Agopiana2f4e562012-04-15 23:34:59 -07002495 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2496 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002497 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
2498 hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002499 if (glGetError() != GL_NO_ERROR) {
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002500 while ( glGetError() != GL_NO_ERROR ) ;
Mathias Agopian59119e62010-10-11 12:37:43 -07002501 GLint tw = (2 << (31 - clz(hw_w)));
2502 GLint th = (2 << (31 - clz(hw_h)));
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002503 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
2504 tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002505 u = GLfloat(hw_w) / tw;
2506 v = GLfloat(hw_h) / th;
2507 }
2508 glGenFramebuffersOES(1, &name);
2509 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002510 glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
2511 GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002512
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002513 // redraw the screen entirely...
Mathias Agopianc492e672011-10-18 14:49:27 -07002514 glDisable(GL_TEXTURE_EXTERNAL_OES);
2515 glDisable(GL_TEXTURE_2D);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002516 glClearColor(0,0,0,1);
2517 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopiana9040d02011-10-10 19:02:07 -07002518 glMatrixMode(GL_MODELVIEW);
2519 glLoadIdentity();
Mathias Agopian42977342012-08-05 00:40:46 -07002520 const Vector< sp<LayerBase> >& layers(hw->getVisibleLayersSortedByZ());
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002521 const size_t count = layers.size();
2522 for (size_t i=0 ; i<count ; ++i) {
2523 const sp<LayerBase>& layer(layers[i]);
Mathias Agopianfcb239d2012-08-02 16:01:34 -07002524 layer->draw(hw);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002525 }
2526
Mathias Agopian42977342012-08-05 00:40:46 -07002527 hw->compositionComplete();
Mathias Agopian118d0242011-10-13 16:02:48 -07002528
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002529 // back to main framebuffer
2530 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002531 glDeleteFramebuffersOES(1, &name);
2532
2533 *textureName = tname;
2534 *uOut = u;
2535 *vOut = v;
2536 return NO_ERROR;
2537}
2538
2539// ---------------------------------------------------------------------------
2540
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002541status_t SurfaceFlinger::captureScreenImplLocked(const sp<IBinder>& display,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002542 sp<IMemoryHeap>* heap,
2543 uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002544 uint32_t sw, uint32_t sh,
2545 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian74c40c02010-09-29 13:02:36 -07002546{
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002547 ATRACE_CALL();
2548
Mathias Agopian74c40c02010-09-29 13:02:36 -07002549 status_t result = PERMISSION_DENIED;
2550
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002551 if (!GLExtensions::getInstance().haveFramebufferObject()) {
Mathias Agopian74c40c02010-09-29 13:02:36 -07002552 return INVALID_OPERATION;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002553 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002554
2555 // get screen geometry
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002556 sp<const DisplayDevice> hw(getDisplayDevice(display));
Mathias Agopian42977342012-08-05 00:40:46 -07002557 const uint32_t hw_w = hw->getWidth();
2558 const uint32_t hw_h = hw->getHeight();
Mathias Agopian74c40c02010-09-29 13:02:36 -07002559
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002560 // if we have secure windows on this display, never allow the screen capture
Mathias Agopian42977342012-08-05 00:40:46 -07002561 if (hw->getSecureLayerVisible()) {
Mathias Agopianef7b9c72012-08-10 15:22:19 -07002562 ALOGW("FB is protected: PERMISSION_DENIED");
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002563 return PERMISSION_DENIED;
2564 }
2565
2566 if ((sw > hw_w) || (sh > hw_h)) {
Mathias Agopianef7b9c72012-08-10 15:22:19 -07002567 ALOGE("size mismatch (%d, %d) > (%d, %d)", sw, sh, hw_w, hw_h);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002568 return BAD_VALUE;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002569 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002570
2571 sw = (!sw) ? hw_w : sw;
2572 sh = (!sh) ? hw_h : sh;
2573 const size_t size = sw * sh * 4;
Mathias Agopianfcb239d2012-08-02 16:01:34 -07002574 const bool filtering = sw != hw_w || sh != hw_h;
Mathias Agopian74c40c02010-09-29 13:02:36 -07002575
Mathias Agopianef7b9c72012-08-10 15:22:19 -07002576// ALOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d",
2577// sw, sh, minLayerZ, maxLayerZ);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002578
Mathias Agopian74c40c02010-09-29 13:02:36 -07002579 // make sure to clear all GL error flags
2580 while ( glGetError() != GL_NO_ERROR ) ;
2581
2582 // create a FBO
2583 GLuint name, tname;
2584 glGenRenderbuffersOES(1, &tname);
2585 glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
2586 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, sw, sh);
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002587
Mathias Agopian74c40c02010-09-29 13:02:36 -07002588 glGenFramebuffersOES(1, &name);
2589 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2590 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
2591 GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
2592
2593 GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002594
Mathias Agopian74c40c02010-09-29 13:02:36 -07002595 if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
2596
2597 // invert everything, b/c glReadPixel() below will invert the FB
2598 glViewport(0, 0, sw, sh);
2599 glMatrixMode(GL_PROJECTION);
2600 glPushMatrix();
2601 glLoadIdentity();
Mathias Agopianffcf4652011-07-07 17:30:31 -07002602 glOrthof(0, hw_w, hw_h, 0, 0, 1);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002603 glMatrixMode(GL_MODELVIEW);
2604
2605 // redraw the screen entirely...
2606 glClearColor(0,0,0,1);
2607 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopianf653b892010-12-16 18:46:17 -08002608
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002609 const Vector< sp<LayerBase> >& layers(hw->getVisibleLayersSortedByZ());
Jamie Gennis9575f602011-10-07 14:51:16 -07002610 const size_t count = layers.size();
Mathias Agopian74c40c02010-09-29 13:02:36 -07002611 for (size_t i=0 ; i<count ; ++i) {
2612 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002613 const uint32_t z = layer->drawingState().z;
2614 if (z >= minLayerZ && z <= maxLayerZ) {
2615 if (filtering) layer->setFiltering(true);
2616 layer->draw(hw);
2617 if (filtering) layer->setFiltering(false);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002618 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002619 }
2620
Mathias Agopian74c40c02010-09-29 13:02:36 -07002621 // check for errors and return screen capture
2622 if (glGetError() != GL_NO_ERROR) {
2623 // error while rendering
2624 result = INVALID_OPERATION;
2625 } else {
2626 // allocate shared memory large enough to hold the
2627 // screen capture
2628 sp<MemoryHeapBase> base(
2629 new MemoryHeapBase(size, 0, "screen-capture") );
2630 void* const ptr = base->getBase();
Mathias Agopian7b190512012-09-25 15:28:44 -07002631 if (ptr != MAP_FAILED) {
Mathias Agopian74c40c02010-09-29 13:02:36 -07002632 // capture the screen with glReadPixels()
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002633 ScopedTrace _t(ATRACE_TAG, "glReadPixels");
Mathias Agopian74c40c02010-09-29 13:02:36 -07002634 glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
2635 if (glGetError() == GL_NO_ERROR) {
2636 *heap = base;
2637 *w = sw;
2638 *h = sh;
2639 *f = PIXEL_FORMAT_RGBA_8888;
2640 result = NO_ERROR;
2641 }
2642 } else {
2643 result = NO_MEMORY;
2644 }
2645 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002646 glViewport(0, 0, hw_w, hw_h);
2647 glMatrixMode(GL_PROJECTION);
2648 glPopMatrix();
2649 glMatrixMode(GL_MODELVIEW);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002650 } else {
2651 result = BAD_VALUE;
2652 }
2653
2654 // release FBO resources
2655 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
2656 glDeleteRenderbuffersOES(1, &tname);
2657 glDeleteFramebuffersOES(1, &name);
Mathias Agopiane6f09842010-12-15 14:41:59 -08002658
Mathias Agopian42977342012-08-05 00:40:46 -07002659 hw->compositionComplete();
Mathias Agopiane6f09842010-12-15 14:41:59 -08002660
Mathias Agopianef7b9c72012-08-10 15:22:19 -07002661// ALOGD("screenshot: result = %s", result<0 ? strerror(result) : "OK");
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002662
Mathias Agopian74c40c02010-09-29 13:02:36 -07002663 return result;
2664}
2665
2666
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002667status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002668 sp<IMemoryHeap>* heap,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002669 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002670 uint32_t sw, uint32_t sh,
2671 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002672{
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002673 if (CC_UNLIKELY(display == 0))
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002674 return BAD_VALUE;
2675
2676 if (!GLExtensions::getInstance().haveFramebufferObject())
2677 return INVALID_OPERATION;
2678
2679 class MessageCaptureScreen : public MessageBase {
2680 SurfaceFlinger* flinger;
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002681 sp<IBinder> display;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002682 sp<IMemoryHeap>* heap;
2683 uint32_t* w;
2684 uint32_t* h;
2685 PixelFormat* f;
Mathias Agopian74c40c02010-09-29 13:02:36 -07002686 uint32_t sw;
2687 uint32_t sh;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002688 uint32_t minLayerZ;
2689 uint32_t maxLayerZ;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002690 status_t result;
2691 public:
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002692 MessageCaptureScreen(SurfaceFlinger* flinger, const sp<IBinder>& display,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002693 sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002694 uint32_t sw, uint32_t sh,
2695 uint32_t minLayerZ, uint32_t maxLayerZ)
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002696 : flinger(flinger), display(display),
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002697 heap(heap), w(w), h(h), f(f), sw(sw), sh(sh),
2698 minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
2699 result(PERMISSION_DENIED)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002700 {
2701 }
2702 status_t getResult() const {
2703 return result;
2704 }
2705 virtual bool handler() {
2706 Mutex::Autolock _l(flinger->mStateLock);
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002707 result = flinger->captureScreenImplLocked(display,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002708 heap, w, h, f, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002709 return true;
2710 }
2711 };
2712
2713 sp<MessageBase> msg = new MessageCaptureScreen(this,
Jeff Brown9d4e3d22012-08-24 20:00:51 -07002714 display, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002715 status_t res = postMessageSync(msg);
2716 if (res == NO_ERROR) {
2717 res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult();
2718 }
2719 return res;
2720}
2721
2722// ---------------------------------------------------------------------------
2723
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002724SurfaceFlinger::LayerVector::LayerVector() {
2725}
2726
2727SurfaceFlinger::LayerVector::LayerVector(const LayerVector& rhs)
2728 : SortedVector<sp<LayerBase> >(rhs) {
2729}
2730
2731int SurfaceFlinger::LayerVector::do_compare(const void* lhs,
2732 const void* rhs) const
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002733{
Mathias Agopianbe246f82012-07-31 22:59:38 -07002734 // sort layers per layer-stack, then by z-order and finally by sequence
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002735 const sp<LayerBase>& l(*reinterpret_cast<const sp<LayerBase>*>(lhs));
2736 const sp<LayerBase>& r(*reinterpret_cast<const sp<LayerBase>*>(rhs));
Mathias Agopianbe246f82012-07-31 22:59:38 -07002737
2738 uint32_t ls = l->currentState().layerStack;
2739 uint32_t rs = r->currentState().layerStack;
2740 if (ls != rs)
2741 return ls - rs;
2742
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002743 uint32_t lz = l->currentState().z;
2744 uint32_t rz = r->currentState().z;
Mathias Agopianbe246f82012-07-31 22:59:38 -07002745 if (lz != rz)
2746 return lz - rz;
2747
2748 return l->sequence - r->sequence;
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002749}
2750
2751// ---------------------------------------------------------------------------
2752
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002753SurfaceFlinger::DisplayDeviceState::DisplayDeviceState()
2754 : type(DisplayDevice::DISPLAY_ID_INVALID) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07002755}
2756
Mathias Agopian3ee454a2012-08-27 16:28:24 -07002757SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type)
2758 : type(type), layerStack(0), orientation(0) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -07002759 viewport.makeInvalid();
2760 frame.makeInvalid();
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002761}
2762
2763// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002764
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002765}; // namespace android