blob: d69bff2130e92f5462388eb9d4333600d32eca07 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdio.h>
19#include <stdint.h>
20#include <unistd.h>
21#include <fcntl.h>
22#include <errno.h>
23#include <math.h>
Jean-Baptiste Queru20763732009-01-26 11:51:12 -080024#include <limits.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <sys/types.h>
26#include <sys/stat.h>
27#include <sys/ioctl.h>
28
29#include <cutils/log.h>
30#include <cutils/properties.h>
31
Mathias Agopian07952722009-05-19 19:08:10 -070032#include <binder/IPCThreadState.h>
33#include <binder/IServiceManager.h>
Mathias Agopiand763b5d2009-07-02 18:11:53 -070034#include <binder/MemoryHeapBase.h>
Mathias Agopian0dd593f2011-06-27 16:05:52 -070035#include <binder/PermissionCache.h>
Mathias Agopiand763b5d2009-07-02 18:11:53 -070036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include <utils/String8.h>
38#include <utils/String16.h>
39#include <utils/StopWatch.h>
40
Mathias Agopian6950e422009-10-05 17:07:12 -070041#include <ui/GraphicBufferAllocator.h>
Mathias Agopian04262e92010-09-13 22:57:58 -070042#include <ui/GraphicLog.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043#include <ui/PixelFormat.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45#include <pixelflinger/pixelflinger.h>
46#include <GLES/gl.h>
47
48#include "clz.h"
Mathias Agopian781953d2010-06-25 18:02:21 -070049#include "GLExtensions.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050#include "Layer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051#include "LayerDim.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54#include "DisplayHardware/DisplayHardware.h"
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070055#include "DisplayHardware/HWComposer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Mathias Agopian7bb843c2011-04-20 14:20:59 -070057#include <private/surfaceflinger/SharedBufferStack.h>
58
Mathias Agopian627e7b52009-05-21 19:21:59 -070059/* ideally AID_GRAPHICS would be in a semi-public header
60 * or there would be a way to map a user/group name to its id
61 */
62#ifndef AID_GRAPHICS
63#define AID_GRAPHICS 1003
64#endif
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066#define DISPLAY_COUNT 1
67
68namespace android {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069// ---------------------------------------------------------------------------
70
Mathias Agopian0dd593f2011-06-27 16:05:52 -070071const String16 sHardwareTest("android.permission.HARDWARE_TEST");
72const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
73const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER");
74const String16 sDump("android.permission.DUMP");
75
76// ---------------------------------------------------------------------------
77
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078SurfaceFlinger::SurfaceFlinger()
79 : BnSurfaceComposer(), Thread(false),
80 mTransactionFlags(0),
Mathias Agopian9779b2212009-09-07 16:32:45 -070081 mResizeTransationPending(false),
Mathias Agopian1473f462009-04-10 14:24:30 -070082 mLayersRemoved(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 mBootTime(systemTime()),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 mVisibleRegionsDirty(false),
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070085 mHwWorkListDirty(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 mDeferReleaseConsole(false),
87 mFreezeDisplay(false),
Mathias Agopiand4e03f32010-10-14 14:54:06 -070088 mElectronBeamAnimationMode(0),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 mFreezeCount(0),
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070090 mFreezeDisplayTime(0),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 mDebugRegion(0),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 mDebugBackground(0),
Mathias Agopian6a969242010-09-22 18:58:01 -070093 mDebugDisableHWC(0),
Mathias Agopiana8d49172009-08-26 16:36:26 -070094 mDebugInSwapBuffers(0),
95 mLastSwapBufferTime(0),
96 mDebugInTransaction(0),
97 mLastTransactionTime(0),
Mathias Agopian6950e422009-10-05 17:07:12 -070098 mBootFinished(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 mConsoleSignals(0),
100 mSecureFrameBuffer(0)
101{
102 init();
103}
104
105void SurfaceFlinger::init()
106{
107 LOGI("SurfaceFlinger is starting");
108
109 // debugging stuff...
110 char value[PROPERTY_VALUE_MAX];
111 property_get("debug.sf.showupdates", value, "0");
112 mDebugRegion = atoi(value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 property_get("debug.sf.showbackground", value, "0");
114 mDebugBackground = atoi(value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700116 LOGI_IF(mDebugRegion, "showupdates enabled");
117 LOGI_IF(mDebugBackground, "showbackground enabled");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118}
119
120SurfaceFlinger::~SurfaceFlinger()
121{
122 glDeleteTextures(1, &mWormholeTexName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123}
124
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700125sp<IMemoryHeap> SurfaceFlinger::getCblk() const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126{
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700127 return mServerHeap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128}
129
Mathias Agopian770492c2010-05-28 14:22:23 -0700130sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131{
Mathias Agopian593c05c2010-06-02 23:28:45 -0700132 sp<ISurfaceComposerClient> bclient;
133 sp<Client> client(new Client(this));
134 status_t err = client->initCheck();
135 if (err == NO_ERROR) {
136 bclient = client;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 return bclient;
139}
140
Jamie Gennisf7acf162011-01-12 18:30:40 -0800141sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
142{
143 sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
144 return gba;
145}
Mathias Agopian7623da42010-06-01 15:12:58 -0700146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const
148{
149 LOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy);
150 const GraphicPlane& plane(mGraphicPlanes[dpy]);
151 return plane;
152}
153
154GraphicPlane& SurfaceFlinger::graphicPlane(int dpy)
155{
156 return const_cast<GraphicPlane&>(
157 const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy));
158}
159
160void SurfaceFlinger::bootFinished()
161{
162 const nsecs_t now = systemTime();
163 const nsecs_t duration = now - mBootTime;
Andreas Hubere3c01832010-08-16 08:49:37 -0700164 LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
Mathias Agopian6950e422009-10-05 17:07:12 -0700165 mBootFinished = true;
Mathias Agopian0c63ef52011-07-01 17:08:43 -0700166
167 // wait patiently for the window manager death
168 const String16 name("window");
169 sp<IBinder> window(defaultServiceManager()->getService(name));
170 if (window != 0) {
171 window->linkToDeath(this);
172 }
173
174 // stop boot animation
Mathias Agopian627e7b52009-05-21 19:21:59 -0700175 property_set("ctl.stop", "bootanim");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176}
177
Mathias Agopian0c63ef52011-07-01 17:08:43 -0700178void SurfaceFlinger::binderDied(const wp<IBinder>& who)
179{
180 // the window manager died on us. prepare its eulogy.
181
182 // unfreeze the screen in case it was... frozen
183 mFreezeDisplayTime = 0;
184 mFreezeCount = 0;
185 mFreezeDisplay = false;
186
187 // reset screen orientation
188 setOrientation(0, eOrientationDefault, 0);
189
190 // restart the boot-animation
191 property_set("ctl.start", "bootanim");
192}
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194void SurfaceFlinger::onFirstRef()
195{
196 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
197
198 // Wait for the main thread to be done with its initialization
199 mReadyToRunBarrier.wait();
200}
201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202static inline uint16_t pack565(int r, int g, int b) {
203 return (r<<11)|(g<<5)|b;
204}
205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206status_t SurfaceFlinger::readyToRun()
207{
208 LOGI( "SurfaceFlinger's main thread ready to run. "
209 "Initializing graphics H/W...");
210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 // we only support one display currently
212 int dpy = 0;
213
214 {
215 // initialize the main display
216 GraphicPlane& plane(graphicPlane(dpy));
217 DisplayHardware* const hw = new DisplayHardware(this, dpy);
218 plane.setDisplayHardware(hw);
219 }
220
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700221 // create the shared control-block
222 mServerHeap = new MemoryHeapBase(4096,
223 MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap");
224 LOGE_IF(mServerHeap==0, "can't create shared memory dealer");
Andreas Hubere3c01832010-08-16 08:49:37 -0700225
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700226 mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase());
227 LOGE_IF(mServerCblk==0, "can't get to shared control block's address");
Andreas Hubere3c01832010-08-16 08:49:37 -0700228
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700229 new(mServerCblk) surface_flinger_cblk_t;
230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 // initialize primary screen
232 // (other display should be initialized in the same manner, but
233 // asynchronously, as they could come and go. None of this is supported
234 // yet).
235 const GraphicPlane& plane(graphicPlane(dpy));
236 const DisplayHardware& hw = plane.displayHardware();
237 const uint32_t w = hw.getWidth();
238 const uint32_t h = hw.getHeight();
239 const uint32_t f = hw.getFormat();
240 hw.makeCurrent();
241
242 // initialize the shared control block
243 mServerCblk->connected |= 1<<dpy;
244 display_cblk_t* dcblk = mServerCblk->displays + dpy;
245 memset(dcblk, 0, sizeof(display_cblk_t));
Mathias Agopian66c77a52010-02-08 15:49:35 -0800246 dcblk->w = plane.getWidth();
247 dcblk->h = plane.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 dcblk->format = f;
249 dcblk->orientation = ISurfaceComposer::eOrientationDefault;
250 dcblk->xdpi = hw.getDpiX();
251 dcblk->ydpi = hw.getDpiY();
252 dcblk->fps = hw.getRefreshRate();
253 dcblk->density = hw.getDensity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254
255 // Initialize OpenGL|ES
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Andreas Hubere3c01832010-08-16 08:49:37 -0700257 glPixelStorei(GL_PACK_ALIGNMENT, 4);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 glEnableClientState(GL_VERTEX_ARRAY);
259 glEnable(GL_SCISSOR_TEST);
260 glShadeModel(GL_FLAT);
261 glDisable(GL_DITHER);
262 glDisable(GL_CULL_FACE);
263
264 const uint16_t g0 = pack565(0x0F,0x1F,0x0F);
265 const uint16_t g1 = pack565(0x17,0x2f,0x17);
266 const uint16_t textureData[4] = { g0, g1, g1, g0 };
267 glGenTextures(1, &mWormholeTexName);
268 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
269 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
270 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
271 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
272 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
273 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0,
274 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData);
275
276 glViewport(0, 0, w, h);
277 glMatrixMode(GL_PROJECTION);
278 glLoadIdentity();
279 glOrthof(0, w, h, 0, 0, 1);
280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 mReadyToRunBarrier.open();
282
283 /*
284 * We're now ready to accept clients...
285 */
286
Mathias Agopian627e7b52009-05-21 19:21:59 -0700287 // start boot animation
288 property_set("ctl.start", "bootanim");
Andreas Hubere3c01832010-08-16 08:49:37 -0700289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 return NO_ERROR;
291}
292
293// ----------------------------------------------------------------------------
294#if 0
295#pragma mark -
296#pragma mark Events Handler
297#endif
298
299void SurfaceFlinger::waitForEvent()
300{
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700301 while (true) {
302 nsecs_t timeout = -1;
Mathias Agopian0e449762009-12-01 17:23:28 -0800303 const nsecs_t freezeDisplayTimeout = ms2ns(5000);
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700304 if (UNLIKELY(isFrozen())) {
305 // wait 5 seconds
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700306 const nsecs_t now = systemTime();
307 if (mFreezeDisplayTime == 0) {
308 mFreezeDisplayTime = now;
309 }
310 nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime);
311 timeout = waitTime>0 ? waitTime : 0;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700312 }
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700313
Mathias Agopian898c4c92010-05-18 17:06:55 -0700314 sp<MessageBase> msg = mEventQueue.waitMessage(timeout);
Mathias Agopian0e449762009-12-01 17:23:28 -0800315
316 // see if we timed out
317 if (isFrozen()) {
318 const nsecs_t now = systemTime();
319 nsecs_t frozenTime = (now - mFreezeDisplayTime);
320 if (frozenTime >= freezeDisplayTimeout) {
321 // we timed out and are still frozen
322 LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d",
323 mFreezeDisplay, mFreezeCount);
324 mFreezeDisplayTime = 0;
325 mFreezeCount = 0;
326 mFreezeDisplay = false;
327 }
328 }
329
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700330 if (msg != 0) {
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700331 switch (msg->what) {
332 case MessageQueue::INVALIDATE:
333 // invalidate message, just return to the main loop
334 return;
335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 }
338}
339
340void SurfaceFlinger::signalEvent() {
Mathias Agopian6ead5d92009-04-20 19:39:12 -0700341 mEventQueue.invalidate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342}
343
Jamie Gennisd2acedf2011-03-08 12:18:54 -0800344bool SurfaceFlinger::authenticateSurface(const sp<ISurface>& surface) const {
345 Mutex::Autolock _l(mStateLock);
346 sp<IBinder> surfBinder(surface->asBinder());
347
348 // Check the visible layer list for the ISurface
349 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
350 size_t count = currentLayers.size();
351 for (size_t i=0 ; i<count ; i++) {
352 const sp<LayerBase>& layer(currentLayers[i]);
353 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
354 if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
355 return true;
356 }
357 }
358
359 // Check the layers in the purgatory. This check is here so that if a
360 // Surface gets destroyed before all the clients are done using it, the
361 // error will not be reported as "surface XYZ is not authenticated", but
362 // will instead fail later on when the client tries to use the surface,
363 // which should be reported as "surface XYZ returned an -ENODEV". The
364 // purgatorized layers are no less authentic than the visible ones, so this
365 // should not cause any harm.
366 size_t purgatorySize = mLayerPurgatory.size();
367 for (size_t i=0 ; i<purgatorySize ; i++) {
368 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
369 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
370 if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
371 return true;
372 }
373 }
374
375 return false;
376}
377
Mathias Agopian898c4c92010-05-18 17:06:55 -0700378status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
379 nsecs_t reltime, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380{
Mathias Agopian898c4c92010-05-18 17:06:55 -0700381 return mEventQueue.postMessage(msg, reltime, flags);
382}
383
384status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
385 nsecs_t reltime, uint32_t flags)
386{
387 status_t res = mEventQueue.postMessage(msg, reltime, flags);
388 if (res == NO_ERROR) {
389 msg->wait();
390 }
391 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392}
393
394// ----------------------------------------------------------------------------
395#if 0
396#pragma mark -
397#pragma mark Main loop
398#endif
399
400bool SurfaceFlinger::threadLoop()
401{
402 waitForEvent();
403
Mathias Agopian69608112011-05-19 15:38:14 -0700404 // call Layer's destructor
405 handleDestroyLayers();
406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 // check for transactions
408 if (UNLIKELY(mConsoleSignals)) {
409 handleConsoleEvents();
410 }
411
Mathias Agopian439863f2011-06-28 19:09:31 -0700412 // if we're in a global transaction, don't do anything.
413 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
414 uint32_t transactionFlags = peekTransactionFlags(mask);
415 if (UNLIKELY(transactionFlags)) {
416 handleTransaction(transactionFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 }
418
419 // post surfaces (if needed)
420 handlePageFlip();
421
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700422 if (UNLIKELY(mHwWorkListDirty)) {
423 // build the h/w work list
424 handleWorkList();
425 }
426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian81384bf2009-09-27 22:47:27 -0700428 if (LIKELY(hw.canDraw() && !isFrozen())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 // repaint the framebuffer (if needed)
Mathias Agopian04262e92010-09-13 22:57:58 -0700430
431 const int index = hw.getCurrentBufferIndex();
432 GraphicLog& logger(GraphicLog::getInstance());
433
434 logger.log(GraphicLog::SF_REPAINT, index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 handleRepaint();
436
Mathias Agopianb1a18742009-09-17 16:18:16 -0700437 // inform the h/w that we're done compositing
Mathias Agopian04262e92010-09-13 22:57:58 -0700438 logger.log(GraphicLog::SF_COMPOSITION_COMPLETE, index);
Mathias Agopianb1a18742009-09-17 16:18:16 -0700439 hw.compositionComplete();
440
Mathias Agopian04262e92010-09-13 22:57:58 -0700441 logger.log(GraphicLog::SF_SWAP_BUFFERS, index);
Antti Hatala4c0a4a22010-09-08 06:37:14 -0700442 postFramebuffer();
443
Mathias Agopian04262e92010-09-13 22:57:58 -0700444 logger.log(GraphicLog::SF_REPAINT_DONE, index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 } else {
446 // pretend we did the post
Mathias Agopiana6b8c1c2010-12-15 14:41:59 -0800447 hw.compositionComplete();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 usleep(16667); // 60 fps period
449 }
450 return true;
451}
452
453void SurfaceFlinger::postFramebuffer()
454{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 if (!mInvalidRegion.isEmpty()) {
456 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana8d49172009-08-26 16:36:26 -0700457 const nsecs_t now = systemTime();
458 mDebugInSwapBuffers = now;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 hw.flip(mInvalidRegion);
Mathias Agopiana8d49172009-08-26 16:36:26 -0700460 mLastSwapBufferTime = systemTime() - now;
461 mDebugInSwapBuffers = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 mInvalidRegion.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 }
464}
465
466void SurfaceFlinger::handleConsoleEvents()
467{
468 // something to do with the console
469 const DisplayHardware& hw = graphicPlane(0).displayHardware();
470
471 int what = android_atomic_and(0, &mConsoleSignals);
472 if (what & eConsoleAcquired) {
473 hw.acquireScreen();
Mathias Agopian2d2b8032010-10-12 16:05:48 -0700474 // this is a temporary work-around, eventually this should be called
475 // by the power-manager
Mathias Agopiand4e03f32010-10-14 14:54:06 -0700476 SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 }
478
Mathias Agopianaab758e2010-10-11 12:37:43 -0700479 if (mDeferReleaseConsole && hw.isScreenAcquired()) {
Mathias Agopianed81f222009-04-14 23:02:51 -0700480 // We got the release signal before the acquire signal
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 mDeferReleaseConsole = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 hw.releaseScreen();
483 }
484
485 if (what & eConsoleReleased) {
Mathias Agopianaab758e2010-10-11 12:37:43 -0700486 if (hw.isScreenAcquired()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 hw.releaseScreen();
488 } else {
489 mDeferReleaseConsole = true;
490 }
491 }
492
493 mDirtyRegion.set(hw.bounds());
494}
495
496void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
497{
Mathias Agopian69608112011-05-19 15:38:14 -0700498 Mutex::Autolock _l(mStateLock);
499 const nsecs_t now = systemTime();
500 mDebugInTransaction = now;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
Mathias Agopian69608112011-05-19 15:38:14 -0700502 // Here we're guaranteed that some transaction flags are set
503 // so we can call handleTransactionLocked() unconditionally.
504 // We call getTransactionFlags(), which will also clear the flags,
505 // with mStateLock held to guarantee that mCurrentState won't change
506 // until the transaction is committed.
Mathias Agopianff1d4102010-08-10 17:19:56 -0700507
Mathias Agopian69608112011-05-19 15:38:14 -0700508 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
509 transactionFlags = getTransactionFlags(mask);
510 handleTransactionLocked(transactionFlags);
Mathias Agopian6dcb1552011-05-03 17:04:02 -0700511
Mathias Agopian69608112011-05-19 15:38:14 -0700512 mLastTransactionTime = systemTime() - now;
513 mDebugInTransaction = 0;
514 invalidateHwcGeometry();
515 // here the transaction has been committed
Mathias Agopian2d5ee252009-06-04 18:46:21 -0700516}
517
Mathias Agopian69608112011-05-19 15:38:14 -0700518void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
Mathias Agopian2d5ee252009-06-04 18:46:21 -0700519{
520 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 const size_t count = currentLayers.size();
522
523 /*
524 * Traversal of the children
525 * (perform the transaction for each of them if needed)
526 */
527
528 const bool layersNeedTransaction = transactionFlags & eTraversalNeeded;
529 if (layersNeedTransaction) {
530 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian1473f462009-04-10 14:24:30 -0700531 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
533 if (!trFlags) continue;
534
535 const uint32_t flags = layer->doTransaction(0);
536 if (flags & Layer::eVisibleRegion)
537 mVisibleRegionsDirty = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 }
539 }
540
541 /*
542 * Perform our own transaction if needed
543 */
544
545 if (transactionFlags & eTransactionNeeded) {
546 if (mCurrentState.orientation != mDrawingState.orientation) {
547 // the orientation has changed, recompute all visible regions
548 // and invalidate everything.
549
550 const int dpy = 0;
551 const int orientation = mCurrentState.orientation;
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700552 const uint32_t type = mCurrentState.orientationType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 GraphicPlane& plane(graphicPlane(dpy));
554 plane.setOrientation(orientation);
555
556 // update the shared control block
557 const DisplayHardware& hw(plane.displayHardware());
558 volatile display_cblk_t* dcblk = mServerCblk->displays + dpy;
559 dcblk->orientation = orientation;
Mathias Agopian66c77a52010-02-08 15:49:35 -0800560 dcblk->w = plane.getWidth();
561 dcblk->h = plane.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562
563 mVisibleRegionsDirty = true;
564 mDirtyRegion.set(hw.bounds());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 }
566
567 if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) {
568 // freezing or unfreezing the display -> trigger animation if needed
569 mFreezeDisplay = mCurrentState.freezeDisplay;
Mathias Agopian31901cc2010-03-01 17:51:17 -0800570 if (mFreezeDisplay)
571 mFreezeDisplayTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700574 if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) {
575 // layers have been added
576 mVisibleRegionsDirty = true;
577 }
578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 // some layers might have been removed, so
580 // we need to update the regions they're exposing.
Mathias Agopian1473f462009-04-10 14:24:30 -0700581 if (mLayersRemoved) {
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700582 mLayersRemoved = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 mVisibleRegionsDirty = true;
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700584 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
Mathias Agopian2d5ee252009-06-04 18:46:21 -0700585 const size_t count = previousLayers.size();
586 for (size_t i=0 ; i<count ; i++) {
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700587 const sp<LayerBase>& layer(previousLayers[i]);
588 if (currentLayers.indexOf( layer ) < 0) {
589 // this layer is not visible anymore
Mathias Agopian33863dd2009-07-28 14:20:21 -0700590 mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700591 }
592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
596 commitTransaction();
597}
598
Mathias Agopian69608112011-05-19 15:38:14 -0700599void SurfaceFlinger::destroyLayer(LayerBase const* layer)
600{
601 Mutex::Autolock _l(mDestroyedLayerLock);
602 mDestroyedLayers.add(layer);
603 signalEvent();
604}
605
606void SurfaceFlinger::handleDestroyLayers()
607{
608 Vector<LayerBase const *> destroyedLayers;
609
610 { // scope for the lock
611 Mutex::Autolock _l(mDestroyedLayerLock);
612 destroyedLayers = mDestroyedLayers;
613 mDestroyedLayers.clear();
614 }
615
616 // call destructors without a lock held
617 const size_t count = destroyedLayers.size();
618 for (size_t i=0 ; i<count ; i++) {
619 //LOGD("destroying %s", destroyedLayers[i]->getName().string());
620 delete destroyedLayers[i];
621 }
622}
623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624sp<FreezeLock> SurfaceFlinger::getFreezeLock() const
625{
626 return new FreezeLock(const_cast<SurfaceFlinger *>(this));
627}
628
629void SurfaceFlinger::computeVisibleRegions(
Mathias Agopianf0ff9062011-03-11 16:54:47 -0800630 const LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631{
632 const GraphicPlane& plane(graphicPlane(0));
633 const Transform& planeTransform(plane.transform());
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700634 const DisplayHardware& hw(plane.displayHardware());
635 const Region screenRegion(hw.bounds());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636
637 Region aboveOpaqueLayers;
638 Region aboveCoveredLayers;
639 Region dirty;
640
641 bool secureFrameBuffer = false;
642
643 size_t i = currentLayers.size();
644 while (i--) {
Mathias Agopian1473f462009-04-10 14:24:30 -0700645 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 layer->validateVisibility(planeTransform);
647
648 // start with the whole surface at its current location
Mathias Agopian12cedff2009-07-28 10:57:27 -0700649 const Layer::State& s(layer->drawingState());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700651 /*
652 * opaqueRegion: area of a surface that is fully opaque.
653 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 Region opaqueRegion;
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700655
656 /*
657 * visibleRegion: area of a surface that is visible on screen
658 * and not fully transparent. This is essentially the layer's
659 * footprint minus the opaque regions above it.
660 * Areas covered by a translucent surface are considered visible.
661 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 Region visibleRegion;
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700663
664 /*
665 * coveredRegion: area of a surface that is covered by all
666 * visible regions above it (which includes the translucent areas).
667 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 Region coveredRegion;
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700669
670
671 // handle hidden surfaces by setting the visible region to empty
Mathias Agopian12cedff2009-07-28 10:57:27 -0700672 if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700673 const bool translucent = !layer->isOpaque();
Mathias Agopian12cedff2009-07-28 10:57:27 -0700674 const Rect bounds(layer->visibleBounds());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 visibleRegion.set(bounds);
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700676 visibleRegion.andSelf(screenRegion);
677 if (!visibleRegion.isEmpty()) {
678 // Remove the transparent area from the visible region
679 if (translucent) {
680 visibleRegion.subtractSelf(layer->transparentRegionScreen);
681 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700683 // compute the opaque region
684 const int32_t layerOrientation = layer->getOrientation();
685 if (s.alpha==255 && !translucent &&
686 ((layerOrientation & Transform::ROT_INVALID) == false)) {
687 // the opaque region is the layer's footprint
688 opaqueRegion = visibleRegion;
689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 }
691 }
692
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700693 // Clip the covered region to the visible region
694 coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
695
696 // Update aboveCoveredLayers for next (lower) layer
697 aboveCoveredLayers.orSelf(visibleRegion);
698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 // subtract the opaque region covered by the layers above us
700 visibleRegion.subtractSelf(aboveOpaqueLayers);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701
702 // compute this layer's dirty region
703 if (layer->contentDirty) {
704 // we need to invalidate the whole region
705 dirty = visibleRegion;
706 // as well, as the old visible region
707 dirty.orSelf(layer->visibleRegionScreen);
708 layer->contentDirty = false;
709 } else {
Mathias Agopian0aed7e92009-06-28 02:54:16 -0700710 /* compute the exposed region:
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700711 * the exposed region consists of two components:
712 * 1) what's VISIBLE now and was COVERED before
713 * 2) what's EXPOSED now less what was EXPOSED before
714 *
715 * note that (1) is conservative, we start with the whole
716 * visible region but only keep what used to be covered by
717 * something -- which mean it may have been exposed.
718 *
719 * (2) handles areas that were not covered by anything but got
720 * exposed because of a resize.
Mathias Agopian0aed7e92009-06-28 02:54:16 -0700721 */
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700722 const Region newExposed = visibleRegion - coveredRegion;
723 const Region oldVisibleRegion = layer->visibleRegionScreen;
724 const Region oldCoveredRegion = layer->coveredRegionScreen;
725 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
726 dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728 dirty.subtractSelf(aboveOpaqueLayers);
729
730 // accumulate to the screen dirty region
731 dirtyRegion.orSelf(dirty);
732
Mathias Agopian9c041bb2010-03-16 16:41:46 -0700733 // Update aboveOpaqueLayers for next (lower) layer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 aboveOpaqueLayers.orSelf(opaqueRegion);
Andreas Hubere3c01832010-08-16 08:49:37 -0700735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 // Store the visible region is screen space
737 layer->setVisibleRegion(visibleRegion);
738 layer->setCoveredRegion(coveredRegion);
739
Mathias Agopian12cedff2009-07-28 10:57:27 -0700740 // If a secure layer is partially visible, lock-down the screen!
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 if (layer->isSecure() && !visibleRegion.isEmpty()) {
742 secureFrameBuffer = true;
743 }
744 }
745
Mathias Agopian12cedff2009-07-28 10:57:27 -0700746 // invalidate the areas where a layer was removed
747 dirtyRegion.orSelf(mDirtyRegionRemovedLayer);
748 mDirtyRegionRemovedLayer.clear();
749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 mSecureFrameBuffer = secureFrameBuffer;
751 opaqueRegion = aboveOpaqueLayers;
752}
753
754
755void SurfaceFlinger::commitTransaction()
756{
757 mDrawingState = mCurrentState;
Mathias Agopian9779b2212009-09-07 16:32:45 -0700758 mResizeTransationPending = false;
759 mTransactionCV.broadcast();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760}
761
762void SurfaceFlinger::handlePageFlip()
763{
764 bool visibleRegions = mVisibleRegionsDirty;
Mathias Agopianf0ff9062011-03-11 16:54:47 -0800765 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 visibleRegions |= lockPageFlip(currentLayers);
767
768 const DisplayHardware& hw = graphicPlane(0).displayHardware();
769 const Region screenRegion(hw.bounds());
770 if (visibleRegions) {
771 Region opaqueRegion;
772 computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion);
Mathias Agopianff1d4102010-08-10 17:19:56 -0700773
774 /*
775 * rebuild the visible layer list
776 */
Mathias Agopianf0ff9062011-03-11 16:54:47 -0800777 const size_t count = currentLayers.size();
Mathias Agopianff1d4102010-08-10 17:19:56 -0700778 mVisibleLayersSortedByZ.clear();
Mathias Agopianff1d4102010-08-10 17:19:56 -0700779 mVisibleLayersSortedByZ.setCapacity(count);
780 for (size_t i=0 ; i<count ; i++) {
781 if (!currentLayers[i]->visibleRegionScreen.isEmpty())
782 mVisibleLayersSortedByZ.add(currentLayers[i]);
783 }
784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 mWormholeRegion = screenRegion.subtract(opaqueRegion);
786 mVisibleRegionsDirty = false;
Mathias Agopianfb4dcb12011-01-13 17:53:01 -0800787 invalidateHwcGeometry();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 }
789
790 unlockPageFlip(currentLayers);
791 mDirtyRegion.andSelf(screenRegion);
792}
793
Mathias Agopianfb4dcb12011-01-13 17:53:01 -0800794void SurfaceFlinger::invalidateHwcGeometry()
795{
796 mHwWorkListDirty = true;
797}
798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers)
800{
801 bool recomputeVisibleRegions = false;
802 size_t count = currentLayers.size();
Mathias Agopian1473f462009-04-10 14:24:30 -0700803 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700805 const sp<LayerBase>& layer(layers[i]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 layer->lockPageFlip(recomputeVisibleRegions);
807 }
808 return recomputeVisibleRegions;
809}
810
811void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers)
812{
813 const GraphicPlane& plane(graphicPlane(0));
814 const Transform& planeTransform(plane.transform());
815 size_t count = currentLayers.size();
Mathias Agopian1473f462009-04-10 14:24:30 -0700816 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700818 const sp<LayerBase>& layer(layers[i]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 layer->unlockPageFlip(planeTransform, mDirtyRegion);
820 }
821}
822
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700823void SurfaceFlinger::handleWorkList()
824{
825 mHwWorkListDirty = false;
826 HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer());
827 if (hwc.initCheck() == NO_ERROR) {
828 const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ);
829 const size_t count = currentLayers.size();
830 hwc.createWorkList(count);
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700831 hwc_layer_t* const cur(hwc.getLayers());
832 for (size_t i=0 ; cur && i<count ; i++) {
833 currentLayers[i]->setGeometry(&cur[i]);
Mathias Agopian6a969242010-09-22 18:58:01 -0700834 if (mDebugDisableHWC) {
835 cur[i].compositionType = HWC_FRAMEBUFFER;
836 cur[i].flags |= HWC_SKIP_LAYER;
837 }
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700838 }
839 }
840}
Mathias Agopian8c9687a2009-06-26 19:06:36 -0700841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842void SurfaceFlinger::handleRepaint()
843{
Mathias Agopian8c9687a2009-06-26 19:06:36 -0700844 // compute the invalid region
845 mInvalidRegion.orSelf(mDirtyRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846
847 if (UNLIKELY(mDebugRegion)) {
848 debugFlashRegions();
849 }
850
Mathias Agopian8c9687a2009-06-26 19:06:36 -0700851 // set the frame buffer
852 const DisplayHardware& hw(graphicPlane(0).displayHardware());
853 glMatrixMode(GL_MODELVIEW);
854 glLoadIdentity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855
856 uint32_t flags = hw.getFlags();
Andreas Hubere3c01832010-08-16 08:49:37 -0700857 if ((flags & DisplayHardware::SWAP_RECTANGLE) ||
858 (flags & DisplayHardware::BUFFER_PRESERVED))
Mathias Agopian2e20bff2009-05-04 19:29:25 -0700859 {
Mathias Agopianecfa7cc2009-06-29 18:49:56 -0700860 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
861 // takes a rectangle, we must make sure to update that whole
862 // rectangle in that case
863 if (flags & DisplayHardware::SWAP_RECTANGLE) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700864 // TODO: we really should be able to pass a region to
Mathias Agopianecfa7cc2009-06-29 18:49:56 -0700865 // SWAP_RECTANGLE so that we don't have to redraw all this.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 mDirtyRegion.set(mInvalidRegion.bounds());
867 } else {
Mathias Agopianecfa7cc2009-06-29 18:49:56 -0700868 // in the BUFFER_PRESERVED case, obviously, we can update only
869 // what's needed and nothing more.
870 // NOTE: this is NOT a common case, as preserving the backbuffer
871 // is costly and usually involves copying the whole update back.
872 }
873 } else {
Mathias Agopianf2d28b72009-09-24 14:57:26 -0700874 if (flags & DisplayHardware::PARTIAL_UPDATES) {
Mathias Agopianecfa7cc2009-06-29 18:49:56 -0700875 // We need to redraw the rectangle that will be updated
876 // (pushed to the framebuffer).
Mathias Agopianf2d28b72009-09-24 14:57:26 -0700877 // This is needed because PARTIAL_UPDATES only takes one
Mathias Agopianecfa7cc2009-06-29 18:49:56 -0700878 // rectangle instead of a region (see DisplayHardware::flip())
879 mDirtyRegion.set(mInvalidRegion.bounds());
880 } else {
881 // we need to redraw everything (the whole screen)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 mDirtyRegion.set(hw.bounds());
883 mInvalidRegion = mDirtyRegion;
884 }
885 }
886
887 // compose all surfaces
888 composeSurfaces(mDirtyRegion);
889
890 // clear the dirty regions
891 mDirtyRegion.clear();
892}
893
894void SurfaceFlinger::composeSurfaces(const Region& dirty)
895{
896 if (UNLIKELY(!mWormholeRegion.isEmpty())) {
897 // should never happen unless the window manager has a bug
898 // draw something...
899 drawWormhole();
900 }
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700901
902 status_t err = NO_ERROR;
Mathias Agopianff1d4102010-08-10 17:19:56 -0700903 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700904 size_t count = layers.size();
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700905
906 const DisplayHardware& hw(graphicPlane(0).displayHardware());
907 HWComposer& hwc(hw.getHwComposer());
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700908 hwc_layer_t* const cur(hwc.getLayers());
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700909
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700910 LOGE_IF(cur && hwc.getNumLayers() != count,
911 "HAL number of layers (%d) doesn't match surfaceflinger (%d)",
912 hwc.getNumLayers(), count);
913
914 // just to be extra-safe, use the smallest count
Erik Gilling0cf2f432010-08-12 23:21:40 -0700915 if (hwc.initCheck() == NO_ERROR) {
916 count = count < hwc.getNumLayers() ? count : hwc.getNumLayers();
917 }
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700918
919 /*
920 * update the per-frame h/w composer data for each layer
921 * and build the transparent region of the FB
922 */
923 Region transparent;
924 if (cur) {
925 for (size_t i=0 ; i<count ; i++) {
926 const sp<LayerBase>& layer(layers[i]);
927 layer->setPerFrameData(&cur[i]);
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700928 }
929 err = hwc.prepare();
930 LOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700931
Mathias Agopian45491692011-01-19 15:24:23 -0800932 if (err == NO_ERROR) {
933 for (size_t i=0 ; i<count ; i++) {
934 if (cur[i].hints & HWC_HINT_CLEAR_FB) {
935 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700936 if (layer->isOpaque()) {
Mathias Agopian45491692011-01-19 15:24:23 -0800937 transparent.orSelf(layer->visibleRegionScreen);
938 }
939 }
940 }
941
942 /*
943 * clear the area of the FB that need to be transparent
944 */
945 transparent.andSelf(dirty);
946 if (!transparent.isEmpty()) {
947 glClearColor(0,0,0,0);
948 Region::const_iterator it = transparent.begin();
949 Region::const_iterator const end = transparent.end();
950 const int32_t height = hw.getHeight();
951 while (it != end) {
952 const Rect& r(*it++);
953 const GLint sy = height - (r.top + r.height());
954 glScissor(r.left, sy, r.width(), r.height());
955 glClear(GL_COLOR_BUFFER_BIT);
956 }
957 }
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700958 }
959 }
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700960
961
962 /*
963 * and then, render the layers targeted at the framebuffer
964 */
965 for (size_t i=0 ; i<count ; i++) {
966 if (cur) {
Antti Hatala982f58b2010-09-09 02:32:30 -0700967 if ((cur[i].compositionType != HWC_FRAMEBUFFER) &&
968 !(cur[i].flags & HWC_SKIP_LAYER)) {
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700969 // skip layers handled by the HAL
970 continue;
971 }
972 }
Mathias Agopian6a969242010-09-22 18:58:01 -0700973
Mathias Agopianf8e705d2010-08-12 15:03:26 -0700974 const sp<LayerBase>& layer(layers[i]);
975 const Region clip(dirty.intersect(layer->visibleRegionScreen));
976 if (!clip.isEmpty()) {
977 layer->draw(clip);
978 }
979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980}
981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982void SurfaceFlinger::debugFlashRegions()
983{
Mathias Agopianf8b4b442010-06-14 21:20:00 -0700984 const DisplayHardware& hw(graphicPlane(0).displayHardware());
985 const uint32_t flags = hw.getFlags();
Mathias Agopian2e20bff2009-05-04 19:29:25 -0700986
Mathias Agopianf8b4b442010-06-14 21:20:00 -0700987 if (!((flags & DisplayHardware::SWAP_RECTANGLE) ||
988 (flags & DisplayHardware::BUFFER_PRESERVED))) {
989 const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
990 mDirtyRegion.bounds() : hw.bounds());
991 composeSurfaces(repaint);
992 }
993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 glDisable(GL_BLEND);
995 glDisable(GL_DITHER);
996 glDisable(GL_SCISSOR_TEST);
997
Mathias Agopiandff8e582009-05-04 14:17:04 -0700998 static int toggle = 0;
999 toggle = 1 - toggle;
1000 if (toggle) {
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001001 glColor4f(1, 0, 1, 1);
Mathias Agopiandff8e582009-05-04 14:17:04 -07001002 } else {
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001003 glColor4f(1, 1, 0, 1);
Mathias Agopiandff8e582009-05-04 14:17:04 -07001004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005
Mathias Agopian6158b1b2009-05-11 00:03:41 -07001006 Region::const_iterator it = mDirtyRegion.begin();
1007 Region::const_iterator const end = mDirtyRegion.end();
1008 while (it != end) {
1009 const Rect& r = *it++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 GLfloat vertices[][2] = {
1011 { r.left, r.top },
1012 { r.left, r.bottom },
1013 { r.right, r.bottom },
1014 { r.right, r.top }
1015 };
1016 glVertexPointer(2, GL_FLOAT, 0, vertices);
1017 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1018 }
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001019
Mathias Agopian8c9687a2009-06-26 19:06:36 -07001020 if (mInvalidRegion.isEmpty()) {
1021 mDirtyRegion.dump("mDirtyRegion");
1022 mInvalidRegion.dump("mInvalidRegion");
1023 }
1024 hw.flip(mInvalidRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025
1026 if (mDebugRegion > 1)
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001027 usleep(mDebugRegion * 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028
1029 glEnable(GL_SCISSOR_TEST);
1030 //mDirtyRegion.dump("mDirtyRegion");
1031}
1032
1033void SurfaceFlinger::drawWormhole() const
1034{
1035 const Region region(mWormholeRegion.intersect(mDirtyRegion));
1036 if (region.isEmpty())
1037 return;
1038
1039 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1040 const int32_t width = hw.getWidth();
1041 const int32_t height = hw.getHeight();
1042
1043 glDisable(GL_BLEND);
1044 glDisable(GL_DITHER);
1045
1046 if (LIKELY(!mDebugBackground)) {
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001047 glClearColor(0,0,0,0);
Mathias Agopian6158b1b2009-05-11 00:03:41 -07001048 Region::const_iterator it = region.begin();
1049 Region::const_iterator const end = region.end();
1050 while (it != end) {
1051 const Rect& r = *it++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 const GLint sy = height - (r.top + r.height());
1053 glScissor(r.left, sy, r.width(), r.height());
1054 glClear(GL_COLOR_BUFFER_BIT);
1055 }
1056 } else {
1057 const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
1058 { width, height }, { 0, height } };
1059 const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
1060 glVertexPointer(2, GL_SHORT, 0, vertices);
1061 glTexCoordPointer(2, GL_SHORT, 0, tcoords);
1062 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Michael I. Golde20a56d2010-09-15 15:46:24 -07001063#if defined(GL_OES_EGL_image_external)
Mathias Agopian781953d2010-06-25 18:02:21 -07001064 if (GLExtensions::getInstance().haveTextureExternal()) {
1065 glDisable(GL_TEXTURE_EXTERNAL_OES);
1066 }
Mathias Agopianf8b4b442010-06-14 21:20:00 -07001067#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 glEnable(GL_TEXTURE_2D);
1069 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
1070 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1071 glMatrixMode(GL_TEXTURE);
1072 glLoadIdentity();
1073 glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
Mathias Agopian6158b1b2009-05-11 00:03:41 -07001074 Region::const_iterator it = region.begin();
1075 Region::const_iterator const end = region.end();
1076 while (it != end) {
1077 const Rect& r = *it++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 const GLint sy = height - (r.top + r.height());
1079 glScissor(r.left, sy, r.width(), r.height());
1080 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1081 }
1082 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian7bb843c2011-04-20 14:20:59 -07001083 glDisable(GL_TEXTURE_2D);
Mathias Agopian04a709e42010-12-14 18:38:36 -08001084 glLoadIdentity();
1085 glMatrixMode(GL_MODELVIEW);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
1087}
1088
1089void SurfaceFlinger::debugShowFPS() const
1090{
1091 static int mFrameCount;
1092 static int mLastFrameCount = 0;
1093 static nsecs_t mLastFpsTime = 0;
1094 static float mFps = 0;
1095 mFrameCount++;
1096 nsecs_t now = systemTime();
1097 nsecs_t diff = now - mLastFpsTime;
1098 if (diff > ms2ns(250)) {
1099 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff;
1100 mLastFpsTime = now;
1101 mLastFrameCount = mFrameCount;
1102 }
1103 // XXX: mFPS has the value we want
1104 }
1105
Mathias Agopian1473f462009-04-10 14:24:30 -07001106status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107{
1108 Mutex::Autolock _l(mStateLock);
1109 addLayer_l(layer);
1110 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1111 return NO_ERROR;
1112}
1113
Mathias Agopian593c05c2010-06-02 23:28:45 -07001114status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer)
1115{
Mathias Agopian1efba9a2010-08-10 18:09:09 -07001116 ssize_t i = mCurrentState.layersSortedByZ.add(layer);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001117 return (i < 0) ? status_t(i) : status_t(NO_ERROR);
1118}
1119
1120ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
1121 const sp<LayerBaseClient>& lbc)
1122{
Mathias Agopian593c05c2010-06-02 23:28:45 -07001123 // attach this layer to the client
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07001124 size_t name = client->attachLayer(lbc);
1125
1126 Mutex::Autolock _l(mStateLock);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001127
1128 // add this layer to the current state list
1129 addLayer_l(lbc);
1130
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07001131 return ssize_t(name);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001132}
1133
Mathias Agopian1473f462009-04-10 14:24:30 -07001134status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135{
1136 Mutex::Autolock _l(mStateLock);
Mathias Agopian2d5ee252009-06-04 18:46:21 -07001137 status_t err = purgatorizeLayer_l(layer);
1138 if (err == NO_ERROR)
1139 setTransactionFlags(eTransactionNeeded);
1140 return err;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141}
1142
Mathias Agopian1473f462009-04-10 14:24:30 -07001143status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144{
Mathias Agopian7623da42010-06-01 15:12:58 -07001145 sp<LayerBaseClient> lbc(layerBase->getLayerBaseClient());
1146 if (lbc != 0) {
Mathias Agopiand35c6662011-01-25 20:17:45 -08001147 mLayerMap.removeItem( lbc->getSurfaceBinder() );
Mathias Agopian7623da42010-06-01 15:12:58 -07001148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase);
1150 if (index >= 0) {
Mathias Agopian1473f462009-04-10 14:24:30 -07001151 mLayersRemoved = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 return NO_ERROR;
1153 }
Mathias Agopian2d5ee252009-06-04 18:46:21 -07001154 return status_t(index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155}
1156
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001157status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase)
1158{
Mathias Agopianf4dfe1b2011-01-14 17:37:42 -08001159 // First add the layer to the purgatory list, which makes sure it won't
1160 // go away, then remove it from the main list (through a transaction).
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001161 ssize_t err = removeLayer_l(layerBase);
Mathias Agopianf4dfe1b2011-01-14 17:37:42 -08001162 if (err >= 0) {
1163 mLayerPurgatory.add(layerBase);
1164 }
Mathias Agopian2e4b68d2009-09-23 16:44:00 -07001165
Mathias Agopian0c4cec72009-10-02 18:12:30 -07001166 layerBase->onRemoved();
1167
Mathias Agopian2d5ee252009-06-04 18:46:21 -07001168 // it's possible that we don't find a layer, because it might
1169 // have been destroyed already -- this is not technically an error
Mathias Agopian593c05c2010-06-02 23:28:45 -07001170 // from the user because there is a race between Client::destroySurface(),
1171 // ~Client() and ~ISurface().
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001172 return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err;
1173}
1174
Mathias Agopian593c05c2010-06-02 23:28:45 -07001175status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176{
Mathias Agopian593c05c2010-06-02 23:28:45 -07001177 layer->forceVisibilityTransaction();
1178 setTransactionFlags(eTraversalNeeded);
1179 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180}
1181
Mathias Agopian6dcb1552011-05-03 17:04:02 -07001182uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
1183{
1184 return android_atomic_release_load(&mTransactionFlags);
1185}
1186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1188{
1189 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1190}
1191
Mathias Agopian898c4c92010-05-18 17:06:55 -07001192uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193{
1194 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1195 if ((old & flags)==0) { // wake the server up
Mathias Agopian898c4c92010-05-18 17:06:55 -07001196 signalEvent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
1198 return old;
1199}
1200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201
Mathias Agopian439863f2011-06-28 19:09:31 -07001202void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state) {
1203 Mutex::Autolock _l(mStateLock);
Mathias Agopian9779b2212009-09-07 16:32:45 -07001204
Mathias Agopian439863f2011-06-28 19:09:31 -07001205 uint32_t flags = 0;
1206 const size_t count = state.size();
1207 for (size_t i=0 ; i<count ; i++) {
1208 const ComposerState& s(state[i]);
1209 sp<Client> client( static_cast<Client *>(s.client.get()) );
1210 flags |= setClientStateLocked(client, s.state);
1211 }
1212 if (flags) {
1213 setTransactionFlags(flags);
1214 }
1215
1216 signalEvent();
1217
1218 // if there is a transaction with a resize, wait for it to
1219 // take effect before returning.
1220 while (mResizeTransationPending) {
1221 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1222 if (CC_UNLIKELY(err != NO_ERROR)) {
1223 // just in case something goes wrong in SF, return to the
1224 // called after a few seconds.
1225 LOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!");
1226 mResizeTransationPending = false;
1227 break;
Mathias Agopian9779b2212009-09-07 16:32:45 -07001228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 }
1230}
1231
1232status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags)
1233{
1234 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1235 return BAD_VALUE;
1236
1237 Mutex::Autolock _l(mStateLock);
1238 mCurrentState.freezeDisplay = 1;
1239 setTransactionFlags(eTransactionNeeded);
1240
1241 // flags is intended to communicate some sort of animation behavior
Mathias Agopianed81f222009-04-14 23:02:51 -07001242 // (for instance fading)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 return NO_ERROR;
1244}
1245
1246status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags)
1247{
1248 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1249 return BAD_VALUE;
1250
1251 Mutex::Autolock _l(mStateLock);
1252 mCurrentState.freezeDisplay = 0;
1253 setTransactionFlags(eTransactionNeeded);
1254
1255 // flags is intended to communicate some sort of animation behavior
Mathias Agopianed81f222009-04-14 23:02:51 -07001256 // (for instance fading)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 return NO_ERROR;
1258}
1259
Andreas Hubere3c01832010-08-16 08:49:37 -07001260int SurfaceFlinger::setOrientation(DisplayID dpy,
Mathias Agopianeb0c86e2009-03-27 18:11:38 -07001261 int orientation, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262{
1263 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1264 return BAD_VALUE;
1265
1266 Mutex::Autolock _l(mStateLock);
1267 if (mCurrentState.orientation != orientation) {
1268 if (uint32_t(orientation)<=eOrientation270 || orientation==42) {
Mathias Agopianeb0c86e2009-03-27 18:11:38 -07001269 mCurrentState.orientationType = flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 mCurrentState.orientation = orientation;
1271 setTransactionFlags(eTransactionNeeded);
1272 mTransactionCV.wait(mStateLock);
1273 } else {
1274 orientation = BAD_VALUE;
1275 }
1276 }
1277 return orientation;
1278}
1279
Mathias Agopian9638e5c2011-04-20 14:19:32 -07001280sp<ISurface> SurfaceFlinger::createSurface(
1281 ISurfaceComposerClient::surface_data_t* params,
1282 const String8& name,
1283 const sp<Client>& client,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 DisplayID d, uint32_t w, uint32_t h, PixelFormat format,
1285 uint32_t flags)
1286{
Mathias Agopian1473f462009-04-10 14:24:30 -07001287 sp<LayerBaseClient> layer;
Mathias Agopian7bb843c2011-04-20 14:20:59 -07001288 sp<ISurface> surfaceHandle;
Mathias Agopian4d2dbeb2009-07-09 18:16:43 -07001289
1290 if (int32_t(w|h) < 0) {
1291 LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)",
1292 int(w), int(h));
1293 return surfaceHandle;
1294 }
Andreas Hubere3c01832010-08-16 08:49:37 -07001295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 //LOGD("createSurface for pid %d (%d x %d)", pid, w, h);
Mathias Agopian7623da42010-06-01 15:12:58 -07001297 sp<Layer> normalLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 switch (flags & eFXSurfaceMask) {
1299 case eFXSurfaceNormal:
Mathias Agopiand2112302010-12-07 19:38:17 -08001300 normalLayer = createNormalSurface(client, d, w, h, flags, format);
1301 layer = normalLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 break;
1303 case eFXSurfaceBlur:
Mathias Agopianc3802d22010-12-08 17:13:19 -08001304 // for now we treat Blur as Dim, until we can implement it
1305 // efficiently.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 case eFXSurfaceDim:
Mathias Agopian593c05c2010-06-02 23:28:45 -07001307 layer = createDimSurface(client, d, w, h, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 break;
1309 }
1310
Mathias Agopian1473f462009-04-10 14:24:30 -07001311 if (layer != 0) {
Mathias Agopian593c05c2010-06-02 23:28:45 -07001312 layer->initStates(w, h, flags);
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08001313 layer->setName(name);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001314 ssize_t token = addClientLayer(client, layer);
Mathias Agopian7623da42010-06-01 15:12:58 -07001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 surfaceHandle = layer->getSurface();
Andreas Hubere3c01832010-08-16 08:49:37 -07001317 if (surfaceHandle != 0) {
Mathias Agopian593c05c2010-06-02 23:28:45 -07001318 params->token = token;
Mathias Agopian7bb843c2011-04-20 14:20:59 -07001319 params->identity = layer->getIdentity();
Mathias Agopian18b6b492009-08-19 17:46:26 -07001320 params->width = w;
1321 params->height = h;
1322 params->format = format;
Mathias Agopian7623da42010-06-01 15:12:58 -07001323 if (normalLayer != 0) {
1324 Mutex::Autolock _l(mStateLock);
Mathias Agopian7bb843c2011-04-20 14:20:59 -07001325 mLayerMap.add(layer->getSurfaceBinder(), normalLayer);
Mathias Agopian7623da42010-06-01 15:12:58 -07001326 }
Mathias Agopian18b6b492009-08-19 17:46:26 -07001327 }
Mathias Agopian7623da42010-06-01 15:12:58 -07001328
Mathias Agopian593c05c2010-06-02 23:28:45 -07001329 setTransactionFlags(eTransactionNeeded);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 }
1331
1332 return surfaceHandle;
1333}
1334
Mathias Agopian7623da42010-06-01 15:12:58 -07001335sp<Layer> SurfaceFlinger::createNormalSurface(
Mathias Agopian6edf5af2009-06-19 17:00:27 -07001336 const sp<Client>& client, DisplayID display,
Mathias Agopian593c05c2010-06-02 23:28:45 -07001337 uint32_t w, uint32_t h, uint32_t flags,
Mathias Agopian18b6b492009-08-19 17:46:26 -07001338 PixelFormat& format)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339{
1340 // initialize the surfaces
1341 switch (format) { // TODO: take h/w into account
1342 case PIXEL_FORMAT_TRANSPARENT:
1343 case PIXEL_FORMAT_TRANSLUCENT:
1344 format = PIXEL_FORMAT_RGBA_8888;
1345 break;
1346 case PIXEL_FORMAT_OPAQUE:
Mathias Agopian4cfb3a62010-06-30 15:43:47 -07001347#ifdef NO_RGBX_8888
1348 format = PIXEL_FORMAT_RGB_565;
1349#else
Mathias Agopian59962ce2010-04-05 18:01:24 -07001350 format = PIXEL_FORMAT_RGBX_8888;
Mathias Agopian4cfb3a62010-06-30 15:43:47 -07001351#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 break;
1353 }
1354
Mathias Agopian4cfb3a62010-06-30 15:43:47 -07001355#ifdef NO_RGBX_8888
1356 if (format == PIXEL_FORMAT_RGBX_8888)
1357 format = PIXEL_FORMAT_RGBA_8888;
1358#endif
1359
Mathias Agopian593c05c2010-06-02 23:28:45 -07001360 sp<Layer> layer = new Layer(this, display, client);
Mathias Agopian6edf5af2009-06-19 17:00:27 -07001361 status_t err = layer->setBuffers(w, h, format, flags);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001362 if (LIKELY(err != NO_ERROR)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err));
Mathias Agopian1473f462009-04-10 14:24:30 -07001364 layer.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 }
1366 return layer;
1367}
1368
Mathias Agopian7623da42010-06-01 15:12:58 -07001369sp<LayerDim> SurfaceFlinger::createDimSurface(
Mathias Agopian6edf5af2009-06-19 17:00:27 -07001370 const sp<Client>& client, DisplayID display,
Mathias Agopian593c05c2010-06-02 23:28:45 -07001371 uint32_t w, uint32_t h, uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372{
Mathias Agopian593c05c2010-06-02 23:28:45 -07001373 sp<LayerDim> layer = new LayerDim(this, display, client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 layer->initStates(w, h, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 return layer;
1376}
1377
Mathias Agopian593c05c2010-06-02 23:28:45 -07001378status_t SurfaceFlinger::removeSurface(const sp<Client>& client, SurfaceID sid)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379{
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001380 /*
1381 * called by the window manager, when a surface should be marked for
1382 * destruction.
Andreas Hubere3c01832010-08-16 08:49:37 -07001383 *
Mathias Agopiana3aa6c92009-04-22 15:23:34 -07001384 * The surface is removed from the current and drawing lists, but placed
1385 * in the purgatory queue, so it's not destroyed right-away (we need
1386 * to wait for all client's references to go away first).
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001387 */
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001388
Mathias Agopian248b5bd2009-09-10 19:41:18 -07001389 status_t err = NAME_NOT_FOUND;
Mathias Agopiana3aa6c92009-04-22 15:23:34 -07001390 Mutex::Autolock _l(mStateLock);
Mathias Agopian593c05c2010-06-02 23:28:45 -07001391 sp<LayerBaseClient> layer = client->getLayerUser(sid);
Mathias Agopian248b5bd2009-09-10 19:41:18 -07001392 if (layer != 0) {
1393 err = purgatorizeLayer_l(layer);
1394 if (err == NO_ERROR) {
Mathias Agopian248b5bd2009-09-10 19:41:18 -07001395 setTransactionFlags(eTransactionNeeded);
1396 }
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001397 }
1398 return err;
1399}
1400
Mathias Agopian69608112011-05-19 15:38:14 -07001401status_t SurfaceFlinger::destroySurface(const wp<LayerBaseClient>& layer)
Mathias Agopian6cf0db22009-04-17 19:36:26 -07001402{
Mathias Agopian359140c2009-07-02 17:33:40 -07001403 // called by ~ISurface() when all references are gone
Mathias Agopian69608112011-05-19 15:38:14 -07001404 status_t err = NO_ERROR;
1405 sp<LayerBaseClient> l(layer.promote());
1406 if (l != NULL) {
1407 Mutex::Autolock _l(mStateLock);
1408 err = removeLayer_l(l);
1409 if (err == NAME_NOT_FOUND) {
1410 // The surface wasn't in the current list, which means it was
1411 // removed already, which means it is in the purgatory,
1412 // and need to be removed from there.
1413 ssize_t idx = mLayerPurgatory.remove(l);
1414 LOGE_IF(idx < 0,
1415 "layer=%p is not in the purgatory list", l.get());
Mathias Agopian6ead5d92009-04-20 19:39:12 -07001416 }
Mathias Agopian69608112011-05-19 15:38:14 -07001417 LOGE_IF(err<0 && err != NAME_NOT_FOUND,
1418 "error removing layer=%p (%s)", l.get(), strerror(-err));
1419 }
1420 return err;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421}
1422
Mathias Agopian439863f2011-06-28 19:09:31 -07001423uint32_t SurfaceFlinger::setClientStateLocked(
Mathias Agopian593c05c2010-06-02 23:28:45 -07001424 const sp<Client>& client,
Mathias Agopian439863f2011-06-28 19:09:31 -07001425 const layer_state_t& s)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 uint32_t flags = 0;
Mathias Agopian439863f2011-06-28 19:09:31 -07001428 sp<LayerBaseClient> layer(client->getLayerUser(s.surface));
1429 if (layer != 0) {
1430 const uint32_t what = s.what;
1431 if (what & ePositionChanged) {
1432 if (layer->setPosition(s.x, s.y))
1433 flags |= eTraversalNeeded;
1434 }
1435 if (what & eLayerChanged) {
1436 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1437 if (layer->setLayer(s.z)) {
1438 mCurrentState.layersSortedByZ.removeAt(idx);
1439 mCurrentState.layersSortedByZ.add(layer);
1440 // we need traversal (state changed)
1441 // AND transaction (list changed)
1442 flags |= eTransactionNeeded|eTraversalNeeded;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 }
1444 }
Mathias Agopian439863f2011-06-28 19:09:31 -07001445 if (what & eSizeChanged) {
1446 if (layer->setSize(s.w, s.h)) {
1447 flags |= eTraversalNeeded;
1448 mResizeTransationPending = true;
1449 }
1450 }
1451 if (what & eAlphaChanged) {
1452 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1453 flags |= eTraversalNeeded;
1454 }
1455 if (what & eMatrixChanged) {
1456 if (layer->setMatrix(s.matrix))
1457 flags |= eTraversalNeeded;
1458 }
1459 if (what & eTransparentRegionChanged) {
1460 if (layer->setTransparentRegionHint(s.transparentRegion))
1461 flags |= eTraversalNeeded;
1462 }
1463 if (what & eVisibilityChanged) {
1464 if (layer->setFlags(s.flags, s.mask))
1465 flags |= eTraversalNeeded;
1466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 }
Mathias Agopian439863f2011-06-28 19:09:31 -07001468 return flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469}
1470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471void SurfaceFlinger::screenReleased(int dpy)
1472{
1473 // this may be called by a signal handler, we can't do too much in here
1474 android_atomic_or(eConsoleReleased, &mConsoleSignals);
1475 signalEvent();
1476}
1477
1478void SurfaceFlinger::screenAcquired(int dpy)
1479{
1480 // this may be called by a signal handler, we can't do too much in here
1481 android_atomic_or(eConsoleAcquired, &mConsoleSignals);
1482 signalEvent();
1483}
1484
1485status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
1486{
Erik Gilling94720d72010-12-01 16:38:01 -08001487 const size_t SIZE = 4096;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 char buffer[SIZE];
1489 String8 result;
Mathias Agopian0dd593f2011-06-27 16:05:52 -07001490
1491 if (!PermissionCache::checkCallingPermission(sDump)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 snprintf(buffer, SIZE, "Permission Denial: "
1493 "can't dump SurfaceFlinger from pid=%d, uid=%d\n",
1494 IPCThreadState::self()->getCallingPid(),
1495 IPCThreadState::self()->getCallingUid());
1496 result.append(buffer);
1497 } else {
Mathias Agopiana8d49172009-08-26 16:36:26 -07001498
1499 // figure out if we're stuck somewhere
1500 const nsecs_t now = systemTime();
1501 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
1502 const nsecs_t inTransaction(mDebugInTransaction);
1503 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
1504 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
1505
1506 // Try to get the main lock, but don't insist if we can't
1507 // (this would indicate SF is stuck, but we want to be able to
1508 // print something in dumpsys).
1509 int retry = 3;
1510 while (mStateLock.tryLock()<0 && --retry>=0) {
1511 usleep(1000000);
1512 }
1513 const bool locked(retry >= 0);
1514 if (!locked) {
Andreas Hubere3c01832010-08-16 08:49:37 -07001515 snprintf(buffer, SIZE,
Mathias Agopiana8d49172009-08-26 16:36:26 -07001516 "SurfaceFlinger appears to be unresponsive, "
1517 "dumping anyways (no locks held)\n");
1518 result.append(buffer);
1519 }
1520
Mathias Agopian06a61e22011-01-19 16:15:53 -08001521 /*
1522 * Dump the visible layer list
1523 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1525 const size_t count = currentLayers.size();
Mathias Agopian06a61e22011-01-19 16:15:53 -08001526 snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count);
1527 result.append(buffer);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian9bce8732010-04-20 17:55:49 -07001529 const sp<LayerBase>& layer(currentLayers[i]);
1530 layer->dump(result, buffer, SIZE);
1531 const Layer::State& s(layer->drawingState());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 s.transparentRegion.dump(result, "transparentRegion");
1533 layer->transparentRegionScreen.dump(result, "transparentRegionScreen");
1534 layer->visibleRegionScreen.dump(result, "visibleRegionScreen");
1535 }
Mathias Agopian9bce8732010-04-20 17:55:49 -07001536
Mathias Agopian06a61e22011-01-19 16:15:53 -08001537 /*
1538 * Dump the layers in the purgatory
1539 */
1540
1541 const size_t purgatorySize = mLayerPurgatory.size();
1542 snprintf(buffer, SIZE, "Purgatory state (%d entries)\n", purgatorySize);
1543 result.append(buffer);
1544 for (size_t i=0 ; i<purgatorySize ; i++) {
1545 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
1546 layer->shortDump(result, buffer, SIZE);
1547 }
1548
1549 /*
1550 * Dump SurfaceFlinger global state
1551 */
1552
1553 snprintf(buffer, SIZE, "SurfaceFlinger global state\n");
1554 result.append(buffer);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 mWormholeRegion.dump(result, "WormholeRegion");
1556 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1557 snprintf(buffer, SIZE,
1558 " display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n",
1559 mFreezeDisplay?"yes":"no", mFreezeCount,
1560 mCurrentState.orientation, hw.canDraw());
1561 result.append(buffer);
Mathias Agopiana8d49172009-08-26 16:36:26 -07001562 snprintf(buffer, SIZE,
1563 " last eglSwapBuffers() time: %f us\n"
1564 " last transaction time : %f us\n",
1565 mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0);
1566 result.append(buffer);
Mathias Agopian9bce8732010-04-20 17:55:49 -07001567
Mathias Agopiana8d49172009-08-26 16:36:26 -07001568 if (inSwapBuffersDuration || !locked) {
1569 snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
1570 inSwapBuffersDuration/1000.0);
1571 result.append(buffer);
1572 }
Mathias Agopian9bce8732010-04-20 17:55:49 -07001573
Mathias Agopiana8d49172009-08-26 16:36:26 -07001574 if (inTransactionDuration || !locked) {
1575 snprintf(buffer, SIZE, " transaction time: %f us\n",
1576 inTransactionDuration/1000.0);
1577 result.append(buffer);
1578 }
Mathias Agopian9bce8732010-04-20 17:55:49 -07001579
Mathias Agopian06a61e22011-01-19 16:15:53 -08001580 /*
1581 * Dump HWComposer state
1582 */
Mathias Agopian6a969242010-09-22 18:58:01 -07001583 HWComposer& hwc(hw.getHwComposer());
1584 snprintf(buffer, SIZE, " h/w composer %s and %s\n",
1585 hwc.initCheck()==NO_ERROR ? "present" : "not present",
1586 mDebugDisableHWC ? "disabled" : "enabled");
1587 result.append(buffer);
Mathias Agopian90da4dd2010-09-23 18:13:21 -07001588 hwc.dump(result, buffer, SIZE);
Mathias Agopian6a969242010-09-22 18:58:01 -07001589
Mathias Agopian06a61e22011-01-19 16:15:53 -08001590 /*
1591 * Dump gralloc state
1592 */
Mathias Agopian6950e422009-10-05 17:07:12 -07001593 const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
Mathias Agopian1473f462009-04-10 14:24:30 -07001594 alloc.dump(result);
Erik Gilling94720d72010-12-01 16:38:01 -08001595 hw.dump(result);
Mathias Agopiana8d49172009-08-26 16:36:26 -07001596
1597 if (locked) {
1598 mStateLock.unlock();
1599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 }
1601 write(fd, result.string(), result.size());
1602 return NO_ERROR;
1603}
1604
1605status_t SurfaceFlinger::onTransact(
1606 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1607{
1608 switch (code) {
1609 case CREATE_CONNECTION:
Mathias Agopian439863f2011-06-28 19:09:31 -07001610 case SET_TRANSACTION_STATE:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 case SET_ORIENTATION:
1612 case FREEZE_DISPLAY:
1613 case UNFREEZE_DISPLAY:
1614 case BOOT_FINISHED:
Mathias Agopianaab758e2010-10-11 12:37:43 -07001615 case TURN_ELECTRON_BEAM_OFF:
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001616 case TURN_ELECTRON_BEAM_ON:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 {
1618 // codes that require permission check
1619 IPCThreadState* ipc = IPCThreadState::self();
1620 const int pid = ipc->getCallingPid();
Mathias Agopian627e7b52009-05-21 19:21:59 -07001621 const int uid = ipc->getCallingUid();
Mathias Agopian0dd593f2011-06-27 16:05:52 -07001622 if ((uid != AID_GRAPHICS) &&
1623 !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
Mathias Agopian151e8592009-06-15 18:24:59 -07001624 LOGE("Permission Denial: "
1625 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
1626 return PERMISSION_DENIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
Mathias Agopianca5edbe2010-09-24 11:26:58 -07001628 break;
1629 }
1630 case CAPTURE_SCREEN:
1631 {
1632 // codes that require permission check
1633 IPCThreadState* ipc = IPCThreadState::self();
1634 const int pid = ipc->getCallingPid();
1635 const int uid = ipc->getCallingUid();
Mathias Agopian0dd593f2011-06-27 16:05:52 -07001636 if ((uid != AID_GRAPHICS) &&
1637 !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
Mathias Agopianca5edbe2010-09-24 11:26:58 -07001638 LOGE("Permission Denial: "
1639 "can't read framebuffer pid=%d, uid=%d", pid, uid);
1640 return PERMISSION_DENIED;
1641 }
1642 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 }
1644 }
Mathias Agopianca5edbe2010-09-24 11:26:58 -07001645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
1647 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
Mathias Agopian8c9687a2009-06-26 19:06:36 -07001648 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Mathias Agopian0dd593f2011-06-27 16:05:52 -07001649 if (UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
Mathias Agopian151e8592009-06-15 18:24:59 -07001650 IPCThreadState* ipc = IPCThreadState::self();
1651 const int pid = ipc->getCallingPid();
1652 const int uid = ipc->getCallingUid();
1653 LOGE("Permission Denial: "
1654 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 return PERMISSION_DENIED;
1656 }
1657 int n;
1658 switch (code) {
Mathias Agopian17f638b2009-04-16 20:04:08 -07001659 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
Mathias Agopian04262e92010-09-13 22:57:58 -07001660 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 return NO_ERROR;
1662 case 1002: // SHOW_UPDATES
1663 n = data.readInt32();
1664 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
1665 return NO_ERROR;
1666 case 1003: // SHOW_BACKGROUND
1667 n = data.readInt32();
1668 mDebugBackground = n ? 1 : 0;
1669 return NO_ERROR;
Mathias Agopian6a969242010-09-22 18:58:01 -07001670 case 1008: // toggle use of hw composer
1671 n = data.readInt32();
1672 mDebugDisableHWC = n ? 1 : 0;
Mathias Agopianfb4dcb12011-01-13 17:53:01 -08001673 invalidateHwcGeometry();
Mathias Agopian6a969242010-09-22 18:58:01 -07001674 // fall-through...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 case 1004:{ // repaint everything
1676 Mutex::Autolock _l(mStateLock);
1677 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1678 mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe
1679 signalEvent();
Mathias Agopian9779b2212009-09-07 16:32:45 -07001680 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 }
Mathias Agopian9779b2212009-09-07 16:32:45 -07001682 case 1005:{ // force transaction
1683 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1684 return NO_ERROR;
1685 }
Mathias Agopian04262e92010-09-13 22:57:58 -07001686 case 1006:{ // enable/disable GraphicLog
1687 int enabled = data.readInt32();
1688 GraphicLog::getInstance().setEnabled(enabled);
1689 return NO_ERROR;
1690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 case 1007: // set mFreezeCount
1692 mFreezeCount = data.readInt32();
Mathias Agopian0e449762009-12-01 17:23:28 -08001693 mFreezeDisplayTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 return NO_ERROR;
1695 case 1010: // interrogate.
Mathias Agopian17f638b2009-04-16 20:04:08 -07001696 reply->writeInt32(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 reply->writeInt32(0);
1698 reply->writeInt32(mDebugRegion);
1699 reply->writeInt32(mDebugBackground);
1700 return NO_ERROR;
1701 case 1013: {
1702 Mutex::Autolock _l(mStateLock);
1703 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1704 reply->writeInt32(hw.getPageFlipCount());
1705 }
1706 return NO_ERROR;
1707 }
1708 }
1709 return err;
1710}
1711
Mathias Agopianaab758e2010-10-11 12:37:43 -07001712// ---------------------------------------------------------------------------
1713
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001714status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
1715 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
Mathias Agopianaab758e2010-10-11 12:37:43 -07001716{
Mathias Agopianaab758e2010-10-11 12:37:43 -07001717 if (!GLExtensions::getInstance().haveFramebufferObject())
1718 return INVALID_OPERATION;
1719
1720 // get screen geometry
Mathias Agopianaab758e2010-10-11 12:37:43 -07001721 const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
Mathias Agopianaab758e2010-10-11 12:37:43 -07001722 const uint32_t hw_w = hw.getWidth();
1723 const uint32_t hw_h = hw.getHeight();
Mathias Agopianaab758e2010-10-11 12:37:43 -07001724 GLfloat u = 1;
1725 GLfloat v = 1;
1726
1727 // make sure to clear all GL error flags
1728 while ( glGetError() != GL_NO_ERROR ) ;
1729
1730 // create a FBO
1731 GLuint name, tname;
1732 glGenTextures(1, &tname);
1733 glBindTexture(GL_TEXTURE_2D, tname);
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001734 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
1735 hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001736 if (glGetError() != GL_NO_ERROR) {
Mathias Agopiana6cd6d32010-10-14 12:19:37 -07001737 while ( glGetError() != GL_NO_ERROR ) ;
Mathias Agopianaab758e2010-10-11 12:37:43 -07001738 GLint tw = (2 << (31 - clz(hw_w)));
1739 GLint th = (2 << (31 - clz(hw_h)));
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001740 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
1741 tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001742 u = GLfloat(hw_w) / tw;
1743 v = GLfloat(hw_h) / th;
1744 }
1745 glGenFramebuffersOES(1, &name);
1746 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001747 glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
1748 GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001749
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001750 // redraw the screen entirely...
1751 glClearColor(0,0,0,1);
1752 glClear(GL_COLOR_BUFFER_BIT);
1753 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
1754 const size_t count = layers.size();
1755 for (size_t i=0 ; i<count ; ++i) {
1756 const sp<LayerBase>& layer(layers[i]);
1757 layer->drawForSreenShot();
1758 }
1759
1760 // back to main framebuffer
1761 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
1762 glDisable(GL_SCISSOR_TEST);
1763 glDeleteFramebuffersOES(1, &name);
1764
1765 *textureName = tname;
1766 *uOut = u;
1767 *vOut = v;
1768 return NO_ERROR;
1769}
1770
1771// ---------------------------------------------------------------------------
1772
1773status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
1774{
1775 status_t result = PERMISSION_DENIED;
1776
1777 if (!GLExtensions::getInstance().haveFramebufferObject())
1778 return INVALID_OPERATION;
1779
1780 // get screen geometry
1781 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1782 const uint32_t hw_w = hw.getWidth();
1783 const uint32_t hw_h = hw.getHeight();
1784 const Region screenBounds(hw.bounds());
1785
1786 GLfloat u, v;
1787 GLuint tname;
1788 result = renderScreenToTextureLocked(0, &tname, &u, &v);
1789 if (result != NO_ERROR) {
1790 return result;
1791 }
1792
1793 GLfloat vtx[8];
1794 const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001795 glBindTexture(GL_TEXTURE_2D, tname);
1796 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1797 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1798 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1799 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
1800 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1801 glVertexPointer(2, GL_FLOAT, 0, vtx);
1802
1803 class s_curve_interpolator {
1804 const float nbFrames, s, v;
1805 public:
1806 s_curve_interpolator(int nbFrames, float s)
1807 : nbFrames(1.0f / (nbFrames-1)), s(s),
1808 v(1.0f + expf(-s + 0.5f*s)) {
1809 }
1810 float operator()(int f) {
1811 const float x = f * nbFrames;
1812 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
1813 }
1814 };
1815
1816 class v_stretch {
1817 const GLfloat hw_w, hw_h;
1818 public:
1819 v_stretch(uint32_t hw_w, uint32_t hw_h)
1820 : hw_w(hw_w), hw_h(hw_h) {
1821 }
1822 void operator()(GLfloat* vtx, float v) {
1823 const GLfloat w = hw_w + (hw_w * v);
1824 const GLfloat h = hw_h - (hw_h * v);
1825 const GLfloat x = (hw_w - w) * 0.5f;
1826 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopian753db222011-06-30 16:23:39 -07001827 vtx[0] = x; vtx[1] = y + h;
1828 vtx[2] = x; vtx[3] = y;
1829 vtx[4] = x + w; vtx[5] = y;
1830 vtx[6] = x + w; vtx[7] = y + h;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001831 }
1832 };
1833
1834 class h_stretch {
1835 const GLfloat hw_w, hw_h;
1836 public:
1837 h_stretch(uint32_t hw_w, uint32_t hw_h)
1838 : hw_w(hw_w), hw_h(hw_h) {
1839 }
1840 void operator()(GLfloat* vtx, float v) {
1841 const GLfloat w = hw_w - (hw_w * v);
1842 const GLfloat h = 1.0f;
1843 const GLfloat x = (hw_w - w) * 0.5f;
1844 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopian753db222011-06-30 16:23:39 -07001845 vtx[0] = x; vtx[1] = y + h;
1846 vtx[2] = x; vtx[3] = y;
1847 vtx[4] = x + w; vtx[5] = y;
1848 vtx[6] = x + w; vtx[7] = y + h;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001849 }
1850 };
1851
1852 // the full animation is 24 frames
1853 const int nbFrames = 12;
1854 s_curve_interpolator itr(nbFrames, 7.5f);
1855 s_curve_interpolator itg(nbFrames, 8.0f);
1856 s_curve_interpolator itb(nbFrames, 8.5f);
1857
1858 v_stretch vverts(hw_w, hw_h);
1859 glEnable(GL_BLEND);
1860 glBlendFunc(GL_ONE, GL_ONE);
1861 for (int i=0 ; i<nbFrames ; i++) {
1862 float x, y, w, h;
1863 const float vr = itr(i);
1864 const float vg = itg(i);
1865 const float vb = itb(i);
1866
1867 // clear screen
1868 glColorMask(1,1,1,1);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001869 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001870 glEnable(GL_TEXTURE_2D);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001871
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001872 // draw the red plane
1873 vverts(vtx, vr);
1874 glColorMask(1,0,0,1);
1875 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001876
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001877 // draw the green plane
1878 vverts(vtx, vg);
1879 glColorMask(0,1,0,1);
1880 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001881
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001882 // draw the blue plane
1883 vverts(vtx, vb);
1884 glColorMask(0,0,1,1);
1885 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001886
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001887 // draw the white highlight (we use the last vertices)
Mathias Agopianaab758e2010-10-11 12:37:43 -07001888 glDisable(GL_TEXTURE_2D);
1889 glColorMask(1,1,1,1);
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001890 glColor4f(vg, vg, vg, 1);
1891 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1892 hw.flip(screenBounds);
Mathias Agopianaab758e2010-10-11 12:37:43 -07001893 }
1894
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001895 h_stretch hverts(hw_w, hw_h);
1896 glDisable(GL_BLEND);
1897 glDisable(GL_TEXTURE_2D);
1898 glColorMask(1,1,1,1);
1899 for (int i=0 ; i<nbFrames ; i++) {
1900 const float v = itg(i);
1901 hverts(vtx, v);
1902 glClear(GL_COLOR_BUFFER_BIT);
1903 glColor4f(1-v, 1-v, 1-v, 1);
1904 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1905 hw.flip(screenBounds);
1906 }
1907
1908 glColorMask(1,1,1,1);
1909 glEnable(GL_SCISSOR_TEST);
1910 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1911 glDeleteTextures(1, &tname);
Mathias Agopian7bb843c2011-04-20 14:20:59 -07001912 glDisable(GL_TEXTURE_2D);
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001913 return NO_ERROR;
1914}
1915
1916status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
1917{
1918 status_t result = PERMISSION_DENIED;
1919
1920 if (!GLExtensions::getInstance().haveFramebufferObject())
1921 return INVALID_OPERATION;
1922
1923
1924 // get screen geometry
1925 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1926 const uint32_t hw_w = hw.getWidth();
1927 const uint32_t hw_h = hw.getHeight();
1928 const Region screenBounds(hw.bounds());
1929
1930 GLfloat u, v;
1931 GLuint tname;
1932 result = renderScreenToTextureLocked(0, &tname, &u, &v);
1933 if (result != NO_ERROR) {
1934 return result;
1935 }
1936
1937 // back to main framebuffer
1938 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
1939 glDisable(GL_SCISSOR_TEST);
1940
1941 GLfloat vtx[8];
1942 const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
Mathias Agopian2d2b8032010-10-12 16:05:48 -07001943 glBindTexture(GL_TEXTURE_2D, tname);
1944 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1945 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1946 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1947 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
1948 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1949 glVertexPointer(2, GL_FLOAT, 0, vtx);
1950
1951 class s_curve_interpolator {
1952 const float nbFrames, s, v;
1953 public:
1954 s_curve_interpolator(int nbFrames, float s)
1955 : nbFrames(1.0f / (nbFrames-1)), s(s),
1956 v(1.0f + expf(-s + 0.5f*s)) {
1957 }
1958 float operator()(int f) {
1959 const float x = f * nbFrames;
1960 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
1961 }
1962 };
1963
1964 class v_stretch {
1965 const GLfloat hw_w, hw_h;
1966 public:
1967 v_stretch(uint32_t hw_w, uint32_t hw_h)
1968 : hw_w(hw_w), hw_h(hw_h) {
1969 }
1970 void operator()(GLfloat* vtx, float v) {
1971 const GLfloat w = hw_w + (hw_w * v);
1972 const GLfloat h = hw_h - (hw_h * v);
1973 const GLfloat x = (hw_w - w) * 0.5f;
1974 const GLfloat y = (hw_h - h) * 0.5f;
1975 vtx[0] = x; vtx[1] = y;
1976 vtx[2] = x; vtx[3] = y + h;
1977 vtx[4] = x + w; vtx[5] = y + h;
1978 vtx[6] = x + w; vtx[7] = y;
1979 }
1980 };
1981
1982 class h_stretch {
1983 const GLfloat hw_w, hw_h;
1984 public:
1985 h_stretch(uint32_t hw_w, uint32_t hw_h)
1986 : hw_w(hw_w), hw_h(hw_h) {
1987 }
1988 void operator()(GLfloat* vtx, float v) {
1989 const GLfloat w = hw_w - (hw_w * v);
1990 const GLfloat h = 1.0f;
1991 const GLfloat x = (hw_w - w) * 0.5f;
1992 const GLfloat y = (hw_h - h) * 0.5f;
1993 vtx[0] = x; vtx[1] = y;
1994 vtx[2] = x; vtx[3] = y + h;
1995 vtx[4] = x + w; vtx[5] = y + h;
1996 vtx[6] = x + w; vtx[7] = y;
1997 }
1998 };
1999
Mathias Agopiandfa08fb2010-10-14 12:33:07 -07002000 // the full animation is 12 frames
2001 int nbFrames = 8;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002002 s_curve_interpolator itr(nbFrames, 7.5f);
2003 s_curve_interpolator itg(nbFrames, 8.0f);
2004 s_curve_interpolator itb(nbFrames, 8.5f);
2005
2006 h_stretch hverts(hw_w, hw_h);
2007 glDisable(GL_BLEND);
2008 glDisable(GL_TEXTURE_2D);
2009 glColorMask(1,1,1,1);
2010 for (int i=nbFrames-1 ; i>=0 ; i--) {
2011 const float v = itg(i);
2012 hverts(vtx, v);
2013 glClear(GL_COLOR_BUFFER_BIT);
2014 glColor4f(1-v, 1-v, 1-v, 1);
2015 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2016 hw.flip(screenBounds);
2017 }
2018
Mathias Agopiandfa08fb2010-10-14 12:33:07 -07002019 nbFrames = 4;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002020 v_stretch vverts(hw_w, hw_h);
2021 glEnable(GL_BLEND);
2022 glBlendFunc(GL_ONE, GL_ONE);
2023 for (int i=nbFrames-1 ; i>=0 ; i--) {
2024 float x, y, w, h;
2025 const float vr = itr(i);
2026 const float vg = itg(i);
2027 const float vb = itb(i);
2028
2029 // clear screen
2030 glColorMask(1,1,1,1);
2031 glClear(GL_COLOR_BUFFER_BIT);
2032 glEnable(GL_TEXTURE_2D);
2033
2034 // draw the red plane
2035 vverts(vtx, vr);
2036 glColorMask(1,0,0,1);
2037 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2038
2039 // draw the green plane
2040 vverts(vtx, vg);
2041 glColorMask(0,1,0,1);
2042 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2043
2044 // draw the blue plane
2045 vverts(vtx, vb);
2046 glColorMask(0,0,1,1);
2047 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2048
2049 hw.flip(screenBounds);
2050 }
2051
2052 glColorMask(1,1,1,1);
2053 glEnable(GL_SCISSOR_TEST);
2054 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianaab758e2010-10-11 12:37:43 -07002055 glDeleteTextures(1, &tname);
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002056 glDisable(GL_TEXTURE_2D);
Mathias Agopianaab758e2010-10-11 12:37:43 -07002057
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002058 return NO_ERROR;
2059}
2060
2061// ---------------------------------------------------------------------------
2062
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002063status_t SurfaceFlinger::turnElectronBeamOffImplLocked(int32_t mode)
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002064{
2065 DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
2066 if (!hw.canDraw()) {
2067 // we're already off
2068 return NO_ERROR;
2069 }
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002070 if (mode & ISurfaceComposer::eElectronBeamAnimationOff) {
2071 electronBeamOffAnimationImplLocked();
2072 }
2073
2074 // always clear the whole screen at the end of the animation
2075 glClearColor(0,0,0,1);
2076 glDisable(GL_SCISSOR_TEST);
2077 glClear(GL_COLOR_BUFFER_BIT);
2078 glEnable(GL_SCISSOR_TEST);
2079 hw.flip( Region(hw.bounds()) );
2080
Mathias Agopiana6cd6d32010-10-14 12:19:37 -07002081 hw.setCanDraw(false);
2082 return NO_ERROR;
Mathias Agopianaab758e2010-10-11 12:37:43 -07002083}
2084
2085status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode)
2086{
Mathias Agopianaab758e2010-10-11 12:37:43 -07002087 class MessageTurnElectronBeamOff : public MessageBase {
2088 SurfaceFlinger* flinger;
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002089 int32_t mode;
Mathias Agopianaab758e2010-10-11 12:37:43 -07002090 status_t result;
2091 public:
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002092 MessageTurnElectronBeamOff(SurfaceFlinger* flinger, int32_t mode)
2093 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopianaab758e2010-10-11 12:37:43 -07002094 }
2095 status_t getResult() const {
2096 return result;
2097 }
2098 virtual bool handler() {
2099 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002100 result = flinger->turnElectronBeamOffImplLocked(mode);
Mathias Agopianaab758e2010-10-11 12:37:43 -07002101 return true;
2102 }
2103 };
2104
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002105 sp<MessageBase> msg = new MessageTurnElectronBeamOff(this, mode);
Mathias Agopianaab758e2010-10-11 12:37:43 -07002106 status_t res = postMessageSync(msg);
2107 if (res == NO_ERROR) {
2108 res = static_cast<MessageTurnElectronBeamOff*>( msg.get() )->getResult();
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002109
2110 // work-around: when the power-manager calls us we activate the
2111 // animation. eventually, the "on" animation will be called
2112 // by the power-manager itself
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002113 mElectronBeamAnimationMode = mode;
Mathias Agopianaab758e2010-10-11 12:37:43 -07002114 }
2115 return res;
2116}
2117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002118// ---------------------------------------------------------------------------
Mathias Agopian7623da42010-06-01 15:12:58 -07002119
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002120status_t SurfaceFlinger::turnElectronBeamOnImplLocked(int32_t mode)
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002121{
2122 DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
2123 if (hw.canDraw()) {
2124 // we're already on
2125 return NO_ERROR;
2126 }
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002127 if (mode & ISurfaceComposer::eElectronBeamAnimationOn) {
2128 electronBeamOnAnimationImplLocked();
2129 }
Mathias Agopiana6cd6d32010-10-14 12:19:37 -07002130 hw.setCanDraw(true);
Mathias Agopian8b6a0542010-10-14 12:46:24 -07002131
2132 // make sure to redraw the whole screen when the animation is done
2133 mDirtyRegion.set(hw.bounds());
2134 signalEvent();
2135
Mathias Agopiana6cd6d32010-10-14 12:19:37 -07002136 return NO_ERROR;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002137}
2138
2139status_t SurfaceFlinger::turnElectronBeamOn(int32_t mode)
2140{
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002141 class MessageTurnElectronBeamOn : public MessageBase {
2142 SurfaceFlinger* flinger;
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002143 int32_t mode;
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002144 status_t result;
2145 public:
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002146 MessageTurnElectronBeamOn(SurfaceFlinger* flinger, int32_t mode)
2147 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002148 }
2149 status_t getResult() const {
2150 return result;
2151 }
2152 virtual bool handler() {
2153 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002154 result = flinger->turnElectronBeamOnImplLocked(mode);
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002155 return true;
2156 }
2157 };
2158
Mathias Agopiand4e03f32010-10-14 14:54:06 -07002159 postMessageAsync( new MessageTurnElectronBeamOn(this, mode) );
Mathias Agopian2d2b8032010-10-12 16:05:48 -07002160 return NO_ERROR;
2161}
2162
2163// ---------------------------------------------------------------------------
2164
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002165status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
2166 sp<IMemoryHeap>* heap,
2167 uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002168 uint32_t sw, uint32_t sh,
2169 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002170{
2171 status_t result = PERMISSION_DENIED;
2172
2173 // only one display supported for now
2174 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
2175 return BAD_VALUE;
2176
Jamie Gennisf72606c2011-03-09 17:05:02 -08002177 // make sure none of the layers are protected
2178 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
2179 const size_t count = layers.size();
2180 for (size_t i=0 ; i<count ; ++i) {
2181 const sp<LayerBase>& layer(layers[i]);
2182 const uint32_t z = layer->drawingState().z;
2183 if (z >= minLayerZ && z <= maxLayerZ) {
2184 if (layer->isProtected()) {
2185 return INVALID_OPERATION;
2186 }
2187 }
2188 }
2189
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002190 if (!GLExtensions::getInstance().haveFramebufferObject())
2191 return INVALID_OPERATION;
2192
2193 // get screen geometry
2194 const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
2195 const uint32_t hw_w = hw.getWidth();
2196 const uint32_t hw_h = hw.getHeight();
2197
2198 if ((sw > hw_w) || (sh > hw_h))
2199 return BAD_VALUE;
2200
2201 sw = (!sw) ? hw_w : sw;
2202 sh = (!sh) ? hw_h : sh;
2203 const size_t size = sw * sh * 4;
2204
Mathias Agopian32ae0942011-03-02 18:45:50 -08002205 //LOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d",
2206 // sw, sh, minLayerZ, maxLayerZ);
Mathias Agopiancd2cfb62011-01-16 14:05:02 -08002207
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002208 // make sure to clear all GL error flags
2209 while ( glGetError() != GL_NO_ERROR ) ;
2210
2211 // create a FBO
2212 GLuint name, tname;
2213 glGenRenderbuffersOES(1, &tname);
2214 glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
2215 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, sw, sh);
2216 glGenFramebuffersOES(1, &name);
2217 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2218 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
2219 GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
2220
2221 GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
Mathias Agopiancd2cfb62011-01-16 14:05:02 -08002222
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002223 if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
2224
2225 // invert everything, b/c glReadPixel() below will invert the FB
2226 glViewport(0, 0, sw, sh);
Mathias Agopian1c4e4fc02010-12-16 18:46:17 -08002227 glScissor(0, 0, sw, sh);
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002228 glMatrixMode(GL_PROJECTION);
2229 glPushMatrix();
2230 glLoadIdentity();
2231 glOrthof(0, hw_w, 0, hw_h, 0, 1);
2232 glMatrixMode(GL_MODELVIEW);
2233
2234 // redraw the screen entirely...
2235 glClearColor(0,0,0,1);
2236 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopian1c4e4fc02010-12-16 18:46:17 -08002237
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002238 for (size_t i=0 ; i<count ; ++i) {
2239 const sp<LayerBase>& layer(layers[i]);
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002240 const uint32_t z = layer->drawingState().z;
2241 if (z >= minLayerZ && z <= maxLayerZ) {
2242 layer->drawForSreenShot();
2243 }
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002244 }
2245
2246 // XXX: this is needed on tegra
2247 glScissor(0, 0, sw, sh);
2248
2249 // check for errors and return screen capture
2250 if (glGetError() != GL_NO_ERROR) {
2251 // error while rendering
2252 result = INVALID_OPERATION;
2253 } else {
2254 // allocate shared memory large enough to hold the
2255 // screen capture
2256 sp<MemoryHeapBase> base(
2257 new MemoryHeapBase(size, 0, "screen-capture") );
2258 void* const ptr = base->getBase();
2259 if (ptr) {
2260 // capture the screen with glReadPixels()
2261 glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
2262 if (glGetError() == GL_NO_ERROR) {
2263 *heap = base;
2264 *w = sw;
2265 *h = sh;
2266 *f = PIXEL_FORMAT_RGBA_8888;
2267 result = NO_ERROR;
2268 }
2269 } else {
2270 result = NO_MEMORY;
2271 }
2272 }
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002273 glEnable(GL_SCISSOR_TEST);
2274 glViewport(0, 0, hw_w, hw_h);
2275 glMatrixMode(GL_PROJECTION);
2276 glPopMatrix();
2277 glMatrixMode(GL_MODELVIEW);
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002278 } else {
2279 result = BAD_VALUE;
2280 }
2281
2282 // release FBO resources
2283 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
2284 glDeleteRenderbuffersOES(1, &tname);
2285 glDeleteFramebuffersOES(1, &name);
Mathias Agopiana6b8c1c2010-12-15 14:41:59 -08002286
2287 hw.compositionComplete();
2288
Mathias Agopian32ae0942011-03-02 18:45:50 -08002289 // LOGD("screenshot: result = %s", result<0 ? strerror(result) : "OK");
Mathias Agopiancd2cfb62011-01-16 14:05:02 -08002290
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002291 return result;
2292}
2293
2294
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002295status_t SurfaceFlinger::captureScreen(DisplayID dpy,
2296 sp<IMemoryHeap>* heap,
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002297 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002298 uint32_t sw, uint32_t sh,
2299 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002300{
2301 // only one display supported for now
2302 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
2303 return BAD_VALUE;
2304
2305 if (!GLExtensions::getInstance().haveFramebufferObject())
2306 return INVALID_OPERATION;
2307
2308 class MessageCaptureScreen : public MessageBase {
2309 SurfaceFlinger* flinger;
2310 DisplayID dpy;
2311 sp<IMemoryHeap>* heap;
2312 uint32_t* w;
2313 uint32_t* h;
2314 PixelFormat* f;
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002315 uint32_t sw;
2316 uint32_t sh;
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002317 uint32_t minLayerZ;
2318 uint32_t maxLayerZ;
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002319 status_t result;
2320 public:
2321 MessageCaptureScreen(SurfaceFlinger* flinger, DisplayID dpy,
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002322 sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002323 uint32_t sw, uint32_t sh,
2324 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002325 : flinger(flinger), dpy(dpy),
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002326 heap(heap), w(w), h(h), f(f), sw(sw), sh(sh),
2327 minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
2328 result(PERMISSION_DENIED)
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002329 {
2330 }
2331 status_t getResult() const {
2332 return result;
2333 }
2334 virtual bool handler() {
2335 Mutex::Autolock _l(flinger->mStateLock);
2336
2337 // if we have secure windows, never allow the screen capture
2338 if (flinger->mSecureFrameBuffer)
2339 return true;
2340
Mathias Agopian38ed2e32010-09-29 13:02:36 -07002341 result = flinger->captureScreenImplLocked(dpy,
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002342 heap, w, h, f, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002343
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002344 return true;
2345 }
2346 };
2347
2348 sp<MessageBase> msg = new MessageCaptureScreen(this,
Mathias Agopian3dd25a62010-12-10 16:22:31 -08002349 dpy, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopianca5edbe2010-09-24 11:26:58 -07002350 status_t res = postMessageSync(msg);
2351 if (res == NO_ERROR) {
2352 res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult();
2353 }
2354 return res;
2355}
2356
2357// ---------------------------------------------------------------------------
2358
Mathias Agopian7623da42010-06-01 15:12:58 -07002359sp<Layer> SurfaceFlinger::getLayer(const sp<ISurface>& sur) const
2360{
2361 sp<Layer> result;
2362 Mutex::Autolock _l(mStateLock);
2363 result = mLayerMap.valueFor( sur->asBinder() ).promote();
2364 return result;
2365}
2366
2367// ---------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368
Mathias Agopian593c05c2010-06-02 23:28:45 -07002369Client::Client(const sp<SurfaceFlinger>& flinger)
Mathias Agopian7623da42010-06-01 15:12:58 -07002370 : mFlinger(flinger), mNameGenerator(1)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372}
2373
Mathias Agopian593c05c2010-06-02 23:28:45 -07002374Client::~Client()
2375{
Mathias Agopian593c05c2010-06-02 23:28:45 -07002376 const size_t count = mLayers.size();
2377 for (size_t i=0 ; i<count ; i++) {
2378 sp<LayerBaseClient> layer(mLayers.valueAt(i).promote());
2379 if (layer != 0) {
2380 mFlinger->removeLayer(layer);
2381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 }
2383}
2384
Mathias Agopian593c05c2010-06-02 23:28:45 -07002385status_t Client::initCheck() const {
Mathias Agopian7623da42010-06-01 15:12:58 -07002386 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387}
Mathias Agopian1473f462009-04-10 14:24:30 -07002388
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07002389size_t Client::attachLayer(const sp<LayerBaseClient>& layer)
Mathias Agopian593c05c2010-06-02 23:28:45 -07002390{
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07002391 Mutex::Autolock _l(mLock);
2392 size_t name = mNameGenerator++;
Mathias Agopian593c05c2010-06-02 23:28:45 -07002393 mLayers.add(name, layer);
2394 return name;
2395}
2396
Mathias Agopian7623da42010-06-01 15:12:58 -07002397void Client::detachLayer(const LayerBaseClient* layer)
Mathias Agopian593c05c2010-06-02 23:28:45 -07002398{
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07002399 Mutex::Autolock _l(mLock);
Mathias Agopian593c05c2010-06-02 23:28:45 -07002400 // we do a linear search here, because this doesn't happen often
2401 const size_t count = mLayers.size();
2402 for (size_t i=0 ; i<count ; i++) {
2403 if (mLayers.valueAt(i) == layer) {
2404 mLayers.removeItemsAt(i, 1);
2405 break;
2406 }
2407 }
2408}
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07002409sp<LayerBaseClient> Client::getLayerUser(int32_t i) const
2410{
2411 Mutex::Autolock _l(mLock);
Mathias Agopian1473f462009-04-10 14:24:30 -07002412 sp<LayerBaseClient> lbc;
Mathias Agopian5fa7ad62011-05-03 16:21:41 -07002413 wp<LayerBaseClient> layer(mLayers.valueFor(i));
Mathias Agopian593c05c2010-06-02 23:28:45 -07002414 if (layer != 0) {
2415 lbc = layer.promote();
2416 LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i));
Mathias Agopian1473f462009-04-10 14:24:30 -07002417 }
2418 return lbc;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419}
2420
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002421
2422status_t Client::onTransact(
2423 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
2424{
2425 // these must be checked
2426 IPCThreadState* ipc = IPCThreadState::self();
2427 const int pid = ipc->getCallingPid();
2428 const int uid = ipc->getCallingUid();
2429 const int self_pid = getpid();
2430 if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
2431 // we're called from a different process, do the real check
Mathias Agopian0dd593f2011-06-27 16:05:52 -07002432 if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger))
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002433 {
2434 LOGE("Permission Denial: "
2435 "can't openGlobalTransaction pid=%d, uid=%d", pid, uid);
2436 return PERMISSION_DENIED;
2437 }
2438 }
2439 return BnSurfaceComposerClient::onTransact(code, data, reply, flags);
Mathias Agopian7623da42010-06-01 15:12:58 -07002440}
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002441
2442
Mathias Agopian593c05c2010-06-02 23:28:45 -07002443sp<ISurface> Client::createSurface(
Mathias Agopian9638e5c2011-04-20 14:19:32 -07002444 ISurfaceComposerClient::surface_data_t* params,
Mathias Agopian7623da42010-06-01 15:12:58 -07002445 const String8& name,
2446 DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 uint32_t flags)
2448{
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002449 /*
2450 * createSurface must be called from the GL thread so that it can
2451 * have access to the GL context.
2452 */
2453
2454 class MessageCreateSurface : public MessageBase {
2455 sp<ISurface> result;
2456 SurfaceFlinger* flinger;
2457 ISurfaceComposerClient::surface_data_t* params;
2458 Client* client;
2459 const String8& name;
2460 DisplayID display;
2461 uint32_t w, h;
2462 PixelFormat format;
2463 uint32_t flags;
2464 public:
2465 MessageCreateSurface(SurfaceFlinger* flinger,
2466 ISurfaceComposerClient::surface_data_t* params,
2467 const String8& name, Client* client,
2468 DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
2469 uint32_t flags)
2470 : flinger(flinger), params(params), client(client), name(name),
2471 display(display), w(w), h(h), format(format), flags(flags)
2472 {
2473 }
2474 sp<ISurface> getResult() const { return result; }
2475 virtual bool handler() {
2476 result = flinger->createSurface(params, name, client,
2477 display, w, h, format, flags);
2478 return true;
2479 }
2480 };
2481
2482 sp<MessageBase> msg = new MessageCreateSurface(mFlinger.get(),
2483 params, name, this, display, w, h, format, flags);
2484 mFlinger->postMessageSync(msg);
2485 return static_cast<MessageCreateSurface*>( msg.get() )->getResult();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486}
Mathias Agopian593c05c2010-06-02 23:28:45 -07002487status_t Client::destroySurface(SurfaceID sid) {
2488 return mFlinger->removeSurface(this, sid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490
2491// ---------------------------------------------------------------------------
2492
Jamie Gennisf7acf162011-01-12 18:30:40 -08002493GraphicBufferAlloc::GraphicBufferAlloc() {}
2494
2495GraphicBufferAlloc::~GraphicBufferAlloc() {}
2496
2497sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h,
2498 PixelFormat format, uint32_t usage) {
2499 sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
2500 status_t err = graphicBuffer->initCheck();
Mathias Agopian7bb843c2011-04-20 14:20:59 -07002501 if (err != 0 || graphicBuffer->handle == 0) {
2502 GraphicBuffer::dumpAllocationsToSystemLog();
2503 LOGE("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) "
2504 "failed (%s), handle=%p",
2505 w, h, strerror(-err), graphicBuffer->handle);
Jamie Gennisf7acf162011-01-12 18:30:40 -08002506 return 0;
2507 }
Jamie Gennisf7acf162011-01-12 18:30:40 -08002508 return graphicBuffer;
2509}
2510
Jamie Gennisf7acf162011-01-12 18:30:40 -08002511// ---------------------------------------------------------------------------
2512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513GraphicPlane::GraphicPlane()
2514 : mHw(0)
2515{
2516}
2517
2518GraphicPlane::~GraphicPlane() {
2519 delete mHw;
2520}
2521
2522bool GraphicPlane::initialized() const {
2523 return mHw ? true : false;
2524}
2525
Mathias Agopian66c77a52010-02-08 15:49:35 -08002526int GraphicPlane::getWidth() const {
2527 return mWidth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528}
2529
Mathias Agopian66c77a52010-02-08 15:49:35 -08002530int GraphicPlane::getHeight() const {
2531 return mHeight;
2532}
2533
2534void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
2535{
2536 mHw = hw;
2537
2538 // initialize the display orientation transform.
2539 // it's a constant that should come from the display driver.
2540 int displayOrientation = ISurfaceComposer::eOrientationDefault;
2541 char property[PROPERTY_VALUE_MAX];
2542 if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
2543 //displayOrientation
2544 switch (atoi(property)) {
2545 case 90:
2546 displayOrientation = ISurfaceComposer::eOrientation90;
2547 break;
2548 case 270:
2549 displayOrientation = ISurfaceComposer::eOrientation270;
2550 break;
2551 }
2552 }
2553
2554 const float w = hw->getWidth();
2555 const float h = hw->getHeight();
2556 GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
2557 &mDisplayTransform);
2558 if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
2559 mDisplayWidth = h;
2560 mDisplayHeight = w;
2561 } else {
2562 mDisplayWidth = w;
2563 mDisplayHeight = h;
2564 }
2565
2566 setOrientation(ISurfaceComposer::eOrientationDefault);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567}
2568
2569status_t GraphicPlane::orientationToTransfrom(
2570 int orientation, int w, int h, Transform* tr)
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002571{
2572 uint32_t flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 switch (orientation) {
2574 case ISurfaceComposer::eOrientationDefault:
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002575 flags = Transform::ROT_0;
2576 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 case ISurfaceComposer::eOrientation90:
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002578 flags = Transform::ROT_90;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 break;
2580 case ISurfaceComposer::eOrientation180:
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002581 flags = Transform::ROT_180;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 break;
2583 case ISurfaceComposer::eOrientation270:
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002584 flags = Transform::ROT_270;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 break;
2586 default:
2587 return BAD_VALUE;
2588 }
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002589 tr->set(flags, w, h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 return NO_ERROR;
2591}
2592
2593status_t GraphicPlane::setOrientation(int orientation)
2594{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 // If the rotation can be handled in hardware, this is where
2596 // the magic should happen.
Mathias Agopian66c77a52010-02-08 15:49:35 -08002597
2598 const DisplayHardware& hw(displayHardware());
2599 const float w = mDisplayWidth;
2600 const float h = mDisplayHeight;
2601 mWidth = int(w);
2602 mHeight = int(h);
2603
2604 Transform orientationTransform;
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002605 GraphicPlane::orientationToTransfrom(orientation, w, h,
2606 &orientationTransform);
2607 if (orientation & ISurfaceComposer::eOrientationSwapMask) {
2608 mWidth = int(h);
2609 mHeight = int(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 }
Mathias Agopian8c20ca32010-02-22 03:15:57 -08002611
Mathias Agopian3552f532009-03-27 17:58:20 -07002612 mOrientation = orientation;
Mathias Agopian66c77a52010-02-08 15:49:35 -08002613 mGlobalTransform = mDisplayTransform * orientationTransform;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 return NO_ERROR;
2615}
2616
2617const DisplayHardware& GraphicPlane::displayHardware() const {
2618 return *mHw;
2619}
2620
Mathias Agopianaab758e2010-10-11 12:37:43 -07002621DisplayHardware& GraphicPlane::editDisplayHardware() {
2622 return *mHw;
2623}
2624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625const Transform& GraphicPlane::transform() const {
2626 return mGlobalTransform;
2627}
2628
Mathias Agopian1473f462009-04-10 14:24:30 -07002629EGLDisplay GraphicPlane::getEGLDisplay() const {
2630 return mHw->getEGLDisplay();
2631}
2632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633// ---------------------------------------------------------------------------
2634
2635}; // namespace android