blob: 92c157edfe88875da691ecbc457950bb5027942f [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Projectedbf3b62009-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 Querua837ba72009-01-26 11:51:12 -080024#include <limits.h>
The Android Open Source Projectedbf3b62009-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 Agopianc5b2c0b2009-05-19 19:08:10 -070032#include <binder/IPCThreadState.h>
33#include <binder/IServiceManager.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070034#include <binder/MemoryHeapBase.h>
Mathias Agopian99b49842011-06-27 16:05:52 -070035#include <binder/PermissionCache.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070036
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <utils/String8.h>
38#include <utils/String16.h>
39#include <utils/StopWatch.h>
40
Mathias Agopian3330b202009-10-05 17:07:12 -070041#include <ui/GraphicBufferAllocator.h>
Mathias Agopian35b48d12010-09-13 22:57:58 -070042#include <ui/GraphicLog.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45#include <pixelflinger/pixelflinger.h>
46#include <GLES/gl.h>
47
48#include "clz.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070049#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051#include "LayerDim.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053
54#include "DisplayHardware/DisplayHardware.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070055#include "DisplayHardware/HWComposer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Mathias Agopiana67932f2011-04-20 14:20:59 -070057#include <private/surfaceflinger/SharedBufferStack.h>
58
Mathias Agopiana1ecca92009-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 Projectedbf3b62009-03-03 19:31:44 -080066#define DISPLAY_COUNT 1
67
68namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069// ---------------------------------------------------------------------------
70
Mathias Agopian99b49842011-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 Projectedbf3b62009-03-03 19:31:44 -080078SurfaceFlinger::SurfaceFlinger()
79 : BnSurfaceComposer(), Thread(false),
80 mTransactionFlags(0),
Mathias Agopiancbb288b2009-09-07 16:32:45 -070081 mResizeTransationPending(false),
Mathias Agopian076b1cc2009-04-10 14:24:30 -070082 mLayersRemoved(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 mBootTime(systemTime()),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 mVisibleRegionsDirty(false),
Mathias Agopiana350ff92010-08-10 17:14:02 -070085 mHwWorkListDirty(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 mDeferReleaseConsole(false),
87 mFreezeDisplay(false),
Mathias Agopianabd671a2010-10-14 14:54:06 -070088 mElectronBeamAnimationMode(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 mFreezeCount(0),
The Android Open Source Projectbcef13b2009-03-11 12:11:56 -070090 mFreezeDisplayTime(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 mDebugRegion(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092 mDebugBackground(0),
Mathias Agopian73d3ba92010-09-22 18:58:01 -070093 mDebugDisableHWC(0),
Mathias Agopian9795c422009-08-26 16:36:26 -070094 mDebugInSwapBuffers(0),
95 mLastSwapBufferTime(0),
96 mDebugInTransaction(0),
97 mLastTransactionTime(0),
Mathias Agopian3330b202009-10-05 17:07:12 -070098 mBootFinished(false),
The Android Open Source Projectedbf3b62009-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 Projectedbf3b62009-03-03 19:31:44 -0800113 property_get("debug.sf.showbackground", value, "0");
114 mDebugBackground = atoi(value);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115
Mathias Agopian78fd5012010-04-20 14:51:04 -0700116 LOGI_IF(mDebugRegion, "showupdates enabled");
117 LOGI_IF(mDebugBackground, "showbackground enabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118}
119
120SurfaceFlinger::~SurfaceFlinger()
121{
122 glDeleteTextures(1, &mWormholeTexName);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123}
124
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700125sp<IMemoryHeap> SurfaceFlinger::getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126{
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700127 return mServerHeap;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128}
129
Mathias Agopian7e27f052010-05-28 14:22:23 -0700130sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131{
Mathias Agopian96f08192010-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 Projectedbf3b62009-03-03 19:31:44 -0800137 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138 return bclient;
139}
140
Jamie Gennis9a78c902011-01-12 18:30:40 -0800141sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
142{
143 sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
144 return gba;
145}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700146
The Android Open Source Projectedbf3b62009-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 Huber8b42e8a2010-08-16 08:49:37 -0700164 LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
Mathias Agopian3330b202009-10-05 17:07:12 -0700165 mBootFinished = true;
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700166 property_set("ctl.stop", "bootanim");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167}
168
169void SurfaceFlinger::onFirstRef()
170{
171 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
172
173 // Wait for the main thread to be done with its initialization
174 mReadyToRunBarrier.wait();
175}
176
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800177static inline uint16_t pack565(int r, int g, int b) {
178 return (r<<11)|(g<<5)|b;
179}
180
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181status_t SurfaceFlinger::readyToRun()
182{
183 LOGI( "SurfaceFlinger's main thread ready to run. "
184 "Initializing graphics H/W...");
185
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186 // we only support one display currently
187 int dpy = 0;
188
189 {
190 // initialize the main display
191 GraphicPlane& plane(graphicPlane(dpy));
192 DisplayHardware* const hw = new DisplayHardware(this, dpy);
193 plane.setDisplayHardware(hw);
194 }
195
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700196 // create the shared control-block
197 mServerHeap = new MemoryHeapBase(4096,
198 MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap");
199 LOGE_IF(mServerHeap==0, "can't create shared memory dealer");
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700200
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700201 mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase());
202 LOGE_IF(mServerCblk==0, "can't get to shared control block's address");
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700203
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700204 new(mServerCblk) surface_flinger_cblk_t;
205
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 // initialize primary screen
207 // (other display should be initialized in the same manner, but
208 // asynchronously, as they could come and go. None of this is supported
209 // yet).
210 const GraphicPlane& plane(graphicPlane(dpy));
211 const DisplayHardware& hw = plane.displayHardware();
212 const uint32_t w = hw.getWidth();
213 const uint32_t h = hw.getHeight();
214 const uint32_t f = hw.getFormat();
215 hw.makeCurrent();
216
217 // initialize the shared control block
218 mServerCblk->connected |= 1<<dpy;
219 display_cblk_t* dcblk = mServerCblk->displays + dpy;
220 memset(dcblk, 0, sizeof(display_cblk_t));
Mathias Agopian2b92d892010-02-08 15:49:35 -0800221 dcblk->w = plane.getWidth();
222 dcblk->h = plane.getHeight();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 dcblk->format = f;
224 dcblk->orientation = ISurfaceComposer::eOrientationDefault;
225 dcblk->xdpi = hw.getDpiX();
226 dcblk->ydpi = hw.getDpiY();
227 dcblk->fps = hw.getRefreshRate();
228 dcblk->density = hw.getDensity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229
230 // Initialize OpenGL|ES
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700232 glPixelStorei(GL_PACK_ALIGNMENT, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 glEnableClientState(GL_VERTEX_ARRAY);
234 glEnable(GL_SCISSOR_TEST);
235 glShadeModel(GL_FLAT);
236 glDisable(GL_DITHER);
237 glDisable(GL_CULL_FACE);
238
239 const uint16_t g0 = pack565(0x0F,0x1F,0x0F);
240 const uint16_t g1 = pack565(0x17,0x2f,0x17);
241 const uint16_t textureData[4] = { g0, g1, g1, g0 };
242 glGenTextures(1, &mWormholeTexName);
243 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
244 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
245 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
246 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
247 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
248 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0,
249 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData);
250
251 glViewport(0, 0, w, h);
252 glMatrixMode(GL_PROJECTION);
253 glLoadIdentity();
254 glOrthof(0, w, h, 0, 0, 1);
255
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 mReadyToRunBarrier.open();
257
258 /*
259 * We're now ready to accept clients...
260 */
261
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700262 // start boot animation
263 property_set("ctl.start", "bootanim");
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700264
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265 return NO_ERROR;
266}
267
268// ----------------------------------------------------------------------------
269#if 0
270#pragma mark -
271#pragma mark Events Handler
272#endif
273
274void SurfaceFlinger::waitForEvent()
275{
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700276 while (true) {
277 nsecs_t timeout = -1;
Mathias Agopian04087722009-12-01 17:23:28 -0800278 const nsecs_t freezeDisplayTimeout = ms2ns(5000);
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700279 if (UNLIKELY(isFrozen())) {
280 // wait 5 seconds
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700281 const nsecs_t now = systemTime();
282 if (mFreezeDisplayTime == 0) {
283 mFreezeDisplayTime = now;
284 }
285 nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime);
286 timeout = waitTime>0 ? waitTime : 0;
The Android Open Source Projectbcef13b2009-03-11 12:11:56 -0700287 }
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700288
Mathias Agopianbb641242010-05-18 17:06:55 -0700289 sp<MessageBase> msg = mEventQueue.waitMessage(timeout);
Mathias Agopian04087722009-12-01 17:23:28 -0800290
291 // see if we timed out
292 if (isFrozen()) {
293 const nsecs_t now = systemTime();
294 nsecs_t frozenTime = (now - mFreezeDisplayTime);
295 if (frozenTime >= freezeDisplayTimeout) {
296 // we timed out and are still frozen
297 LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d",
298 mFreezeDisplay, mFreezeCount);
299 mFreezeDisplayTime = 0;
300 mFreezeCount = 0;
301 mFreezeDisplay = false;
302 }
303 }
304
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700305 if (msg != 0) {
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700306 switch (msg->what) {
307 case MessageQueue::INVALIDATE:
308 // invalidate message, just return to the main loop
309 return;
310 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312 }
313}
314
315void SurfaceFlinger::signalEvent() {
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700316 mEventQueue.invalidate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317}
318
Jamie Gennis134f0422011-03-08 12:18:54 -0800319bool SurfaceFlinger::authenticateSurface(const sp<ISurface>& surface) const {
320 Mutex::Autolock _l(mStateLock);
321 sp<IBinder> surfBinder(surface->asBinder());
322
323 // Check the visible layer list for the ISurface
324 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
325 size_t count = currentLayers.size();
326 for (size_t i=0 ; i<count ; i++) {
327 const sp<LayerBase>& layer(currentLayers[i]);
328 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
329 if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
330 return true;
331 }
332 }
333
334 // Check the layers in the purgatory. This check is here so that if a
335 // Surface gets destroyed before all the clients are done using it, the
336 // error will not be reported as "surface XYZ is not authenticated", but
337 // will instead fail later on when the client tries to use the surface,
338 // which should be reported as "surface XYZ returned an -ENODEV". The
339 // purgatorized layers are no less authentic than the visible ones, so this
340 // should not cause any harm.
341 size_t purgatorySize = mLayerPurgatory.size();
342 for (size_t i=0 ; i<purgatorySize ; i++) {
343 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
344 sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
345 if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
346 return true;
347 }
348 }
349
350 return false;
351}
352
Mathias Agopianbb641242010-05-18 17:06:55 -0700353status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
354 nsecs_t reltime, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355{
Mathias Agopianbb641242010-05-18 17:06:55 -0700356 return mEventQueue.postMessage(msg, reltime, flags);
357}
358
359status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
360 nsecs_t reltime, uint32_t flags)
361{
362 status_t res = mEventQueue.postMessage(msg, reltime, flags);
363 if (res == NO_ERROR) {
364 msg->wait();
365 }
366 return res;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800367}
368
369// ----------------------------------------------------------------------------
370#if 0
371#pragma mark -
372#pragma mark Main loop
373#endif
374
375bool SurfaceFlinger::threadLoop()
376{
377 waitForEvent();
378
Mathias Agopianca4d3602011-05-19 15:38:14 -0700379 // call Layer's destructor
380 handleDestroyLayers();
381
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382 // check for transactions
383 if (UNLIKELY(mConsoleSignals)) {
384 handleConsoleEvents();
385 }
386
Mathias Agopian698c0872011-06-28 19:09:31 -0700387 // if we're in a global transaction, don't do anything.
388 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
389 uint32_t transactionFlags = peekTransactionFlags(mask);
390 if (UNLIKELY(transactionFlags)) {
391 handleTransaction(transactionFlags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392 }
393
394 // post surfaces (if needed)
395 handlePageFlip();
396
Mathias Agopiana350ff92010-08-10 17:14:02 -0700397 if (UNLIKELY(mHwWorkListDirty)) {
398 // build the h/w work list
399 handleWorkList();
400 }
401
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800402 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian8a77baa2009-09-27 22:47:27 -0700403 if (LIKELY(hw.canDraw() && !isFrozen())) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800404 // repaint the framebuffer (if needed)
Mathias Agopian35b48d12010-09-13 22:57:58 -0700405
406 const int index = hw.getCurrentBufferIndex();
407 GraphicLog& logger(GraphicLog::getInstance());
408
409 logger.log(GraphicLog::SF_REPAINT, index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800410 handleRepaint();
411
Mathias Agopian74faca22009-09-17 16:18:16 -0700412 // inform the h/w that we're done compositing
Mathias Agopian35b48d12010-09-13 22:57:58 -0700413 logger.log(GraphicLog::SF_COMPOSITION_COMPLETE, index);
Mathias Agopian74faca22009-09-17 16:18:16 -0700414 hw.compositionComplete();
415
Mathias Agopian35b48d12010-09-13 22:57:58 -0700416 logger.log(GraphicLog::SF_SWAP_BUFFERS, index);
Antti Hatala8392b502010-09-08 06:37:14 -0700417 postFramebuffer();
418
Mathias Agopian35b48d12010-09-13 22:57:58 -0700419 logger.log(GraphicLog::SF_REPAINT_DONE, index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800420 } else {
421 // pretend we did the post
Mathias Agopiane6f09842010-12-15 14:41:59 -0800422 hw.compositionComplete();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800423 usleep(16667); // 60 fps period
424 }
425 return true;
426}
427
428void SurfaceFlinger::postFramebuffer()
429{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800430 if (!mInvalidRegion.isEmpty()) {
431 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian9795c422009-08-26 16:36:26 -0700432 const nsecs_t now = systemTime();
433 mDebugInSwapBuffers = now;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434 hw.flip(mInvalidRegion);
Mathias Agopian9795c422009-08-26 16:36:26 -0700435 mLastSwapBufferTime = systemTime() - now;
436 mDebugInSwapBuffers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437 mInvalidRegion.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438 }
439}
440
441void SurfaceFlinger::handleConsoleEvents()
442{
443 // something to do with the console
444 const DisplayHardware& hw = graphicPlane(0).displayHardware();
445
446 int what = android_atomic_and(0, &mConsoleSignals);
447 if (what & eConsoleAcquired) {
448 hw.acquireScreen();
Mathias Agopian9daa5c92010-10-12 16:05:48 -0700449 // this is a temporary work-around, eventually this should be called
450 // by the power-manager
Mathias Agopianabd671a2010-10-14 14:54:06 -0700451 SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800452 }
453
Mathias Agopian59119e62010-10-11 12:37:43 -0700454 if (mDeferReleaseConsole && hw.isScreenAcquired()) {
Mathias Agopian62b74442009-04-14 23:02:51 -0700455 // We got the release signal before the acquire signal
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456 mDeferReleaseConsole = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800457 hw.releaseScreen();
458 }
459
460 if (what & eConsoleReleased) {
Mathias Agopian59119e62010-10-11 12:37:43 -0700461 if (hw.isScreenAcquired()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462 hw.releaseScreen();
463 } else {
464 mDeferReleaseConsole = true;
465 }
466 }
467
468 mDirtyRegion.set(hw.bounds());
469}
470
471void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
472{
Mathias Agopianca4d3602011-05-19 15:38:14 -0700473 Mutex::Autolock _l(mStateLock);
474 const nsecs_t now = systemTime();
475 mDebugInTransaction = now;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800476
Mathias Agopianca4d3602011-05-19 15:38:14 -0700477 // Here we're guaranteed that some transaction flags are set
478 // so we can call handleTransactionLocked() unconditionally.
479 // We call getTransactionFlags(), which will also clear the flags,
480 // with mStateLock held to guarantee that mCurrentState won't change
481 // until the transaction is committed.
Mathias Agopian4da75192010-08-10 17:19:56 -0700482
Mathias Agopianca4d3602011-05-19 15:38:14 -0700483 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
484 transactionFlags = getTransactionFlags(mask);
485 handleTransactionLocked(transactionFlags);
Mathias Agopiandea20b12011-05-03 17:04:02 -0700486
Mathias Agopianca4d3602011-05-19 15:38:14 -0700487 mLastTransactionTime = systemTime() - now;
488 mDebugInTransaction = 0;
489 invalidateHwcGeometry();
490 // here the transaction has been committed
Mathias Agopian3d579642009-06-04 18:46:21 -0700491}
492
Mathias Agopianca4d3602011-05-19 15:38:14 -0700493void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
Mathias Agopian3d579642009-06-04 18:46:21 -0700494{
495 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496 const size_t count = currentLayers.size();
497
498 /*
499 * Traversal of the children
500 * (perform the transaction for each of them if needed)
501 */
502
503 const bool layersNeedTransaction = transactionFlags & eTraversalNeeded;
504 if (layersNeedTransaction) {
505 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700506 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800507 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
508 if (!trFlags) continue;
509
510 const uint32_t flags = layer->doTransaction(0);
511 if (flags & Layer::eVisibleRegion)
512 mVisibleRegionsDirty = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800513 }
514 }
515
516 /*
517 * Perform our own transaction if needed
518 */
519
520 if (transactionFlags & eTransactionNeeded) {
521 if (mCurrentState.orientation != mDrawingState.orientation) {
522 // the orientation has changed, recompute all visible regions
523 // and invalidate everything.
524
525 const int dpy = 0;
526 const int orientation = mCurrentState.orientation;
Mathias Agopianc08731e2009-03-27 18:11:38 -0700527 const uint32_t type = mCurrentState.orientationType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800528 GraphicPlane& plane(graphicPlane(dpy));
529 plane.setOrientation(orientation);
530
531 // update the shared control block
532 const DisplayHardware& hw(plane.displayHardware());
533 volatile display_cblk_t* dcblk = mServerCblk->displays + dpy;
534 dcblk->orientation = orientation;
Mathias Agopian2b92d892010-02-08 15:49:35 -0800535 dcblk->w = plane.getWidth();
536 dcblk->h = plane.getHeight();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800537
538 mVisibleRegionsDirty = true;
539 mDirtyRegion.set(hw.bounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800540 }
541
542 if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) {
543 // freezing or unfreezing the display -> trigger animation if needed
544 mFreezeDisplay = mCurrentState.freezeDisplay;
Mathias Agopian064e1e62010-03-01 17:51:17 -0800545 if (mFreezeDisplay)
546 mFreezeDisplayTime = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800547 }
548
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700549 if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) {
550 // layers have been added
551 mVisibleRegionsDirty = true;
552 }
553
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800554 // some layers might have been removed, so
555 // we need to update the regions they're exposing.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700556 if (mLayersRemoved) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700557 mLayersRemoved = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800558 mVisibleRegionsDirty = true;
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700559 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
Mathias Agopian3d579642009-06-04 18:46:21 -0700560 const size_t count = previousLayers.size();
561 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700562 const sp<LayerBase>& layer(previousLayers[i]);
563 if (currentLayers.indexOf( layer ) < 0) {
564 // this layer is not visible anymore
Mathias Agopian5d7126b2009-07-28 14:20:21 -0700565 mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700566 }
567 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800568 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800569 }
570
571 commitTransaction();
572}
573
Mathias Agopianca4d3602011-05-19 15:38:14 -0700574void SurfaceFlinger::destroyLayer(LayerBase const* layer)
575{
576 Mutex::Autolock _l(mDestroyedLayerLock);
577 mDestroyedLayers.add(layer);
578 signalEvent();
579}
580
581void SurfaceFlinger::handleDestroyLayers()
582{
583 Vector<LayerBase const *> destroyedLayers;
584
585 { // scope for the lock
586 Mutex::Autolock _l(mDestroyedLayerLock);
587 destroyedLayers = mDestroyedLayers;
588 mDestroyedLayers.clear();
589 }
590
591 // call destructors without a lock held
592 const size_t count = destroyedLayers.size();
593 for (size_t i=0 ; i<count ; i++) {
594 //LOGD("destroying %s", destroyedLayers[i]->getName().string());
595 delete destroyedLayers[i];
596 }
597}
598
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599sp<FreezeLock> SurfaceFlinger::getFreezeLock() const
600{
601 return new FreezeLock(const_cast<SurfaceFlinger *>(this));
602}
603
604void SurfaceFlinger::computeVisibleRegions(
Mathias Agopian1bbafb92011-03-11 16:54:47 -0800605 const LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800606{
607 const GraphicPlane& plane(graphicPlane(0));
608 const Transform& planeTransform(plane.transform());
Mathias Agopianab028732010-03-16 16:41:46 -0700609 const DisplayHardware& hw(plane.displayHardware());
610 const Region screenRegion(hw.bounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800611
612 Region aboveOpaqueLayers;
613 Region aboveCoveredLayers;
614 Region dirty;
615
616 bool secureFrameBuffer = false;
617
618 size_t i = currentLayers.size();
619 while (i--) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700620 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800621 layer->validateVisibility(planeTransform);
622
623 // start with the whole surface at its current location
Mathias Agopian97011222009-07-28 10:57:27 -0700624 const Layer::State& s(layer->drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800625
Mathias Agopianab028732010-03-16 16:41:46 -0700626 /*
627 * opaqueRegion: area of a surface that is fully opaque.
628 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800629 Region opaqueRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700630
631 /*
632 * visibleRegion: area of a surface that is visible on screen
633 * and not fully transparent. This is essentially the layer's
634 * footprint minus the opaque regions above it.
635 * Areas covered by a translucent surface are considered visible.
636 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800637 Region visibleRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700638
639 /*
640 * coveredRegion: area of a surface that is covered by all
641 * visible regions above it (which includes the translucent areas).
642 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800643 Region coveredRegion;
Mathias Agopianab028732010-03-16 16:41:46 -0700644
645
646 // handle hidden surfaces by setting the visible region to empty
Mathias Agopian97011222009-07-28 10:57:27 -0700647 if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
Mathias Agopiana67932f2011-04-20 14:20:59 -0700648 const bool translucent = !layer->isOpaque();
Mathias Agopian97011222009-07-28 10:57:27 -0700649 const Rect bounds(layer->visibleBounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800650 visibleRegion.set(bounds);
Mathias Agopianab028732010-03-16 16:41:46 -0700651 visibleRegion.andSelf(screenRegion);
652 if (!visibleRegion.isEmpty()) {
653 // Remove the transparent area from the visible region
654 if (translucent) {
655 visibleRegion.subtractSelf(layer->transparentRegionScreen);
656 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800657
Mathias Agopianab028732010-03-16 16:41:46 -0700658 // compute the opaque region
659 const int32_t layerOrientation = layer->getOrientation();
660 if (s.alpha==255 && !translucent &&
661 ((layerOrientation & Transform::ROT_INVALID) == false)) {
662 // the opaque region is the layer's footprint
663 opaqueRegion = visibleRegion;
664 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800665 }
666 }
667
Mathias Agopianab028732010-03-16 16:41:46 -0700668 // Clip the covered region to the visible region
669 coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
670
671 // Update aboveCoveredLayers for next (lower) layer
672 aboveCoveredLayers.orSelf(visibleRegion);
673
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800674 // subtract the opaque region covered by the layers above us
675 visibleRegion.subtractSelf(aboveOpaqueLayers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800676
677 // compute this layer's dirty region
678 if (layer->contentDirty) {
679 // we need to invalidate the whole region
680 dirty = visibleRegion;
681 // as well, as the old visible region
682 dirty.orSelf(layer->visibleRegionScreen);
683 layer->contentDirty = false;
684 } else {
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700685 /* compute the exposed region:
Mathias Agopianab028732010-03-16 16:41:46 -0700686 * the exposed region consists of two components:
687 * 1) what's VISIBLE now and was COVERED before
688 * 2) what's EXPOSED now less what was EXPOSED before
689 *
690 * note that (1) is conservative, we start with the whole
691 * visible region but only keep what used to be covered by
692 * something -- which mean it may have been exposed.
693 *
694 * (2) handles areas that were not covered by anything but got
695 * exposed because of a resize.
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700696 */
Mathias Agopianab028732010-03-16 16:41:46 -0700697 const Region newExposed = visibleRegion - coveredRegion;
698 const Region oldVisibleRegion = layer->visibleRegionScreen;
699 const Region oldCoveredRegion = layer->coveredRegionScreen;
700 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
701 dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800702 }
703 dirty.subtractSelf(aboveOpaqueLayers);
704
705 // accumulate to the screen dirty region
706 dirtyRegion.orSelf(dirty);
707
Mathias Agopianab028732010-03-16 16:41:46 -0700708 // Update aboveOpaqueLayers for next (lower) layer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800709 aboveOpaqueLayers.orSelf(opaqueRegion);
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700710
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800711 // Store the visible region is screen space
712 layer->setVisibleRegion(visibleRegion);
713 layer->setCoveredRegion(coveredRegion);
714
Mathias Agopian97011222009-07-28 10:57:27 -0700715 // If a secure layer is partially visible, lock-down the screen!
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800716 if (layer->isSecure() && !visibleRegion.isEmpty()) {
717 secureFrameBuffer = true;
718 }
719 }
720
Mathias Agopian97011222009-07-28 10:57:27 -0700721 // invalidate the areas where a layer was removed
722 dirtyRegion.orSelf(mDirtyRegionRemovedLayer);
723 mDirtyRegionRemovedLayer.clear();
724
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800725 mSecureFrameBuffer = secureFrameBuffer;
726 opaqueRegion = aboveOpaqueLayers;
727}
728
729
730void SurfaceFlinger::commitTransaction()
731{
732 mDrawingState = mCurrentState;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700733 mResizeTransationPending = false;
734 mTransactionCV.broadcast();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800735}
736
737void SurfaceFlinger::handlePageFlip()
738{
739 bool visibleRegions = mVisibleRegionsDirty;
Mathias Agopian1bbafb92011-03-11 16:54:47 -0800740 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800741 visibleRegions |= lockPageFlip(currentLayers);
742
743 const DisplayHardware& hw = graphicPlane(0).displayHardware();
744 const Region screenRegion(hw.bounds());
745 if (visibleRegions) {
746 Region opaqueRegion;
747 computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion);
Mathias Agopian4da75192010-08-10 17:19:56 -0700748
749 /*
750 * rebuild the visible layer list
751 */
Mathias Agopian1bbafb92011-03-11 16:54:47 -0800752 const size_t count = currentLayers.size();
Mathias Agopian4da75192010-08-10 17:19:56 -0700753 mVisibleLayersSortedByZ.clear();
Mathias Agopian4da75192010-08-10 17:19:56 -0700754 mVisibleLayersSortedByZ.setCapacity(count);
755 for (size_t i=0 ; i<count ; i++) {
756 if (!currentLayers[i]->visibleRegionScreen.isEmpty())
757 mVisibleLayersSortedByZ.add(currentLayers[i]);
758 }
759
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800760 mWormholeRegion = screenRegion.subtract(opaqueRegion);
761 mVisibleRegionsDirty = false;
Mathias Agopianad456f92011-01-13 17:53:01 -0800762 invalidateHwcGeometry();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800763 }
764
765 unlockPageFlip(currentLayers);
766 mDirtyRegion.andSelf(screenRegion);
767}
768
Mathias Agopianad456f92011-01-13 17:53:01 -0800769void SurfaceFlinger::invalidateHwcGeometry()
770{
771 mHwWorkListDirty = true;
772}
773
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800774bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers)
775{
776 bool recomputeVisibleRegions = false;
777 size_t count = currentLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700778 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800779 for (size_t i=0 ; i<count ; i++) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700780 const sp<LayerBase>& layer(layers[i]);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800781 layer->lockPageFlip(recomputeVisibleRegions);
782 }
783 return recomputeVisibleRegions;
784}
785
786void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers)
787{
788 const GraphicPlane& plane(graphicPlane(0));
789 const Transform& planeTransform(plane.transform());
790 size_t count = currentLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700791 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800792 for (size_t i=0 ; i<count ; i++) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700793 const sp<LayerBase>& layer(layers[i]);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800794 layer->unlockPageFlip(planeTransform, mDirtyRegion);
795 }
796}
797
Mathias Agopiana350ff92010-08-10 17:14:02 -0700798void SurfaceFlinger::handleWorkList()
799{
800 mHwWorkListDirty = false;
801 HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer());
802 if (hwc.initCheck() == NO_ERROR) {
803 const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ);
804 const size_t count = currentLayers.size();
805 hwc.createWorkList(count);
Mathias Agopian45721772010-08-12 15:03:26 -0700806 hwc_layer_t* const cur(hwc.getLayers());
807 for (size_t i=0 ; cur && i<count ; i++) {
808 currentLayers[i]->setGeometry(&cur[i]);
Mathias Agopian73d3ba92010-09-22 18:58:01 -0700809 if (mDebugDisableHWC) {
810 cur[i].compositionType = HWC_FRAMEBUFFER;
811 cur[i].flags |= HWC_SKIP_LAYER;
812 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700813 }
814 }
815}
Mathias Agopianb8a55602009-06-26 19:06:36 -0700816
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800817void SurfaceFlinger::handleRepaint()
818{
Mathias Agopianb8a55602009-06-26 19:06:36 -0700819 // compute the invalid region
820 mInvalidRegion.orSelf(mDirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800821
822 if (UNLIKELY(mDebugRegion)) {
823 debugFlashRegions();
824 }
825
Mathias Agopianb8a55602009-06-26 19:06:36 -0700826 // set the frame buffer
827 const DisplayHardware& hw(graphicPlane(0).displayHardware());
828 glMatrixMode(GL_MODELVIEW);
829 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800830
831 uint32_t flags = hw.getFlags();
Andreas Huber8b42e8a2010-08-16 08:49:37 -0700832 if ((flags & DisplayHardware::SWAP_RECTANGLE) ||
833 (flags & DisplayHardware::BUFFER_PRESERVED))
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700834 {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700835 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
836 // takes a rectangle, we must make sure to update that whole
837 // rectangle in that case
838 if (flags & DisplayHardware::SWAP_RECTANGLE) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700839 // TODO: we really should be able to pass a region to
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700840 // SWAP_RECTANGLE so that we don't have to redraw all this.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800841 mDirtyRegion.set(mInvalidRegion.bounds());
842 } else {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700843 // in the BUFFER_PRESERVED case, obviously, we can update only
844 // what's needed and nothing more.
845 // NOTE: this is NOT a common case, as preserving the backbuffer
846 // is costly and usually involves copying the whole update back.
847 }
848 } else {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700849 if (flags & DisplayHardware::PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700850 // We need to redraw the rectangle that will be updated
851 // (pushed to the framebuffer).
Mathias Agopian95a666b2009-09-24 14:57:26 -0700852 // This is needed because PARTIAL_UPDATES only takes one
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700853 // rectangle instead of a region (see DisplayHardware::flip())
854 mDirtyRegion.set(mInvalidRegion.bounds());
855 } else {
856 // we need to redraw everything (the whole screen)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800857 mDirtyRegion.set(hw.bounds());
858 mInvalidRegion = mDirtyRegion;
859 }
860 }
861
862 // compose all surfaces
863 composeSurfaces(mDirtyRegion);
864
865 // clear the dirty regions
866 mDirtyRegion.clear();
867}
868
869void SurfaceFlinger::composeSurfaces(const Region& dirty)
870{
871 if (UNLIKELY(!mWormholeRegion.isEmpty())) {
872 // should never happen unless the window manager has a bug
873 // draw something...
874 drawWormhole();
875 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700876
877 status_t err = NO_ERROR;
Mathias Agopian4da75192010-08-10 17:19:56 -0700878 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
Mathias Agopian45721772010-08-12 15:03:26 -0700879 size_t count = layers.size();
Mathias Agopiana350ff92010-08-10 17:14:02 -0700880
881 const DisplayHardware& hw(graphicPlane(0).displayHardware());
882 HWComposer& hwc(hw.getHwComposer());
Mathias Agopian45721772010-08-12 15:03:26 -0700883 hwc_layer_t* const cur(hwc.getLayers());
Mathias Agopiana350ff92010-08-10 17:14:02 -0700884
Mathias Agopian45721772010-08-12 15:03:26 -0700885 LOGE_IF(cur && hwc.getNumLayers() != count,
886 "HAL number of layers (%d) doesn't match surfaceflinger (%d)",
887 hwc.getNumLayers(), count);
888
889 // just to be extra-safe, use the smallest count
Erik Gilling24925bf2010-08-12 23:21:40 -0700890 if (hwc.initCheck() == NO_ERROR) {
891 count = count < hwc.getNumLayers() ? count : hwc.getNumLayers();
892 }
Mathias Agopian45721772010-08-12 15:03:26 -0700893
894 /*
895 * update the per-frame h/w composer data for each layer
896 * and build the transparent region of the FB
897 */
898 Region transparent;
899 if (cur) {
900 for (size_t i=0 ; i<count ; i++) {
901 const sp<LayerBase>& layer(layers[i]);
902 layer->setPerFrameData(&cur[i]);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700903 }
904 err = hwc.prepare();
905 LOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
Mathias Agopiana350ff92010-08-10 17:14:02 -0700906
Mathias Agopianf20a3242011-01-19 15:24:23 -0800907 if (err == NO_ERROR) {
908 for (size_t i=0 ; i<count ; i++) {
909 if (cur[i].hints & HWC_HINT_CLEAR_FB) {
910 const sp<LayerBase>& layer(layers[i]);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700911 if (layer->isOpaque()) {
Mathias Agopianf20a3242011-01-19 15:24:23 -0800912 transparent.orSelf(layer->visibleRegionScreen);
913 }
914 }
915 }
916
917 /*
918 * clear the area of the FB that need to be transparent
919 */
920 transparent.andSelf(dirty);
921 if (!transparent.isEmpty()) {
922 glClearColor(0,0,0,0);
923 Region::const_iterator it = transparent.begin();
924 Region::const_iterator const end = transparent.end();
925 const int32_t height = hw.getHeight();
926 while (it != end) {
927 const Rect& r(*it++);
928 const GLint sy = height - (r.top + r.height());
929 glScissor(r.left, sy, r.width(), r.height());
930 glClear(GL_COLOR_BUFFER_BIT);
931 }
932 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700933 }
934 }
Mathias Agopian45721772010-08-12 15:03:26 -0700935
936
937 /*
938 * and then, render the layers targeted at the framebuffer
939 */
940 for (size_t i=0 ; i<count ; i++) {
941 if (cur) {
Antti Hatala586a0de2010-09-09 02:32:30 -0700942 if ((cur[i].compositionType != HWC_FRAMEBUFFER) &&
943 !(cur[i].flags & HWC_SKIP_LAYER)) {
Mathias Agopian45721772010-08-12 15:03:26 -0700944 // skip layers handled by the HAL
945 continue;
946 }
947 }
Mathias Agopian73d3ba92010-09-22 18:58:01 -0700948
Mathias Agopian45721772010-08-12 15:03:26 -0700949 const sp<LayerBase>& layer(layers[i]);
950 const Region clip(dirty.intersect(layer->visibleRegionScreen));
951 if (!clip.isEmpty()) {
952 layer->draw(clip);
953 }
954 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800955}
956
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800957void SurfaceFlinger::debugFlashRegions()
958{
Mathias Agopian0a917752010-06-14 21:20:00 -0700959 const DisplayHardware& hw(graphicPlane(0).displayHardware());
960 const uint32_t flags = hw.getFlags();
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700961
Mathias Agopian0a917752010-06-14 21:20:00 -0700962 if (!((flags & DisplayHardware::SWAP_RECTANGLE) ||
963 (flags & DisplayHardware::BUFFER_PRESERVED))) {
964 const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
965 mDirtyRegion.bounds() : hw.bounds());
966 composeSurfaces(repaint);
967 }
968
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800969 glDisable(GL_BLEND);
970 glDisable(GL_DITHER);
971 glDisable(GL_SCISSOR_TEST);
972
Mathias Agopian0926f502009-05-04 14:17:04 -0700973 static int toggle = 0;
974 toggle = 1 - toggle;
975 if (toggle) {
Mathias Agopian0a917752010-06-14 21:20:00 -0700976 glColor4f(1, 0, 1, 1);
Mathias Agopian0926f502009-05-04 14:17:04 -0700977 } else {
Mathias Agopian0a917752010-06-14 21:20:00 -0700978 glColor4f(1, 1, 0, 1);
Mathias Agopian0926f502009-05-04 14:17:04 -0700979 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800980
Mathias Agopian20f68782009-05-11 00:03:41 -0700981 Region::const_iterator it = mDirtyRegion.begin();
982 Region::const_iterator const end = mDirtyRegion.end();
983 while (it != end) {
984 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800985 GLfloat vertices[][2] = {
986 { r.left, r.top },
987 { r.left, r.bottom },
988 { r.right, r.bottom },
989 { r.right, r.top }
990 };
991 glVertexPointer(2, GL_FLOAT, 0, vertices);
992 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
993 }
Mathias Agopian0a917752010-06-14 21:20:00 -0700994
Mathias Agopianb8a55602009-06-26 19:06:36 -0700995 if (mInvalidRegion.isEmpty()) {
996 mDirtyRegion.dump("mDirtyRegion");
997 mInvalidRegion.dump("mInvalidRegion");
998 }
999 hw.flip(mInvalidRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001000
1001 if (mDebugRegion > 1)
Mathias Agopian0a917752010-06-14 21:20:00 -07001002 usleep(mDebugRegion * 1000);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001003
1004 glEnable(GL_SCISSOR_TEST);
1005 //mDirtyRegion.dump("mDirtyRegion");
1006}
1007
1008void SurfaceFlinger::drawWormhole() const
1009{
1010 const Region region(mWormholeRegion.intersect(mDirtyRegion));
1011 if (region.isEmpty())
1012 return;
1013
1014 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1015 const int32_t width = hw.getWidth();
1016 const int32_t height = hw.getHeight();
1017
1018 glDisable(GL_BLEND);
1019 glDisable(GL_DITHER);
1020
1021 if (LIKELY(!mDebugBackground)) {
Mathias Agopian0a917752010-06-14 21:20:00 -07001022 glClearColor(0,0,0,0);
Mathias Agopian20f68782009-05-11 00:03:41 -07001023 Region::const_iterator it = region.begin();
1024 Region::const_iterator const end = region.end();
1025 while (it != end) {
1026 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001027 const GLint sy = height - (r.top + r.height());
1028 glScissor(r.left, sy, r.width(), r.height());
1029 glClear(GL_COLOR_BUFFER_BIT);
1030 }
1031 } else {
1032 const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
1033 { width, height }, { 0, height } };
1034 const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
1035 glVertexPointer(2, GL_SHORT, 0, vertices);
1036 glTexCoordPointer(2, GL_SHORT, 0, tcoords);
1037 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Michael I. Gold7f198b62010-09-15 15:46:24 -07001038#if defined(GL_OES_EGL_image_external)
Mathias Agopian1f7bec62010-06-25 18:02:21 -07001039 if (GLExtensions::getInstance().haveTextureExternal()) {
1040 glDisable(GL_TEXTURE_EXTERNAL_OES);
1041 }
Mathias Agopian0a917752010-06-14 21:20:00 -07001042#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001043 glEnable(GL_TEXTURE_2D);
1044 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
1045 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1046 glMatrixMode(GL_TEXTURE);
1047 glLoadIdentity();
1048 glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
Mathias Agopian20f68782009-05-11 00:03:41 -07001049 Region::const_iterator it = region.begin();
1050 Region::const_iterator const end = region.end();
1051 while (it != end) {
1052 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001053 const GLint sy = height - (r.top + r.height());
1054 glScissor(r.left, sy, r.width(), r.height());
1055 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1056 }
1057 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopiana67932f2011-04-20 14:20:59 -07001058 glDisable(GL_TEXTURE_2D);
Mathias Agopianebeb7092010-12-14 18:38:36 -08001059 glLoadIdentity();
1060 glMatrixMode(GL_MODELVIEW);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001061 }
1062}
1063
1064void SurfaceFlinger::debugShowFPS() const
1065{
1066 static int mFrameCount;
1067 static int mLastFrameCount = 0;
1068 static nsecs_t mLastFpsTime = 0;
1069 static float mFps = 0;
1070 mFrameCount++;
1071 nsecs_t now = systemTime();
1072 nsecs_t diff = now - mLastFpsTime;
1073 if (diff > ms2ns(250)) {
1074 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff;
1075 mLastFpsTime = now;
1076 mLastFrameCount = mFrameCount;
1077 }
1078 // XXX: mFPS has the value we want
1079 }
1080
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001081status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001082{
1083 Mutex::Autolock _l(mStateLock);
1084 addLayer_l(layer);
1085 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1086 return NO_ERROR;
1087}
1088
Mathias Agopian96f08192010-06-02 23:28:45 -07001089status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer)
1090{
Mathias Agopianf6679fc2010-08-10 18:09:09 -07001091 ssize_t i = mCurrentState.layersSortedByZ.add(layer);
Mathias Agopian96f08192010-06-02 23:28:45 -07001092 return (i < 0) ? status_t(i) : status_t(NO_ERROR);
1093}
1094
1095ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
1096 const sp<LayerBaseClient>& lbc)
1097{
Mathias Agopian96f08192010-06-02 23:28:45 -07001098 // attach this layer to the client
Mathias Agopian4f113742011-05-03 16:21:41 -07001099 size_t name = client->attachLayer(lbc);
1100
1101 Mutex::Autolock _l(mStateLock);
Mathias Agopian96f08192010-06-02 23:28:45 -07001102
1103 // add this layer to the current state list
1104 addLayer_l(lbc);
1105
Mathias Agopian4f113742011-05-03 16:21:41 -07001106 return ssize_t(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001107}
1108
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001109status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001110{
1111 Mutex::Autolock _l(mStateLock);
Mathias Agopian3d579642009-06-04 18:46:21 -07001112 status_t err = purgatorizeLayer_l(layer);
1113 if (err == NO_ERROR)
1114 setTransactionFlags(eTransactionNeeded);
1115 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001116}
1117
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001118status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001119{
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001120 sp<LayerBaseClient> lbc(layerBase->getLayerBaseClient());
1121 if (lbc != 0) {
Mathias Agopian0d156122011-01-25 20:17:45 -08001122 mLayerMap.removeItem( lbc->getSurfaceBinder() );
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001123 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001124 ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase);
1125 if (index >= 0) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001126 mLayersRemoved = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001127 return NO_ERROR;
1128 }
Mathias Agopian3d579642009-06-04 18:46:21 -07001129 return status_t(index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001130}
1131
Mathias Agopian9a112062009-04-17 19:36:26 -07001132status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase)
1133{
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001134 // First add the layer to the purgatory list, which makes sure it won't
1135 // go away, then remove it from the main list (through a transaction).
Mathias Agopian9a112062009-04-17 19:36:26 -07001136 ssize_t err = removeLayer_l(layerBase);
Mathias Agopian76cd4dd2011-01-14 17:37:42 -08001137 if (err >= 0) {
1138 mLayerPurgatory.add(layerBase);
1139 }
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001140
Mathias Agopian0b3ad462009-10-02 18:12:30 -07001141 layerBase->onRemoved();
1142
Mathias Agopian3d579642009-06-04 18:46:21 -07001143 // it's possible that we don't find a layer, because it might
1144 // have been destroyed already -- this is not technically an error
Mathias Agopian96f08192010-06-02 23:28:45 -07001145 // from the user because there is a race between Client::destroySurface(),
1146 // ~Client() and ~ISurface().
Mathias Agopian9a112062009-04-17 19:36:26 -07001147 return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err;
1148}
1149
Mathias Agopian96f08192010-06-02 23:28:45 -07001150status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001151{
Mathias Agopian96f08192010-06-02 23:28:45 -07001152 layer->forceVisibilityTransaction();
1153 setTransactionFlags(eTraversalNeeded);
1154 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001155}
1156
Mathias Agopiandea20b12011-05-03 17:04:02 -07001157uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
1158{
1159 return android_atomic_release_load(&mTransactionFlags);
1160}
1161
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001162uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1163{
1164 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1165}
1166
Mathias Agopianbb641242010-05-18 17:06:55 -07001167uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001168{
1169 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1170 if ((old & flags)==0) { // wake the server up
Mathias Agopianbb641242010-05-18 17:06:55 -07001171 signalEvent();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001172 }
1173 return old;
1174}
1175
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001176
Mathias Agopian698c0872011-06-28 19:09:31 -07001177void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state) {
1178 Mutex::Autolock _l(mStateLock);
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001179
Mathias Agopian698c0872011-06-28 19:09:31 -07001180 uint32_t flags = 0;
1181 const size_t count = state.size();
1182 for (size_t i=0 ; i<count ; i++) {
1183 const ComposerState& s(state[i]);
1184 sp<Client> client( static_cast<Client *>(s.client.get()) );
1185 flags |= setClientStateLocked(client, s.state);
1186 }
1187 if (flags) {
1188 setTransactionFlags(flags);
1189 }
1190
1191 signalEvent();
1192
1193 // if there is a transaction with a resize, wait for it to
1194 // take effect before returning.
1195 while (mResizeTransationPending) {
1196 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1197 if (CC_UNLIKELY(err != NO_ERROR)) {
1198 // just in case something goes wrong in SF, return to the
1199 // called after a few seconds.
1200 LOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!");
1201 mResizeTransationPending = false;
1202 break;
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001203 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001204 }
1205}
1206
1207status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags)
1208{
1209 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1210 return BAD_VALUE;
1211
1212 Mutex::Autolock _l(mStateLock);
1213 mCurrentState.freezeDisplay = 1;
1214 setTransactionFlags(eTransactionNeeded);
1215
1216 // flags is intended to communicate some sort of animation behavior
Mathias Agopian62b74442009-04-14 23:02:51 -07001217 // (for instance fading)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001218 return NO_ERROR;
1219}
1220
1221status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags)
1222{
1223 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1224 return BAD_VALUE;
1225
1226 Mutex::Autolock _l(mStateLock);
1227 mCurrentState.freezeDisplay = 0;
1228 setTransactionFlags(eTransactionNeeded);
1229
1230 // flags is intended to communicate some sort of animation behavior
Mathias Agopian62b74442009-04-14 23:02:51 -07001231 // (for instance fading)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001232 return NO_ERROR;
1233}
1234
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001235int SurfaceFlinger::setOrientation(DisplayID dpy,
Mathias Agopianc08731e2009-03-27 18:11:38 -07001236 int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001237{
1238 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1239 return BAD_VALUE;
1240
1241 Mutex::Autolock _l(mStateLock);
1242 if (mCurrentState.orientation != orientation) {
1243 if (uint32_t(orientation)<=eOrientation270 || orientation==42) {
Mathias Agopianc08731e2009-03-27 18:11:38 -07001244 mCurrentState.orientationType = flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001245 mCurrentState.orientation = orientation;
1246 setTransactionFlags(eTransactionNeeded);
1247 mTransactionCV.wait(mStateLock);
1248 } else {
1249 orientation = BAD_VALUE;
1250 }
1251 }
1252 return orientation;
1253}
1254
Mathias Agopian0ef4e152011-04-20 14:19:32 -07001255sp<ISurface> SurfaceFlinger::createSurface(
1256 ISurfaceComposerClient::surface_data_t* params,
1257 const String8& name,
1258 const sp<Client>& client,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001259 DisplayID d, uint32_t w, uint32_t h, PixelFormat format,
1260 uint32_t flags)
1261{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001262 sp<LayerBaseClient> layer;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001263 sp<ISurface> surfaceHandle;
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001264
1265 if (int32_t(w|h) < 0) {
1266 LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)",
1267 int(w), int(h));
1268 return surfaceHandle;
1269 }
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001270
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001271 //LOGD("createSurface for pid %d (%d x %d)", pid, w, h);
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001272 sp<Layer> normalLayer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001273 switch (flags & eFXSurfaceMask) {
1274 case eFXSurfaceNormal:
Mathias Agopiana5529c82010-12-07 19:38:17 -08001275 normalLayer = createNormalSurface(client, d, w, h, flags, format);
1276 layer = normalLayer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001277 break;
1278 case eFXSurfaceBlur:
Mathias Agopian1293a8e2010-12-08 17:13:19 -08001279 // for now we treat Blur as Dim, until we can implement it
1280 // efficiently.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001281 case eFXSurfaceDim:
Mathias Agopian96f08192010-06-02 23:28:45 -07001282 layer = createDimSurface(client, d, w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001283 break;
1284 }
1285
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001286 if (layer != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001287 layer->initStates(w, h, flags);
Mathias Agopian285dbde2010-03-01 16:09:43 -08001288 layer->setName(name);
Mathias Agopian96f08192010-06-02 23:28:45 -07001289 ssize_t token = addClientLayer(client, layer);
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001290
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001291 surfaceHandle = layer->getSurface();
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001292 if (surfaceHandle != 0) {
Mathias Agopian96f08192010-06-02 23:28:45 -07001293 params->token = token;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001294 params->identity = layer->getIdentity();
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001295 params->width = w;
1296 params->height = h;
1297 params->format = format;
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001298 if (normalLayer != 0) {
1299 Mutex::Autolock _l(mStateLock);
Mathias Agopiana67932f2011-04-20 14:20:59 -07001300 mLayerMap.add(layer->getSurfaceBinder(), normalLayer);
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001301 }
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001302 }
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001303
Mathias Agopian96f08192010-06-02 23:28:45 -07001304 setTransactionFlags(eTransactionNeeded);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001305 }
1306
1307 return surfaceHandle;
1308}
1309
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001310sp<Layer> SurfaceFlinger::createNormalSurface(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001311 const sp<Client>& client, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -07001312 uint32_t w, uint32_t h, uint32_t flags,
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001313 PixelFormat& format)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001314{
1315 // initialize the surfaces
1316 switch (format) { // TODO: take h/w into account
1317 case PIXEL_FORMAT_TRANSPARENT:
1318 case PIXEL_FORMAT_TRANSLUCENT:
1319 format = PIXEL_FORMAT_RGBA_8888;
1320 break;
1321 case PIXEL_FORMAT_OPAQUE:
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001322#ifdef NO_RGBX_8888
1323 format = PIXEL_FORMAT_RGB_565;
1324#else
Mathias Agopian8f105402010-04-05 18:01:24 -07001325 format = PIXEL_FORMAT_RGBX_8888;
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001326#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001327 break;
1328 }
1329
Mathias Agopiana8f3e4e2010-06-30 15:43:47 -07001330#ifdef NO_RGBX_8888
1331 if (format == PIXEL_FORMAT_RGBX_8888)
1332 format = PIXEL_FORMAT_RGBA_8888;
1333#endif
1334
Mathias Agopian96f08192010-06-02 23:28:45 -07001335 sp<Layer> layer = new Layer(this, display, client);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001336 status_t err = layer->setBuffers(w, h, format, flags);
Mathias Agopian96f08192010-06-02 23:28:45 -07001337 if (LIKELY(err != NO_ERROR)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001338 LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001339 layer.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001340 }
1341 return layer;
1342}
1343
Mathias Agopianb7e930d2010-06-01 15:12:58 -07001344sp<LayerDim> SurfaceFlinger::createDimSurface(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001345 const sp<Client>& client, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -07001346 uint32_t w, uint32_t h, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001347{
Mathias Agopian96f08192010-06-02 23:28:45 -07001348 sp<LayerDim> layer = new LayerDim(this, display, client);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001349 layer->initStates(w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001350 return layer;
1351}
1352
Mathias Agopian96f08192010-06-02 23:28:45 -07001353status_t SurfaceFlinger::removeSurface(const sp<Client>& client, SurfaceID sid)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001354{
Mathias Agopian9a112062009-04-17 19:36:26 -07001355 /*
1356 * called by the window manager, when a surface should be marked for
1357 * destruction.
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001358 *
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001359 * The surface is removed from the current and drawing lists, but placed
1360 * in the purgatory queue, so it's not destroyed right-away (we need
1361 * to wait for all client's references to go away first).
Mathias Agopian9a112062009-04-17 19:36:26 -07001362 */
Mathias Agopian9a112062009-04-17 19:36:26 -07001363
Mathias Agopian48d819a2009-09-10 19:41:18 -07001364 status_t err = NAME_NOT_FOUND;
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001365 Mutex::Autolock _l(mStateLock);
Mathias Agopian96f08192010-06-02 23:28:45 -07001366 sp<LayerBaseClient> layer = client->getLayerUser(sid);
Mathias Agopian48d819a2009-09-10 19:41:18 -07001367 if (layer != 0) {
1368 err = purgatorizeLayer_l(layer);
1369 if (err == NO_ERROR) {
Mathias Agopian48d819a2009-09-10 19:41:18 -07001370 setTransactionFlags(eTransactionNeeded);
1371 }
Mathias Agopian9a112062009-04-17 19:36:26 -07001372 }
1373 return err;
1374}
1375
Mathias Agopianca4d3602011-05-19 15:38:14 -07001376status_t SurfaceFlinger::destroySurface(const wp<LayerBaseClient>& layer)
Mathias Agopian9a112062009-04-17 19:36:26 -07001377{
Mathias Agopian759fdb22009-07-02 17:33:40 -07001378 // called by ~ISurface() when all references are gone
Mathias Agopianca4d3602011-05-19 15:38:14 -07001379 status_t err = NO_ERROR;
1380 sp<LayerBaseClient> l(layer.promote());
1381 if (l != NULL) {
1382 Mutex::Autolock _l(mStateLock);
1383 err = removeLayer_l(l);
1384 if (err == NAME_NOT_FOUND) {
1385 // The surface wasn't in the current list, which means it was
1386 // removed already, which means it is in the purgatory,
1387 // and need to be removed from there.
1388 ssize_t idx = mLayerPurgatory.remove(l);
1389 LOGE_IF(idx < 0,
1390 "layer=%p is not in the purgatory list", l.get());
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001391 }
Mathias Agopianca4d3602011-05-19 15:38:14 -07001392 LOGE_IF(err<0 && err != NAME_NOT_FOUND,
1393 "error removing layer=%p (%s)", l.get(), strerror(-err));
1394 }
1395 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001396}
1397
Mathias Agopian698c0872011-06-28 19:09:31 -07001398uint32_t SurfaceFlinger::setClientStateLocked(
Mathias Agopian96f08192010-06-02 23:28:45 -07001399 const sp<Client>& client,
Mathias Agopian698c0872011-06-28 19:09:31 -07001400 const layer_state_t& s)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001401{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001402 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -07001403 sp<LayerBaseClient> layer(client->getLayerUser(s.surface));
1404 if (layer != 0) {
1405 const uint32_t what = s.what;
1406 if (what & ePositionChanged) {
1407 if (layer->setPosition(s.x, s.y))
1408 flags |= eTraversalNeeded;
1409 }
1410 if (what & eLayerChanged) {
1411 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1412 if (layer->setLayer(s.z)) {
1413 mCurrentState.layersSortedByZ.removeAt(idx);
1414 mCurrentState.layersSortedByZ.add(layer);
1415 // we need traversal (state changed)
1416 // AND transaction (list changed)
1417 flags |= eTransactionNeeded|eTraversalNeeded;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001418 }
1419 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001420 if (what & eSizeChanged) {
1421 if (layer->setSize(s.w, s.h)) {
1422 flags |= eTraversalNeeded;
1423 mResizeTransationPending = true;
1424 }
1425 }
1426 if (what & eAlphaChanged) {
1427 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1428 flags |= eTraversalNeeded;
1429 }
1430 if (what & eMatrixChanged) {
1431 if (layer->setMatrix(s.matrix))
1432 flags |= eTraversalNeeded;
1433 }
1434 if (what & eTransparentRegionChanged) {
1435 if (layer->setTransparentRegionHint(s.transparentRegion))
1436 flags |= eTraversalNeeded;
1437 }
1438 if (what & eVisibilityChanged) {
1439 if (layer->setFlags(s.flags, s.mask))
1440 flags |= eTraversalNeeded;
1441 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001442 }
Mathias Agopian698c0872011-06-28 19:09:31 -07001443 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001444}
1445
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001446void SurfaceFlinger::screenReleased(int dpy)
1447{
1448 // this may be called by a signal handler, we can't do too much in here
1449 android_atomic_or(eConsoleReleased, &mConsoleSignals);
1450 signalEvent();
1451}
1452
1453void SurfaceFlinger::screenAcquired(int dpy)
1454{
1455 // this may be called by a signal handler, we can't do too much in here
1456 android_atomic_or(eConsoleAcquired, &mConsoleSignals);
1457 signalEvent();
1458}
1459
1460status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
1461{
Erik Gilling1d21a9c2010-12-01 16:38:01 -08001462 const size_t SIZE = 4096;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001463 char buffer[SIZE];
1464 String8 result;
Mathias Agopian99b49842011-06-27 16:05:52 -07001465
1466 if (!PermissionCache::checkCallingPermission(sDump)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001467 snprintf(buffer, SIZE, "Permission Denial: "
1468 "can't dump SurfaceFlinger from pid=%d, uid=%d\n",
1469 IPCThreadState::self()->getCallingPid(),
1470 IPCThreadState::self()->getCallingUid());
1471 result.append(buffer);
1472 } else {
Mathias Agopian9795c422009-08-26 16:36:26 -07001473
1474 // figure out if we're stuck somewhere
1475 const nsecs_t now = systemTime();
1476 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
1477 const nsecs_t inTransaction(mDebugInTransaction);
1478 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
1479 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
1480
1481 // Try to get the main lock, but don't insist if we can't
1482 // (this would indicate SF is stuck, but we want to be able to
1483 // print something in dumpsys).
1484 int retry = 3;
1485 while (mStateLock.tryLock()<0 && --retry>=0) {
1486 usleep(1000000);
1487 }
1488 const bool locked(retry >= 0);
1489 if (!locked) {
Andreas Huber8b42e8a2010-08-16 08:49:37 -07001490 snprintf(buffer, SIZE,
Mathias Agopian9795c422009-08-26 16:36:26 -07001491 "SurfaceFlinger appears to be unresponsive, "
1492 "dumping anyways (no locks held)\n");
1493 result.append(buffer);
1494 }
1495
Mathias Agopian48b888a2011-01-19 16:15:53 -08001496 /*
1497 * Dump the visible layer list
1498 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001499 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1500 const size_t count = currentLayers.size();
Mathias Agopian48b888a2011-01-19 16:15:53 -08001501 snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count);
1502 result.append(buffer);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001503 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001504 const sp<LayerBase>& layer(currentLayers[i]);
1505 layer->dump(result, buffer, SIZE);
1506 const Layer::State& s(layer->drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001507 s.transparentRegion.dump(result, "transparentRegion");
1508 layer->transparentRegionScreen.dump(result, "transparentRegionScreen");
1509 layer->visibleRegionScreen.dump(result, "visibleRegionScreen");
1510 }
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001511
Mathias Agopian48b888a2011-01-19 16:15:53 -08001512 /*
1513 * Dump the layers in the purgatory
1514 */
1515
1516 const size_t purgatorySize = mLayerPurgatory.size();
1517 snprintf(buffer, SIZE, "Purgatory state (%d entries)\n", purgatorySize);
1518 result.append(buffer);
1519 for (size_t i=0 ; i<purgatorySize ; i++) {
1520 const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
1521 layer->shortDump(result, buffer, SIZE);
1522 }
1523
1524 /*
1525 * Dump SurfaceFlinger global state
1526 */
1527
1528 snprintf(buffer, SIZE, "SurfaceFlinger global state\n");
1529 result.append(buffer);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001530 mWormholeRegion.dump(result, "WormholeRegion");
1531 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1532 snprintf(buffer, SIZE,
1533 " display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n",
1534 mFreezeDisplay?"yes":"no", mFreezeCount,
1535 mCurrentState.orientation, hw.canDraw());
1536 result.append(buffer);
Mathias Agopian9795c422009-08-26 16:36:26 -07001537 snprintf(buffer, SIZE,
1538 " last eglSwapBuffers() time: %f us\n"
1539 " last transaction time : %f us\n",
1540 mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0);
1541 result.append(buffer);
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001542
Mathias Agopian9795c422009-08-26 16:36:26 -07001543 if (inSwapBuffersDuration || !locked) {
1544 snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
1545 inSwapBuffersDuration/1000.0);
1546 result.append(buffer);
1547 }
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001548
Mathias Agopian9795c422009-08-26 16:36:26 -07001549 if (inTransactionDuration || !locked) {
1550 snprintf(buffer, SIZE, " transaction time: %f us\n",
1551 inTransactionDuration/1000.0);
1552 result.append(buffer);
1553 }
Mathias Agopian1b5e1022010-04-20 17:55:49 -07001554
Mathias Agopian48b888a2011-01-19 16:15:53 -08001555 /*
1556 * Dump HWComposer state
1557 */
Mathias Agopian73d3ba92010-09-22 18:58:01 -07001558 HWComposer& hwc(hw.getHwComposer());
1559 snprintf(buffer, SIZE, " h/w composer %s and %s\n",
1560 hwc.initCheck()==NO_ERROR ? "present" : "not present",
1561 mDebugDisableHWC ? "disabled" : "enabled");
1562 result.append(buffer);
Mathias Agopian83727852010-09-23 18:13:21 -07001563 hwc.dump(result, buffer, SIZE);
Mathias Agopian73d3ba92010-09-22 18:58:01 -07001564
Mathias Agopian48b888a2011-01-19 16:15:53 -08001565 /*
1566 * Dump gralloc state
1567 */
Mathias Agopian3330b202009-10-05 17:07:12 -07001568 const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001569 alloc.dump(result);
Erik Gilling1d21a9c2010-12-01 16:38:01 -08001570 hw.dump(result);
Mathias Agopian9795c422009-08-26 16:36:26 -07001571
1572 if (locked) {
1573 mStateLock.unlock();
1574 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001575 }
1576 write(fd, result.string(), result.size());
1577 return NO_ERROR;
1578}
1579
1580status_t SurfaceFlinger::onTransact(
1581 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1582{
1583 switch (code) {
1584 case CREATE_CONNECTION:
Mathias Agopian698c0872011-06-28 19:09:31 -07001585 case SET_TRANSACTION_STATE:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001586 case SET_ORIENTATION:
1587 case FREEZE_DISPLAY:
1588 case UNFREEZE_DISPLAY:
1589 case BOOT_FINISHED:
Mathias Agopian59119e62010-10-11 12:37:43 -07001590 case TURN_ELECTRON_BEAM_OFF:
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001591 case TURN_ELECTRON_BEAM_ON:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001592 {
1593 // codes that require permission check
1594 IPCThreadState* ipc = IPCThreadState::self();
1595 const int pid = ipc->getCallingPid();
Mathias Agopiana1ecca92009-05-21 19:21:59 -07001596 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07001597 if ((uid != AID_GRAPHICS) &&
1598 !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
Mathias Agopian375f5632009-06-15 18:24:59 -07001599 LOGE("Permission Denial: "
1600 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
1601 return PERMISSION_DENIED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001602 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001603 break;
1604 }
1605 case CAPTURE_SCREEN:
1606 {
1607 // codes that require permission check
1608 IPCThreadState* ipc = IPCThreadState::self();
1609 const int pid = ipc->getCallingPid();
1610 const int uid = ipc->getCallingUid();
Mathias Agopian99b49842011-06-27 16:05:52 -07001611 if ((uid != AID_GRAPHICS) &&
1612 !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001613 LOGE("Permission Denial: "
1614 "can't read framebuffer pid=%d, uid=%d", pid, uid);
1615 return PERMISSION_DENIED;
1616 }
1617 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001618 }
1619 }
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07001620
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001621 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
1622 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
Mathias Agopianb8a55602009-06-26 19:06:36 -07001623 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Mathias Agopian99b49842011-06-27 16:05:52 -07001624 if (UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
Mathias Agopian375f5632009-06-15 18:24:59 -07001625 IPCThreadState* ipc = IPCThreadState::self();
1626 const int pid = ipc->getCallingPid();
1627 const int uid = ipc->getCallingUid();
1628 LOGE("Permission Denial: "
1629 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001630 return PERMISSION_DENIED;
1631 }
1632 int n;
1633 switch (code) {
Mathias Agopian01b76682009-04-16 20:04:08 -07001634 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
Mathias Agopian35b48d12010-09-13 22:57:58 -07001635 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001636 return NO_ERROR;
1637 case 1002: // SHOW_UPDATES
1638 n = data.readInt32();
1639 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
1640 return NO_ERROR;
1641 case 1003: // SHOW_BACKGROUND
1642 n = data.readInt32();
1643 mDebugBackground = n ? 1 : 0;
1644 return NO_ERROR;
Mathias Agopian73d3ba92010-09-22 18:58:01 -07001645 case 1008: // toggle use of hw composer
1646 n = data.readInt32();
1647 mDebugDisableHWC = n ? 1 : 0;
Mathias Agopianad456f92011-01-13 17:53:01 -08001648 invalidateHwcGeometry();
Mathias Agopian73d3ba92010-09-22 18:58:01 -07001649 // fall-through...
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001650 case 1004:{ // repaint everything
1651 Mutex::Autolock _l(mStateLock);
1652 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1653 mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe
1654 signalEvent();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001655 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001656 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001657 case 1005:{ // force transaction
1658 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1659 return NO_ERROR;
1660 }
Mathias Agopian35b48d12010-09-13 22:57:58 -07001661 case 1006:{ // enable/disable GraphicLog
1662 int enabled = data.readInt32();
1663 GraphicLog::getInstance().setEnabled(enabled);
1664 return NO_ERROR;
1665 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001666 case 1007: // set mFreezeCount
1667 mFreezeCount = data.readInt32();
Mathias Agopian04087722009-12-01 17:23:28 -08001668 mFreezeDisplayTime = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001669 return NO_ERROR;
1670 case 1010: // interrogate.
Mathias Agopian01b76682009-04-16 20:04:08 -07001671 reply->writeInt32(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001672 reply->writeInt32(0);
1673 reply->writeInt32(mDebugRegion);
1674 reply->writeInt32(mDebugBackground);
1675 return NO_ERROR;
1676 case 1013: {
1677 Mutex::Autolock _l(mStateLock);
1678 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1679 reply->writeInt32(hw.getPageFlipCount());
1680 }
1681 return NO_ERROR;
1682 }
1683 }
1684 return err;
1685}
1686
Mathias Agopian59119e62010-10-11 12:37:43 -07001687// ---------------------------------------------------------------------------
1688
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001689status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
1690 GLuint* textureName, GLfloat* uOut, GLfloat* vOut)
Mathias Agopian59119e62010-10-11 12:37:43 -07001691{
Mathias Agopian59119e62010-10-11 12:37:43 -07001692 if (!GLExtensions::getInstance().haveFramebufferObject())
1693 return INVALID_OPERATION;
1694
1695 // get screen geometry
Mathias Agopian59119e62010-10-11 12:37:43 -07001696 const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
Mathias Agopian59119e62010-10-11 12:37:43 -07001697 const uint32_t hw_w = hw.getWidth();
1698 const uint32_t hw_h = hw.getHeight();
Mathias Agopian59119e62010-10-11 12:37:43 -07001699 GLfloat u = 1;
1700 GLfloat v = 1;
1701
1702 // make sure to clear all GL error flags
1703 while ( glGetError() != GL_NO_ERROR ) ;
1704
1705 // create a FBO
1706 GLuint name, tname;
1707 glGenTextures(1, &tname);
1708 glBindTexture(GL_TEXTURE_2D, tname);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001709 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
1710 hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07001711 if (glGetError() != GL_NO_ERROR) {
Mathias Agopian015fb3f2010-10-14 12:19:37 -07001712 while ( glGetError() != GL_NO_ERROR ) ;
Mathias Agopian59119e62010-10-11 12:37:43 -07001713 GLint tw = (2 << (31 - clz(hw_w)));
1714 GLint th = (2 << (31 - clz(hw_h)));
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001715 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
1716 tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07001717 u = GLfloat(hw_w) / tw;
1718 v = GLfloat(hw_h) / th;
1719 }
1720 glGenFramebuffersOES(1, &name);
1721 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001722 glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
1723 GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
Mathias Agopian59119e62010-10-11 12:37:43 -07001724
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001725 // redraw the screen entirely...
1726 glClearColor(0,0,0,1);
1727 glClear(GL_COLOR_BUFFER_BIT);
1728 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
1729 const size_t count = layers.size();
1730 for (size_t i=0 ; i<count ; ++i) {
1731 const sp<LayerBase>& layer(layers[i]);
1732 layer->drawForSreenShot();
1733 }
1734
1735 // back to main framebuffer
1736 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
1737 glDisable(GL_SCISSOR_TEST);
1738 glDeleteFramebuffersOES(1, &name);
1739
1740 *textureName = tname;
1741 *uOut = u;
1742 *vOut = v;
1743 return NO_ERROR;
1744}
1745
1746// ---------------------------------------------------------------------------
1747
1748status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
1749{
1750 status_t result = PERMISSION_DENIED;
1751
1752 if (!GLExtensions::getInstance().haveFramebufferObject())
1753 return INVALID_OPERATION;
1754
1755 // get screen geometry
1756 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1757 const uint32_t hw_w = hw.getWidth();
1758 const uint32_t hw_h = hw.getHeight();
1759 const Region screenBounds(hw.bounds());
1760
1761 GLfloat u, v;
1762 GLuint tname;
1763 result = renderScreenToTextureLocked(0, &tname, &u, &v);
1764 if (result != NO_ERROR) {
1765 return result;
1766 }
1767
1768 GLfloat vtx[8];
1769 const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001770 glBindTexture(GL_TEXTURE_2D, tname);
1771 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1772 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1773 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1774 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
1775 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1776 glVertexPointer(2, GL_FLOAT, 0, vtx);
1777
1778 class s_curve_interpolator {
1779 const float nbFrames, s, v;
1780 public:
1781 s_curve_interpolator(int nbFrames, float s)
1782 : nbFrames(1.0f / (nbFrames-1)), s(s),
1783 v(1.0f + expf(-s + 0.5f*s)) {
1784 }
1785 float operator()(int f) {
1786 const float x = f * nbFrames;
1787 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
1788 }
1789 };
1790
1791 class v_stretch {
1792 const GLfloat hw_w, hw_h;
1793 public:
1794 v_stretch(uint32_t hw_w, uint32_t hw_h)
1795 : hw_w(hw_w), hw_h(hw_h) {
1796 }
1797 void operator()(GLfloat* vtx, float v) {
1798 const GLfloat w = hw_w + (hw_w * v);
1799 const GLfloat h = hw_h - (hw_h * v);
1800 const GLfloat x = (hw_w - w) * 0.5f;
1801 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopian2dbf9ff2011-06-30 16:23:39 -07001802 vtx[0] = x; vtx[1] = y + h;
1803 vtx[2] = x; vtx[3] = y;
1804 vtx[4] = x + w; vtx[5] = y;
1805 vtx[6] = x + w; vtx[7] = y + h;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001806 }
1807 };
1808
1809 class h_stretch {
1810 const GLfloat hw_w, hw_h;
1811 public:
1812 h_stretch(uint32_t hw_w, uint32_t hw_h)
1813 : hw_w(hw_w), hw_h(hw_h) {
1814 }
1815 void operator()(GLfloat* vtx, float v) {
1816 const GLfloat w = hw_w - (hw_w * v);
1817 const GLfloat h = 1.0f;
1818 const GLfloat x = (hw_w - w) * 0.5f;
1819 const GLfloat y = (hw_h - h) * 0.5f;
Mathias Agopian2dbf9ff2011-06-30 16:23:39 -07001820 vtx[0] = x; vtx[1] = y + h;
1821 vtx[2] = x; vtx[3] = y;
1822 vtx[4] = x + w; vtx[5] = y;
1823 vtx[6] = x + w; vtx[7] = y + h;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001824 }
1825 };
1826
1827 // the full animation is 24 frames
1828 const int nbFrames = 12;
1829 s_curve_interpolator itr(nbFrames, 7.5f);
1830 s_curve_interpolator itg(nbFrames, 8.0f);
1831 s_curve_interpolator itb(nbFrames, 8.5f);
1832
1833 v_stretch vverts(hw_w, hw_h);
1834 glEnable(GL_BLEND);
1835 glBlendFunc(GL_ONE, GL_ONE);
1836 for (int i=0 ; i<nbFrames ; i++) {
1837 float x, y, w, h;
1838 const float vr = itr(i);
1839 const float vg = itg(i);
1840 const float vb = itb(i);
1841
1842 // clear screen
1843 glColorMask(1,1,1,1);
Mathias Agopian59119e62010-10-11 12:37:43 -07001844 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopian59119e62010-10-11 12:37:43 -07001845 glEnable(GL_TEXTURE_2D);
Mathias Agopian59119e62010-10-11 12:37:43 -07001846
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001847 // draw the red plane
1848 vverts(vtx, vr);
1849 glColorMask(1,0,0,1);
1850 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07001851
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001852 // draw the green plane
1853 vverts(vtx, vg);
1854 glColorMask(0,1,0,1);
1855 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07001856
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001857 // draw the blue plane
1858 vverts(vtx, vb);
1859 glColorMask(0,0,1,1);
1860 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
Mathias Agopian59119e62010-10-11 12:37:43 -07001861
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001862 // draw the white highlight (we use the last vertices)
Mathias Agopian59119e62010-10-11 12:37:43 -07001863 glDisable(GL_TEXTURE_2D);
1864 glColorMask(1,1,1,1);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001865 glColor4f(vg, vg, vg, 1);
1866 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1867 hw.flip(screenBounds);
Mathias Agopian59119e62010-10-11 12:37:43 -07001868 }
1869
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001870 h_stretch hverts(hw_w, hw_h);
1871 glDisable(GL_BLEND);
1872 glDisable(GL_TEXTURE_2D);
1873 glColorMask(1,1,1,1);
1874 for (int i=0 ; i<nbFrames ; i++) {
1875 const float v = itg(i);
1876 hverts(vtx, v);
1877 glClear(GL_COLOR_BUFFER_BIT);
1878 glColor4f(1-v, 1-v, 1-v, 1);
1879 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1880 hw.flip(screenBounds);
1881 }
1882
1883 glColorMask(1,1,1,1);
1884 glEnable(GL_SCISSOR_TEST);
1885 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1886 glDeleteTextures(1, &tname);
Mathias Agopiana67932f2011-04-20 14:20:59 -07001887 glDisable(GL_TEXTURE_2D);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001888 return NO_ERROR;
1889}
1890
1891status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
1892{
1893 status_t result = PERMISSION_DENIED;
1894
1895 if (!GLExtensions::getInstance().haveFramebufferObject())
1896 return INVALID_OPERATION;
1897
1898
1899 // get screen geometry
1900 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1901 const uint32_t hw_w = hw.getWidth();
1902 const uint32_t hw_h = hw.getHeight();
1903 const Region screenBounds(hw.bounds());
1904
1905 GLfloat u, v;
1906 GLuint tname;
1907 result = renderScreenToTextureLocked(0, &tname, &u, &v);
1908 if (result != NO_ERROR) {
1909 return result;
1910 }
1911
1912 // back to main framebuffer
1913 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
1914 glDisable(GL_SCISSOR_TEST);
1915
1916 GLfloat vtx[8];
1917 const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001918 glBindTexture(GL_TEXTURE_2D, tname);
1919 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1920 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1921 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1922 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
1923 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1924 glVertexPointer(2, GL_FLOAT, 0, vtx);
1925
1926 class s_curve_interpolator {
1927 const float nbFrames, s, v;
1928 public:
1929 s_curve_interpolator(int nbFrames, float s)
1930 : nbFrames(1.0f / (nbFrames-1)), s(s),
1931 v(1.0f + expf(-s + 0.5f*s)) {
1932 }
1933 float operator()(int f) {
1934 const float x = f * nbFrames;
1935 return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
1936 }
1937 };
1938
1939 class v_stretch {
1940 const GLfloat hw_w, hw_h;
1941 public:
1942 v_stretch(uint32_t hw_w, uint32_t hw_h)
1943 : hw_w(hw_w), hw_h(hw_h) {
1944 }
1945 void operator()(GLfloat* vtx, float v) {
1946 const GLfloat w = hw_w + (hw_w * v);
1947 const GLfloat h = hw_h - (hw_h * v);
1948 const GLfloat x = (hw_w - w) * 0.5f;
1949 const GLfloat y = (hw_h - h) * 0.5f;
1950 vtx[0] = x; vtx[1] = y;
1951 vtx[2] = x; vtx[3] = y + h;
1952 vtx[4] = x + w; vtx[5] = y + h;
1953 vtx[6] = x + w; vtx[7] = y;
1954 }
1955 };
1956
1957 class h_stretch {
1958 const GLfloat hw_w, hw_h;
1959 public:
1960 h_stretch(uint32_t hw_w, uint32_t hw_h)
1961 : hw_w(hw_w), hw_h(hw_h) {
1962 }
1963 void operator()(GLfloat* vtx, float v) {
1964 const GLfloat w = hw_w - (hw_w * v);
1965 const GLfloat h = 1.0f;
1966 const GLfloat x = (hw_w - w) * 0.5f;
1967 const GLfloat y = (hw_h - h) * 0.5f;
1968 vtx[0] = x; vtx[1] = y;
1969 vtx[2] = x; vtx[3] = y + h;
1970 vtx[4] = x + w; vtx[5] = y + h;
1971 vtx[6] = x + w; vtx[7] = y;
1972 }
1973 };
1974
Mathias Agopiana6546e52010-10-14 12:33:07 -07001975 // the full animation is 12 frames
1976 int nbFrames = 8;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001977 s_curve_interpolator itr(nbFrames, 7.5f);
1978 s_curve_interpolator itg(nbFrames, 8.0f);
1979 s_curve_interpolator itb(nbFrames, 8.5f);
1980
1981 h_stretch hverts(hw_w, hw_h);
1982 glDisable(GL_BLEND);
1983 glDisable(GL_TEXTURE_2D);
1984 glColorMask(1,1,1,1);
1985 for (int i=nbFrames-1 ; i>=0 ; i--) {
1986 const float v = itg(i);
1987 hverts(vtx, v);
1988 glClear(GL_COLOR_BUFFER_BIT);
1989 glColor4f(1-v, 1-v, 1-v, 1);
1990 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1991 hw.flip(screenBounds);
1992 }
1993
Mathias Agopiana6546e52010-10-14 12:33:07 -07001994 nbFrames = 4;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07001995 v_stretch vverts(hw_w, hw_h);
1996 glEnable(GL_BLEND);
1997 glBlendFunc(GL_ONE, GL_ONE);
1998 for (int i=nbFrames-1 ; i>=0 ; i--) {
1999 float x, y, w, h;
2000 const float vr = itr(i);
2001 const float vg = itg(i);
2002 const float vb = itb(i);
2003
2004 // clear screen
2005 glColorMask(1,1,1,1);
2006 glClear(GL_COLOR_BUFFER_BIT);
2007 glEnable(GL_TEXTURE_2D);
2008
2009 // draw the red plane
2010 vverts(vtx, vr);
2011 glColorMask(1,0,0,1);
2012 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2013
2014 // draw the green plane
2015 vverts(vtx, vg);
2016 glColorMask(0,1,0,1);
2017 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2018
2019 // draw the blue plane
2020 vverts(vtx, vb);
2021 glColorMask(0,0,1,1);
2022 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
2023
2024 hw.flip(screenBounds);
2025 }
2026
2027 glColorMask(1,1,1,1);
2028 glEnable(GL_SCISSOR_TEST);
2029 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian59119e62010-10-11 12:37:43 -07002030 glDeleteTextures(1, &tname);
Mathias Agopiana67932f2011-04-20 14:20:59 -07002031 glDisable(GL_TEXTURE_2D);
Mathias Agopian59119e62010-10-11 12:37:43 -07002032
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002033 return NO_ERROR;
2034}
2035
2036// ---------------------------------------------------------------------------
2037
Mathias Agopianabd671a2010-10-14 14:54:06 -07002038status_t SurfaceFlinger::turnElectronBeamOffImplLocked(int32_t mode)
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002039{
2040 DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
2041 if (!hw.canDraw()) {
2042 // we're already off
2043 return NO_ERROR;
2044 }
Mathias Agopianabd671a2010-10-14 14:54:06 -07002045 if (mode & ISurfaceComposer::eElectronBeamAnimationOff) {
2046 electronBeamOffAnimationImplLocked();
2047 }
2048
2049 // always clear the whole screen at the end of the animation
2050 glClearColor(0,0,0,1);
2051 glDisable(GL_SCISSOR_TEST);
2052 glClear(GL_COLOR_BUFFER_BIT);
2053 glEnable(GL_SCISSOR_TEST);
2054 hw.flip( Region(hw.bounds()) );
2055
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002056 hw.setCanDraw(false);
2057 return NO_ERROR;
Mathias Agopian59119e62010-10-11 12:37:43 -07002058}
2059
2060status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode)
2061{
Mathias Agopian59119e62010-10-11 12:37:43 -07002062 class MessageTurnElectronBeamOff : public MessageBase {
2063 SurfaceFlinger* flinger;
Mathias Agopianabd671a2010-10-14 14:54:06 -07002064 int32_t mode;
Mathias Agopian59119e62010-10-11 12:37:43 -07002065 status_t result;
2066 public:
Mathias Agopianabd671a2010-10-14 14:54:06 -07002067 MessageTurnElectronBeamOff(SurfaceFlinger* flinger, int32_t mode)
2068 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopian59119e62010-10-11 12:37:43 -07002069 }
2070 status_t getResult() const {
2071 return result;
2072 }
2073 virtual bool handler() {
2074 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002075 result = flinger->turnElectronBeamOffImplLocked(mode);
Mathias Agopian59119e62010-10-11 12:37:43 -07002076 return true;
2077 }
2078 };
2079
Mathias Agopianabd671a2010-10-14 14:54:06 -07002080 sp<MessageBase> msg = new MessageTurnElectronBeamOff(this, mode);
Mathias Agopian59119e62010-10-11 12:37:43 -07002081 status_t res = postMessageSync(msg);
2082 if (res == NO_ERROR) {
2083 res = static_cast<MessageTurnElectronBeamOff*>( msg.get() )->getResult();
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002084
2085 // work-around: when the power-manager calls us we activate the
2086 // animation. eventually, the "on" animation will be called
2087 // by the power-manager itself
Mathias Agopianabd671a2010-10-14 14:54:06 -07002088 mElectronBeamAnimationMode = mode;
Mathias Agopian59119e62010-10-11 12:37:43 -07002089 }
2090 return res;
2091}
2092
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002093// ---------------------------------------------------------------------------
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002094
Mathias Agopianabd671a2010-10-14 14:54:06 -07002095status_t SurfaceFlinger::turnElectronBeamOnImplLocked(int32_t mode)
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002096{
2097 DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
2098 if (hw.canDraw()) {
2099 // we're already on
2100 return NO_ERROR;
2101 }
Mathias Agopianabd671a2010-10-14 14:54:06 -07002102 if (mode & ISurfaceComposer::eElectronBeamAnimationOn) {
2103 electronBeamOnAnimationImplLocked();
2104 }
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002105 hw.setCanDraw(true);
Mathias Agopiana7f03732010-10-14 12:46:24 -07002106
2107 // make sure to redraw the whole screen when the animation is done
2108 mDirtyRegion.set(hw.bounds());
2109 signalEvent();
2110
Mathias Agopian015fb3f2010-10-14 12:19:37 -07002111 return NO_ERROR;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002112}
2113
2114status_t SurfaceFlinger::turnElectronBeamOn(int32_t mode)
2115{
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002116 class MessageTurnElectronBeamOn : public MessageBase {
2117 SurfaceFlinger* flinger;
Mathias Agopianabd671a2010-10-14 14:54:06 -07002118 int32_t mode;
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002119 status_t result;
2120 public:
Mathias Agopianabd671a2010-10-14 14:54:06 -07002121 MessageTurnElectronBeamOn(SurfaceFlinger* flinger, int32_t mode)
2122 : flinger(flinger), mode(mode), result(PERMISSION_DENIED) {
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002123 }
2124 status_t getResult() const {
2125 return result;
2126 }
2127 virtual bool handler() {
2128 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopianabd671a2010-10-14 14:54:06 -07002129 result = flinger->turnElectronBeamOnImplLocked(mode);
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002130 return true;
2131 }
2132 };
2133
Mathias Agopianabd671a2010-10-14 14:54:06 -07002134 postMessageAsync( new MessageTurnElectronBeamOn(this, mode) );
Mathias Agopian9daa5c92010-10-12 16:05:48 -07002135 return NO_ERROR;
2136}
2137
2138// ---------------------------------------------------------------------------
2139
Mathias Agopian74c40c02010-09-29 13:02:36 -07002140status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
2141 sp<IMemoryHeap>* heap,
2142 uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002143 uint32_t sw, uint32_t sh,
2144 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian74c40c02010-09-29 13:02:36 -07002145{
2146 status_t result = PERMISSION_DENIED;
2147
2148 // only one display supported for now
2149 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
2150 return BAD_VALUE;
2151
Jamie Gennis7a4d0df2011-03-09 17:05:02 -08002152 // make sure none of the layers are protected
2153 const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
2154 const size_t count = layers.size();
2155 for (size_t i=0 ; i<count ; ++i) {
2156 const sp<LayerBase>& layer(layers[i]);
2157 const uint32_t z = layer->drawingState().z;
2158 if (z >= minLayerZ && z <= maxLayerZ) {
2159 if (layer->isProtected()) {
2160 return INVALID_OPERATION;
2161 }
2162 }
2163 }
2164
Mathias Agopian74c40c02010-09-29 13:02:36 -07002165 if (!GLExtensions::getInstance().haveFramebufferObject())
2166 return INVALID_OPERATION;
2167
2168 // get screen geometry
2169 const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
2170 const uint32_t hw_w = hw.getWidth();
2171 const uint32_t hw_h = hw.getHeight();
2172
2173 if ((sw > hw_w) || (sh > hw_h))
2174 return BAD_VALUE;
2175
2176 sw = (!sw) ? hw_w : sw;
2177 sh = (!sh) ? hw_h : sh;
2178 const size_t size = sw * sh * 4;
2179
Mathias Agopian1c71a472011-03-02 18:45:50 -08002180 //LOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d",
2181 // sw, sh, minLayerZ, maxLayerZ);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002182
Mathias Agopian74c40c02010-09-29 13:02:36 -07002183 // make sure to clear all GL error flags
2184 while ( glGetError() != GL_NO_ERROR ) ;
2185
2186 // create a FBO
2187 GLuint name, tname;
2188 glGenRenderbuffersOES(1, &tname);
2189 glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
2190 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, sw, sh);
2191 glGenFramebuffersOES(1, &name);
2192 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2193 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
2194 GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
2195
2196 GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002197
Mathias Agopian74c40c02010-09-29 13:02:36 -07002198 if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
2199
2200 // invert everything, b/c glReadPixel() below will invert the FB
2201 glViewport(0, 0, sw, sh);
Mathias Agopianf653b892010-12-16 18:46:17 -08002202 glScissor(0, 0, sw, sh);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002203 glMatrixMode(GL_PROJECTION);
2204 glPushMatrix();
2205 glLoadIdentity();
2206 glOrthof(0, hw_w, 0, hw_h, 0, 1);
2207 glMatrixMode(GL_MODELVIEW);
2208
2209 // redraw the screen entirely...
2210 glClearColor(0,0,0,1);
2211 glClear(GL_COLOR_BUFFER_BIT);
Mathias Agopianf653b892010-12-16 18:46:17 -08002212
Mathias Agopian74c40c02010-09-29 13:02:36 -07002213 for (size_t i=0 ; i<count ; ++i) {
2214 const sp<LayerBase>& layer(layers[i]);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002215 const uint32_t z = layer->drawingState().z;
2216 if (z >= minLayerZ && z <= maxLayerZ) {
2217 layer->drawForSreenShot();
2218 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002219 }
2220
2221 // XXX: this is needed on tegra
2222 glScissor(0, 0, sw, sh);
2223
2224 // check for errors and return screen capture
2225 if (glGetError() != GL_NO_ERROR) {
2226 // error while rendering
2227 result = INVALID_OPERATION;
2228 } else {
2229 // allocate shared memory large enough to hold the
2230 // screen capture
2231 sp<MemoryHeapBase> base(
2232 new MemoryHeapBase(size, 0, "screen-capture") );
2233 void* const ptr = base->getBase();
2234 if (ptr) {
2235 // capture the screen with glReadPixels()
2236 glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
2237 if (glGetError() == GL_NO_ERROR) {
2238 *heap = base;
2239 *w = sw;
2240 *h = sh;
2241 *f = PIXEL_FORMAT_RGBA_8888;
2242 result = NO_ERROR;
2243 }
2244 } else {
2245 result = NO_MEMORY;
2246 }
2247 }
Mathias Agopian74c40c02010-09-29 13:02:36 -07002248 glEnable(GL_SCISSOR_TEST);
2249 glViewport(0, 0, hw_w, hw_h);
2250 glMatrixMode(GL_PROJECTION);
2251 glPopMatrix();
2252 glMatrixMode(GL_MODELVIEW);
Mathias Agopian74c40c02010-09-29 13:02:36 -07002253 } else {
2254 result = BAD_VALUE;
2255 }
2256
2257 // release FBO resources
2258 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
2259 glDeleteRenderbuffersOES(1, &tname);
2260 glDeleteFramebuffersOES(1, &name);
Mathias Agopiane6f09842010-12-15 14:41:59 -08002261
2262 hw.compositionComplete();
2263
Mathias Agopian1c71a472011-03-02 18:45:50 -08002264 // LOGD("screenshot: result = %s", result<0 ? strerror(result) : "OK");
Mathias Agopianc1d1b0d2011-01-16 14:05:02 -08002265
Mathias Agopian74c40c02010-09-29 13:02:36 -07002266 return result;
2267}
2268
2269
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002270status_t SurfaceFlinger::captureScreen(DisplayID dpy,
2271 sp<IMemoryHeap>* heap,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002272 uint32_t* width, uint32_t* height, PixelFormat* format,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002273 uint32_t sw, uint32_t sh,
2274 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002275{
2276 // only one display supported for now
2277 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
2278 return BAD_VALUE;
2279
2280 if (!GLExtensions::getInstance().haveFramebufferObject())
2281 return INVALID_OPERATION;
2282
2283 class MessageCaptureScreen : public MessageBase {
2284 SurfaceFlinger* flinger;
2285 DisplayID dpy;
2286 sp<IMemoryHeap>* heap;
2287 uint32_t* w;
2288 uint32_t* h;
2289 PixelFormat* f;
Mathias Agopian74c40c02010-09-29 13:02:36 -07002290 uint32_t sw;
2291 uint32_t sh;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002292 uint32_t minLayerZ;
2293 uint32_t maxLayerZ;
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002294 status_t result;
2295 public:
2296 MessageCaptureScreen(SurfaceFlinger* flinger, DisplayID dpy,
Mathias Agopian74c40c02010-09-29 13:02:36 -07002297 sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h, PixelFormat* f,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002298 uint32_t sw, uint32_t sh,
2299 uint32_t minLayerZ, uint32_t maxLayerZ)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002300 : flinger(flinger), dpy(dpy),
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002301 heap(heap), w(w), h(h), f(f), sw(sw), sh(sh),
2302 minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
2303 result(PERMISSION_DENIED)
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002304 {
2305 }
2306 status_t getResult() const {
2307 return result;
2308 }
2309 virtual bool handler() {
2310 Mutex::Autolock _l(flinger->mStateLock);
2311
2312 // if we have secure windows, never allow the screen capture
2313 if (flinger->mSecureFrameBuffer)
2314 return true;
2315
Mathias Agopian74c40c02010-09-29 13:02:36 -07002316 result = flinger->captureScreenImplLocked(dpy,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002317 heap, w, h, f, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002318
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002319 return true;
2320 }
2321 };
2322
2323 sp<MessageBase> msg = new MessageCaptureScreen(this,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -08002324 dpy, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ);
Mathias Agopian1b0b30d2010-09-24 11:26:58 -07002325 status_t res = postMessageSync(msg);
2326 if (res == NO_ERROR) {
2327 res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult();
2328 }
2329 return res;
2330}
2331
2332// ---------------------------------------------------------------------------
2333
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002334sp<Layer> SurfaceFlinger::getLayer(const sp<ISurface>& sur) const
2335{
2336 sp<Layer> result;
2337 Mutex::Autolock _l(mStateLock);
2338 result = mLayerMap.valueFor( sur->asBinder() ).promote();
2339 return result;
2340}
2341
2342// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002343
Mathias Agopian96f08192010-06-02 23:28:45 -07002344Client::Client(const sp<SurfaceFlinger>& flinger)
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002345 : mFlinger(flinger), mNameGenerator(1)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002346{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002347}
2348
Mathias Agopian96f08192010-06-02 23:28:45 -07002349Client::~Client()
2350{
Mathias Agopian96f08192010-06-02 23:28:45 -07002351 const size_t count = mLayers.size();
2352 for (size_t i=0 ; i<count ; i++) {
2353 sp<LayerBaseClient> layer(mLayers.valueAt(i).promote());
2354 if (layer != 0) {
2355 mFlinger->removeLayer(layer);
2356 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002357 }
2358}
2359
Mathias Agopian96f08192010-06-02 23:28:45 -07002360status_t Client::initCheck() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002361 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002362}
Mathias Agopian076b1cc2009-04-10 14:24:30 -07002363
Mathias Agopian4f113742011-05-03 16:21:41 -07002364size_t Client::attachLayer(const sp<LayerBaseClient>& layer)
Mathias Agopian96f08192010-06-02 23:28:45 -07002365{
Mathias Agopian4f113742011-05-03 16:21:41 -07002366 Mutex::Autolock _l(mLock);
2367 size_t name = mNameGenerator++;
Mathias Agopian96f08192010-06-02 23:28:45 -07002368 mLayers.add(name, layer);
2369 return name;
2370}
2371
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002372void Client::detachLayer(const LayerBaseClient* layer)
Mathias Agopian96f08192010-06-02 23:28:45 -07002373{
Mathias Agopian4f113742011-05-03 16:21:41 -07002374 Mutex::Autolock _l(mLock);
Mathias Agopian96f08192010-06-02 23:28:45 -07002375 // we do a linear search here, because this doesn't happen often
2376 const size_t count = mLayers.size();
2377 for (size_t i=0 ; i<count ; i++) {
2378 if (mLayers.valueAt(i) == layer) {
2379 mLayers.removeItemsAt(i, 1);
2380 break;
2381 }
2382 }
2383}
Mathias Agopian4f113742011-05-03 16:21:41 -07002384sp<LayerBaseClient> Client::getLayerUser(int32_t i) const
2385{
2386 Mutex::Autolock _l(mLock);
Mathias Agopian076b1cc2009-04-10 14:24:30 -07002387 sp<LayerBaseClient> lbc;
Mathias Agopian4f113742011-05-03 16:21:41 -07002388 wp<LayerBaseClient> layer(mLayers.valueFor(i));
Mathias Agopian96f08192010-06-02 23:28:45 -07002389 if (layer != 0) {
2390 lbc = layer.promote();
2391 LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07002392 }
2393 return lbc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002394}
2395
Mathias Agopiana67932f2011-04-20 14:20:59 -07002396
2397status_t Client::onTransact(
2398 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
2399{
2400 // these must be checked
2401 IPCThreadState* ipc = IPCThreadState::self();
2402 const int pid = ipc->getCallingPid();
2403 const int uid = ipc->getCallingUid();
2404 const int self_pid = getpid();
2405 if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
2406 // we're called from a different process, do the real check
Mathias Agopian99b49842011-06-27 16:05:52 -07002407 if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger))
Mathias Agopiana67932f2011-04-20 14:20:59 -07002408 {
2409 LOGE("Permission Denial: "
2410 "can't openGlobalTransaction pid=%d, uid=%d", pid, uid);
2411 return PERMISSION_DENIED;
2412 }
2413 }
2414 return BnSurfaceComposerClient::onTransact(code, data, reply, flags);
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002415}
Mathias Agopiana67932f2011-04-20 14:20:59 -07002416
2417
Mathias Agopian96f08192010-06-02 23:28:45 -07002418sp<ISurface> Client::createSurface(
Mathias Agopian0ef4e152011-04-20 14:19:32 -07002419 ISurfaceComposerClient::surface_data_t* params,
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002420 const String8& name,
2421 DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002422 uint32_t flags)
2423{
Mathias Agopiana67932f2011-04-20 14:20:59 -07002424 /*
2425 * createSurface must be called from the GL thread so that it can
2426 * have access to the GL context.
2427 */
2428
2429 class MessageCreateSurface : public MessageBase {
2430 sp<ISurface> result;
2431 SurfaceFlinger* flinger;
2432 ISurfaceComposerClient::surface_data_t* params;
2433 Client* client;
2434 const String8& name;
2435 DisplayID display;
2436 uint32_t w, h;
2437 PixelFormat format;
2438 uint32_t flags;
2439 public:
2440 MessageCreateSurface(SurfaceFlinger* flinger,
2441 ISurfaceComposerClient::surface_data_t* params,
2442 const String8& name, Client* client,
2443 DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
2444 uint32_t flags)
2445 : flinger(flinger), params(params), client(client), name(name),
2446 display(display), w(w), h(h), format(format), flags(flags)
2447 {
2448 }
2449 sp<ISurface> getResult() const { return result; }
2450 virtual bool handler() {
2451 result = flinger->createSurface(params, name, client,
2452 display, w, h, format, flags);
2453 return true;
2454 }
2455 };
2456
2457 sp<MessageBase> msg = new MessageCreateSurface(mFlinger.get(),
2458 params, name, this, display, w, h, format, flags);
2459 mFlinger->postMessageSync(msg);
2460 return static_cast<MessageCreateSurface*>( msg.get() )->getResult();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002461}
Mathias Agopian96f08192010-06-02 23:28:45 -07002462status_t Client::destroySurface(SurfaceID sid) {
2463 return mFlinger->removeSurface(this, sid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002464}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002465
2466// ---------------------------------------------------------------------------
2467
Jamie Gennis9a78c902011-01-12 18:30:40 -08002468GraphicBufferAlloc::GraphicBufferAlloc() {}
2469
2470GraphicBufferAlloc::~GraphicBufferAlloc() {}
2471
2472sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h,
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002473 PixelFormat format, uint32_t usage, status_t* error) {
Jamie Gennis9a78c902011-01-12 18:30:40 -08002474 sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
2475 status_t err = graphicBuffer->initCheck();
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002476 *error = err;
Mathias Agopiana67932f2011-04-20 14:20:59 -07002477 if (err != 0 || graphicBuffer->handle == 0) {
Mathias Agopiand9e8c642011-07-01 14:53:49 -07002478 if (err == NO_MEMORY) {
2479 GraphicBuffer::dumpAllocationsToSystemLog();
2480 }
Mathias Agopiana67932f2011-04-20 14:20:59 -07002481 LOGE("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) "
2482 "failed (%s), handle=%p",
2483 w, h, strerror(-err), graphicBuffer->handle);
Jamie Gennis9a78c902011-01-12 18:30:40 -08002484 return 0;
2485 }
Jamie Gennis9a78c902011-01-12 18:30:40 -08002486 return graphicBuffer;
2487}
2488
Jamie Gennis9a78c902011-01-12 18:30:40 -08002489// ---------------------------------------------------------------------------
2490
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002491GraphicPlane::GraphicPlane()
2492 : mHw(0)
2493{
2494}
2495
2496GraphicPlane::~GraphicPlane() {
2497 delete mHw;
2498}
2499
2500bool GraphicPlane::initialized() const {
2501 return mHw ? true : false;
2502}
2503
Mathias Agopian2b92d892010-02-08 15:49:35 -08002504int GraphicPlane::getWidth() const {
2505 return mWidth;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002506}
2507
Mathias Agopian2b92d892010-02-08 15:49:35 -08002508int GraphicPlane::getHeight() const {
2509 return mHeight;
2510}
2511
2512void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
2513{
2514 mHw = hw;
2515
2516 // initialize the display orientation transform.
2517 // it's a constant that should come from the display driver.
2518 int displayOrientation = ISurfaceComposer::eOrientationDefault;
2519 char property[PROPERTY_VALUE_MAX];
2520 if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
2521 //displayOrientation
2522 switch (atoi(property)) {
2523 case 90:
2524 displayOrientation = ISurfaceComposer::eOrientation90;
2525 break;
2526 case 270:
2527 displayOrientation = ISurfaceComposer::eOrientation270;
2528 break;
2529 }
2530 }
2531
2532 const float w = hw->getWidth();
2533 const float h = hw->getHeight();
2534 GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
2535 &mDisplayTransform);
2536 if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
2537 mDisplayWidth = h;
2538 mDisplayHeight = w;
2539 } else {
2540 mDisplayWidth = w;
2541 mDisplayHeight = h;
2542 }
2543
2544 setOrientation(ISurfaceComposer::eOrientationDefault);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002545}
2546
2547status_t GraphicPlane::orientationToTransfrom(
2548 int orientation, int w, int h, Transform* tr)
Mathias Agopianeda65402010-02-22 03:15:57 -08002549{
2550 uint32_t flags = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002551 switch (orientation) {
2552 case ISurfaceComposer::eOrientationDefault:
Mathias Agopianeda65402010-02-22 03:15:57 -08002553 flags = Transform::ROT_0;
2554 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002555 case ISurfaceComposer::eOrientation90:
Mathias Agopianeda65402010-02-22 03:15:57 -08002556 flags = Transform::ROT_90;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002557 break;
2558 case ISurfaceComposer::eOrientation180:
Mathias Agopianeda65402010-02-22 03:15:57 -08002559 flags = Transform::ROT_180;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002560 break;
2561 case ISurfaceComposer::eOrientation270:
Mathias Agopianeda65402010-02-22 03:15:57 -08002562 flags = Transform::ROT_270;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002563 break;
2564 default:
2565 return BAD_VALUE;
2566 }
Mathias Agopianeda65402010-02-22 03:15:57 -08002567 tr->set(flags, w, h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002568 return NO_ERROR;
2569}
2570
2571status_t GraphicPlane::setOrientation(int orientation)
2572{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002573 // If the rotation can be handled in hardware, this is where
2574 // the magic should happen.
Mathias Agopian2b92d892010-02-08 15:49:35 -08002575
2576 const DisplayHardware& hw(displayHardware());
2577 const float w = mDisplayWidth;
2578 const float h = mDisplayHeight;
2579 mWidth = int(w);
2580 mHeight = int(h);
2581
2582 Transform orientationTransform;
Mathias Agopianeda65402010-02-22 03:15:57 -08002583 GraphicPlane::orientationToTransfrom(orientation, w, h,
2584 &orientationTransform);
2585 if (orientation & ISurfaceComposer::eOrientationSwapMask) {
2586 mWidth = int(h);
2587 mHeight = int(w);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002588 }
Mathias Agopianeda65402010-02-22 03:15:57 -08002589
Mathias Agopian0d1318b2009-03-27 17:58:20 -07002590 mOrientation = orientation;
Mathias Agopian2b92d892010-02-08 15:49:35 -08002591 mGlobalTransform = mDisplayTransform * orientationTransform;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002592 return NO_ERROR;
2593}
2594
2595const DisplayHardware& GraphicPlane::displayHardware() const {
2596 return *mHw;
2597}
2598
Mathias Agopian59119e62010-10-11 12:37:43 -07002599DisplayHardware& GraphicPlane::editDisplayHardware() {
2600 return *mHw;
2601}
2602
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002603const Transform& GraphicPlane::transform() const {
2604 return mGlobalTransform;
2605}
2606
Mathias Agopian076b1cc2009-04-10 14:24:30 -07002607EGLDisplay GraphicPlane::getEGLDisplay() const {
2608 return mHw->getEGLDisplay();
2609}
2610
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002611// ---------------------------------------------------------------------------
2612
2613}; // namespace android