blob: c344870e21a3839d6020687288ae8771ae4aa644 [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>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070023
24#include <EGL/egl.h>
25#include <GLES/gl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
27#include <cutils/log.h>
28#include <cutils/properties.h>
29
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070030#include <binder/IPCThreadState.h>
31#include <binder/IServiceManager.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070032#include <binder/MemoryHeapBase.h>
Mathias Agopian99b49842011-06-27 16:05:52 -070033#include <binder/PermissionCache.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070034
Mathias Agopianc666cae2012-07-25 18:56:13 -070035#include <ui/DisplayInfo.h>
36
Mathias Agopiand0566bc2011-11-17 17:49:17 -080037#include <gui/IDisplayEventConnection.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070038#include <gui/BitTube.h>
39#include <gui/SurfaceTextureClient.h>
40
41#include <ui/GraphicBufferAllocator.h>
42#include <ui/PixelFormat.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080043
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044#include <utils/String8.h>
45#include <utils/String16.h>
46#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080047#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048
Mathias Agopian921e6ac2012-07-23 23:11:29 -070049#include <private/android_filesystem_config.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050
51#include "clz.h"
Mathias Agopian90ac7992012-02-25 18:48:35 -080052#include "DdmConnection.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070053#include "DisplayHardware.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070054#include "Client.h"
Mathias Agopiand0566bc2011-11-17 17:49:17 -080055#include "EventThread.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070056#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058#include "LayerDim.h"
Mathias Agopian118d0242011-10-13 16:02:48 -070059#include "LayerScreenshot.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061
Mathias Agopiana4912602012-07-12 14:25:33 -070062#include "DisplayHardware/FramebufferSurface.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070063#include "DisplayHardware/HWComposer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
Mathias Agopiana67932f2011-04-20 14:20:59 -070065
Mathias Agopianbc2d79e2011-11-29 17:55:46 -080066#define EGL_VERSION_HW_ANDROID 0x3143
67
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068#define DISPLAY_COUNT 1
69
70namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071// ---------------------------------------------------------------------------
72
Mathias Agopian99b49842011-06-27 16:05:52 -070073const String16 sHardwareTest("android.permission.HARDWARE_TEST");
74const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
75const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER");
76const String16 sDump("android.permission.DUMP");
77
78// ---------------------------------------------------------------------------
79
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080SurfaceFlinger::SurfaceFlinger()
81 : BnSurfaceComposer(), Thread(false),
82 mTransactionFlags(0),
Jamie Gennis28378392011-10-12 17:39:00 -070083 mTransationPending(false),
Mathias Agopian076b1cc2009-04-10 14:24:30 -070084 mLayersRemoved(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 mBootTime(systemTime()),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 mVisibleRegionsDirty(false),
Mathias Agopiana350ff92010-08-10 17:14:02 -070087 mHwWorkListDirty(false),
Mathias Agopianabd671a2010-10-14 14:54:06 -070088 mElectronBeamAnimationMode(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 mDebugRegion(0),
Mathias Agopian8afb7e32011-08-15 20:44:40 -070090 mDebugDDMS(0),
Mathias Agopian73d3ba92010-09-22 18:58:01 -070091 mDebugDisableHWC(0),
Mathias Agopiana4583642011-08-23 18:03:18 -070092 mDebugDisableTransformHint(0),
Mathias Agopian9795c422009-08-26 16:36:26 -070093 mDebugInSwapBuffers(0),
94 mLastSwapBufferTime(0),
95 mDebugInTransaction(0),
96 mLastTransactionTime(0),
Mathias Agopian3330b202009-10-05 17:07:12 -070097 mBootFinished(false),
Mathias Agopian3094df32012-06-18 18:06:45 -070098 mExternalDisplaySurface(EGL_NO_SURFACE)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099{
Steve Blocka19954a2012-01-04 20:05:49 +0000100 ALOGI("SurfaceFlinger is starting");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101
102 // debugging stuff...
103 char value[PROPERTY_VALUE_MAX];
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700104
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 property_get("debug.sf.showupdates", value, "0");
106 mDebugRegion = atoi(value);
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700107
Colin Cross3854ed52012-03-23 14:17:18 -0700108#ifdef DDMS_DEBUGGING
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700109 property_get("debug.sf.ddms", value, "0");
110 mDebugDDMS = atoi(value);
111 if (mDebugDDMS) {
112 DdmConnection::start(getServiceName());
113 }
Mathias Agopian5df99622012-06-18 17:27:56 -0700114#else
115#warning "DDMS_DEBUGGING disabled"
Colin Cross3854ed52012-03-23 14:17:18 -0700116#endif
Mathias Agopian8afb7e32011-08-15 20:44:40 -0700117
Steve Blocka19954a2012-01-04 20:05:49 +0000118 ALOGI_IF(mDebugRegion, "showupdates enabled");
Steve Blocka19954a2012-01-04 20:05:49 +0000119 ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120}
121
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800122void SurfaceFlinger::onFirstRef()
123{
124 mEventQueue.init(this);
125
126 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
127
128 // Wait for the main thread to be done with its initialization
129 mReadyToRunBarrier.wait();
130}
131
132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133SurfaceFlinger::~SurfaceFlinger()
134{
Mathias Agopiana4912602012-07-12 14:25:33 -0700135 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
136 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
137 eglTerminate(display);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138}
139
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800140void SurfaceFlinger::binderDied(const wp<IBinder>& who)
141{
142 // the window manager died on us. prepare its eulogy.
143
144 // reset screen orientation
145 Vector<ComposerState> state;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700146 Vector<DisplayState> displays;
147 DisplayState d;
148 d.orientation = eOrientationDefault;
149 displays.add(d);
150 setTransactionState(state, displays, 0);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800151
152 // restart the boot-animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700153 startBootAnim();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800154}
155
Mathias Agopian7e27f052010-05-28 14:22:23 -0700156sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800157{
Mathias Agopian96f08192010-06-02 23:28:45 -0700158 sp<ISurfaceComposerClient> bclient;
159 sp<Client> client(new Client(this));
160 status_t err = client->initCheck();
161 if (err == NO_ERROR) {
162 bclient = client;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800164 return bclient;
165}
166
Jamie Gennis9a78c902011-01-12 18:30:40 -0800167sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
168{
169 sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
170 return gba;
171}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700172
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173void SurfaceFlinger::bootFinished()
174{
175 const nsecs_t now = systemTime();
176 const nsecs_t duration = now - mBootTime;
Steve Blocka19954a2012-01-04 20:05:49 +0000177 ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
Mathias Agopian3330b202009-10-05 17:07:12 -0700178 mBootFinished = true;
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700179
180 // wait patiently for the window manager death
181 const String16 name("window");
182 sp<IBinder> window(defaultServiceManager()->getService(name));
183 if (window != 0) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700184 window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this));
Mathias Agopian1f339ff2011-07-01 17:08:43 -0700185 }
186
187 // stop boot animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700188 // formerly we would just kill the process, but we now ask it to exit so it
189 // can choose where to stop the animation.
190 property_set("service.bootanim.exit", "1");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191}
192
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700193void SurfaceFlinger::deleteTextureAsync(GLuint texture) {
194 class MessageDestroyGLTexture : public MessageBase {
195 GLuint texture;
196 public:
197 MessageDestroyGLTexture(GLuint texture)
198 : texture(texture) {
199 }
200 virtual bool handler() {
201 glDeleteTextures(1, &texture);
202 return true;
203 }
204 };
205 postMessageAsync(new MessageDestroyGLTexture(texture));
206}
207
Mathias Agopiana4912602012-07-12 14:25:33 -0700208status_t SurfaceFlinger::selectConfigForPixelFormat(
209 EGLDisplay dpy,
210 EGLint const* attrs,
211 PixelFormat format,
212 EGLConfig* outConfig)
213{
214 EGLConfig config = NULL;
215 EGLint numConfigs = -1, n=0;
216 eglGetConfigs(dpy, NULL, 0, &numConfigs);
217 EGLConfig* const configs = new EGLConfig[numConfigs];
218 eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
219 for (int i=0 ; i<n ; i++) {
220 EGLint nativeVisualId = 0;
221 eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId);
222 if (nativeVisualId>0 && format == nativeVisualId) {
223 *outConfig = configs[i];
224 delete [] configs;
225 return NO_ERROR;
226 }
227 }
228 delete [] configs;
229 return NAME_NOT_FOUND;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800230}
231
Mathias Agopiana4912602012-07-12 14:25:33 -0700232EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
233 // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
234 // it is to be used with WIFI displays
235 EGLConfig config;
236 EGLint dummy;
237 status_t err;
238 EGLint attribs[] = {
239 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
240 EGL_RECORDABLE_ANDROID, EGL_TRUE,
241 EGL_NONE
242 };
243 err = selectConfigForPixelFormat(display, attribs, nativeVisualId, &config);
244 if (err) {
245 // maybe we failed because of EGL_RECORDABLE_ANDROID
246 ALOGW("couldn't find an EGLConfig with EGL_RECORDABLE_ANDROID");
247 attribs[2] = EGL_NONE;
248 err = selectConfigForPixelFormat(display, attribs, nativeVisualId, &config);
249 }
250 ALOGE_IF(err, "couldn't find an EGLConfig matching the screen format");
251 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) {
252 ALOGW_IF(dummy == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
253 }
254 return config;
255}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256
Mathias Agopiana4912602012-07-12 14:25:33 -0700257EGLContext SurfaceFlinger::createGLContext(EGLDisplay display, EGLConfig config) {
258 // Also create our EGLContext
259 EGLint contextAttributes[] = {
260#ifdef EGL_IMG_context_priority
261#ifdef HAS_CONTEXT_PRIORITY
262#warning "using EGL_IMG_context_priority"
263 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
264#endif
265#endif
266 EGL_NONE, EGL_NONE
267 };
268 EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
269 ALOGE_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
270 return ctxt;
271}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272
Mathias Agopiana4912602012-07-12 14:25:33 -0700273void SurfaceFlinger::initializeGL(EGLDisplay display, EGLSurface surface) {
274 EGLBoolean result = eglMakeCurrent(display, surface, surface, mEGLContext);
275 if (!result) {
276 ALOGE("Couldn't create a working GLES context. check logs. exiting...");
277 exit(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278 }
279
Mathias Agopiana4912602012-07-12 14:25:33 -0700280 GLExtensions& extensions(GLExtensions::getInstance());
281 extensions.initWithGLStrings(
282 glGetString(GL_VENDOR),
283 glGetString(GL_RENDERER),
284 glGetString(GL_VERSION),
285 glGetString(GL_EXTENSIONS),
286 eglQueryString(display, EGL_VENDOR),
287 eglQueryString(display, EGL_VERSION),
288 eglQueryString(display, EGL_EXTENSIONS));
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700289
Mathias Agopiana4912602012-07-12 14:25:33 -0700290 EGLint w, h;
291 eglQuerySurface(display, surface, EGL_WIDTH, &w);
292 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700293
Mathias Agopiana4912602012-07-12 14:25:33 -0700294 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
295 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700296
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800297 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700298 glPixelStorei(GL_PACK_ALIGNMENT, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800299 glEnableClientState(GL_VERTEX_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800300 glShadeModel(GL_FLAT);
301 glDisable(GL_DITHER);
302 glDisable(GL_CULL_FACE);
303
Mathias Agopiana4912602012-07-12 14:25:33 -0700304 struct pack565 {
305 inline uint16_t operator() (int r, int g, int b) const {
306 return (r<<11)|(g<<5)|b;
307 }
308 } pack565;
309
Jamie Gennis9575f602011-10-07 14:51:16 -0700310 const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) };
311 glGenTextures(1, &mProtectedTexName);
312 glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
313 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
314 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
315 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
316 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
317 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
318 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800319
320 glViewport(0, 0, w, h);
321 glMatrixMode(GL_PROJECTION);
322 glLoadIdentity();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700323 // put the origin in the left-bottom corner
324 glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325
Mathias Agopiana4912602012-07-12 14:25:33 -0700326 // print some debugging info
327 EGLint r,g,b,a;
328 eglGetConfigAttrib(display, mEGLConfig, EGL_RED_SIZE, &r);
329 eglGetConfigAttrib(display, mEGLConfig, EGL_GREEN_SIZE, &g);
330 eglGetConfigAttrib(display, mEGLConfig, EGL_BLUE_SIZE, &b);
331 eglGetConfigAttrib(display, mEGLConfig, EGL_ALPHA_SIZE, &a);
332 ALOGI("EGL informations:");
333 ALOGI("vendor : %s", extensions.getEglVendor());
334 ALOGI("version : %s", extensions.getEglVersion());
335 ALOGI("extensions: %s", extensions.getEglExtension());
336 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
337 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, mEGLConfig);
338 ALOGI("OpenGL ES informations:");
339 ALOGI("vendor : %s", extensions.getVendor());
340 ALOGI("renderer : %s", extensions.getRenderer());
341 ALOGI("version : %s", extensions.getVersion());
342 ALOGI("extensions: %s", extensions.getExtension());
343 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
344 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
345}
346
Mathias Agopiana4912602012-07-12 14:25:33 -0700347status_t SurfaceFlinger::readyToRun()
348{
349 ALOGI( "SurfaceFlinger's main thread ready to run. "
350 "Initializing graphics H/W...");
351
Mathias Agopiana4912602012-07-12 14:25:33 -0700352 // initialize EGL
Jesse Hall34a09ba2012-07-29 22:35:34 -0700353 mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
354 eglInitialize(mEGLDisplay, NULL, NULL);
Mathias Agopiana4912602012-07-12 14:25:33 -0700355
356 // Initialize the main display
357 // create native window to main display
358 sp<FramebufferSurface> anw = FramebufferSurface::create();
359 ANativeWindow* const window = anw.get();
360 if (!window) {
361 ALOGE("Display subsystem failed to initialize. check logs. exiting...");
362 exit(0);
363 }
364
365 // initialize the config and context
366 int format;
367 window->query(window, NATIVE_WINDOW_FORMAT, &format);
Jesse Hall34a09ba2012-07-29 22:35:34 -0700368 mEGLConfig = selectEGLConfig(mEGLDisplay, format);
369 mEGLContext = createGLContext(mEGLDisplay, mEGLConfig);
Mathias Agopiana4912602012-07-12 14:25:33 -0700370
371 // initialize our main display hardware
372 DisplayHardware* const hw = new DisplayHardware(this, 0, anw, mEGLConfig);
373 mDisplayHardwares[0] = hw;
374
375 // initialize OpenGL ES
376 EGLSurface surface = hw->getEGLSurface();
Jesse Hall34a09ba2012-07-29 22:35:34 -0700377 initializeGL(mEGLDisplay, surface);
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800378
Mathias Agopian028508c2012-07-25 21:12:12 -0700379 // start the EventThread
380 mEventThread = new EventThread(this);
381 mEventQueue.setEventThread(mEventThread);
382
Mathias Agopian86303202012-07-24 22:46:10 -0700383 // initialize the H/W composer
384 mHwc = new HWComposer(this,
385 *static_cast<HWComposer::EventHandler *>(this),
386 hw->getRefreshPeriod());
Mathias Agopian86303202012-07-24 22:46:10 -0700387
Mathias Agopiana4912602012-07-12 14:25:33 -0700388 // We're now ready to accept clients...
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800389 mReadyToRunBarrier.open();
390
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700391 // start boot animation
Mathias Agopiana67e4182012-06-19 17:26:12 -0700392 startBootAnim();
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700393
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394 return NO_ERROR;
395}
396
Mathias Agopiana67e4182012-06-19 17:26:12 -0700397void SurfaceFlinger::startBootAnim() {
398 // start boot animation
399 property_set("service.bootanim.exit", "0");
400 property_set("ctl.start", "bootanim");
401}
402
Mathias Agopiana4912602012-07-12 14:25:33 -0700403uint32_t SurfaceFlinger::getMaxTextureSize() const {
404 return mMaxTextureSize;
405}
406
407uint32_t SurfaceFlinger::getMaxViewportDims() const {
408 return mMaxViewportDims[0] < mMaxViewportDims[1] ?
409 mMaxViewportDims[0] : mMaxViewportDims[1];
410}
411
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800412// ----------------------------------------------------------------------------
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800413
Jamie Gennis582270d2011-08-17 18:19:00 -0700414bool SurfaceFlinger::authenticateSurfaceTexture(
415 const sp<ISurfaceTexture>& surfaceTexture) const {
Jamie Gennis134f0422011-03-08 12:18:54 -0800416 Mutex::Autolock _l(mStateLock);
Jamie Gennis582270d2011-08-17 18:19:00 -0700417 sp<IBinder> surfaceTextureBinder(surfaceTexture->asBinder());
Jamie Gennis134f0422011-03-08 12:18:54 -0800418
419 // Check the visible layer list for the ISurface
420 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
421 size_t count = currentLayers.size();
422 for (size_t i=0 ; i<count ; i++) {
423 const sp<LayerBase>& layer(currentLayers[i]);
424 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
Jamie Gennis582270d2011-08-17 18:19:00 -0700425 if (lbc != NULL) {
426 wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
427 if (lbcBinder == surfaceTextureBinder) {
428 return true;
429 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800430 }
431 }
432
433 // Check the layers in the purgatory. This check is here so that if a
Jamie Gennis582270d2011-08-17 18:19:00 -0700434 // SurfaceTexture gets destroyed before all the clients are done using it,
435 // the error will not be reported as "surface XYZ is not authenticated", but
Jamie Gennis134f0422011-03-08 12:18:54 -0800436 // will instead fail later on when the client tries to use the surface,
437 // which should be reported as "surface XYZ returned an -ENODEV". The
438 // purgatorized layers are no less authentic than the visible ones, so this
439 // should not cause any harm.
440 size_t purgatorySize = mLayerPurgatory.size();
441 for (size_t i=0 ; i<purgatorySize ; i++) {
442 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
443 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
Jamie Gennis582270d2011-08-17 18:19:00 -0700444 if (lbc != NULL) {
445 wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder();
446 if (lbcBinder == surfaceTextureBinder) {
447 return true;
448 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800449 }
450 }
451
452 return false;
453}
454
Mathias Agopianc666cae2012-07-25 18:56:13 -0700455status_t SurfaceFlinger::getDisplayInfo(DisplayID dpy, DisplayInfo* info) {
456 if (uint32_t(dpy) >= 2) {
457 return BAD_INDEX;
458 }
459 const DisplayHardware& hw(getDefaultDisplayHardware());
460 return hw.getInfo(info);
461}
462
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800463// ----------------------------------------------------------------------------
464
465sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {
Mathias Agopian8aedd472012-01-24 16:39:14 -0800466 return mEventThread->createEventConnection();
Mathias Agopianbb641242010-05-18 17:06:55 -0700467}
468
Mathias Agopian3094df32012-06-18 18:06:45 -0700469void SurfaceFlinger::connectDisplay(const sp<ISurfaceTexture> display) {
Mathias Agopian1b031492012-06-20 17:51:20 -0700470 const DisplayHardware& hw(getDefaultDisplayHardware());
Mathias Agopian3094df32012-06-18 18:06:45 -0700471 EGLSurface result = EGL_NO_SURFACE;
472 EGLSurface old_surface = EGL_NO_SURFACE;
473 sp<SurfaceTextureClient> stc;
474
475 if (display != NULL) {
476 stc = new SurfaceTextureClient(display);
477 result = eglCreateWindowSurface(hw.getEGLDisplay(),
Mathias Agopiana4912602012-07-12 14:25:33 -0700478 mEGLConfig, (EGLNativeWindowType)stc.get(), NULL);
Mathias Agopian3094df32012-06-18 18:06:45 -0700479 ALOGE_IF(result == EGL_NO_SURFACE,
480 "eglCreateWindowSurface failed (ISurfaceTexture=%p)",
481 display.get());
482 }
483
484 { // scope for the lock
485 Mutex::Autolock _l(mStateLock);
486 old_surface = mExternalDisplaySurface;
487 mExternalDisplayNativeWindow = stc;
488 mExternalDisplaySurface = result;
489 ALOGD("mExternalDisplaySurface = %p", result);
490 }
491
492 if (old_surface != EGL_NO_SURFACE) {
493 // Note: EGL allows to destroy an object while its current
494 // it will fail to become current next time though.
495 eglDestroySurface(hw.getEGLDisplay(), old_surface);
496 }
497}
498
499EGLSurface SurfaceFlinger::getExternalDisplaySurface() const {
500 Mutex::Autolock _l(mStateLock);
501 return mExternalDisplaySurface;
502}
503
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800504// ----------------------------------------------------------------------------
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800505
506void SurfaceFlinger::waitForEvent() {
507 mEventQueue.waitMessage();
508}
509
510void SurfaceFlinger::signalTransaction() {
511 mEventQueue.invalidate();
512}
513
514void SurfaceFlinger::signalLayerUpdate() {
515 mEventQueue.invalidate();
516}
517
518void SurfaceFlinger::signalRefresh() {
519 mEventQueue.refresh();
520}
521
522status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
523 nsecs_t reltime, uint32_t flags) {
524 return mEventQueue.postMessage(msg, reltime);
525}
526
527status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
528 nsecs_t reltime, uint32_t flags) {
529 status_t res = mEventQueue.postMessage(msg, reltime);
530 if (res == NO_ERROR) {
531 msg->wait();
532 }
533 return res;
534}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535
Mathias Agopian4fec8732012-06-29 14:12:52 -0700536bool SurfaceFlinger::threadLoop() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800537 waitForEvent();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800538 return true;
539}
540
Mathias Agopian86303202012-07-24 22:46:10 -0700541void SurfaceFlinger::onVSyncReceived(int dpy, nsecs_t timestamp) {
542 DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(dpy)));
543 hw.onVSyncReceived(timestamp);
544 mEventThread->onVSyncReceived(dpy, timestamp);
545}
546
547void SurfaceFlinger::eventControl(int event, int enabled) {
548 getHwComposer().eventControl(event, enabled);
549}
550
Mathias Agopian4fec8732012-06-29 14:12:52 -0700551void SurfaceFlinger::onMessageReceived(int32_t what) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800552 ATRACE_CALL();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800553 switch (what) {
Mathias Agopian4fec8732012-06-29 14:12:52 -0700554 case MessageQueue::INVALIDATE:
555 handleMessageTransaction();
556 handleMessageInvalidate();
557 signalRefresh();
558 break;
559 case MessageQueue::REFRESH:
560 handleMessageRefresh();
561 break;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800562 }
563}
564
Mathias Agopian4fec8732012-06-29 14:12:52 -0700565void SurfaceFlinger::handleMessageTransaction() {
566 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
567 uint32_t transactionFlags = peekTransactionFlags(mask);
568 if (transactionFlags) {
Mathias Agopian87baae12012-07-31 12:38:26 -0700569 handleTransaction(transactionFlags);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700570 }
571}
572
573void SurfaceFlinger::handleMessageInvalidate() {
Mathias Agopian87baae12012-07-31 12:38:26 -0700574 handlePageFlip();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700575}
576
577void SurfaceFlinger::handleMessageRefresh() {
578 handleRefresh();
579
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700580 if (mVisibleRegionsDirty) {
Mathias Agopian87baae12012-07-31 12:38:26 -0700581 mVisibleRegionsDirty = false;
582 invalidateHwcGeometry();
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700583
584 /*
585 * rebuild the visible layer list per screen
586 */
587
Mathias Agopian87baae12012-07-31 12:38:26 -0700588 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700589 // TODO: iterate through all displays
Mathias Agopian87baae12012-07-31 12:38:26 -0700590 {
591 DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(0)));
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700592
Mathias Agopian87baae12012-07-31 12:38:26 -0700593 Region opaqueRegion;
594 Region dirtyRegion;
595 computeVisibleRegions(currentLayers,
596 hw.getLayerStack(), dirtyRegion, opaqueRegion);
597 hw.dirtyRegion.orSelf(dirtyRegion);
598
599 Vector< sp<LayerBase> > layersSortedByZ;
600 const size_t count = currentLayers.size();
601 for (size_t i=0 ; i<count ; i++) {
602 const Layer::State& s(currentLayers[i]->drawingState());
603 if (s.layerStack == hw.getLayerStack()) {
604 if (!currentLayers[i]->visibleRegion.isEmpty()) {
605 layersSortedByZ.add(currentLayers[i]);
606 }
607 }
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700608 }
Mathias Agopian87baae12012-07-31 12:38:26 -0700609 hw.setVisibleLayersSortedByZ(layersSortedByZ);
610 hw.undefinedRegion.set(hw.getBounds());
611 hw.undefinedRegion.subtractSelf(hw.getTransform().transform(opaqueRegion));
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700612 }
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700613 }
614
Mathias Agopian87baae12012-07-31 12:38:26 -0700615 const bool repaintEverything = android_atomic_and(0, &mRepaintEverything);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700616
617 // TODO: iterate through all displays
Mathias Agopian87baae12012-07-31 12:38:26 -0700618 for (int dpy=0 ; dpy<1 ; dpy++) {
619 DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(0)));
620 if (hw.dirtyRegion.isEmpty()) {
621 continue;
622 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700623
Mathias Agopian87baae12012-07-31 12:38:26 -0700624 // transform the dirty region into this screen's coordinate space
625 const Transform& planeTransform(hw.getTransform());
626 Region dirtyRegion;
627 if (repaintEverything) {
628 dirtyRegion = planeTransform.transform(hw.dirtyRegion);
629 dirtyRegion.andSelf(hw.bounds());
630 } else {
631 dirtyRegion.set(hw.bounds());
632 }
633 hw.dirtyRegion.clear();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700634
Mathias Agopian4fec8732012-06-29 14:12:52 -0700635 // build the h/w work list
Mathias Agopian87baae12012-07-31 12:38:26 -0700636 if (CC_UNLIKELY(mHwWorkListDirty)) {
637 handleWorkList(hw);
638 }
639
640 if (CC_LIKELY(hw.canDraw())) {
641 // repaint the framebuffer (if needed)
642 handleRepaint(hw, dirtyRegion);
643 // inform the h/w that we're done compositing
644 hw.compositionComplete();
645 postFramebuffer();
646 } else {
647 // pretend we did the post
648 hw.compositionComplete();
649 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700650 }
651
Mathias Agopian4fec8732012-06-29 14:12:52 -0700652
Mathias Agopian87baae12012-07-31 12:38:26 -0700653#if 0
Mathias Agopian4fec8732012-06-29 14:12:52 -0700654 // render to the external display if we have one
655 EGLSurface externalDisplaySurface = getExternalDisplaySurface();
656 if (externalDisplaySurface != EGL_NO_SURFACE) {
657 EGLSurface cur = eglGetCurrentSurface(EGL_DRAW);
658 EGLBoolean success = eglMakeCurrent(eglGetCurrentDisplay(),
659 externalDisplaySurface, externalDisplaySurface,
660 eglGetCurrentContext());
661
662 ALOGE_IF(!success, "eglMakeCurrent -> external failed");
663
664 if (success) {
665 // redraw the screen entirely...
666 glDisable(GL_TEXTURE_EXTERNAL_OES);
667 glDisable(GL_TEXTURE_2D);
668 glClearColor(0,0,0,1);
669 glClear(GL_COLOR_BUFFER_BIT);
670 glMatrixMode(GL_MODELVIEW);
671 glLoadIdentity();
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700672
673 const Vector< sp<LayerBase> >& layers( hw.getVisibleLayersSortedByZ() );
Mathias Agopian4fec8732012-06-29 14:12:52 -0700674 const size_t count = layers.size();
675 for (size_t i=0 ; i<count ; ++i) {
676 const sp<LayerBase>& layer(layers[i]);
677 layer->drawForSreenShot(hw);
678 }
679
680 success = eglSwapBuffers(eglGetCurrentDisplay(), externalDisplaySurface);
681 ALOGE_IF(!success, "external display eglSwapBuffers failed");
682
683 hw.compositionComplete();
684 }
685
686 success = eglMakeCurrent(eglGetCurrentDisplay(),
687 cur, cur, eglGetCurrentContext());
688
689 ALOGE_IF(!success, "eglMakeCurrent -> internal failed");
690 }
Mathias Agopian87baae12012-07-31 12:38:26 -0700691#endif
Mathias Agopian4fec8732012-06-29 14:12:52 -0700692
693}
694
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800695void SurfaceFlinger::postFramebuffer()
696{
Mathias Agopian841cde52012-03-01 15:44:37 -0800697 ATRACE_CALL();
Mathias Agopianb048cef2012-02-04 15:44:04 -0800698 // mSwapRegion can be empty here is some cases, for instance if a hidden
699 // or fully transparent window is updating.
700 // in that case, we need to flip anyways to not risk a deadlock with
701 // h/w composer.
702
Mathias Agopian1b031492012-06-20 17:51:20 -0700703 const DisplayHardware& hw(getDefaultDisplayHardware());
Mathias Agopian86303202012-07-24 22:46:10 -0700704 HWComposer& hwc(getHwComposer());
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700705 const Vector< sp<LayerBase> >& layers(hw.getVisibleLayersSortedByZ());
706 size_t numLayers = layers.size();
Mathias Agopiana44b0412011-10-16 18:46:35 -0700707 const nsecs_t now = systemTime();
708 mDebugInSwapBuffers = now;
Jesse Hallc5c5a142012-07-02 16:49:28 -0700709
710 if (hwc.initCheck() == NO_ERROR) {
711 HWComposer::LayerListIterator cur = hwc.begin();
712 const HWComposer::LayerListIterator end = hwc.end();
713 for (size_t i = 0; cur != end && i < numLayers; ++i, ++cur) {
714 if (cur->getCompositionType() == HWC_OVERLAY) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700715 layers[i]->setAcquireFence(*cur);
Jesse Hallc5c5a142012-07-02 16:49:28 -0700716 } else {
717 cur->setAcquireFenceFd(-1);
718 }
719 }
720 }
721
Mathias Agopian87baae12012-07-31 12:38:26 -0700722 hw.flip(hw.swapRegion);
723 hw.swapRegion.clear();
Jamie Gennise8696a42012-01-15 18:54:57 -0800724
Jesse Hallef194142012-06-14 14:45:17 -0700725 if (hwc.initCheck() == NO_ERROR) {
Jesse Hall34a09ba2012-07-29 22:35:34 -0700726 hwc.commit(mEGLDisplay, hw.getEGLSurface());
Jesse Hallef194142012-06-14 14:45:17 -0700727 HWComposer::LayerListIterator cur = hwc.begin();
728 const HWComposer::LayerListIterator end = hwc.end();
729 for (size_t i = 0; cur != end && i < numLayers; ++i, ++cur) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700730 layers[i]->onLayerDisplayed(&*cur);
Jesse Hallef194142012-06-14 14:45:17 -0700731 }
732 } else {
Jesse Hall34a09ba2012-07-29 22:35:34 -0700733 eglSwapBuffers(mEGLDisplay, hw.getEGLSurface());
Jesse Hallef194142012-06-14 14:45:17 -0700734 for (size_t i = 0; i < numLayers; i++) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700735 layers[i]->onLayerDisplayed(NULL);
Jesse Hallef194142012-06-14 14:45:17 -0700736 }
Jamie Gennise8696a42012-01-15 18:54:57 -0800737 }
738
Mathias Agopiana44b0412011-10-16 18:46:35 -0700739 mLastSwapBufferTime = systemTime() - now;
740 mDebugInSwapBuffers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800741}
742
Mathias Agopian87baae12012-07-31 12:38:26 -0700743void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800744{
Mathias Agopian841cde52012-03-01 15:44:37 -0800745 ATRACE_CALL();
746
Mathias Agopianca4d3602011-05-19 15:38:14 -0700747 Mutex::Autolock _l(mStateLock);
748 const nsecs_t now = systemTime();
749 mDebugInTransaction = now;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800750
Mathias Agopianca4d3602011-05-19 15:38:14 -0700751 // Here we're guaranteed that some transaction flags are set
752 // so we can call handleTransactionLocked() unconditionally.
753 // We call getTransactionFlags(), which will also clear the flags,
754 // with mStateLock held to guarantee that mCurrentState won't change
755 // until the transaction is committed.
Mathias Agopian4da75192010-08-10 17:19:56 -0700756
Mathias Agopianca4d3602011-05-19 15:38:14 -0700757 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
758 transactionFlags = getTransactionFlags(mask);
Mathias Agopian87baae12012-07-31 12:38:26 -0700759 handleTransactionLocked(transactionFlags);
Mathias Agopiandea20b12011-05-03 17:04:02 -0700760
Mathias Agopianca4d3602011-05-19 15:38:14 -0700761 mLastTransactionTime = systemTime() - now;
762 mDebugInTransaction = 0;
763 invalidateHwcGeometry();
764 // here the transaction has been committed
Mathias Agopian3d579642009-06-04 18:46:21 -0700765}
766
Mathias Agopian87baae12012-07-31 12:38:26 -0700767void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
Mathias Agopian3d579642009-06-04 18:46:21 -0700768{
769 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800770 const size_t count = currentLayers.size();
771
772 /*
773 * Traversal of the children
774 * (perform the transaction for each of them if needed)
775 */
776
777 const bool layersNeedTransaction = transactionFlags & eTraversalNeeded;
778 if (layersNeedTransaction) {
779 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700780 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800781 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
782 if (!trFlags) continue;
783
784 const uint32_t flags = layer->doTransaction(0);
785 if (flags & Layer::eVisibleRegion)
786 mVisibleRegionsDirty = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800787 }
788 }
789
790 /*
791 * Perform our own transaction if needed
792 */
793
794 if (transactionFlags & eTransactionNeeded) {
795 if (mCurrentState.orientation != mDrawingState.orientation) {
796 // the orientation has changed, recompute all visible regions
797 // and invalidate everything.
798
Mathias Agopian87baae12012-07-31 12:38:26 -0700799 const int dpy = 0; // FIXME: should be a parameter
Mathias Agopian1b031492012-06-20 17:51:20 -0700800 DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(dpy)));
Mathias Agopian98a121a2012-07-24 21:08:59 -0700801 hw.setOrientation(mCurrentState.orientation);
Mathias Agopian87baae12012-07-31 12:38:26 -0700802 hw.dirtyRegion.set(hw.bounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800803
804 mVisibleRegionsDirty = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800805 }
806
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700807 if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) {
808 // layers have been added
809 mVisibleRegionsDirty = true;
810 }
811
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800812 // some layers might have been removed, so
813 // we need to update the regions they're exposing.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700814 if (mLayersRemoved) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700815 mLayersRemoved = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800816 mVisibleRegionsDirty = true;
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700817 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
Mathias Agopian3d579642009-06-04 18:46:21 -0700818 const size_t count = previousLayers.size();
819 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700820 const sp<LayerBase>& layer(previousLayers[i]);
Mathias Agopian87baae12012-07-31 12:38:26 -0700821 if (currentLayers.indexOf(layer) < 0) {
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700822 // this layer is not visible anymore
Mathias Agopian87baae12012-07-31 12:38:26 -0700823 // TODO: we could traverse the tree from front to back and
824 // compute the actual visible region
Mathias Agopian4fec8732012-06-29 14:12:52 -0700825 // TODO: we could cache the transformed region
826 Layer::State front(layer->drawingState());
827 Region visibleReg = front.transform.transform(
828 Region(Rect(front.active.w, front.active.h)));
Mathias Agopian87baae12012-07-31 12:38:26 -0700829 invalidateLayerStack(front.layerStack, visibleReg);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700830 }
831 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800832 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800833 }
834
835 commitTransaction();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700836}
837
838void SurfaceFlinger::commitTransaction()
839{
840 if (!mLayersPendingRemoval.isEmpty()) {
841 // Notify removed layers now that they can't be drawn from
842 for (size_t i = 0; i < mLayersPendingRemoval.size(); i++) {
843 mLayersPendingRemoval[i]->onRemoved();
844 }
845 mLayersPendingRemoval.clear();
846 }
847
848 mDrawingState = mCurrentState;
849 mTransationPending = false;
850 mTransactionCV.broadcast();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800851}
852
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800853void SurfaceFlinger::computeVisibleRegions(
Mathias Agopian87baae12012-07-31 12:38:26 -0700854 const LayerVector& currentLayers, uint32_t layerStack,
855 Region& outDirtyRegion, Region& outOpaqueRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800856{
Mathias Agopian841cde52012-03-01 15:44:37 -0800857 ATRACE_CALL();
858
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800859 Region aboveOpaqueLayers;
860 Region aboveCoveredLayers;
861 Region dirty;
862
Mathias Agopian87baae12012-07-31 12:38:26 -0700863 outDirtyRegion.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800864
865 size_t i = currentLayers.size();
866 while (i--) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700867 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800868
869 // start with the whole surface at its current location
Mathias Agopian97011222009-07-28 10:57:27 -0700870 const Layer::State& s(layer->drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800871
Mathias Agopian87baae12012-07-31 12:38:26 -0700872 // only consider the layers on the given later stack
873 if (s.layerStack != layerStack)
874 continue;
875
Mathias Agopianab028732010-03-16 16:41:46 -0700876 /*
877 * opaqueRegion: area of a surface that is fully opaque.
878 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800879 Region opaqueRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700880
881 /*
882 * visibleRegion: area of a surface that is visible on screen
883 * and not fully transparent. This is essentially the layer's
884 * footprint minus the opaque regions above it.
885 * Areas covered by a translucent surface are considered visible.
886 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800887 Region visibleRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700888
889 /*
890 * coveredRegion: area of a surface that is covered by all
891 * visible regions above it (which includes the translucent areas).
892 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800893 Region coveredRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700894
895
896 // handle hidden surfaces by setting the visible region to empty
Glenn Kasten99ed2242011-12-15 09:51:17 -0800897 if (CC_LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
Mathias Agopiana67932f2011-04-20 14:20:59 -0700898 const bool translucent = !layer->isOpaque();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700899 Rect bounds(layer->computeBounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800900 visibleRegion.set(bounds);
Mathias Agopianab028732010-03-16 16:41:46 -0700901 if (!visibleRegion.isEmpty()) {
902 // Remove the transparent area from the visible region
903 if (translucent) {
Mathias Agopian4fec8732012-06-29 14:12:52 -0700904 Region transparentRegionScreen;
905 const Transform tr(s.transform);
906 if (tr.transformed()) {
907 if (tr.preserveRects()) {
908 // transform the transparent region
909 transparentRegionScreen = tr.transform(s.transparentRegion);
910 } else {
911 // transformation too complex, can't do the
912 // transparent region optimization.
913 transparentRegionScreen.clear();
914 }
915 } else {
916 transparentRegionScreen = s.transparentRegion;
917 }
918 visibleRegion.subtractSelf(transparentRegionScreen);
Mathias Agopianab028732010-03-16 16:41:46 -0700919 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800920
Mathias Agopianab028732010-03-16 16:41:46 -0700921 // compute the opaque region
Mathias Agopian4fec8732012-06-29 14:12:52 -0700922 const int32_t layerOrientation = s.transform.getOrientation();
Mathias Agopianab028732010-03-16 16:41:46 -0700923 if (s.alpha==255 && !translucent &&
924 ((layerOrientation & Transform::ROT_INVALID) == false)) {
925 // the opaque region is the layer's footprint
926 opaqueRegion = visibleRegion;
927 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800928 }
929 }
930
Mathias Agopianab028732010-03-16 16:41:46 -0700931 // Clip the covered region to the visible region
932 coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
933
934 // Update aboveCoveredLayers for next (lower) layer
935 aboveCoveredLayers.orSelf(visibleRegion);
936
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800937 // subtract the opaque region covered by the layers above us
938 visibleRegion.subtractSelf(aboveOpaqueLayers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800939
940 // compute this layer's dirty region
941 if (layer->contentDirty) {
942 // we need to invalidate the whole region
943 dirty = visibleRegion;
944 // as well, as the old visible region
Mathias Agopian4fec8732012-06-29 14:12:52 -0700945 dirty.orSelf(layer->visibleRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800946 layer->contentDirty = false;
947 } else {
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700948 /* compute the exposed region:
Mathias Agopianab028732010-03-16 16:41:46 -0700949 * the exposed region consists of two components:
950 * 1) what's VISIBLE now and was COVERED before
951 * 2) what's EXPOSED now less what was EXPOSED before
952 *
953 * note that (1) is conservative, we start with the whole
954 * visible region but only keep what used to be covered by
955 * something -- which mean it may have been exposed.
956 *
957 * (2) handles areas that were not covered by anything but got
958 * exposed because of a resize.
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700959 */
Mathias Agopianab028732010-03-16 16:41:46 -0700960 const Region newExposed = visibleRegion - coveredRegion;
Mathias Agopian4fec8732012-06-29 14:12:52 -0700961 const Region oldVisibleRegion = layer->visibleRegion;
962 const Region oldCoveredRegion = layer->coveredRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700963 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
964 dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800965 }
966 dirty.subtractSelf(aboveOpaqueLayers);
967
968 // accumulate to the screen dirty region
Mathias Agopian87baae12012-07-31 12:38:26 -0700969 outDirtyRegion.orSelf(dirty);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800970
Mathias Agopianab028732010-03-16 16:41:46 -0700971 // Update aboveOpaqueLayers for next (lower) layer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800972 aboveOpaqueLayers.orSelf(opaqueRegion);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700973
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800974 // Store the visible region is screen space
975 layer->setVisibleRegion(visibleRegion);
976 layer->setCoveredRegion(coveredRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800977 }
978
Mathias Agopian87baae12012-07-31 12:38:26 -0700979 outOpaqueRegion = aboveOpaqueLayers;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800980}
981
Mathias Agopian87baae12012-07-31 12:38:26 -0700982void SurfaceFlinger::invalidateLayerStack(uint32_t layerStack,
983 const Region& dirty) {
984 // FIXME: update the dirty region of all displays
985 // presenting this layer's layer stack.
986 DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(0)));
987 hw.dirtyRegion.orSelf(dirty);
988}
989
990void SurfaceFlinger::handlePageFlip()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800991{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800992 ATRACE_CALL();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700993 Region dirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800994
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800995 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800996
Mathias Agopian4fec8732012-06-29 14:12:52 -0700997 bool visibleRegions = false;
998 const size_t count = currentLayers.size();
999 sp<LayerBase> const* layers = currentLayers.array();
1000 for (size_t i=0 ; i<count ; i++) {
1001 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian87baae12012-07-31 12:38:26 -07001002 const Region dirty(layer->latchBuffer(visibleRegions));
1003 Layer::State s(layer->drawingState());
1004 invalidateLayerStack(s.layerStack, dirty);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001005 }
Mathias Agopian4da75192010-08-10 17:19:56 -07001006
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001007 mVisibleRegionsDirty |= visibleRegions;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001008}
1009
Mathias Agopianad456f92011-01-13 17:53:01 -08001010void SurfaceFlinger::invalidateHwcGeometry()
1011{
1012 mHwWorkListDirty = true;
1013}
1014
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001015void SurfaceFlinger::handleRefresh()
1016{
1017 bool needInvalidate = false;
1018 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
1019 const size_t count = currentLayers.size();
1020 for (size_t i=0 ; i<count ; i++) {
1021 const sp<LayerBase>& layer(currentLayers[i]);
1022 if (layer->onPreComposition()) {
1023 needInvalidate = true;
1024 }
1025 }
1026 if (needInvalidate) {
1027 signalLayerUpdate();
1028 }
1029}
1030
1031
Mathias Agopian1b031492012-06-20 17:51:20 -07001032void SurfaceFlinger::handleWorkList(const DisplayHardware& hw)
Mathias Agopiana350ff92010-08-10 17:14:02 -07001033{
1034 mHwWorkListDirty = false;
Mathias Agopian86303202012-07-24 22:46:10 -07001035 HWComposer& hwc(getHwComposer());
Mathias Agopiana350ff92010-08-10 17:14:02 -07001036 if (hwc.initCheck() == NO_ERROR) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001037 const Vector< sp<LayerBase> >& currentLayers(hw.getVisibleLayersSortedByZ());
Mathias Agopiana350ff92010-08-10 17:14:02 -07001038 const size_t count = currentLayers.size();
1039 hwc.createWorkList(count);
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001040
1041 HWComposer::LayerListIterator cur = hwc.begin();
1042 const HWComposer::LayerListIterator end = hwc.end();
1043 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
Mathias Agopian4fec8732012-06-29 14:12:52 -07001044 currentLayers[i]->setGeometry(hw, *cur);
Mathias Agopian53331da2011-08-22 21:44:41 -07001045 if (mDebugDisableHWC || mDebugRegion) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001046 cur->setSkip(true);
Mathias Agopian73d3ba92010-09-22 18:58:01 -07001047 }
Mathias Agopiana350ff92010-08-10 17:14:02 -07001048 }
1049 }
1050}
Mathias Agopianb8a55602009-06-26 19:06:36 -07001051
Mathias Agopian87baae12012-07-31 12:38:26 -07001052void SurfaceFlinger::handleRepaint(const DisplayHardware& hw,
1053 const Region& inDirtyRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001054{
Mathias Agopian841cde52012-03-01 15:44:37 -08001055 ATRACE_CALL();
1056
Mathias Agopian87baae12012-07-31 12:38:26 -07001057 Region dirtyRegion(inDirtyRegion);
1058
Mathias Agopianb8a55602009-06-26 19:06:36 -07001059 // compute the invalid region
Mathias Agopian87baae12012-07-31 12:38:26 -07001060 hw.swapRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001061
Glenn Kasten99ed2242011-12-15 09:51:17 -08001062 if (CC_UNLIKELY(mDebugRegion)) {
Mathias Agopian87baae12012-07-31 12:38:26 -07001063 debugFlashRegions(hw, dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001064 }
1065
Mathias Agopianb8a55602009-06-26 19:06:36 -07001066 // set the frame buffer
Mathias Agopianb8a55602009-06-26 19:06:36 -07001067 glMatrixMode(GL_MODELVIEW);
1068 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001069
1070 uint32_t flags = hw.getFlags();
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001071 if (flags & DisplayHardware::SWAP_RECTANGLE) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001072 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
1073 // takes a rectangle, we must make sure to update that whole
1074 // rectangle in that case
Mathias Agopian87baae12012-07-31 12:38:26 -07001075 dirtyRegion.set(hw.swapRegion.bounds());
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001076 } else {
Mathias Agopian95a666b2009-09-24 14:57:26 -07001077 if (flags & DisplayHardware::PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001078 // We need to redraw the rectangle that will be updated
1079 // (pushed to the framebuffer).
Mathias Agopian95a666b2009-09-24 14:57:26 -07001080 // This is needed because PARTIAL_UPDATES only takes one
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001081 // rectangle instead of a region (see DisplayHardware::flip())
Mathias Agopian87baae12012-07-31 12:38:26 -07001082 dirtyRegion.set(hw.swapRegion.bounds());
Mathias Agopian29d06ac2009-06-29 18:49:56 -07001083 } else {
1084 // we need to redraw everything (the whole screen)
Mathias Agopian87baae12012-07-31 12:38:26 -07001085 dirtyRegion.set(hw.bounds());
1086 hw.swapRegion = dirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001087 }
1088 }
1089
Mathias Agopian1b031492012-06-20 17:51:20 -07001090 setupHardwareComposer(hw);
Mathias Agopian87baae12012-07-31 12:38:26 -07001091 composeSurfaces(hw, dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001092
Mathias Agopian9c6e2972011-09-20 17:21:56 -07001093 // update the swap region and clear the dirty region
Mathias Agopian87baae12012-07-31 12:38:26 -07001094 hw.swapRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001095}
1096
Mathias Agopian1b031492012-06-20 17:51:20 -07001097void SurfaceFlinger::setupHardwareComposer(const DisplayHardware& hw)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001098{
Mathias Agopian86303202012-07-24 22:46:10 -07001099 HWComposer& hwc(getHwComposer());
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001100 HWComposer::LayerListIterator cur = hwc.begin();
1101 const HWComposer::LayerListIterator end = hwc.end();
1102 if (cur == end) {
Mathias Agopian9c6e2972011-09-20 17:21:56 -07001103 return;
Mathias Agopianf384cc32011-09-08 18:31:55 -07001104 }
Mathias Agopiana350ff92010-08-10 17:14:02 -07001105
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001106 const Vector< sp<LayerBase> >& layers(hw.getVisibleLayersSortedByZ());
Mathias Agopianf384cc32011-09-08 18:31:55 -07001107 size_t count = layers.size();
1108
Steve Blocke6f43dd2012-01-06 19:20:56 +00001109 ALOGE_IF(hwc.getNumLayers() != count,
Mathias Agopian45721772010-08-12 15:03:26 -07001110 "HAL number of layers (%d) doesn't match surfaceflinger (%d)",
1111 hwc.getNumLayers(), count);
1112
1113 // just to be extra-safe, use the smallest count
Erik Gilling24925bf2010-08-12 23:21:40 -07001114 if (hwc.initCheck() == NO_ERROR) {
1115 count = count < hwc.getNumLayers() ? count : hwc.getNumLayers();
1116 }
Mathias Agopian45721772010-08-12 15:03:26 -07001117
1118 /*
1119 * update the per-frame h/w composer data for each layer
1120 * and build the transparent region of the FB
1121 */
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001122 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
Mathias Agopianf384cc32011-09-08 18:31:55 -07001123 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001124 layer->setPerFrameData(*cur);
Mathias Agopianf384cc32011-09-08 18:31:55 -07001125 }
1126 status_t err = hwc.prepare();
Steve Blocke6f43dd2012-01-06 19:20:56 +00001127 ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
Mathias Agopianf384cc32011-09-08 18:31:55 -07001128}
Mathias Agopian45721772010-08-12 15:03:26 -07001129
Mathias Agopian1b031492012-06-20 17:51:20 -07001130void SurfaceFlinger::composeSurfaces(const DisplayHardware& hw, const Region& dirty)
Mathias Agopianf384cc32011-09-08 18:31:55 -07001131{
Mathias Agopian86303202012-07-24 22:46:10 -07001132 HWComposer& hwc(getHwComposer());
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001133 HWComposer::LayerListIterator cur = hwc.begin();
1134 const HWComposer::LayerListIterator end = hwc.end();
Mathias Agopiancd20eb02011-09-22 20:57:04 -07001135
1136 const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER);
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001137 if (cur==end || fbLayerCount) {
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001138 // Never touch the framebuffer if we don't have any framebuffer layers
Mathias Agopianf384cc32011-09-08 18:31:55 -07001139
Mathias Agopianb9494d52012-04-18 02:28:45 -07001140 if (hwc.getLayerCount(HWC_OVERLAY)) {
1141 // when using overlays, we assume a fully transparent framebuffer
1142 // NOTE: we could reduce how much we need to clear, for instance
1143 // remove where there are opaque FB layers. however, on some
1144 // GPUs doing a "clean slate" glClear might be more efficient.
1145 // We'll revisit later if needed.
1146 glClearColor(0, 0, 0, 0);
1147 glClear(GL_COLOR_BUFFER_BIT);
1148 } else {
Mathias Agopian87baae12012-07-31 12:38:26 -07001149 const Region region(hw.undefinedRegion.intersect(dirty));
Mathias Agopianb9494d52012-04-18 02:28:45 -07001150 // screen is already cleared here
Mathias Agopian87baae12012-07-31 12:38:26 -07001151 if (!region.isEmpty()) {
Mathias Agopianb9494d52012-04-18 02:28:45 -07001152 // can happen with SurfaceView
Mathias Agopian87baae12012-07-31 12:38:26 -07001153 drawWormhole(region);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001154 }
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001155 }
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001156
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001157 /*
1158 * and then, render the layers targeted at the framebuffer
1159 */
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001160
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001161 const Vector< sp<LayerBase> >& layers(hw.getVisibleLayersSortedByZ());
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001162 const size_t count = layers.size();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001163 const Transform& tr = hw.getTransform();
Jesse Halla6b32db2012-07-19 16:44:38 -07001164 for (size_t i=0 ; i<count ; ++i) {
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001165 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian4fec8732012-06-29 14:12:52 -07001166 const Region clip(dirty.intersect(tr.transform(layer->visibleRegion)));
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001167 if (!clip.isEmpty()) {
Jesse Halla6b32db2012-07-19 16:44:38 -07001168 if (cur != end && cur->getCompositionType() == HWC_OVERLAY) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -07001169 if (i && (cur->getHints() & HWC_HINT_CLEAR_FB)
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001170 && layer->isOpaque()) {
Mathias Agopianb9494d52012-04-18 02:28:45 -07001171 // never clear the very first layer since we're
1172 // guaranteed the FB is already cleared
Mathias Agopian1b031492012-06-20 17:51:20 -07001173 layer->clearWithOpenGL(hw, clip);
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001174 }
Jesse Hall6ee93c02012-07-23 13:11:19 -07001175 ++cur;
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001176 continue;
1177 }
1178 // render the layer
Mathias Agopian1b031492012-06-20 17:51:20 -07001179 layer->draw(hw, clip);
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001180 }
Jesse Halla6b32db2012-07-19 16:44:38 -07001181 if (cur != end) {
1182 ++cur;
1183 }
Mathias Agopian4b2ba532012-03-29 12:23:51 -07001184 }
1185 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001186}
1187
Mathias Agopian87baae12012-07-31 12:38:26 -07001188void SurfaceFlinger::debugFlashRegions(const DisplayHardware& hw,
1189 const Region& dirtyRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001190{
Mathias Agopian0a917752010-06-14 21:20:00 -07001191 const uint32_t flags = hw.getFlags();
Mathias Agopian53331da2011-08-22 21:44:41 -07001192 const int32_t height = hw.getHeight();
Mathias Agopian87baae12012-07-31 12:38:26 -07001193 if (hw.swapRegion.isEmpty()) {
Mathias Agopian53331da2011-08-22 21:44:41 -07001194 return;
1195 }
Mathias Agopiandf3ca302009-05-04 19:29:25 -07001196
Mathias Agopiana2f4e562012-04-15 23:34:59 -07001197 if (!(flags & DisplayHardware::SWAP_RECTANGLE)) {
Mathias Agopian0a917752010-06-14 21:20:00 -07001198 const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
Mathias Agopian87baae12012-07-31 12:38:26 -07001199 dirtyRegion.bounds() : hw.bounds());
Mathias Agopian1b031492012-06-20 17:51:20 -07001200 composeSurfaces(hw, repaint);
Mathias Agopian0a917752010-06-14 21:20:00 -07001201 }
1202
Mathias Agopianc492e672011-10-18 14:49:27 -07001203 glDisable(GL_TEXTURE_EXTERNAL_OES);
1204 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001205 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001206
Mathias Agopian0926f502009-05-04 14:17:04 -07001207 static int toggle = 0;
1208 toggle = 1 - toggle;
1209 if (toggle) {
Mathias Agopian0a917752010-06-14 21:20:00 -07001210 glColor4f(1, 0, 1, 1);
Mathias Agopian0926f502009-05-04 14:17:04 -07001211 } else {
Mathias Agopian0a917752010-06-14 21:20:00 -07001212 glColor4f(1, 1, 0, 1);
Mathias Agopian0926f502009-05-04 14:17:04 -07001213 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001214
Mathias Agopian87baae12012-07-31 12:38:26 -07001215 Region::const_iterator it = dirtyRegion.begin();
1216 Region::const_iterator const end = dirtyRegion.end();
Mathias Agopian20f68782009-05-11 00:03:41 -07001217 while (it != end) {
1218 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001219 GLfloat vertices[][2] = {
Mathias Agopian53331da2011-08-22 21:44:41 -07001220 { r.left, height - r.top },
1221 { r.left, height - r.bottom },
1222 { r.right, height - r.bottom },
1223 { r.right, height - r.top }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001224 };
1225 glVertexPointer(2, GL_FLOAT, 0, vertices);
1226 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1227 }
Mathias Agopian0a917752010-06-14 21:20:00 -07001228
Mathias Agopian87baae12012-07-31 12:38:26 -07001229 hw.flip(hw.swapRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001230
1231 if (mDebugRegion > 1)
Mathias Agopian0a917752010-06-14 21:20:00 -07001232 usleep(mDebugRegion * 1000);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001233}
1234
Mathias Agopian87baae12012-07-31 12:38:26 -07001235void SurfaceFlinger::drawWormhole(const Region& region) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001236{
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001237 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001238 glDisable(GL_TEXTURE_2D);
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001239 glDisable(GL_BLEND);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001240 glColor4f(0,0,0,0);
Mathias Agopianf74e8e02012-04-16 03:14:05 -07001241
1242 GLfloat vertices[4][2];
1243 glVertexPointer(2, GL_FLOAT, 0, vertices);
1244 Region::const_iterator it = region.begin();
1245 Region::const_iterator const end = region.end();
1246 while (it != end) {
1247 const Rect& r = *it++;
1248 vertices[0][0] = r.left;
1249 vertices[0][1] = r.top;
1250 vertices[1][0] = r.right;
1251 vertices[1][1] = r.top;
1252 vertices[2][0] = r.right;
1253 vertices[2][1] = r.bottom;
1254 vertices[3][0] = r.left;
1255 vertices[3][1] = r.bottom;
1256 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1257 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001258}
1259
Mathias Agopian96f08192010-06-02 23:28:45 -07001260ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
1261 const sp<LayerBaseClient>& lbc)
1262{
Mathias Agopian96f08192010-06-02 23:28:45 -07001263 // attach this layer to the client
Mathias Agopian4f113742011-05-03 16:21:41 -07001264 size_t name = client->attachLayer(lbc);
1265
Mathias Agopian96f08192010-06-02 23:28:45 -07001266 // add this layer to the current state list
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001267 Mutex::Autolock _l(mStateLock);
1268 mCurrentState.layersSortedByZ.add(lbc);
Mathias Agopian96f08192010-06-02 23:28:45 -07001269
Mathias Agopian4f113742011-05-03 16:21:41 -07001270 return ssize_t(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001271}
1272
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001273status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001274{
1275 Mutex::Autolock _l(mStateLock);
Mathias Agopian3d579642009-06-04 18:46:21 -07001276 status_t err = purgatorizeLayer_l(layer);
1277 if (err == NO_ERROR)
1278 setTransactionFlags(eTransactionNeeded);
1279 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001280}
1281
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001282status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001283{
1284 ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase);
1285 if (index >= 0) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001286 mLayersRemoved = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001287 return NO_ERROR;
1288 }
Mathias Agopian3d579642009-06-04 18:46:21 -07001289 return status_t(index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001290}
1291
Mathias Agopian9a112062009-04-17 19:36:26 -07001292status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase)
1293{
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001294 // First add the layer to the purgatory list, which makes sure it won't
1295 // go away, then remove it from the main list (through a transaction).
Mathias Agopian9a112062009-04-17 19:36:26 -07001296 ssize_t err = removeLayer_l(layerBase);
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001297 if (err >= 0) {
1298 mLayerPurgatory.add(layerBase);
1299 }
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001300
Jesse Hall2f4b68d2011-12-02 10:00:00 -08001301 mLayersPendingRemoval.push(layerBase);
Mathias Agopian0b3ad462009-10-02 18:12:30 -07001302
Mathias Agopian3d579642009-06-04 18:46:21 -07001303 // it's possible that we don't find a layer, because it might
1304 // have been destroyed already -- this is not technically an error
Mathias Agopian96f08192010-06-02 23:28:45 -07001305 // from the user because there is a race between Client::destroySurface(),
1306 // ~Client() and ~ISurface().
Mathias Agopian9a112062009-04-17 19:36:26 -07001307 return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err;
1308}
1309
Mathias Agopiandea20b12011-05-03 17:04:02 -07001310uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
1311{
1312 return android_atomic_release_load(&mTransactionFlags);
1313}
1314
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001315uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1316{
1317 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1318}
1319
Mathias Agopianbb641242010-05-18 17:06:55 -07001320uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001321{
1322 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1323 if ((old & flags)==0) { // wake the server up
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001324 signalTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001325 }
1326 return old;
1327}
1328
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001329
Mathias Agopian8b33f032012-07-24 20:43:54 -07001330void SurfaceFlinger::setTransactionState(
1331 const Vector<ComposerState>& state,
1332 const Vector<DisplayState>& displays,
1333 uint32_t flags)
1334{
Mathias Agopian698c0872011-06-28 19:09:31 -07001335 Mutex::Autolock _l(mStateLock);
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001336
Mathias Agopian8b33f032012-07-24 20:43:54 -07001337 int orientation = eOrientationUnchanged;
1338 if (displays.size()) {
1339 // TODO: handle all displays
1340 orientation = displays[0].orientation;
1341 }
1342
Jamie Gennis28378392011-10-12 17:39:00 -07001343 uint32_t transactionFlags = 0;
Jamie Gennisb8d69a52011-10-10 15:48:06 -07001344 if (mCurrentState.orientation != orientation) {
1345 if (uint32_t(orientation)<=eOrientation270 || orientation==42) {
1346 mCurrentState.orientation = orientation;
Jamie Gennis28378392011-10-12 17:39:00 -07001347 transactionFlags |= eTransactionNeeded;
Jamie Gennisb8d69a52011-10-10 15:48:06 -07001348 } else if (orientation != eOrientationUnchanged) {
Steve Block32397c12012-01-05 23:22:43 +00001349 ALOGW("setTransactionState: ignoring unrecognized orientation: %d",
Jamie Gennisb8d69a52011-10-10 15:48:06 -07001350 orientation);
1351 }
1352 }
1353
Mathias Agopian698c0872011-06-28 19:09:31 -07001354 const size_t count = state.size();
1355 for (size_t i=0 ; i<count ; i++) {
1356 const ComposerState& s(state[i]);
1357 sp<Client> client( static_cast<Client *>(s.client.get()) );
Jamie Gennis28378392011-10-12 17:39:00 -07001358 transactionFlags |= setClientStateLocked(client, s.state);
Mathias Agopian698c0872011-06-28 19:09:31 -07001359 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001360
Mathias Agopian386aa982011-11-07 21:58:03 -08001361 if (transactionFlags) {
1362 // this triggers the transaction
1363 setTransactionFlags(transactionFlags);
1364
1365 // if this is a synchronous transaction, wait for it to take effect
1366 // before returning.
1367 if (flags & eSynchronous) {
1368 mTransationPending = true;
1369 }
1370 while (mTransationPending) {
1371 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1372 if (CC_UNLIKELY(err != NO_ERROR)) {
1373 // just in case something goes wrong in SF, return to the
1374 // called after a few seconds.
Steve Block32397c12012-01-05 23:22:43 +00001375 ALOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!");
Mathias Agopian386aa982011-11-07 21:58:03 -08001376 mTransationPending = false;
1377 break;
1378 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001379 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001380 }
1381}
1382
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001383sp<ISurface> SurfaceFlinger::createLayer(
Mathias Agopian0ef4e152011-04-20 14:19:32 -07001384 ISurfaceComposerClient::surface_data_t* params,
1385 const String8& name,
1386 const sp<Client>& client,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001387 DisplayID d, uint32_t w, uint32_t h, PixelFormat format,
1388 uint32_t flags)
1389{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001390 sp<LayerBaseClient> layer;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001391 sp<ISurface> surfaceHandle;
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001392
1393 if (int32_t(w|h) < 0) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001394 ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)",
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001395 int(w), int(h));
1396 return surfaceHandle;
1397 }
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001398
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001399 //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001400 switch (flags & eFXSurfaceMask) {
1401 case eFXSurfaceNormal:
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001402 layer = createNormalLayer(client, d, w, h, flags, format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001403 break;
1404 case eFXSurfaceBlur:
Mathias Agopian1293a8e2010-12-08 17:13:19 -08001405 // for now we treat Blur as Dim, until we can implement it
1406 // efficiently.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001407 case eFXSurfaceDim:
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001408 layer = createDimLayer(client, d, w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001409 break;
Mathias Agopian118d0242011-10-13 16:02:48 -07001410 case eFXSurfaceScreenshot:
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001411 layer = createScreenshotLayer(client, d, w, h, flags);
Mathias Agopian118d0242011-10-13 16:02:48 -07001412 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001413 }
1414
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001415 if (layer != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001416 layer->initStates(w, h, flags);
Mathias Agopian285dbde2010-03-01 16:09:43 -08001417 layer->setName(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001418 ssize_t token = addClientLayer(client, layer);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001419 surfaceHandle = layer->getSurface();
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001420 if (surfaceHandle != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001421 params->token = token;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001422 params->identity = layer->getIdentity();
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001423 }
Mathias Agopian96f08192010-06-02 23:28:45 -07001424 setTransactionFlags(eTransactionNeeded);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001425 }
1426
1427 return surfaceHandle;
1428}
1429
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001430sp<Layer> SurfaceFlinger::createNormalLayer(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001431 const sp<Client>& client, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -07001432 uint32_t w, uint32_t h, uint32_t flags,
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001433 PixelFormat& format)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001434{
1435 // initialize the surfaces
1436 switch (format) { // TODO: take h/w into account
1437 case PIXEL_FORMAT_TRANSPARENT:
1438 case PIXEL_FORMAT_TRANSLUCENT:
1439 format = PIXEL_FORMAT_RGBA_8888;
1440 break;
1441 case PIXEL_FORMAT_OPAQUE:
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001442#ifdef NO_RGBX_8888
1443 format = PIXEL_FORMAT_RGB_565;
1444#else
Mathias Agopian8f105402010-04-05 18:01:24 -07001445 format = PIXEL_FORMAT_RGBX_8888;
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001446#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001447 break;
1448 }
1449
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001450#ifdef NO_RGBX_8888
1451 if (format == PIXEL_FORMAT_RGBX_8888)
1452 format = PIXEL_FORMAT_RGBA_8888;
1453#endif
1454
Mathias Agopian96f08192010-06-02 23:28:45 -07001455 sp<Layer> layer = new Layer(this, display, client);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001456 status_t err = layer->setBuffers(w, h, format, flags);
Glenn Kasten99ed2242011-12-15 09:51:17 -08001457 if (CC_LIKELY(err != NO_ERROR)) {
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001458 ALOGE("createNormalLayer() failed (%s)", strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001459 layer.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001460 }
1461 return layer;
1462}
1463
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001464sp<LayerDim> SurfaceFlinger::createDimLayer(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001465 const sp<Client>& client, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -07001466 uint32_t w, uint32_t h, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001467{
Mathias Agopian96f08192010-06-02 23:28:45 -07001468 sp<LayerDim> layer = new LayerDim(this, display, client);
Mathias Agopian118d0242011-10-13 16:02:48 -07001469 return layer;
1470}
1471
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001472sp<LayerScreenshot> SurfaceFlinger::createScreenshotLayer(
Mathias Agopian118d0242011-10-13 16:02:48 -07001473 const sp<Client>& client, DisplayID display,
1474 uint32_t w, uint32_t h, uint32_t flags)
1475{
1476 sp<LayerScreenshot> layer = new LayerScreenshot(this, display, client);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001477 return layer;
1478}
1479
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001480status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, SurfaceID sid)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001481{
Mathias Agopian9a112062009-04-17 19:36:26 -07001482 /*
1483 * called by the window manager, when a surface should be marked for
1484 * destruction.
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001485 *
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001486 * The surface is removed from the current and drawing lists, but placed
1487 * in the purgatory queue, so it's not destroyed right-away (we need
1488 * to wait for all client's references to go away first).
Mathias Agopian9a112062009-04-17 19:36:26 -07001489 */
Mathias Agopian9a112062009-04-17 19:36:26 -07001490
Mathias Agopian48d819a2009-09-10 19:41:18 -07001491 status_t err = NAME_NOT_FOUND;
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001492 Mutex::Autolock _l(mStateLock);
Mathias Agopian96f08192010-06-02 23:28:45 -07001493 sp<LayerBaseClient> layer = client->getLayerUser(sid);
Daniel Lamb2675792012-02-23 14:35:13 -08001494
Mathias Agopian48d819a2009-09-10 19:41:18 -07001495 if (layer != 0) {
1496 err = purgatorizeLayer_l(layer);
1497 if (err == NO_ERROR) {
Mathias Agopian48d819a2009-09-10 19:41:18 -07001498 setTransactionFlags(eTransactionNeeded);
1499 }
Mathias Agopian9a112062009-04-17 19:36:26 -07001500 }
1501 return err;
1502}
1503
Mathias Agopian921e6ac2012-07-23 23:11:29 -07001504status_t SurfaceFlinger::onLayerDestroyed(const wp<LayerBaseClient>& layer)
Mathias Agopian9a112062009-04-17 19:36:26 -07001505{
Mathias Agopian759fdb22009-07-02 17:33:40 -07001506 // called by ~ISurface() when all references are gone
Mathias Agopianca4d3602011-05-19 15:38:14 -07001507 status_t err = NO_ERROR;
1508 sp<LayerBaseClient> l(layer.promote());
1509 if (l != NULL) {
1510 Mutex::Autolock _l(mStateLock);
1511 err = removeLayer_l(l);
1512 if (err == NAME_NOT_FOUND) {
1513 // The surface wasn't in the current list, which means it was
1514 // removed already, which means it is in the purgatory,
1515 // and need to be removed from there.
1516 ssize_t idx = mLayerPurgatory.remove(l);
Steve Blocke6f43dd2012-01-06 19:20:56 +00001517 ALOGE_IF(idx < 0,
Mathias Agopianca4d3602011-05-19 15:38:14 -07001518 "layer=%p is not in the purgatory list", l.get());
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001519 }
Steve Blocke6f43dd2012-01-06 19:20:56 +00001520 ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
Mathias Agopianca4d3602011-05-19 15:38:14 -07001521 "error removing layer=%p (%s)", l.get(), strerror(-err));
1522 }
1523 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001524}
1525
Mathias Agopian698c0872011-06-28 19:09:31 -07001526uint32_t SurfaceFlinger::setClientStateLocked(
Mathias Agopian96f08192010-06-02 23:28:45 -07001527 const sp<Client>& client,
Mathias Agopian698c0872011-06-28 19:09:31 -07001528 const layer_state_t& s)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001529{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001530 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -07001531 sp<LayerBaseClient> layer(client->getLayerUser(s.surface));
1532 if (layer != 0) {
1533 const uint32_t what = s.what;
1534 if (what & ePositionChanged) {
1535 if (layer->setPosition(s.x, s.y))
1536 flags |= eTraversalNeeded;
1537 }
1538 if (what & eLayerChanged) {
1539 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1540 if (layer->setLayer(s.z)) {
1541 mCurrentState.layersSortedByZ.removeAt(idx);
1542 mCurrentState.layersSortedByZ.add(layer);
1543 // we need traversal (state changed)
1544 // AND transaction (list changed)
1545 flags |= eTransactionNeeded|eTraversalNeeded;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001546 }
1547 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001548 if (what & eSizeChanged) {
1549 if (layer->setSize(s.w, s.h)) {
1550 flags |= eTraversalNeeded;
Mathias Agopian698c0872011-06-28 19:09:31 -07001551 }
1552 }
1553 if (what & eAlphaChanged) {
1554 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1555 flags |= eTraversalNeeded;
1556 }
1557 if (what & eMatrixChanged) {
1558 if (layer->setMatrix(s.matrix))
1559 flags |= eTraversalNeeded;
1560 }
1561 if (what & eTransparentRegionChanged) {
1562 if (layer->setTransparentRegionHint(s.transparentRegion))
1563 flags |= eTraversalNeeded;
1564 }
1565 if (what & eVisibilityChanged) {
1566 if (layer->setFlags(s.flags, s.mask))
1567 flags |= eTraversalNeeded;
1568 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -07001569 if (what & eCropChanged) {
1570 if (layer->setCrop(s.crop))
1571 flags |= eTraversalNeeded;
1572 }
Mathias Agopian87855782012-07-24 21:41:09 -07001573 if (what & eLayerStackChanged) {
1574 if (layer->setLayerStack(s.layerStack))
1575 flags |= eTraversalNeeded;
1576 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001577 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001578 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001579}
1580
Mathias Agopianb60314a2012-04-10 22:09:54 -07001581// ---------------------------------------------------------------------------
1582
1583void SurfaceFlinger::onScreenAcquired() {
Colin Cross8e533062012-06-07 13:17:52 -07001584 ALOGD("Screen about to return, flinger = %p", this);
Mathias Agopian1b031492012-06-20 17:51:20 -07001585 const DisplayHardware& hw(getDefaultDisplayHardware()); // XXX: this should be per DisplayHardware
Mathias Agopian86303202012-07-24 22:46:10 -07001586 getHwComposer().acquire();
Mathias Agopianb60314a2012-04-10 22:09:54 -07001587 hw.acquireScreen();
Mathias Agopian22ffb112012-04-10 21:04:02 -07001588 mEventThread->onScreenAcquired();
Mathias Agopianb60314a2012-04-10 22:09:54 -07001589 // this is a temporary work-around, eventually this should be called
1590 // by the power-manager
1591 SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
Mathias Agopian22ffb112012-04-10 21:04:02 -07001592 // from this point on, SF will process updates again
Mathias Agopian8acce202012-04-13 16:18:55 -07001593 repaintEverything();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001594}
1595
Mathias Agopianb60314a2012-04-10 22:09:54 -07001596void SurfaceFlinger::onScreenReleased() {
Colin Cross8e533062012-06-07 13:17:52 -07001597 ALOGD("About to give-up screen, flinger = %p", this);
Mathias Agopian1b031492012-06-20 17:51:20 -07001598 const DisplayHardware& hw(getDefaultDisplayHardware()); // XXX: this should be per DisplayHardware
Mathias Agopianb60314a2012-04-10 22:09:54 -07001599 if (hw.isScreenAcquired()) {
Mathias Agopian22ffb112012-04-10 21:04:02 -07001600 mEventThread->onScreenReleased();
Mathias Agopianb60314a2012-04-10 22:09:54 -07001601 hw.releaseScreen();
Mathias Agopian86303202012-07-24 22:46:10 -07001602 getHwComposer().release();
Mathias Agopianb60314a2012-04-10 22:09:54 -07001603 // from this point on, SF will stop drawing
1604 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001605}
1606
Colin Cross8e533062012-06-07 13:17:52 -07001607void SurfaceFlinger::unblank() {
Mathias Agopianb60314a2012-04-10 22:09:54 -07001608 class MessageScreenAcquired : public MessageBase {
1609 SurfaceFlinger* flinger;
1610 public:
1611 MessageScreenAcquired(SurfaceFlinger* flinger) : flinger(flinger) { }
1612 virtual bool handler() {
1613 flinger->onScreenAcquired();
1614 return true;
1615 }
1616 };
1617 sp<MessageBase> msg = new MessageScreenAcquired(this);
1618 postMessageSync(msg);
1619}
1620
Colin Cross8e533062012-06-07 13:17:52 -07001621void SurfaceFlinger::blank() {
Mathias Agopianb60314a2012-04-10 22:09:54 -07001622 class MessageScreenReleased : public MessageBase {
1623 SurfaceFlinger* flinger;
1624 public:
1625 MessageScreenReleased(SurfaceFlinger* flinger) : flinger(flinger) { }
1626 virtual bool handler() {
1627 flinger->onScreenReleased();
1628 return true;
1629 }
1630 };
1631 sp<MessageBase> msg = new MessageScreenReleased(this);
1632 postMessageSync(msg);
1633}
1634
1635// ---------------------------------------------------------------------------
1636
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001637status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
1638{
Erik Gilling1d21a9c2010-12-01 16:38:01 -08001639 const size_t SIZE = 4096;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001640 char buffer[SIZE];
1641 String8 result;
Mathias Agopian99b49842011-06-27 16:05:52 -07001642
1643 if (!PermissionCache::checkCallingPermission(sDump)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001644 snprintf(buffer, SIZE, "Permission Denial: "
1645 "can't dump SurfaceFlinger from pid=%d, uid=%d\n",
1646 IPCThreadState::self()->getCallingPid(),
1647 IPCThreadState::self()->getCallingUid());
1648 result.append(buffer);
1649 } else {
Mathias Agopian9795c422009-08-26 16:36:26 -07001650 // Try to get the main lock, but don't insist if we can't
1651 // (this would indicate SF is stuck, but we want to be able to
1652 // print something in dumpsys).
1653 int retry = 3;
1654 while (mStateLock.tryLock()<0 && --retry>=0) {
1655 usleep(1000000);
1656 }
1657 const bool locked(retry >= 0);
1658 if (!locked) {
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001659 snprintf(buffer, SIZE,
Mathias Agopian9795c422009-08-26 16:36:26 -07001660 "SurfaceFlinger appears to be unresponsive, "
1661 "dumping anyways (no locks held)\n");
1662 result.append(buffer);
1663 }
1664
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001665 bool dumpAll = true;
1666 size_t index = 0;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001667 size_t numArgs = args.size();
1668 if (numArgs) {
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001669 if ((index < numArgs) &&
1670 (args[index] == String16("--list"))) {
1671 index++;
1672 listLayersLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08001673 dumpAll = false;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001674 }
1675
1676 if ((index < numArgs) &&
1677 (args[index] == String16("--latency"))) {
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001678 index++;
1679 dumpStatsLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08001680 dumpAll = false;
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001681 }
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001682
1683 if ((index < numArgs) &&
1684 (args[index] == String16("--latency-clear"))) {
1685 index++;
1686 clearStatsLocked(args, index, result, buffer, SIZE);
Mathias Agopian35aadd62012-03-08 22:01:51 -08001687 dumpAll = false;
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001688 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001689 }
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001690
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001691 if (dumpAll) {
1692 dumpAllLocked(result, buffer, SIZE);
Mathias Agopian48b888a2011-01-19 16:15:53 -08001693 }
1694
Mathias Agopian9795c422009-08-26 16:36:26 -07001695 if (locked) {
1696 mStateLock.unlock();
1697 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001698 }
1699 write(fd, result.string(), result.size());
1700 return NO_ERROR;
1701}
1702
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001703void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index,
1704 String8& result, char* buffer, size_t SIZE) const
1705{
1706 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1707 const size_t count = currentLayers.size();
1708 for (size_t i=0 ; i<count ; i++) {
1709 const sp<LayerBase>& layer(currentLayers[i]);
1710 snprintf(buffer, SIZE, "%s\n", layer->getName().string());
1711 result.append(buffer);
1712 }
1713}
1714
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001715void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index,
1716 String8& result, char* buffer, size_t SIZE) const
1717{
1718 String8 name;
1719 if (index < args.size()) {
1720 name = String8(args[index]);
1721 index++;
1722 }
1723
1724 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1725 const size_t count = currentLayers.size();
1726 for (size_t i=0 ; i<count ; i++) {
1727 const sp<LayerBase>& layer(currentLayers[i]);
1728 if (name.isEmpty()) {
1729 snprintf(buffer, SIZE, "%s\n", layer->getName().string());
1730 result.append(buffer);
1731 }
1732 if (name.isEmpty() || (name == layer->getName())) {
1733 layer->dumpStats(result, buffer, SIZE);
1734 }
1735 }
1736}
1737
Mathias Agopian25e66fc2012-01-28 22:31:55 -08001738void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
1739 String8& result, char* buffer, size_t SIZE) const
1740{
1741 String8 name;
1742 if (index < args.size()) {
1743 name = String8(args[index]);
1744 index++;
1745 }
1746
1747 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1748 const size_t count = currentLayers.size();
1749 for (size_t i=0 ; i<count ; i++) {
1750 const sp<LayerBase>& layer(currentLayers[i]);
1751 if (name.isEmpty() || (name == layer->getName())) {
1752 layer->clearStats();
1753 }
1754 }
1755}
1756
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001757void SurfaceFlinger::dumpAllLocked(
1758 String8& result, char* buffer, size_t SIZE) const
1759{
1760 // figure out if we're stuck somewhere
1761 const nsecs_t now = systemTime();
1762 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
1763 const nsecs_t inTransaction(mDebugInTransaction);
1764 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
1765 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
1766
1767 /*
1768 * Dump the visible layer list
1769 */
1770 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1771 const size_t count = currentLayers.size();
1772 snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count);
1773 result.append(buffer);
1774 for (size_t i=0 ; i<count ; i++) {
1775 const sp<LayerBase>& layer(currentLayers[i]);
1776 layer->dump(result, buffer, SIZE);
1777 }
1778
1779 /*
1780 * Dump the layers in the purgatory
1781 */
1782
1783 const size_t purgatorySize = mLayerPurgatory.size();
1784 snprintf(buffer, SIZE, "Purgatory state (%d entries)\n", purgatorySize);
1785 result.append(buffer);
1786 for (size_t i=0 ; i<purgatorySize ; i++) {
1787 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
1788 layer->shortDump(result, buffer, SIZE);
1789 }
1790
1791 /*
1792 * Dump SurfaceFlinger global state
1793 */
1794
1795 snprintf(buffer, SIZE, "SurfaceFlinger global state:\n");
1796 result.append(buffer);
1797
Mathias Agopian1b031492012-06-20 17:51:20 -07001798 const DisplayHardware& hw(getDefaultDisplayHardware());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001799 const GLExtensions& extensions(GLExtensions::getInstance());
1800 snprintf(buffer, SIZE, "GLES: %s, %s, %s\n",
1801 extensions.getVendor(),
1802 extensions.getRenderer(),
1803 extensions.getVersion());
1804 result.append(buffer);
1805
1806 snprintf(buffer, SIZE, "EGL : %s\n",
Mathias Agopian1b031492012-06-20 17:51:20 -07001807 eglQueryString(hw.getEGLDisplay(),
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001808 EGL_VERSION_HW_ANDROID));
1809 result.append(buffer);
1810
1811 snprintf(buffer, SIZE, "EXTS: %s\n", extensions.getExtension());
1812 result.append(buffer);
1813
Mathias Agopian87baae12012-07-31 12:38:26 -07001814 hw.undefinedRegion.dump(result, "undefinedRegion");
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001815 snprintf(buffer, SIZE,
1816 " orientation=%d, canDraw=%d\n",
1817 mCurrentState.orientation, hw.canDraw());
1818 result.append(buffer);
1819 snprintf(buffer, SIZE,
1820 " last eglSwapBuffers() time: %f us\n"
1821 " last transaction time : %f us\n"
Mathias Agopianc95dbdc2012-02-05 00:19:27 -08001822 " transaction-flags : %08x\n"
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001823 " refresh-rate : %f fps\n"
1824 " x-dpi : %f\n"
Mathias Agopianb5dd9c02012-03-22 12:15:54 -07001825 " y-dpi : %f\n"
1826 " density : %f\n",
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001827 mLastSwapBufferTime/1000.0,
1828 mLastTransactionTime/1000.0,
Mathias Agopianc95dbdc2012-02-05 00:19:27 -08001829 mTransactionFlags,
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001830 hw.getRefreshRate(),
1831 hw.getDpiX(),
Mathias Agopianb5dd9c02012-03-22 12:15:54 -07001832 hw.getDpiY(),
1833 hw.getDensity());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001834 result.append(buffer);
1835
1836 snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
1837 inSwapBuffersDuration/1000.0);
1838 result.append(buffer);
1839
1840 snprintf(buffer, SIZE, " transaction time: %f us\n",
1841 inTransactionDuration/1000.0);
1842 result.append(buffer);
1843
1844 /*
1845 * VSYNC state
1846 */
1847 mEventThread->dump(result, buffer, SIZE);
1848
1849 /*
1850 * Dump HWComposer state
1851 */
Mathias Agopian86303202012-07-24 22:46:10 -07001852 HWComposer& hwc(getHwComposer());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001853 snprintf(buffer, SIZE, "h/w composer state:\n");
1854 result.append(buffer);
1855 snprintf(buffer, SIZE, " h/w composer %s and %s\n",
1856 hwc.initCheck()==NO_ERROR ? "present" : "not present",
1857 (mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled");
1858 result.append(buffer);
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07001859 hwc.dump(result, buffer, SIZE, hw.getVisibleLayersSortedByZ());
Mathias Agopian82d7ab62012-01-19 18:34:40 -08001860
1861 /*
1862 * Dump gralloc state
1863 */
1864 const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
1865 alloc.dump(result);
1866 hw.dump(result);
1867}
1868
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001869status_t SurfaceFlinger::onTransact(
1870 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1871{
1872 switch (code) {
1873 case CREATE_CONNECTION:
Mathias Agopian698c0872011-06-28 19:09:31 -07001874 case SET_TRANSACTION_STATE:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001875 case SET_ORIENTATION:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001876 case BOOT_FINISHED:
Mathias Agopian59119e62010-10-11 12:37:43 -07001877 case TURN_ELECTRON_BEAM_OFF:
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001878 case TURN_ELECTRON_BEAM_ON:
Colin Cross8e533062012-06-07 13:17:52 -07001879 case BLANK:
1880 case UNBLANK:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001881 {
1882 // codes that require permission check
1883 IPCThreadState* ipc = IPCThreadState::self();
1884 const int pid = ipc->getCallingPid();
Mathias Agopiana1ecca92009-05-21 19:21:59 -07001885 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07001886 if ((uid != AID_GRAPHICS) &&
1887 !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
Steve Blocke6f43dd2012-01-06 19:20:56 +00001888 ALOGE("Permission Denial: "
Mathias Agopian375f5632009-06-15 18:24:59 -07001889 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
1890 return PERMISSION_DENIED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001891 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001892 break;
1893 }
1894 case CAPTURE_SCREEN:
1895 {
1896 // codes that require permission check
1897 IPCThreadState* ipc = IPCThreadState::self();
1898 const int pid = ipc->getCallingPid();
1899 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07001900 if ((uid != AID_GRAPHICS) &&
1901 !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
Steve Blocke6f43dd2012-01-06 19:20:56 +00001902 ALOGE("Permission Denial: "
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001903 "can't read framebuffer pid=%d, uid=%d", pid, uid);
1904 return PERMISSION_DENIED;
1905 }
1906 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001907 }
1908 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001909
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001910 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
1911 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
Mathias Agopianb8a55602009-06-26 19:06:36 -07001912 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Glenn Kasten99ed2242011-12-15 09:51:17 -08001913 if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
Mathias Agopian375f5632009-06-15 18:24:59 -07001914 IPCThreadState* ipc = IPCThreadState::self();
1915 const int pid = ipc->getCallingPid();
1916 const int uid = ipc->getCallingUid();
Steve Blocke6f43dd2012-01-06 19:20:56 +00001917 ALOGE("Permission Denial: "
Mathias Agopian375f5632009-06-15 18:24:59 -07001918 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001919 return PERMISSION_DENIED;
1920 }
1921 int n;
1922 switch (code) {
Mathias Agopian01b76682009-04-16 20:04:08 -07001923 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
Mathias Agopian35b48d12010-09-13 22:57:58 -07001924 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001925 return NO_ERROR;
1926 case 1002: // SHOW_UPDATES
1927 n = data.readInt32();
1928 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
Mathias Agopian53331da2011-08-22 21:44:41 -07001929 invalidateHwcGeometry();
1930 repaintEverything();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001931 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001932 case 1004:{ // repaint everything
Mathias Agopian53331da2011-08-22 21:44:41 -07001933 repaintEverything();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001934 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001935 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001936 case 1005:{ // force transaction
1937 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1938 return NO_ERROR;
1939 }
Mathias Agopian4d143ee2012-02-23 20:05:39 -08001940 case 1006:{ // send empty update
1941 signalRefresh();
1942 return NO_ERROR;
1943 }
Mathias Agopian53331da2011-08-22 21:44:41 -07001944 case 1008: // toggle use of hw composer
1945 n = data.readInt32();
1946 mDebugDisableHWC = n ? 1 : 0;
1947 invalidateHwcGeometry();
1948 repaintEverything();
1949 return NO_ERROR;
Mathias Agopiana4583642011-08-23 18:03:18 -07001950 case 1009: // toggle use of transform hint
1951 n = data.readInt32();
1952 mDebugDisableTransformHint = n ? 1 : 0;
1953 invalidateHwcGeometry();
1954 repaintEverything();
1955 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001956 case 1010: // interrogate.
Mathias Agopian01b76682009-04-16 20:04:08 -07001957 reply->writeInt32(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001958 reply->writeInt32(0);
1959 reply->writeInt32(mDebugRegion);
Mathias Agopianb9494d52012-04-18 02:28:45 -07001960 reply->writeInt32(0);
Dianne Hackborn12839be2012-02-06 21:21:05 -08001961 reply->writeInt32(mDebugDisableHWC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001962 return NO_ERROR;
1963 case 1013: {
1964 Mutex::Autolock _l(mStateLock);
Mathias Agopian1b031492012-06-20 17:51:20 -07001965 const DisplayHardware& hw(getDefaultDisplayHardware());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001966 reply->writeInt32(hw.getPageFlipCount());
1967 }
1968 return NO_ERROR;
1969 }
1970 }
1971 return err;
1972}
1973
Mathias Agopian53331da2011-08-22 21:44:41 -07001974void SurfaceFlinger::repaintEverything() {
Mathias Agopian87baae12012-07-31 12:38:26 -07001975 android_atomic_or(1, &mRepaintEverything);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001976 signalTransaction();
Mathias Agopian53331da2011-08-22 21:44:41 -07001977}
1978
Mathias Agopian59119e62010-10-11 12:37:43 -07001979// ---------------------------------------------------------------------------
1980
Mathias Agopian118d0242011-10-13 16:02:48 -07001981status_t SurfaceFlinger::renderScreenToTexture(DisplayID dpy,
1982 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
1983{
1984 Mutex::Autolock _l(mStateLock);
1985 return renderScreenToTextureLocked(dpy, textureName, uOut, vOut);
1986}
1987
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001988status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
1989 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
Mathias Agopian59119e62010-10-11 12:37:43 -07001990{
Mathias Agopian22ffb112012-04-10 21:04:02 -07001991 ATRACE_CALL();
1992
Mathias Agopian59119e62010-10-11 12:37:43 -07001993 if (!GLExtensions::getInstance().haveFramebufferObject())
1994 return INVALID_OPERATION;
1995
1996 // get screen geometry
Mathias Agopian1b031492012-06-20 17:51:20 -07001997 const DisplayHardware& hw(getDisplayHardware(dpy));
Mathias Agopian59119e62010-10-11 12:37:43 -07001998 const uint32_t hw_w = hw.getWidth();
1999 const uint32_t hw_h = hw.getHeight();
Mathias Agopian59119e62010-10-11 12:37:43 -07002000 GLfloat u = 1;
2001 GLfloat v = 1;
2002
2003 // make sure to clear all GL error flags
2004 while ( glGetError() != GL_NO_ERROR ) ;
2005
2006 // create a FBO
2007 GLuint name, tname;
2008 glGenTextures(1, &tname);
2009 glBindTexture(GL_TEXTURE_2D, tname);
Mathias Agopiana2f4e562012-04-15 23:34:59 -07002010 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2011 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002012 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
2013 hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002014 if (glGetError() != GL_NO_ERROR) {
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002015 while ( glGetError() != GL_NO_ERROR ) ;
Mathias Agopian59119e62010-10-11 12:37:43 -07002016 GLint tw = (2 << (31 - clz(hw_w)));
2017 GLint th = (2 << (31 - clz(hw_h)));
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002018 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
2019 tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002020 u = GLfloat(hw_w) / tw;
2021 v = GLfloat(hw_h) / th;
2022 }
2023 glGenFramebuffersOES(1, &name);
2024 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002025 glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
2026 GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07002027
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002028 // redraw the screen entirely...
Mathias Agopianc492e672011-10-18 14:49:27 -07002029 glDisable(GL_TEXTURE_EXTERNAL_OES);
2030 glDisable(GL_TEXTURE_2D);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002031 glClearColor(0,0,0,1);
2032 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopiana9040d02011-10-10 19:02:07 -07002033 glMatrixMode(GL_MODELVIEW);
2034 glLoadIdentity();
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002035 const Vector< sp<LayerBase> >& layers(hw.getVisibleLayersSortedByZ());
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002036 const size_t count = layers.size();
2037 for (size_t i=0 ; i<count ; ++i) {
2038 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian1b031492012-06-20 17:51:20 -07002039 layer->drawForSreenShot(hw);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002040 }
2041
Mathias Agopian118d0242011-10-13 16:02:48 -07002042 hw.compositionComplete();
2043
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002044 // back to main framebuffer
2045 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002046 glDeleteFramebuffersOES(1, &name);
2047
2048 *textureName = tname;
2049 *uOut = u;
2050 *vOut = v;
2051 return NO_ERROR;
2052}
2053
2054// ---------------------------------------------------------------------------
2055
Mathias Agopianed9807b2012-05-18 14:18:08 -07002056class VSyncWaiter {
2057 DisplayEventReceiver::Event buffer[4];
2058 sp<Looper> looper;
2059 sp<IDisplayEventConnection> events;
2060 sp<BitTube> eventTube;
2061public:
2062 VSyncWaiter(const sp<EventThread>& eventThread) {
2063 looper = new Looper(true);
2064 events = eventThread->createEventConnection();
2065 eventTube = events->getDataChannel();
2066 looper->addFd(eventTube->getFd(), 0, ALOOPER_EVENT_INPUT, 0, 0);
2067 events->requestNextVsync();
2068 }
2069
2070 void wait() {
2071 ssize_t n;
2072
2073 looper->pollOnce(-1);
2074 // we don't handle any errors here, it doesn't matter
2075 // and we don't want to take the risk to get stuck.
2076
2077 // drain the events...
2078 while ((n = DisplayEventReceiver::getEvents(
2079 eventTube, buffer, 4)) > 0) ;
2080
2081 events->requestNextVsync();
2082 }
2083};
2084
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002085status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
2086{
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002087 // get screen geometry
Mathias Agopian1b031492012-06-20 17:51:20 -07002088 const DisplayHardware& hw(getDefaultDisplayHardware());
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002089 const uint32_t hw_w = hw.getWidth();
2090 const uint32_t hw_h = hw.getHeight();
Mathias Agopiana9040d02011-10-10 19:02:07 -07002091 const Region screenBounds(hw.getBounds());
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002092
2093 GLfloat u, v;
2094 GLuint tname;
Mathias Agopian118d0242011-10-13 16:02:48 -07002095 status_t result = renderScreenToTextureLocked(0, &tname, &u, &v);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002096 if (result != NO_ERROR) {
2097 return result;
2098 }
2099
2100 GLfloat vtx[8];
Mathias Agopiana9040d02011-10-10 19:02:07 -07002101 const GLfloat texCoords[4][2] = { {0,0}, {0,v}, {u,v}, {u,0} };
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002102 glBindTexture(GL_TEXTURE_2D, tname);
2103 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2104 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2105 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Michael I. Goldb1d1c6d2012-01-13 00:36:45 -08002106 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2107 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002108 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
2109 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2110 glVertexPointer(2, GL_FLOAT, 0, vtx);
2111
Mathias Agopianffcf4652011-07-07 17:30:31 -07002112 /*
2113 * Texture coordinate mapping
2114 *
2115 * u
2116 * 1 +----------+---+
2117 * | | | | image is inverted
2118 * | V | | w.r.t. the texture
2119 * 1-v +----------+ | coordinates
2120 * | |
2121 * | |
2122 * | |
2123 * 0 +--------------+
2124 * 0 1
2125 *
2126 */
2127
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002128 class s_curve_interpolator {
2129 const float nbFrames, s, v;
2130 public:
2131 s_curve_interpolator(int nbFrames, float s)
2132 : nbFrames(1.0f / (nbFrames-1)), s(s),
2133 v(1.0f + expf(-s + 0.5f*s)) {
2134 }
2135 float operator()(int f) {
2136 const float x = f * nbFrames;
2137 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
2138 }
2139 };
2140
2141 class v_stretch {
2142 const GLfloat hw_w, hw_h;
2143 public:
2144 v_stretch(uint32_t hw_w, uint32_t hw_h)
2145 : hw_w(hw_w), hw_h(hw_h) {
2146 }
2147 void operator()(GLfloat* vtx, float v) {
2148 const GLfloat w = hw_w + (hw_w * v);
2149 const GLfloat h = hw_h - (hw_h * v);
2150 const GLfloat x = (hw_w - w) * 0.5f;
2151 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopianffcf4652011-07-07 17:30:31 -07002152 vtx[0] = x; vtx[1] = y;
2153 vtx[2] = x; vtx[3] = y + h;
2154 vtx[4] = x + w; vtx[5] = y + h;
2155 vtx[6] = x + w; vtx[7] = y;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002156 }
2157 };
2158
2159 class h_stretch {
2160 const GLfloat hw_w, hw_h;
2161 public:
2162 h_stretch(uint32_t hw_w, uint32_t hw_h)
2163 : hw_w(hw_w), hw_h(hw_h) {
2164 }
2165 void operator()(GLfloat* vtx, float v) {
2166 const GLfloat w = hw_w - (hw_w * v);
2167 const GLfloat h = 1.0f;
2168 const GLfloat x = (hw_w - w) * 0.5f;
2169 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopianffcf4652011-07-07 17:30:31 -07002170 vtx[0] = x; vtx[1] = y;
2171 vtx[2] = x; vtx[3] = y + h;
2172 vtx[4] = x + w; vtx[5] = y + h;
2173 vtx[6] = x + w; vtx[7] = y;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002174 }
2175 };
2176
Mathias Agopianed9807b2012-05-18 14:18:08 -07002177 VSyncWaiter vsync(mEventThread);
2178
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002179 // the full animation is 24 frames
Mathias Agopianffcf4652011-07-07 17:30:31 -07002180 char value[PROPERTY_VALUE_MAX];
2181 property_get("debug.sf.electron_frames", value, "24");
2182 int nbFrames = (atoi(value) + 1) >> 1;
2183 if (nbFrames <= 0) // just in case
2184 nbFrames = 24;
2185
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002186 s_curve_interpolator itr(nbFrames, 7.5f);
2187 s_curve_interpolator itg(nbFrames, 8.0f);
2188 s_curve_interpolator itb(nbFrames, 8.5f);
2189
2190 v_stretch vverts(hw_w, hw_h);
Mathias Agopiana9040d02011-10-10 19:02:07 -07002191
2192 glMatrixMode(GL_TEXTURE);
2193 glLoadIdentity();
2194 glMatrixMode(GL_MODELVIEW);
2195 glLoadIdentity();
2196
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002197 glEnable(GL_BLEND);
2198 glBlendFunc(GL_ONE, GL_ONE);
2199 for (int i=0 ; i<nbFrames ; i++) {
2200 float x, y, w, h;
2201 const float vr = itr(i);
2202 const float vg = itg(i);
2203 const float vb = itb(i);
2204
Mathias Agopianed9807b2012-05-18 14:18:08 -07002205 // wait for vsync
2206 vsync.wait();
2207
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002208 // clear screen
2209 glColorMask(1,1,1,1);
Mathias Agopian59119e62010-10-11 12:37:43 -07002210 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopian59119e62010-10-11 12:37:43 -07002211 glEnable(GL_TEXTURE_2D);
Mathias Agopian59119e62010-10-11 12:37:43 -07002212
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002213 // draw the red plane
2214 vverts(vtx, vr);
2215 glColorMask(1,0,0,1);
2216 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07002217
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002218 // draw the green plane
2219 vverts(vtx, vg);
2220 glColorMask(0,1,0,1);
2221 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07002222
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002223 // draw the blue plane
2224 vverts(vtx, vb);
2225 glColorMask(0,0,1,1);
2226 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07002227
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002228 // draw the white highlight (we use the last vertices)
Mathias Agopian59119e62010-10-11 12:37:43 -07002229 glDisable(GL_TEXTURE_2D);
2230 glColorMask(1,1,1,1);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002231 glColor4f(vg, vg, vg, 1);
2232 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2233 hw.flip(screenBounds);
Mathias Agopian59119e62010-10-11 12:37:43 -07002234 }
2235
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002236 h_stretch hverts(hw_w, hw_h);
2237 glDisable(GL_BLEND);
2238 glDisable(GL_TEXTURE_2D);
2239 glColorMask(1,1,1,1);
2240 for (int i=0 ; i<nbFrames ; i++) {
2241 const float v = itg(i);
2242 hverts(vtx, v);
Mathias Agopianed9807b2012-05-18 14:18:08 -07002243
2244 // wait for vsync
2245 vsync.wait();
2246
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002247 glClear(GL_COLOR_BUFFER_BIT);
2248 glColor4f(1-v, 1-v, 1-v, 1);
2249 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2250 hw.flip(screenBounds);
2251 }
2252
2253 glColorMask(1,1,1,1);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002254 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2255 glDeleteTextures(1, &tname);
Mathias Agopiana67932f2011-04-20 14:20:59 -07002256 glDisable(GL_TEXTURE_2D);
Mathias Agopianc492e672011-10-18 14:49:27 -07002257 glDisable(GL_BLEND);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002258 return NO_ERROR;
2259}
2260
2261status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
2262{
2263 status_t result = PERMISSION_DENIED;
2264
2265 if (!GLExtensions::getInstance().haveFramebufferObject())
2266 return INVALID_OPERATION;
2267
2268
2269 // get screen geometry
Mathias Agopian1b031492012-06-20 17:51:20 -07002270 const DisplayHardware& hw(getDefaultDisplayHardware());
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002271 const uint32_t hw_w = hw.getWidth();
2272 const uint32_t hw_h = hw.getHeight();
2273 const Region screenBounds(hw.bounds());
2274
2275 GLfloat u, v;
2276 GLuint tname;
2277 result = renderScreenToTextureLocked(0, &tname, &u, &v);
2278 if (result != NO_ERROR) {
2279 return result;
2280 }
2281
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002282 GLfloat vtx[8];
2283 const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002284 glBindTexture(GL_TEXTURE_2D, tname);
2285 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2286 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2287 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Michael I. Goldb1d1c6d2012-01-13 00:36:45 -08002288 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2289 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002290 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
2291 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2292 glVertexPointer(2, GL_FLOAT, 0, vtx);
2293
2294 class s_curve_interpolator {
2295 const float nbFrames, s, v;
2296 public:
2297 s_curve_interpolator(int nbFrames, float s)
2298 : nbFrames(1.0f / (nbFrames-1)), s(s),
2299 v(1.0f + expf(-s + 0.5f*s)) {
2300 }
2301 float operator()(int f) {
2302 const float x = f * nbFrames;
2303 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
2304 }
2305 };
2306
2307 class v_stretch {
2308 const GLfloat hw_w, hw_h;
2309 public:
2310 v_stretch(uint32_t hw_w, uint32_t hw_h)
2311 : hw_w(hw_w), hw_h(hw_h) {
2312 }
2313 void operator()(GLfloat* vtx, float v) {
2314 const GLfloat w = hw_w + (hw_w * v);
2315 const GLfloat h = hw_h - (hw_h * v);
2316 const GLfloat x = (hw_w - w) * 0.5f;
2317 const GLfloat y = (hw_h - h) * 0.5f;
2318 vtx[0] = x; vtx[1] = y;
2319 vtx[2] = x; vtx[3] = y + h;
2320 vtx[4] = x + w; vtx[5] = y + h;
2321 vtx[6] = x + w; vtx[7] = y;
2322 }
2323 };
2324
2325 class h_stretch {
2326 const GLfloat hw_w, hw_h;
2327 public:
2328 h_stretch(uint32_t hw_w, uint32_t hw_h)
2329 : hw_w(hw_w), hw_h(hw_h) {
2330 }
2331 void operator()(GLfloat* vtx, float v) {
2332 const GLfloat w = hw_w - (hw_w * v);
2333 const GLfloat h = 1.0f;
2334 const GLfloat x = (hw_w - w) * 0.5f;
2335 const GLfloat y = (hw_h - h) * 0.5f;
2336 vtx[0] = x; vtx[1] = y;
2337 vtx[2] = x; vtx[3] = y + h;
2338 vtx[4] = x + w; vtx[5] = y + h;
2339 vtx[6] = x + w; vtx[7] = y;
2340 }
2341 };
2342
Mathias Agopianed9807b2012-05-18 14:18:08 -07002343 VSyncWaiter vsync(mEventThread);
2344
Mathias Agopiana6546e52010-10-14 12:33:07 -07002345 // the full animation is 12 frames
2346 int nbFrames = 8;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002347 s_curve_interpolator itr(nbFrames, 7.5f);
2348 s_curve_interpolator itg(nbFrames, 8.0f);
2349 s_curve_interpolator itb(nbFrames, 8.5f);
2350
2351 h_stretch hverts(hw_w, hw_h);
2352 glDisable(GL_BLEND);
2353 glDisable(GL_TEXTURE_2D);
2354 glColorMask(1,1,1,1);
2355 for (int i=nbFrames-1 ; i>=0 ; i--) {
2356 const float v = itg(i);
2357 hverts(vtx, v);
Mathias Agopianed9807b2012-05-18 14:18:08 -07002358
2359 // wait for vsync
2360 vsync.wait();
2361
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002362 glClear(GL_COLOR_BUFFER_BIT);
2363 glColor4f(1-v, 1-v, 1-v, 1);
2364 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2365 hw.flip(screenBounds);
2366 }
2367
Mathias Agopiana6546e52010-10-14 12:33:07 -07002368 nbFrames = 4;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002369 v_stretch vverts(hw_w, hw_h);
2370 glEnable(GL_BLEND);
2371 glBlendFunc(GL_ONE, GL_ONE);
2372 for (int i=nbFrames-1 ; i>=0 ; i--) {
2373 float x, y, w, h;
2374 const float vr = itr(i);
2375 const float vg = itg(i);
2376 const float vb = itb(i);
2377
Mathias Agopianed9807b2012-05-18 14:18:08 -07002378 // wait for vsync
2379 vsync.wait();
2380
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002381 // clear screen
2382 glColorMask(1,1,1,1);
2383 glClear(GL_COLOR_BUFFER_BIT);
2384 glEnable(GL_TEXTURE_2D);
2385
2386 // draw the red plane
2387 vverts(vtx, vr);
2388 glColorMask(1,0,0,1);
2389 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2390
2391 // draw the green plane
2392 vverts(vtx, vg);
2393 glColorMask(0,1,0,1);
2394 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2395
2396 // draw the blue plane
2397 vverts(vtx, vb);
2398 glColorMask(0,0,1,1);
2399 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2400
2401 hw.flip(screenBounds);
2402 }
2403
2404 glColorMask(1,1,1,1);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002405 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian59119e62010-10-11 12:37:43 -07002406 glDeleteTextures(1, &tname);
Mathias Agopiana67932f2011-04-20 14:20:59 -07002407 glDisable(GL_TEXTURE_2D);
Mathias Agopianc492e672011-10-18 14:49:27 -07002408 glDisable(GL_BLEND);
Mathias Agopian59119e62010-10-11 12:37:43 -07002409
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002410 return NO_ERROR;
2411}
2412
2413// ---------------------------------------------------------------------------
2414
Mathias Agopianabd671a2010-10-14 14:54:06 -07002415status_t SurfaceFlinger::turnElectronBeamOffImplLocked(int32_t mode)
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002416{
Mathias Agopian22ffb112012-04-10 21:04:02 -07002417 ATRACE_CALL();
2418
Mathias Agopian1b031492012-06-20 17:51:20 -07002419 DisplayHardware& hw(const_cast<DisplayHardware&>(getDefaultDisplayHardware()));
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002420 if (!hw.canDraw()) {
2421 // we're already off
2422 return NO_ERROR;
2423 }
Mathias Agopian7ee4cd52011-09-02 12:22:39 -07002424
2425 // turn off hwc while we're doing the animation
Mathias Agopian86303202012-07-24 22:46:10 -07002426 getHwComposer().disable();
Mathias Agopian7ee4cd52011-09-02 12:22:39 -07002427 // and make sure to turn it back on (if needed) next time we compose
2428 invalidateHwcGeometry();
2429
Mathias Agopianabd671a2010-10-14 14:54:06 -07002430 if (mode & ISurfaceComposer::eElectronBeamAnimationOff) {
2431 electronBeamOffAnimationImplLocked();
2432 }
2433
2434 // always clear the whole screen at the end of the animation
2435 glClearColor(0,0,0,1);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002436 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002437 hw.flip( Region(hw.bounds()) );
2438
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002439 return NO_ERROR;
Mathias Agopian59119e62010-10-11 12:37:43 -07002440}
2441
2442status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode)
2443{
Mathias Agopian59119e62010-10-11 12:37:43 -07002444 class MessageTurnElectronBeamOff : public MessageBase {
2445 SurfaceFlinger* flinger;
Mathias Agopianabd671a2010-10-14 14:54:06 -07002446 int32_t mode;
Mathias Agopian59119e62010-10-11 12:37:43 -07002447 status_t result;
2448 public:
Mathias Agopianabd671a2010-10-14 14:54:06 -07002449 MessageTurnElectronBeamOff(SurfaceFlinger* flinger, int32_t mode)
2450 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopian59119e62010-10-11 12:37:43 -07002451 }
2452 status_t getResult() const {
2453 return result;
2454 }
2455 virtual bool handler() {
2456 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002457 result = flinger->turnElectronBeamOffImplLocked(mode);
Mathias Agopian59119e62010-10-11 12:37:43 -07002458 return true;
2459 }
2460 };
2461
Mathias Agopianabd671a2010-10-14 14:54:06 -07002462 sp<MessageBase> msg = new MessageTurnElectronBeamOff(this, mode);
Mathias Agopian59119e62010-10-11 12:37:43 -07002463 status_t res = postMessageSync(msg);
2464 if (res == NO_ERROR) {
2465 res = static_cast<MessageTurnElectronBeamOff*>( msg.get() )->getResult();
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002466
2467 // work-around: when the power-manager calls us we activate the
2468 // animation. eventually, the "on" animation will be called
2469 // by the power-manager itself
Mathias Agopianabd671a2010-10-14 14:54:06 -07002470 mElectronBeamAnimationMode = mode;
Mathias Agopian59119e62010-10-11 12:37:43 -07002471 }
2472 return res;
2473}
2474
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002475// ---------------------------------------------------------------------------
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002476
Mathias Agopianabd671a2010-10-14 14:54:06 -07002477status_t SurfaceFlinger::turnElectronBeamOnImplLocked(int32_t mode)
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002478{
Mathias Agopian1b031492012-06-20 17:51:20 -07002479 DisplayHardware& hw(const_cast<DisplayHardware&>(getDefaultDisplayHardware()));
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002480 if (hw.canDraw()) {
2481 // we're already on
2482 return NO_ERROR;
2483 }
Mathias Agopianabd671a2010-10-14 14:54:06 -07002484 if (mode & ISurfaceComposer::eElectronBeamAnimationOn) {
2485 electronBeamOnAnimationImplLocked();
2486 }
Mathias Agopiana7f03732010-10-14 12:46:24 -07002487
2488 // make sure to redraw the whole screen when the animation is done
Mathias Agopian87baae12012-07-31 12:38:26 -07002489 hw.dirtyRegion.set(hw.bounds());
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08002490 signalTransaction();
Mathias Agopiana7f03732010-10-14 12:46:24 -07002491
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002492 return NO_ERROR;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002493}
2494
2495status_t SurfaceFlinger::turnElectronBeamOn(int32_t mode)
2496{
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002497 class MessageTurnElectronBeamOn : public MessageBase {
2498 SurfaceFlinger* flinger;
Mathias Agopianabd671a2010-10-14 14:54:06 -07002499 int32_t mode;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002500 status_t result;
2501 public:
Mathias Agopianabd671a2010-10-14 14:54:06 -07002502 MessageTurnElectronBeamOn(SurfaceFlinger* flinger, int32_t mode)
2503 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002504 }
2505 status_t getResult() const {
2506 return result;
2507 }
2508 virtual bool handler() {
2509 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002510 result = flinger->turnElectronBeamOnImplLocked(mode);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002511 return true;
2512 }
2513 };
2514
Mathias Agopianabd671a2010-10-14 14:54:06 -07002515 postMessageAsync( new MessageTurnElectronBeamOn(this, mode) );
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002516 return NO_ERROR;
2517}
2518
2519// ---------------------------------------------------------------------------
2520
Mathias Agopian74c40c02010-09-29 13:02:36 -07002521status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
2522 sp<IMemoryHeap>* heap,
2523 uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002524 uint32_t sw, uint32_t sh,
2525 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian74c40c02010-09-29 13:02:36 -07002526{
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002527 ATRACE_CALL();
2528
Mathias Agopian74c40c02010-09-29 13:02:36 -07002529 status_t result = PERMISSION_DENIED;
2530
2531 // only one display supported for now
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002532 if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) {
Mathias Agopian74c40c02010-09-29 13:02:36 -07002533 return BAD_VALUE;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002534 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002535
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002536 if (!GLExtensions::getInstance().haveFramebufferObject()) {
Mathias Agopian74c40c02010-09-29 13:02:36 -07002537 return INVALID_OPERATION;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002538 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002539
2540 // get screen geometry
Mathias Agopian1b031492012-06-20 17:51:20 -07002541 const DisplayHardware& hw(getDisplayHardware(dpy));
Mathias Agopian74c40c02010-09-29 13:02:36 -07002542 const uint32_t hw_w = hw.getWidth();
2543 const uint32_t hw_h = hw.getHeight();
2544
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002545 // if we have secure windows on this display, never allow the screen capture
2546 if (hw.getSecureLayerVisible()) {
2547 return PERMISSION_DENIED;
2548 }
2549
2550 if ((sw > hw_w) || (sh > hw_h)) {
Mathias Agopian74c40c02010-09-29 13:02:36 -07002551 return BAD_VALUE;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -07002552 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002553
2554 sw = (!sw) ? hw_w : sw;
2555 sh = (!sh) ? hw_h : sh;
2556 const size_t size = sw * sh * 4;
2557
Steve Block9d453682011-12-20 16:23:08 +00002558 //ALOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d",
Mathias Agopian1c71a472011-03-02 18:45:50 -08002559 // sw, sh, minLayerZ, maxLayerZ);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002560
Mathias Agopian74c40c02010-09-29 13:02:36 -07002561 // make sure to clear all GL error flags
2562 while ( glGetError() != GL_NO_ERROR ) ;
2563
2564 // create a FBO
2565 GLuint name, tname;
2566 glGenRenderbuffersOES(1, &tname);
2567 glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
2568 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, sw, sh);
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002569
Mathias Agopian74c40c02010-09-29 13:02:36 -07002570 glGenFramebuffersOES(1, &name);
2571 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2572 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
2573 GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
2574
2575 GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002576
Mathias Agopian74c40c02010-09-29 13:02:36 -07002577 if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
2578
2579 // invert everything, b/c glReadPixel() below will invert the FB
2580 glViewport(0, 0, sw, sh);
2581 glMatrixMode(GL_PROJECTION);
2582 glPushMatrix();
2583 glLoadIdentity();
Mathias Agopianffcf4652011-07-07 17:30:31 -07002584 glOrthof(0, hw_w, hw_h, 0, 0, 1);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002585 glMatrixMode(GL_MODELVIEW);
2586
2587 // redraw the screen entirely...
2588 glClearColor(0,0,0,1);
2589 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopianf653b892010-12-16 18:46:17 -08002590
Jamie Gennis9575f602011-10-07 14:51:16 -07002591 const LayerVector& layers(mDrawingState.layersSortedByZ);
2592 const size_t count = layers.size();
Mathias Agopian74c40c02010-09-29 13:02:36 -07002593 for (size_t i=0 ; i<count ; ++i) {
2594 const sp<LayerBase>& layer(layers[i]);
Mathias Agopianb0610332011-08-25 14:36:43 -07002595 const uint32_t flags = layer->drawingState().flags;
2596 if (!(flags & ISurfaceComposer::eLayerHidden)) {
2597 const uint32_t z = layer->drawingState().z;
2598 if (z >= minLayerZ && z <= maxLayerZ) {
Mathias Agopian1b031492012-06-20 17:51:20 -07002599 layer->drawForSreenShot(hw);
Mathias Agopianb0610332011-08-25 14:36:43 -07002600 }
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002601 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002602 }
2603
Mathias Agopian74c40c02010-09-29 13:02:36 -07002604 // check for errors and return screen capture
2605 if (glGetError() != GL_NO_ERROR) {
2606 // error while rendering
2607 result = INVALID_OPERATION;
2608 } else {
2609 // allocate shared memory large enough to hold the
2610 // screen capture
2611 sp<MemoryHeapBase> base(
2612 new MemoryHeapBase(size, 0, "screen-capture") );
2613 void* const ptr = base->getBase();
2614 if (ptr) {
2615 // capture the screen with glReadPixels()
Mathias Agopianfddc28d2012-03-12 15:18:42 -04002616 ScopedTrace _t(ATRACE_TAG, "glReadPixels");
Mathias Agopian74c40c02010-09-29 13:02:36 -07002617 glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
2618 if (glGetError() == GL_NO_ERROR) {
2619 *heap = base;
2620 *w = sw;
2621 *h = sh;
2622 *f = PIXEL_FORMAT_RGBA_8888;
2623 result = NO_ERROR;
2624 }
2625 } else {
2626 result = NO_MEMORY;
2627 }
2628 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002629 glViewport(0, 0, hw_w, hw_h);
2630 glMatrixMode(GL_PROJECTION);
2631 glPopMatrix();
2632 glMatrixMode(GL_MODELVIEW);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002633 } else {
2634 result = BAD_VALUE;
2635 }
2636
2637 // release FBO resources
2638 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
2639 glDeleteRenderbuffersOES(1, &tname);
2640 glDeleteFramebuffersOES(1, &name);
Mathias Agopiane6f09842010-12-15 14:41:59 -08002641
2642 hw.compositionComplete();
2643
Steve Block9d453682011-12-20 16:23:08 +00002644 // ALOGD("screenshot: result = %s", result<0 ? strerror(result) : "OK");
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002645
Mathias Agopian74c40c02010-09-29 13:02:36 -07002646 return result;
2647}
2648
2649
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002650status_t SurfaceFlinger::captureScreen(DisplayID dpy,
2651 sp<IMemoryHeap>* heap,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002652 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002653 uint32_t sw, uint32_t sh,
2654 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002655{
2656 // only one display supported for now
Glenn Kasten99ed2242011-12-15 09:51:17 -08002657 if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002658 return BAD_VALUE;
2659
2660 if (!GLExtensions::getInstance().haveFramebufferObject())
2661 return INVALID_OPERATION;
2662
2663 class MessageCaptureScreen : public MessageBase {
2664 SurfaceFlinger* flinger;
2665 DisplayID dpy;
2666 sp<IMemoryHeap>* heap;
2667 uint32_t* w;
2668 uint32_t* h;
2669 PixelFormat* f;
Mathias Agopian74c40c02010-09-29 13:02:36 -07002670 uint32_t sw;
2671 uint32_t sh;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002672 uint32_t minLayerZ;
2673 uint32_t maxLayerZ;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002674 status_t result;
2675 public:
2676 MessageCaptureScreen(SurfaceFlinger* flinger, DisplayID dpy,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002677 sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002678 uint32_t sw, uint32_t sh,
2679 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002680 : flinger(flinger), dpy(dpy),
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002681 heap(heap), w(w), h(h), f(f), sw(sw), sh(sh),
2682 minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
2683 result(PERMISSION_DENIED)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002684 {
2685 }
2686 status_t getResult() const {
2687 return result;
2688 }
2689 virtual bool handler() {
2690 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002691 result = flinger->captureScreenImplLocked(dpy,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002692 heap, w, h, f, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002693 return true;
2694 }
2695 };
2696
2697 sp<MessageBase> msg = new MessageCaptureScreen(this,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002698 dpy, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002699 status_t res = postMessageSync(msg);
2700 if (res == NO_ERROR) {
2701 res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult();
2702 }
2703 return res;
2704}
2705
2706// ---------------------------------------------------------------------------
2707
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002708SurfaceFlinger::LayerVector::LayerVector() {
2709}
2710
2711SurfaceFlinger::LayerVector::LayerVector(const LayerVector& rhs)
2712 : SortedVector<sp<LayerBase> >(rhs) {
2713}
2714
2715int SurfaceFlinger::LayerVector::do_compare(const void* lhs,
2716 const void* rhs) const
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002717{
Mathias Agopian921e6ac2012-07-23 23:11:29 -07002718 const sp<LayerBase>& l(*reinterpret_cast<const sp<LayerBase>*>(lhs));
2719 const sp<LayerBase>& r(*reinterpret_cast<const sp<LayerBase>*>(rhs));
2720 // sort layers by Z order
2721 uint32_t lz = l->currentState().z;
2722 uint32_t rz = r->currentState().z;
2723 // then by sequence, so we get a stable ordering
2724 return (lz != rz) ? (lz - rz) : (l->sequence - r->sequence);
2725}
2726
2727// ---------------------------------------------------------------------------
2728
2729SurfaceFlinger::State::State()
2730 : orientation(ISurfaceComposer::eOrientationDefault),
2731 orientationFlags(0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002732}
2733
2734// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002735
Jamie Gennis9a78c902011-01-12 18:30:40 -08002736GraphicBufferAlloc::GraphicBufferAlloc() {}
2737
2738GraphicBufferAlloc::~GraphicBufferAlloc() {}
2739
2740sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h,
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002741 PixelFormat format, uint32_t usage, status_t* error) {
Jamie Gennis9a78c902011-01-12 18:30:40 -08002742 sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
2743 status_t err = graphicBuffer->initCheck();
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002744 *error = err;
Mathias Agopiana67932f2011-04-20 14:20:59 -07002745 if (err != 0 || graphicBuffer->handle == 0) {
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002746 if (err == NO_MEMORY) {
2747 GraphicBuffer::dumpAllocationsToSystemLog();
2748 }
Steve Blocke6f43dd2012-01-06 19:20:56 +00002749 ALOGE("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) "
Mathias Agopiana67932f2011-04-20 14:20:59 -07002750 "failed (%s), handle=%p",
2751 w, h, strerror(-err), graphicBuffer->handle);
Jamie Gennis9a78c902011-01-12 18:30:40 -08002752 return 0;
2753 }
Jamie Gennis9a78c902011-01-12 18:30:40 -08002754 return graphicBuffer;
2755}
2756
Jamie Gennis9a78c902011-01-12 18:30:40 -08002757// ---------------------------------------------------------------------------
2758
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002759}; // namespace android