The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #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 Queru | 2076373 | 2009-01-26 11:51:12 -0800 | [diff] [blame] | 24 | #include <limits.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #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 Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> |
| 33 | #include <binder/IServiceManager.h> |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 34 | #include <binder/MemoryHeapBase.h> |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 35 | #include <binder/PermissionCache.h> |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | #include <utils/String8.h> |
| 38 | #include <utils/String16.h> |
| 39 | #include <utils/StopWatch.h> |
| 40 | |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 41 | #include <ui/GraphicBufferAllocator.h> |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 42 | #include <ui/GraphicLog.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | #include <ui/PixelFormat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | #include <pixelflinger/pixelflinger.h> |
| 46 | #include <GLES/gl.h> |
| 47 | |
| 48 | #include "clz.h" |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 49 | #include "GLExtensions.h" |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 50 | #include "DdmConnection.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | #include "Layer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | #include "LayerDim.h" |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 53 | #include "LayerScreenshot.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | #include "SurfaceFlinger.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| 56 | #include "DisplayHardware/DisplayHardware.h" |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 57 | #include "DisplayHardware/HWComposer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 59 | #include <private/surfaceflinger/SharedBufferStack.h> |
| 60 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 61 | /* ideally AID_GRAPHICS would be in a semi-public header |
| 62 | * or there would be a way to map a user/group name to its id |
| 63 | */ |
| 64 | #ifndef AID_GRAPHICS |
| 65 | #define AID_GRAPHICS 1003 |
| 66 | #endif |
| 67 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | #define DISPLAY_COUNT 1 |
| 69 | |
| 70 | namespace android { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | // --------------------------------------------------------------------------- |
| 72 | |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 73 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 74 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
| 75 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
| 76 | const String16 sDump("android.permission.DUMP"); |
| 77 | |
| 78 | // --------------------------------------------------------------------------- |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | SurfaceFlinger::SurfaceFlinger() |
| 81 | : BnSurfaceComposer(), Thread(false), |
| 82 | mTransactionFlags(0), |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 83 | mResizeTransationPending(false), |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 84 | mLayersRemoved(false), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | mBootTime(systemTime()), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | mVisibleRegionsDirty(false), |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 87 | mHwWorkListDirty(false), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | mFreezeDisplay(false), |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 89 | mElectronBeamAnimationMode(0), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | mFreezeCount(0), |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 91 | mFreezeDisplayTime(0), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | mDebugRegion(0), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | mDebugBackground(0), |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 94 | mDebugDDMS(0), |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 95 | mDebugDisableHWC(0), |
Mathias Agopian | 2143fe0 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 96 | mDebugDisableTransformHint(0), |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 97 | mDebugInSwapBuffers(0), |
| 98 | mLastSwapBufferTime(0), |
| 99 | mDebugInTransaction(0), |
| 100 | mLastTransactionTime(0), |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 101 | mBootFinished(false), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | mConsoleSignals(0), |
| 103 | mSecureFrameBuffer(0) |
| 104 | { |
| 105 | init(); |
| 106 | } |
| 107 | |
| 108 | void SurfaceFlinger::init() |
| 109 | { |
| 110 | LOGI("SurfaceFlinger is starting"); |
| 111 | |
| 112 | // debugging stuff... |
| 113 | char value[PROPERTY_VALUE_MAX]; |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | property_get("debug.sf.showupdates", value, "0"); |
| 116 | mDebugRegion = atoi(value); |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | property_get("debug.sf.showbackground", value, "0"); |
| 119 | mDebugBackground = atoi(value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 121 | property_get("debug.sf.ddms", value, "0"); |
| 122 | mDebugDDMS = atoi(value); |
| 123 | if (mDebugDDMS) { |
| 124 | DdmConnection::start(getServiceName()); |
| 125 | } |
| 126 | |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 127 | LOGI_IF(mDebugRegion, "showupdates enabled"); |
| 128 | LOGI_IF(mDebugBackground, "showbackground enabled"); |
Mathias Agopian | 93d75ec | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 129 | LOGI_IF(mDebugDDMS, "DDMS debugging enabled"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | SurfaceFlinger::~SurfaceFlinger() |
| 133 | { |
| 134 | glDeleteTextures(1, &mWormholeTexName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 137 | sp<IMemoryHeap> SurfaceFlinger::getCblk() const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | { |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 139 | return mServerHeap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 142 | sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 144 | sp<ISurfaceComposerClient> bclient; |
| 145 | sp<Client> client(new Client(this)); |
| 146 | status_t err = client->initCheck(); |
| 147 | if (err == NO_ERROR) { |
| 148 | bclient = client; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | return bclient; |
| 151 | } |
| 152 | |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 153 | sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc() |
| 154 | { |
| 155 | sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc()); |
| 156 | return gba; |
| 157 | } |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const |
| 160 | { |
| 161 | LOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy); |
| 162 | const GraphicPlane& plane(mGraphicPlanes[dpy]); |
| 163 | return plane; |
| 164 | } |
| 165 | |
| 166 | GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) |
| 167 | { |
| 168 | return const_cast<GraphicPlane&>( |
| 169 | const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy)); |
| 170 | } |
| 171 | |
| 172 | void SurfaceFlinger::bootFinished() |
| 173 | { |
| 174 | const nsecs_t now = systemTime(); |
| 175 | const nsecs_t duration = now - mBootTime; |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 176 | LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 177 | mBootFinished = true; |
Mathias Agopian | 0c63ef5 | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 178 | |
| 179 | // wait patiently for the window manager death |
| 180 | const String16 name("window"); |
| 181 | sp<IBinder> window(defaultServiceManager()->getService(name)); |
| 182 | if (window != 0) { |
| 183 | window->linkToDeath(this); |
| 184 | } |
| 185 | |
| 186 | // stop boot animation |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 187 | property_set("ctl.stop", "bootanim"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Mathias Agopian | 0c63ef5 | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 190 | void SurfaceFlinger::binderDied(const wp<IBinder>& who) |
| 191 | { |
| 192 | // the window manager died on us. prepare its eulogy. |
| 193 | |
| 194 | // unfreeze the screen in case it was... frozen |
| 195 | mFreezeDisplayTime = 0; |
| 196 | mFreezeCount = 0; |
| 197 | mFreezeDisplay = false; |
| 198 | |
| 199 | // reset screen orientation |
| 200 | setOrientation(0, eOrientationDefault, 0); |
| 201 | |
| 202 | // restart the boot-animation |
| 203 | property_set("ctl.start", "bootanim"); |
| 204 | } |
| 205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | void SurfaceFlinger::onFirstRef() |
| 207 | { |
| 208 | run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY); |
| 209 | |
| 210 | // Wait for the main thread to be done with its initialization |
| 211 | mReadyToRunBarrier.wait(); |
| 212 | } |
| 213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | static inline uint16_t pack565(int r, int g, int b) { |
| 215 | return (r<<11)|(g<<5)|b; |
| 216 | } |
| 217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | status_t SurfaceFlinger::readyToRun() |
| 219 | { |
| 220 | LOGI( "SurfaceFlinger's main thread ready to run. " |
| 221 | "Initializing graphics H/W..."); |
| 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | // we only support one display currently |
| 224 | int dpy = 0; |
| 225 | |
| 226 | { |
| 227 | // initialize the main display |
| 228 | GraphicPlane& plane(graphicPlane(dpy)); |
| 229 | DisplayHardware* const hw = new DisplayHardware(this, dpy); |
| 230 | plane.setDisplayHardware(hw); |
| 231 | } |
| 232 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 233 | // create the shared control-block |
| 234 | mServerHeap = new MemoryHeapBase(4096, |
| 235 | MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap"); |
| 236 | LOGE_IF(mServerHeap==0, "can't create shared memory dealer"); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 237 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 238 | mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase()); |
| 239 | LOGE_IF(mServerCblk==0, "can't get to shared control block's address"); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 240 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 241 | new(mServerCblk) surface_flinger_cblk_t; |
| 242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | // initialize primary screen |
| 244 | // (other display should be initialized in the same manner, but |
| 245 | // asynchronously, as they could come and go. None of this is supported |
| 246 | // yet). |
| 247 | const GraphicPlane& plane(graphicPlane(dpy)); |
| 248 | const DisplayHardware& hw = plane.displayHardware(); |
| 249 | const uint32_t w = hw.getWidth(); |
| 250 | const uint32_t h = hw.getHeight(); |
| 251 | const uint32_t f = hw.getFormat(); |
| 252 | hw.makeCurrent(); |
| 253 | |
| 254 | // initialize the shared control block |
| 255 | mServerCblk->connected |= 1<<dpy; |
| 256 | display_cblk_t* dcblk = mServerCblk->displays + dpy; |
| 257 | memset(dcblk, 0, sizeof(display_cblk_t)); |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 258 | dcblk->w = plane.getWidth(); |
| 259 | dcblk->h = plane.getHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | dcblk->format = f; |
| 261 | dcblk->orientation = ISurfaceComposer::eOrientationDefault; |
| 262 | dcblk->xdpi = hw.getDpiX(); |
| 263 | dcblk->ydpi = hw.getDpiY(); |
| 264 | dcblk->fps = hw.getRefreshRate(); |
| 265 | dcblk->density = hw.getDensity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | |
| 267 | // Initialize OpenGL|ES |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 269 | glPixelStorei(GL_PACK_ALIGNMENT, 4); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | glEnableClientState(GL_VERTEX_ARRAY); |
| 271 | glEnable(GL_SCISSOR_TEST); |
| 272 | glShadeModel(GL_FLAT); |
| 273 | glDisable(GL_DITHER); |
| 274 | glDisable(GL_CULL_FACE); |
| 275 | |
| 276 | const uint16_t g0 = pack565(0x0F,0x1F,0x0F); |
| 277 | const uint16_t g1 = pack565(0x17,0x2f,0x17); |
Jamie Gennis | 830d083 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 278 | const uint16_t wormholeTexData[4] = { g0, g1, g1, g0 }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | glGenTextures(1, &mWormholeTexName); |
| 280 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); |
| 281 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 282 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 283 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 284 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 285 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, |
Jamie Gennis | 830d083 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 286 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, wormholeTexData); |
| 287 | |
| 288 | const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) }; |
| 289 | glGenTextures(1, &mProtectedTexName); |
| 290 | glBindTexture(GL_TEXTURE_2D, mProtectedTexName); |
| 291 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 292 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 293 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 294 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 295 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, |
| 296 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | |
| 298 | glViewport(0, 0, w, h); |
| 299 | glMatrixMode(GL_PROJECTION); |
| 300 | glLoadIdentity(); |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 301 | // put the origin in the left-bottom corner |
| 302 | glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | mReadyToRunBarrier.open(); |
| 305 | |
| 306 | /* |
| 307 | * We're now ready to accept clients... |
| 308 | */ |
| 309 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 310 | // start boot animation |
| 311 | property_set("ctl.start", "bootanim"); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | return NO_ERROR; |
| 314 | } |
| 315 | |
| 316 | // ---------------------------------------------------------------------------- |
| 317 | #if 0 |
| 318 | #pragma mark - |
| 319 | #pragma mark Events Handler |
| 320 | #endif |
| 321 | |
| 322 | void SurfaceFlinger::waitForEvent() |
| 323 | { |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 324 | while (true) { |
| 325 | nsecs_t timeout = -1; |
Mathias Agopian | 0e44976 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 326 | const nsecs_t freezeDisplayTimeout = ms2ns(5000); |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 327 | if (UNLIKELY(isFrozen())) { |
| 328 | // wait 5 seconds |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 329 | const nsecs_t now = systemTime(); |
| 330 | if (mFreezeDisplayTime == 0) { |
| 331 | mFreezeDisplayTime = now; |
| 332 | } |
| 333 | nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime); |
| 334 | timeout = waitTime>0 ? waitTime : 0; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 335 | } |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 336 | |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 337 | sp<MessageBase> msg = mEventQueue.waitMessage(timeout); |
Mathias Agopian | 0e44976 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 338 | |
| 339 | // see if we timed out |
| 340 | if (isFrozen()) { |
| 341 | const nsecs_t now = systemTime(); |
| 342 | nsecs_t frozenTime = (now - mFreezeDisplayTime); |
| 343 | if (frozenTime >= freezeDisplayTimeout) { |
| 344 | // we timed out and are still frozen |
| 345 | LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d", |
| 346 | mFreezeDisplay, mFreezeCount); |
| 347 | mFreezeDisplayTime = 0; |
| 348 | mFreezeCount = 0; |
| 349 | mFreezeDisplay = false; |
| 350 | } |
| 351 | } |
| 352 | |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 353 | if (msg != 0) { |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 354 | switch (msg->what) { |
| 355 | case MessageQueue::INVALIDATE: |
| 356 | // invalidate message, just return to the main loop |
| 357 | return; |
| 358 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | void SurfaceFlinger::signalEvent() { |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 364 | mEventQueue.invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 367 | bool SurfaceFlinger::authenticateSurfaceTexture( |
| 368 | const sp<ISurfaceTexture>& surfaceTexture) const { |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 369 | Mutex::Autolock _l(mStateLock); |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 370 | sp<IBinder> surfaceTextureBinder(surfaceTexture->asBinder()); |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 371 | |
| 372 | // Check the visible layer list for the ISurface |
| 373 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 374 | size_t count = currentLayers.size(); |
| 375 | for (size_t i=0 ; i<count ; i++) { |
| 376 | const sp<LayerBase>& layer(currentLayers[i]); |
| 377 | sp<LayerBaseClient> lbc(layer->getLayerBaseClient()); |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 378 | if (lbc != NULL) { |
| 379 | wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder(); |
| 380 | if (lbcBinder == surfaceTextureBinder) { |
| 381 | return true; |
| 382 | } |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | // Check the layers in the purgatory. This check is here so that if a |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 387 | // SurfaceTexture gets destroyed before all the clients are done using it, |
| 388 | // the error will not be reported as "surface XYZ is not authenticated", but |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 389 | // will instead fail later on when the client tries to use the surface, |
| 390 | // which should be reported as "surface XYZ returned an -ENODEV". The |
| 391 | // purgatorized layers are no less authentic than the visible ones, so this |
| 392 | // should not cause any harm. |
| 393 | size_t purgatorySize = mLayerPurgatory.size(); |
| 394 | for (size_t i=0 ; i<purgatorySize ; i++) { |
| 395 | const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i)); |
| 396 | sp<LayerBaseClient> lbc(layer->getLayerBaseClient()); |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 397 | if (lbc != NULL) { |
| 398 | wp<IBinder> lbcBinder = lbc->getSurfaceTextureBinder(); |
| 399 | if (lbcBinder == surfaceTextureBinder) { |
| 400 | return true; |
| 401 | } |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | return false; |
| 406 | } |
| 407 | |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 408 | status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg, |
| 409 | nsecs_t reltime, uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | { |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 411 | return mEventQueue.postMessage(msg, reltime, flags); |
| 412 | } |
| 413 | |
| 414 | status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg, |
| 415 | nsecs_t reltime, uint32_t flags) |
| 416 | { |
| 417 | status_t res = mEventQueue.postMessage(msg, reltime, flags); |
| 418 | if (res == NO_ERROR) { |
| 419 | msg->wait(); |
| 420 | } |
| 421 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | // ---------------------------------------------------------------------------- |
| 425 | #if 0 |
| 426 | #pragma mark - |
| 427 | #pragma mark Main loop |
| 428 | #endif |
| 429 | |
| 430 | bool SurfaceFlinger::threadLoop() |
| 431 | { |
| 432 | waitForEvent(); |
| 433 | |
| 434 | // check for transactions |
| 435 | if (UNLIKELY(mConsoleSignals)) { |
| 436 | handleConsoleEvents(); |
| 437 | } |
| 438 | |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 439 | // if we're in a global transaction, don't do anything. |
| 440 | const uint32_t mask = eTransactionNeeded | eTraversalNeeded; |
| 441 | uint32_t transactionFlags = peekTransactionFlags(mask); |
| 442 | if (UNLIKELY(transactionFlags)) { |
| 443 | handleTransaction(transactionFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | // post surfaces (if needed) |
| 447 | handlePageFlip(); |
| 448 | |
Mathias Agopian | 0d0fba4 | 2011-10-18 17:36:28 -0700 | [diff] [blame] | 449 | if (mDirtyRegion.isEmpty()) { |
| 450 | // nothing new to do. |
| 451 | return true; |
| 452 | } |
| 453 | |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 454 | if (UNLIKELY(mHwWorkListDirty)) { |
| 455 | // build the h/w work list |
| 456 | handleWorkList(); |
| 457 | } |
| 458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | e757a87 | 2011-10-16 18:46:35 -0700 | [diff] [blame] | 460 | if (LIKELY(hw.canDraw())) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | // repaint the framebuffer (if needed) |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 462 | |
| 463 | const int index = hw.getCurrentBufferIndex(); |
| 464 | GraphicLog& logger(GraphicLog::getInstance()); |
| 465 | |
| 466 | logger.log(GraphicLog::SF_REPAINT, index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | handleRepaint(); |
| 468 | |
Mathias Agopian | b1a1874 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 469 | // inform the h/w that we're done compositing |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 470 | logger.log(GraphicLog::SF_COMPOSITION_COMPLETE, index); |
Mathias Agopian | b1a1874 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 471 | hw.compositionComplete(); |
| 472 | |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 473 | logger.log(GraphicLog::SF_SWAP_BUFFERS, index); |
Antti Hatala | 4c0a4a2 | 2010-09-08 06:37:14 -0700 | [diff] [blame] | 474 | postFramebuffer(); |
| 475 | |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 476 | logger.log(GraphicLog::SF_REPAINT_DONE, index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | } else { |
| 478 | // pretend we did the post |
Mathias Agopian | a6b8c1c | 2010-12-15 14:41:59 -0800 | [diff] [blame] | 479 | hw.compositionComplete(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | usleep(16667); // 60 fps period |
| 481 | } |
| 482 | return true; |
| 483 | } |
| 484 | |
| 485 | void SurfaceFlinger::postFramebuffer() |
| 486 | { |
Mathias Agopian | 0d0fba4 | 2011-10-18 17:36:28 -0700 | [diff] [blame] | 487 | // this should never happen. we do the flip anyways so we don't |
| 488 | // risk to cause a deadlock with hwc |
| 489 | LOGW_IF(mSwapRegion.isEmpty(), "mSwapRegion is empty"); |
Mathias Agopian | e757a87 | 2011-10-16 18:46:35 -0700 | [diff] [blame] | 490 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 491 | const nsecs_t now = systemTime(); |
| 492 | mDebugInSwapBuffers = now; |
| 493 | hw.flip(mSwapRegion); |
| 494 | mLastSwapBufferTime = systemTime() - now; |
| 495 | mDebugInSwapBuffers = 0; |
| 496 | mSwapRegion.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void SurfaceFlinger::handleConsoleEvents() |
| 500 | { |
| 501 | // something to do with the console |
| 502 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); |
| 503 | |
| 504 | int what = android_atomic_and(0, &mConsoleSignals); |
| 505 | if (what & eConsoleAcquired) { |
| 506 | hw.acquireScreen(); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 507 | // this is a temporary work-around, eventually this should be called |
| 508 | // by the power-manager |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 509 | SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
| 511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | if (what & eConsoleReleased) { |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 513 | if (hw.isScreenAcquired()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | hw.releaseScreen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | mDirtyRegion.set(hw.bounds()); |
| 519 | } |
| 520 | |
| 521 | void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) |
| 522 | { |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 523 | Mutex::Autolock _l(mStateLock); |
| 524 | const nsecs_t now = systemTime(); |
| 525 | mDebugInTransaction = now; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 527 | // Here we're guaranteed that some transaction flags are set |
| 528 | // so we can call handleTransactionLocked() unconditionally. |
| 529 | // We call getTransactionFlags(), which will also clear the flags, |
| 530 | // with mStateLock held to guarantee that mCurrentState won't change |
| 531 | // until the transaction is committed. |
Mathias Agopian | ff1d410 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 532 | |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 533 | const uint32_t mask = eTransactionNeeded | eTraversalNeeded; |
| 534 | transactionFlags = getTransactionFlags(mask); |
| 535 | handleTransactionLocked(transactionFlags); |
Mathias Agopian | 6dcb155 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 536 | |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 537 | mLastTransactionTime = systemTime() - now; |
| 538 | mDebugInTransaction = 0; |
| 539 | invalidateHwcGeometry(); |
| 540 | // here the transaction has been committed |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 543 | void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 544 | { |
| 545 | const LayerVector& currentLayers(mCurrentState.layersSortedByZ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | const size_t count = currentLayers.size(); |
| 547 | |
| 548 | /* |
| 549 | * Traversal of the children |
| 550 | * (perform the transaction for each of them if needed) |
| 551 | */ |
| 552 | |
| 553 | const bool layersNeedTransaction = transactionFlags & eTraversalNeeded; |
| 554 | if (layersNeedTransaction) { |
| 555 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 556 | const sp<LayerBase>& layer = currentLayers[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); |
| 558 | if (!trFlags) continue; |
| 559 | |
| 560 | const uint32_t flags = layer->doTransaction(0); |
| 561 | if (flags & Layer::eVisibleRegion) |
| 562 | mVisibleRegionsDirty = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * Perform our own transaction if needed |
| 568 | */ |
| 569 | |
| 570 | if (transactionFlags & eTransactionNeeded) { |
| 571 | if (mCurrentState.orientation != mDrawingState.orientation) { |
| 572 | // the orientation has changed, recompute all visible regions |
| 573 | // and invalidate everything. |
| 574 | |
| 575 | const int dpy = 0; |
| 576 | const int orientation = mCurrentState.orientation; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 577 | // Currently unused: const uint32_t flags = mCurrentState.orientationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | GraphicPlane& plane(graphicPlane(dpy)); |
| 579 | plane.setOrientation(orientation); |
| 580 | |
| 581 | // update the shared control block |
| 582 | const DisplayHardware& hw(plane.displayHardware()); |
| 583 | volatile display_cblk_t* dcblk = mServerCblk->displays + dpy; |
| 584 | dcblk->orientation = orientation; |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 585 | dcblk->w = plane.getWidth(); |
| 586 | dcblk->h = plane.getHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | |
| 588 | mVisibleRegionsDirty = true; |
| 589 | mDirtyRegion.set(hw.bounds()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) { |
| 593 | // freezing or unfreezing the display -> trigger animation if needed |
| 594 | mFreezeDisplay = mCurrentState.freezeDisplay; |
Mathias Agopian | 31901cc | 2010-03-01 17:51:17 -0800 | [diff] [blame] | 595 | if (mFreezeDisplay) |
| 596 | mFreezeDisplayTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 599 | if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) { |
| 600 | // layers have been added |
| 601 | mVisibleRegionsDirty = true; |
| 602 | } |
| 603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | // some layers might have been removed, so |
| 605 | // we need to update the regions they're exposing. |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 606 | if (mLayersRemoved) { |
Mathias Agopian | 248b5bd | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 607 | mLayersRemoved = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | mVisibleRegionsDirty = true; |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 609 | const LayerVector& previousLayers(mDrawingState.layersSortedByZ); |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 610 | const size_t count = previousLayers.size(); |
| 611 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 612 | const sp<LayerBase>& layer(previousLayers[i]); |
| 613 | if (currentLayers.indexOf( layer ) < 0) { |
| 614 | // this layer is not visible anymore |
Mathias Agopian | 33863dd | 2009-07-28 14:20:21 -0700 | [diff] [blame] | 615 | mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen); |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | commitTransaction(); |
| 622 | } |
| 623 | |
| 624 | sp<FreezeLock> SurfaceFlinger::getFreezeLock() const |
| 625 | { |
| 626 | return new FreezeLock(const_cast<SurfaceFlinger *>(this)); |
| 627 | } |
| 628 | |
| 629 | void SurfaceFlinger::computeVisibleRegions( |
Mathias Agopian | f0ff906 | 2011-03-11 16:54:47 -0800 | [diff] [blame] | 630 | const LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | { |
| 632 | const GraphicPlane& plane(graphicPlane(0)); |
| 633 | const Transform& planeTransform(plane.transform()); |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 634 | const DisplayHardware& hw(plane.displayHardware()); |
| 635 | const Region screenRegion(hw.bounds()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | |
| 637 | Region aboveOpaqueLayers; |
| 638 | Region aboveCoveredLayers; |
| 639 | Region dirty; |
| 640 | |
| 641 | bool secureFrameBuffer = false; |
| 642 | |
| 643 | size_t i = currentLayers.size(); |
| 644 | while (i--) { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 645 | const sp<LayerBase>& layer = currentLayers[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | layer->validateVisibility(planeTransform); |
| 647 | |
| 648 | // start with the whole surface at its current location |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 649 | const Layer::State& s(layer->drawingState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 651 | /* |
| 652 | * opaqueRegion: area of a surface that is fully opaque. |
| 653 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | Region opaqueRegion; |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 655 | |
| 656 | /* |
| 657 | * visibleRegion: area of a surface that is visible on screen |
| 658 | * and not fully transparent. This is essentially the layer's |
| 659 | * footprint minus the opaque regions above it. |
| 660 | * Areas covered by a translucent surface are considered visible. |
| 661 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | Region visibleRegion; |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 663 | |
| 664 | /* |
| 665 | * coveredRegion: area of a surface that is covered by all |
| 666 | * visible regions above it (which includes the translucent areas). |
| 667 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | Region coveredRegion; |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 669 | |
| 670 | |
| 671 | // handle hidden surfaces by setting the visible region to empty |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 672 | if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) { |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 673 | const bool translucent = !layer->isOpaque(); |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 674 | const Rect bounds(layer->visibleBounds()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | visibleRegion.set(bounds); |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 676 | visibleRegion.andSelf(screenRegion); |
| 677 | if (!visibleRegion.isEmpty()) { |
| 678 | // Remove the transparent area from the visible region |
| 679 | if (translucent) { |
| 680 | visibleRegion.subtractSelf(layer->transparentRegionScreen); |
| 681 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 683 | // compute the opaque region |
| 684 | const int32_t layerOrientation = layer->getOrientation(); |
| 685 | if (s.alpha==255 && !translucent && |
| 686 | ((layerOrientation & Transform::ROT_INVALID) == false)) { |
| 687 | // the opaque region is the layer's footprint |
| 688 | opaqueRegion = visibleRegion; |
| 689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 693 | // Clip the covered region to the visible region |
| 694 | coveredRegion = aboveCoveredLayers.intersect(visibleRegion); |
| 695 | |
| 696 | // Update aboveCoveredLayers for next (lower) layer |
| 697 | aboveCoveredLayers.orSelf(visibleRegion); |
| 698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | // subtract the opaque region covered by the layers above us |
| 700 | visibleRegion.subtractSelf(aboveOpaqueLayers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | |
| 702 | // compute this layer's dirty region |
| 703 | if (layer->contentDirty) { |
| 704 | // we need to invalidate the whole region |
| 705 | dirty = visibleRegion; |
| 706 | // as well, as the old visible region |
| 707 | dirty.orSelf(layer->visibleRegionScreen); |
| 708 | layer->contentDirty = false; |
| 709 | } else { |
Mathias Agopian | 0aed7e9 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 710 | /* compute the exposed region: |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 711 | * the exposed region consists of two components: |
| 712 | * 1) what's VISIBLE now and was COVERED before |
| 713 | * 2) what's EXPOSED now less what was EXPOSED before |
| 714 | * |
| 715 | * note that (1) is conservative, we start with the whole |
| 716 | * visible region but only keep what used to be covered by |
| 717 | * something -- which mean it may have been exposed. |
| 718 | * |
| 719 | * (2) handles areas that were not covered by anything but got |
| 720 | * exposed because of a resize. |
Mathias Agopian | 0aed7e9 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 721 | */ |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 722 | const Region newExposed = visibleRegion - coveredRegion; |
| 723 | const Region oldVisibleRegion = layer->visibleRegionScreen; |
| 724 | const Region oldCoveredRegion = layer->coveredRegionScreen; |
| 725 | const Region oldExposed = oldVisibleRegion - oldCoveredRegion; |
| 726 | dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | } |
| 728 | dirty.subtractSelf(aboveOpaqueLayers); |
| 729 | |
| 730 | // accumulate to the screen dirty region |
| 731 | dirtyRegion.orSelf(dirty); |
| 732 | |
Mathias Agopian | 9c041bb | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 733 | // Update aboveOpaqueLayers for next (lower) layer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | aboveOpaqueLayers.orSelf(opaqueRegion); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | // Store the visible region is screen space |
| 737 | layer->setVisibleRegion(visibleRegion); |
| 738 | layer->setCoveredRegion(coveredRegion); |
| 739 | |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 740 | // If a secure layer is partially visible, lock-down the screen! |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | if (layer->isSecure() && !visibleRegion.isEmpty()) { |
| 742 | secureFrameBuffer = true; |
| 743 | } |
| 744 | } |
| 745 | |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 746 | // invalidate the areas where a layer was removed |
| 747 | dirtyRegion.orSelf(mDirtyRegionRemovedLayer); |
| 748 | mDirtyRegionRemovedLayer.clear(); |
| 749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | mSecureFrameBuffer = secureFrameBuffer; |
| 751 | opaqueRegion = aboveOpaqueLayers; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | void SurfaceFlinger::commitTransaction() |
| 756 | { |
| 757 | mDrawingState = mCurrentState; |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 758 | mResizeTransationPending = false; |
| 759 | mTransactionCV.broadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void SurfaceFlinger::handlePageFlip() |
| 763 | { |
| 764 | bool visibleRegions = mVisibleRegionsDirty; |
Mathias Agopian | f0ff906 | 2011-03-11 16:54:47 -0800 | [diff] [blame] | 765 | const LayerVector& currentLayers(mDrawingState.layersSortedByZ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | visibleRegions |= lockPageFlip(currentLayers); |
| 767 | |
| 768 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); |
| 769 | const Region screenRegion(hw.bounds()); |
| 770 | if (visibleRegions) { |
| 771 | Region opaqueRegion; |
| 772 | computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion); |
Mathias Agopian | ff1d410 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 773 | |
| 774 | /* |
| 775 | * rebuild the visible layer list |
| 776 | */ |
Mathias Agopian | f0ff906 | 2011-03-11 16:54:47 -0800 | [diff] [blame] | 777 | const size_t count = currentLayers.size(); |
Mathias Agopian | ff1d410 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 778 | mVisibleLayersSortedByZ.clear(); |
Mathias Agopian | ff1d410 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 779 | mVisibleLayersSortedByZ.setCapacity(count); |
| 780 | for (size_t i=0 ; i<count ; i++) { |
| 781 | if (!currentLayers[i]->visibleRegionScreen.isEmpty()) |
| 782 | mVisibleLayersSortedByZ.add(currentLayers[i]); |
| 783 | } |
| 784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | mWormholeRegion = screenRegion.subtract(opaqueRegion); |
| 786 | mVisibleRegionsDirty = false; |
Mathias Agopian | fb4dcb1 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 787 | invalidateHwcGeometry(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | unlockPageFlip(currentLayers); |
Mathias Agopian | 6497eab | 2011-10-21 15:18:28 -0700 | [diff] [blame^] | 791 | |
| 792 | mDirtyRegion.orSelf(getAndClearInvalidateRegion()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | mDirtyRegion.andSelf(screenRegion); |
| 794 | } |
| 795 | |
Mathias Agopian | fb4dcb1 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 796 | void SurfaceFlinger::invalidateHwcGeometry() |
| 797 | { |
| 798 | mHwWorkListDirty = true; |
| 799 | } |
| 800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers) |
| 802 | { |
| 803 | bool recomputeVisibleRegions = false; |
| 804 | size_t count = currentLayers.size(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 805 | sp<LayerBase> const* layers = currentLayers.array(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 807 | const sp<LayerBase>& layer(layers[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | layer->lockPageFlip(recomputeVisibleRegions); |
| 809 | } |
| 810 | return recomputeVisibleRegions; |
| 811 | } |
| 812 | |
| 813 | void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers) |
| 814 | { |
| 815 | const GraphicPlane& plane(graphicPlane(0)); |
| 816 | const Transform& planeTransform(plane.transform()); |
| 817 | size_t count = currentLayers.size(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 818 | sp<LayerBase> const* layers = currentLayers.array(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 820 | const sp<LayerBase>& layer(layers[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | layer->unlockPageFlip(planeTransform, mDirtyRegion); |
| 822 | } |
| 823 | } |
| 824 | |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 825 | void SurfaceFlinger::handleWorkList() |
| 826 | { |
| 827 | mHwWorkListDirty = false; |
| 828 | HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer()); |
| 829 | if (hwc.initCheck() == NO_ERROR) { |
| 830 | const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ); |
| 831 | const size_t count = currentLayers.size(); |
| 832 | hwc.createWorkList(count); |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 833 | hwc_layer_t* const cur(hwc.getLayers()); |
| 834 | for (size_t i=0 ; cur && i<count ; i++) { |
| 835 | currentLayers[i]->setGeometry(&cur[i]); |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 836 | if (mDebugDisableHWC || mDebugRegion) { |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 837 | cur[i].compositionType = HWC_FRAMEBUFFER; |
| 838 | cur[i].flags |= HWC_SKIP_LAYER; |
| 839 | } |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | } |
Mathias Agopian | 8c9687a | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | void SurfaceFlinger::handleRepaint() |
| 845 | { |
Mathias Agopian | 8c9687a | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 846 | // compute the invalid region |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 847 | mSwapRegion.orSelf(mDirtyRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | |
| 849 | if (UNLIKELY(mDebugRegion)) { |
| 850 | debugFlashRegions(); |
| 851 | } |
| 852 | |
Mathias Agopian | 8c9687a | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 853 | // set the frame buffer |
| 854 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 855 | glMatrixMode(GL_MODELVIEW); |
| 856 | glLoadIdentity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | |
| 858 | uint32_t flags = hw.getFlags(); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 859 | if ((flags & DisplayHardware::SWAP_RECTANGLE) || |
| 860 | (flags & DisplayHardware::BUFFER_PRESERVED)) |
Mathias Agopian | 2e20bff | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 861 | { |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 862 | // we can redraw only what's dirty, but since SWAP_RECTANGLE only |
| 863 | // takes a rectangle, we must make sure to update that whole |
| 864 | // rectangle in that case |
| 865 | if (flags & DisplayHardware::SWAP_RECTANGLE) { |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 866 | // TODO: we really should be able to pass a region to |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 867 | // SWAP_RECTANGLE so that we don't have to redraw all this. |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 868 | mDirtyRegion.set(mSwapRegion.bounds()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | } else { |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 870 | // in the BUFFER_PRESERVED case, obviously, we can update only |
| 871 | // what's needed and nothing more. |
| 872 | // NOTE: this is NOT a common case, as preserving the backbuffer |
| 873 | // is costly and usually involves copying the whole update back. |
| 874 | } |
| 875 | } else { |
Mathias Agopian | f2d28b7 | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 876 | if (flags & DisplayHardware::PARTIAL_UPDATES) { |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 877 | // We need to redraw the rectangle that will be updated |
| 878 | // (pushed to the framebuffer). |
Mathias Agopian | f2d28b7 | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 879 | // This is needed because PARTIAL_UPDATES only takes one |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 880 | // rectangle instead of a region (see DisplayHardware::flip()) |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 881 | mDirtyRegion.set(mSwapRegion.bounds()); |
Mathias Agopian | ecfa7cc | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 882 | } else { |
| 883 | // we need to redraw everything (the whole screen) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | mDirtyRegion.set(hw.bounds()); |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 885 | mSwapRegion = mDirtyRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 889 | setupHardwareComposer(mDirtyRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | composeSurfaces(mDirtyRegion); |
| 891 | |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 892 | // update the swap region and clear the dirty region |
| 893 | mSwapRegion.orSelf(mDirtyRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | mDirtyRegion.clear(); |
| 895 | } |
| 896 | |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 897 | void SurfaceFlinger::setupHardwareComposer(Region& dirtyInOut) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | { |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 899 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 900 | HWComposer& hwc(hw.getHwComposer()); |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 901 | hwc_layer_t* const cur(hwc.getLayers()); |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 902 | if (!cur) { |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 903 | return; |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 904 | } |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 905 | |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 906 | const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ); |
| 907 | size_t count = layers.size(); |
| 908 | |
| 909 | LOGE_IF(hwc.getNumLayers() != count, |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 910 | "HAL number of layers (%d) doesn't match surfaceflinger (%d)", |
| 911 | hwc.getNumLayers(), count); |
| 912 | |
| 913 | // just to be extra-safe, use the smallest count |
Erik Gilling | 0cf2f43 | 2010-08-12 23:21:40 -0700 | [diff] [blame] | 914 | if (hwc.initCheck() == NO_ERROR) { |
| 915 | count = count < hwc.getNumLayers() ? count : hwc.getNumLayers(); |
| 916 | } |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 917 | |
| 918 | /* |
| 919 | * update the per-frame h/w composer data for each layer |
| 920 | * and build the transparent region of the FB |
| 921 | */ |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 922 | for (size_t i=0 ; i<count ; i++) { |
| 923 | const sp<LayerBase>& layer(layers[i]); |
| 924 | layer->setPerFrameData(&cur[i]); |
| 925 | } |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 926 | const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER); |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 927 | status_t err = hwc.prepare(); |
| 928 | LOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err)); |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 929 | |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 930 | if (err == NO_ERROR) { |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 931 | // what's happening here is tricky. |
| 932 | // we want to clear all the layers with the CLEAR_FB flags |
| 933 | // that are opaque. |
| 934 | // however, since some GPU are efficient at preserving |
| 935 | // the backbuffer, we want to take advantage of that so we do the |
| 936 | // clear only in the dirty region (other areas will be preserved |
| 937 | // on those GPUs). |
| 938 | // NOTE: on non backbuffer preserving GPU, the dirty region |
| 939 | // has already been expanded as needed, so the code is correct |
| 940 | // there too. |
| 941 | // |
| 942 | // However, the content of the framebuffer cannot be trusted when |
| 943 | // we switch to/from FB/OVERLAY, in which case we need to |
| 944 | // expand the dirty region to those areas too. |
| 945 | // |
| 946 | // Note also that there is a special case when switching from |
| 947 | // "no layers in FB" to "some layers in FB", where we need to redraw |
| 948 | // the entire FB, since some areas might contain uninitialized |
| 949 | // data. |
| 950 | // |
| 951 | // Also we want to make sure to not clear areas that belong to |
Mathias Agopian | 0d0fba4 | 2011-10-18 17:36:28 -0700 | [diff] [blame] | 952 | // layers above that won't redraw (we would just be erasing them), |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 953 | // that is, we can't erase anything outside the dirty region. |
| 954 | |
Mathias Agopian | 0a5abdb | 2011-09-09 01:47:48 -0700 | [diff] [blame] | 955 | Region transparent; |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 956 | |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 957 | if (!fbLayerCount && hwc.getLayerCount(HWC_FRAMEBUFFER)) { |
| 958 | transparent.set(hw.getBounds()); |
| 959 | dirtyInOut = transparent; |
| 960 | } else { |
| 961 | for (size_t i=0 ; i<count ; i++) { |
| 962 | const sp<LayerBase>& layer(layers[i]); |
| 963 | if ((cur[i].hints & HWC_HINT_CLEAR_FB) && layer->isOpaque()) { |
| 964 | transparent.orSelf(layer->visibleRegionScreen); |
| 965 | } |
| 966 | bool isOverlay = (cur[i].compositionType != HWC_FRAMEBUFFER); |
| 967 | if (isOverlay != layer->isOverlay()) { |
| 968 | // we transitioned to/from overlay, so add this layer |
| 969 | // to the dirty region so the framebuffer can be either |
| 970 | // cleared or redrawn. |
| 971 | dirtyInOut.orSelf(layer->visibleRegionScreen); |
| 972 | } |
| 973 | layer->setOverlay(isOverlay); |
Mathias Agopian | 4549169 | 2011-01-19 15:24:23 -0800 | [diff] [blame] | 974 | } |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 975 | // don't erase stuff outside the dirty region |
| 976 | transparent.andSelf(dirtyInOut); |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | /* |
| 980 | * clear the area of the FB that need to be transparent |
| 981 | */ |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 982 | if (!transparent.isEmpty()) { |
| 983 | glClearColor(0,0,0,0); |
| 984 | Region::const_iterator it = transparent.begin(); |
| 985 | Region::const_iterator const end = transparent.end(); |
| 986 | const int32_t height = hw.getHeight(); |
| 987 | while (it != end) { |
| 988 | const Rect& r(*it++); |
| 989 | const GLint sy = height - (r.top + r.height()); |
| 990 | glScissor(r.left, sy, r.width(), r.height()); |
| 991 | glClear(GL_COLOR_BUFFER_BIT); |
Mathias Agopian | 4549169 | 2011-01-19 15:24:23 -0800 | [diff] [blame] | 992 | } |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 995 | } |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 996 | |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 997 | void SurfaceFlinger::composeSurfaces(const Region& dirty) |
| 998 | { |
Mathias Agopian | 9fe9654 | 2011-09-22 20:57:04 -0700 | [diff] [blame] | 999 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1000 | HWComposer& hwc(hw.getHwComposer()); |
| 1001 | |
| 1002 | const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER); |
| 1003 | if (UNLIKELY(fbLayerCount && !mWormholeRegion.isEmpty())) { |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 1004 | // should never happen unless the window manager has a bug |
| 1005 | // draw something... |
| 1006 | drawWormhole(); |
| 1007 | } |
| 1008 | |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 1009 | /* |
| 1010 | * and then, render the layers targeted at the framebuffer |
| 1011 | */ |
Mathias Agopian | 9fe9654 | 2011-09-22 20:57:04 -0700 | [diff] [blame] | 1012 | hwc_layer_t* const cur(hwc.getLayers()); |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 1013 | const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ); |
| 1014 | size_t count = layers.size(); |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 1015 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 88cde07 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 1016 | if (cur && (cur[i].compositionType != HWC_FRAMEBUFFER)) { |
Mathias Agopian | 4bacc9d | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 1017 | continue; |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 1018 | } |
| 1019 | const sp<LayerBase>& layer(layers[i]); |
| 1020 | const Region clip(dirty.intersect(layer->visibleRegionScreen)); |
| 1021 | if (!clip.isEmpty()) { |
| 1022 | layer->draw(clip); |
| 1023 | } |
| 1024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | void SurfaceFlinger::debugFlashRegions() |
| 1028 | { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1029 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1030 | const uint32_t flags = hw.getFlags(); |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1031 | const int32_t height = hw.getHeight(); |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 1032 | if (mSwapRegion.isEmpty()) { |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1033 | return; |
| 1034 | } |
Mathias Agopian | 2e20bff | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 1035 | |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1036 | if (!((flags & DisplayHardware::SWAP_RECTANGLE) || |
| 1037 | (flags & DisplayHardware::BUFFER_PRESERVED))) { |
| 1038 | const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ? |
| 1039 | mDirtyRegion.bounds() : hw.bounds()); |
| 1040 | composeSurfaces(repaint); |
| 1041 | } |
| 1042 | |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 1043 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 1044 | glDisable(GL_TEXTURE_2D); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | glDisable(GL_SCISSOR_TEST); |
| 1047 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 1048 | static int toggle = 0; |
| 1049 | toggle = 1 - toggle; |
| 1050 | if (toggle) { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1051 | glColor4f(1, 0, 1, 1); |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 1052 | } else { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1053 | glColor4f(1, 1, 0, 1); |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 1054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 1056 | Region::const_iterator it = mDirtyRegion.begin(); |
| 1057 | Region::const_iterator const end = mDirtyRegion.end(); |
| 1058 | while (it != end) { |
| 1059 | const Rect& r = *it++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | GLfloat vertices[][2] = { |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1061 | { r.left, height - r.top }, |
| 1062 | { r.left, height - r.bottom }, |
| 1063 | { r.right, height - r.bottom }, |
| 1064 | { r.right, height - r.top } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | }; |
| 1066 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
| 1067 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 1068 | } |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1069 | |
Mathias Agopian | d0f2f0d | 2011-09-20 17:22:44 -0700 | [diff] [blame] | 1070 | hw.flip(mSwapRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | |
| 1072 | if (mDebugRegion > 1) |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1073 | usleep(mDebugRegion * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | |
| 1075 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | void SurfaceFlinger::drawWormhole() const |
| 1079 | { |
| 1080 | const Region region(mWormholeRegion.intersect(mDirtyRegion)); |
| 1081 | if (region.isEmpty()) |
| 1082 | return; |
| 1083 | |
| 1084 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1085 | const int32_t width = hw.getWidth(); |
| 1086 | const int32_t height = hw.getHeight(); |
| 1087 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | if (LIKELY(!mDebugBackground)) { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1089 | glClearColor(0,0,0,0); |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 1090 | Region::const_iterator it = region.begin(); |
| 1091 | Region::const_iterator const end = region.end(); |
| 1092 | while (it != end) { |
| 1093 | const Rect& r = *it++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | const GLint sy = height - (r.top + r.height()); |
| 1095 | glScissor(r.left, sy, r.width(), r.height()); |
| 1096 | glClear(GL_COLOR_BUFFER_BIT); |
| 1097 | } |
| 1098 | } else { |
| 1099 | const GLshort vertices[][2] = { { 0, 0 }, { width, 0 }, |
| 1100 | { width, height }, { 0, height } }; |
| 1101 | const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } }; |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 1102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | glVertexPointer(2, GL_SHORT, 0, vertices); |
| 1104 | glTexCoordPointer(2, GL_SHORT, 0, tcoords); |
| 1105 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 1106 | |
| 1107 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | glEnable(GL_TEXTURE_2D); |
| 1109 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); |
| 1110 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 1111 | glMatrixMode(GL_TEXTURE); |
| 1112 | glLoadIdentity(); |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 1113 | |
| 1114 | glDisable(GL_BLEND); |
| 1115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1); |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 1117 | Region::const_iterator it = region.begin(); |
| 1118 | Region::const_iterator const end = region.end(); |
| 1119 | while (it != end) { |
| 1120 | const Rect& r = *it++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | const GLint sy = height - (r.top + r.height()); |
| 1122 | glScissor(r.left, sy, r.width(), r.height()); |
| 1123 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 1124 | } |
| 1125 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1126 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 04a709e4 | 2010-12-14 18:38:36 -0800 | [diff] [blame] | 1127 | glLoadIdentity(); |
| 1128 | glMatrixMode(GL_MODELVIEW); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | void SurfaceFlinger::debugShowFPS() const |
| 1133 | { |
| 1134 | static int mFrameCount; |
| 1135 | static int mLastFrameCount = 0; |
| 1136 | static nsecs_t mLastFpsTime = 0; |
| 1137 | static float mFps = 0; |
| 1138 | mFrameCount++; |
| 1139 | nsecs_t now = systemTime(); |
| 1140 | nsecs_t diff = now - mLastFpsTime; |
| 1141 | if (diff > ms2ns(250)) { |
| 1142 | mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; |
| 1143 | mLastFpsTime = now; |
| 1144 | mLastFrameCount = mFrameCount; |
| 1145 | } |
| 1146 | // XXX: mFPS has the value we want |
| 1147 | } |
| 1148 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1149 | status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | { |
| 1151 | Mutex::Autolock _l(mStateLock); |
| 1152 | addLayer_l(layer); |
| 1153 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); |
| 1154 | return NO_ERROR; |
| 1155 | } |
| 1156 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1157 | status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer) |
| 1158 | { |
Mathias Agopian | 1efba9a | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 1159 | ssize_t i = mCurrentState.layersSortedByZ.add(layer); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1160 | return (i < 0) ? status_t(i) : status_t(NO_ERROR); |
| 1161 | } |
| 1162 | |
| 1163 | ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client, |
| 1164 | const sp<LayerBaseClient>& lbc) |
| 1165 | { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1166 | // attach this layer to the client |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 1167 | size_t name = client->attachLayer(lbc); |
| 1168 | |
| 1169 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1170 | |
| 1171 | // add this layer to the current state list |
| 1172 | addLayer_l(lbc); |
| 1173 | |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 1174 | return ssize_t(name); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1177 | status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | { |
| 1179 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1180 | status_t err = purgatorizeLayer_l(layer); |
| 1181 | if (err == NO_ERROR) |
| 1182 | setTransactionFlags(eTransactionNeeded); |
| 1183 | return err; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1186 | status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | { |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1188 | sp<LayerBaseClient> lbc(layerBase->getLayerBaseClient()); |
| 1189 | if (lbc != 0) { |
Mathias Agopian | d35c666 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 1190 | mLayerMap.removeItem( lbc->getSurfaceBinder() ); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase); |
| 1193 | if (index >= 0) { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1194 | mLayersRemoved = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | return NO_ERROR; |
| 1196 | } |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1197 | return status_t(index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1200 | status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase) |
| 1201 | { |
Mathias Agopian | f4dfe1b | 2011-01-14 17:37:42 -0800 | [diff] [blame] | 1202 | // First add the layer to the purgatory list, which makes sure it won't |
| 1203 | // go away, then remove it from the main list (through a transaction). |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1204 | ssize_t err = removeLayer_l(layerBase); |
Mathias Agopian | f4dfe1b | 2011-01-14 17:37:42 -0800 | [diff] [blame] | 1205 | if (err >= 0) { |
| 1206 | mLayerPurgatory.add(layerBase); |
| 1207 | } |
Mathias Agopian | 2e4b68d | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1208 | |
Mathias Agopian | 0c4cec7 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 1209 | layerBase->onRemoved(); |
| 1210 | |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1211 | // it's possible that we don't find a layer, because it might |
| 1212 | // have been destroyed already -- this is not technically an error |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1213 | // from the user because there is a race between Client::destroySurface(), |
| 1214 | // ~Client() and ~ISurface(). |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1215 | return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err; |
| 1216 | } |
| 1217 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1218 | status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1220 | layer->forceVisibilityTransaction(); |
| 1221 | setTransactionFlags(eTraversalNeeded); |
| 1222 | return NO_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Mathias Agopian | 6dcb155 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 1225 | uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags) |
| 1226 | { |
| 1227 | return android_atomic_release_load(&mTransactionFlags); |
| 1228 | } |
| 1229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) |
| 1231 | { |
| 1232 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 1233 | } |
| 1234 | |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1235 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | { |
| 1237 | uint32_t old = android_atomic_or(flags, &mTransactionFlags); |
| 1238 | if ((old & flags)==0) { // wake the server up |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1239 | signalEvent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | } |
| 1241 | return old; |
| 1242 | } |
| 1243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 1245 | void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& state, |
| 1246 | int orientation) { |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1247 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1248 | |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1249 | uint32_t flags = 0; |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 1250 | if (mCurrentState.orientation != orientation) { |
| 1251 | if (uint32_t(orientation)<=eOrientation270 || orientation==42) { |
| 1252 | mCurrentState.orientation = orientation; |
| 1253 | flags |= eTransactionNeeded; |
| 1254 | mResizeTransationPending = true; |
| 1255 | } else if (orientation != eOrientationUnchanged) { |
| 1256 | LOGW("setTransactionState: ignoring unrecognized orientation: %d", |
| 1257 | orientation); |
| 1258 | } |
| 1259 | } |
| 1260 | |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1261 | const size_t count = state.size(); |
| 1262 | for (size_t i=0 ; i<count ; i++) { |
| 1263 | const ComposerState& s(state[i]); |
| 1264 | sp<Client> client( static_cast<Client *>(s.client.get()) ); |
| 1265 | flags |= setClientStateLocked(client, s.state); |
| 1266 | } |
| 1267 | if (flags) { |
| 1268 | setTransactionFlags(flags); |
| 1269 | } |
| 1270 | |
| 1271 | signalEvent(); |
| 1272 | |
| 1273 | // if there is a transaction with a resize, wait for it to |
| 1274 | // take effect before returning. |
| 1275 | while (mResizeTransationPending) { |
| 1276 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
| 1277 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 1278 | // just in case something goes wrong in SF, return to the |
| 1279 | // called after a few seconds. |
| 1280 | LOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!"); |
| 1281 | mResizeTransationPending = false; |
| 1282 | break; |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags) |
| 1288 | { |
| 1289 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1290 | return BAD_VALUE; |
| 1291 | |
| 1292 | Mutex::Autolock _l(mStateLock); |
| 1293 | mCurrentState.freezeDisplay = 1; |
| 1294 | setTransactionFlags(eTransactionNeeded); |
| 1295 | |
| 1296 | // flags is intended to communicate some sort of animation behavior |
Mathias Agopian | ed81f22 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1297 | // (for instance fading) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | return NO_ERROR; |
| 1299 | } |
| 1300 | |
| 1301 | status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags) |
| 1302 | { |
| 1303 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1304 | return BAD_VALUE; |
| 1305 | |
| 1306 | Mutex::Autolock _l(mStateLock); |
| 1307 | mCurrentState.freezeDisplay = 0; |
| 1308 | setTransactionFlags(eTransactionNeeded); |
| 1309 | |
| 1310 | // flags is intended to communicate some sort of animation behavior |
Mathias Agopian | ed81f22 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1311 | // (for instance fading) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | return NO_ERROR; |
| 1313 | } |
| 1314 | |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1315 | int SurfaceFlinger::setOrientation(DisplayID dpy, |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 1316 | int orientation, uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | { |
| 1318 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1319 | return BAD_VALUE; |
| 1320 | |
| 1321 | Mutex::Autolock _l(mStateLock); |
| 1322 | if (mCurrentState.orientation != orientation) { |
| 1323 | if (uint32_t(orientation)<=eOrientation270 || orientation==42) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1324 | mCurrentState.orientationFlags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | mCurrentState.orientation = orientation; |
| 1326 | setTransactionFlags(eTransactionNeeded); |
| 1327 | mTransactionCV.wait(mStateLock); |
| 1328 | } else { |
| 1329 | orientation = BAD_VALUE; |
| 1330 | } |
| 1331 | } |
| 1332 | return orientation; |
| 1333 | } |
| 1334 | |
Mathias Agopian | 9638e5c | 2011-04-20 14:19:32 -0700 | [diff] [blame] | 1335 | sp<ISurface> SurfaceFlinger::createSurface( |
| 1336 | ISurfaceComposerClient::surface_data_t* params, |
| 1337 | const String8& name, |
| 1338 | const sp<Client>& client, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | DisplayID d, uint32_t w, uint32_t h, PixelFormat format, |
| 1340 | uint32_t flags) |
| 1341 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1342 | sp<LayerBaseClient> layer; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1343 | sp<ISurface> surfaceHandle; |
Mathias Agopian | 4d2dbeb | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1344 | |
| 1345 | if (int32_t(w|h) < 0) { |
| 1346 | LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)", |
| 1347 | int(w), int(h)); |
| 1348 | return surfaceHandle; |
| 1349 | } |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | //LOGD("createSurface for pid %d (%d x %d)", pid, w, h); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1352 | sp<Layer> normalLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | switch (flags & eFXSurfaceMask) { |
| 1354 | case eFXSurfaceNormal: |
Mathias Agopian | d211230 | 2010-12-07 19:38:17 -0800 | [diff] [blame] | 1355 | normalLayer = createNormalSurface(client, d, w, h, flags, format); |
| 1356 | layer = normalLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | break; |
| 1358 | case eFXSurfaceBlur: |
Mathias Agopian | c3802d2 | 2010-12-08 17:13:19 -0800 | [diff] [blame] | 1359 | // for now we treat Blur as Dim, until we can implement it |
| 1360 | // efficiently. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | case eFXSurfaceDim: |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1362 | layer = createDimSurface(client, d, w, h, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1363 | break; |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1364 | case eFXSurfaceScreenshot: |
| 1365 | layer = createScreenshotSurface(client, d, w, h, flags); |
| 1366 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | } |
| 1368 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1369 | if (layer != 0) { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1370 | layer->initStates(w, h, flags); |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 1371 | layer->setName(name); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1372 | ssize_t token = addClientLayer(client, layer); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | surfaceHandle = layer->getSurface(); |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1375 | if (surfaceHandle != 0) { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1376 | params->token = token; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1377 | params->identity = layer->getIdentity(); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1378 | if (normalLayer != 0) { |
| 1379 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1380 | mLayerMap.add(layer->getSurfaceBinder(), normalLayer); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1381 | } |
Mathias Agopian | 18b6b49 | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1382 | } |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1383 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1384 | setTransactionFlags(eTransactionNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | return surfaceHandle; |
| 1388 | } |
| 1389 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1390 | sp<Layer> SurfaceFlinger::createNormalSurface( |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1391 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1392 | uint32_t w, uint32_t h, uint32_t flags, |
Mathias Agopian | 18b6b49 | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1393 | PixelFormat& format) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | { |
| 1395 | // initialize the surfaces |
| 1396 | switch (format) { // TODO: take h/w into account |
| 1397 | case PIXEL_FORMAT_TRANSPARENT: |
| 1398 | case PIXEL_FORMAT_TRANSLUCENT: |
| 1399 | format = PIXEL_FORMAT_RGBA_8888; |
| 1400 | break; |
| 1401 | case PIXEL_FORMAT_OPAQUE: |
Mathias Agopian | 4cfb3a6 | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1402 | #ifdef NO_RGBX_8888 |
| 1403 | format = PIXEL_FORMAT_RGB_565; |
| 1404 | #else |
Mathias Agopian | 59962ce | 2010-04-05 18:01:24 -0700 | [diff] [blame] | 1405 | format = PIXEL_FORMAT_RGBX_8888; |
Mathias Agopian | 4cfb3a6 | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1406 | #endif |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | break; |
| 1408 | } |
| 1409 | |
Mathias Agopian | 4cfb3a6 | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1410 | #ifdef NO_RGBX_8888 |
| 1411 | if (format == PIXEL_FORMAT_RGBX_8888) |
| 1412 | format = PIXEL_FORMAT_RGBA_8888; |
| 1413 | #endif |
| 1414 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1415 | sp<Layer> layer = new Layer(this, display, client); |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1416 | status_t err = layer->setBuffers(w, h, format, flags); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1417 | if (LIKELY(err != NO_ERROR)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err)); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1419 | layer.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | } |
| 1421 | return layer; |
| 1422 | } |
| 1423 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1424 | sp<LayerDim> SurfaceFlinger::createDimSurface( |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1425 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1426 | uint32_t w, uint32_t h, uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1428 | sp<LayerDim> layer = new LayerDim(this, display, client); |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1429 | return layer; |
| 1430 | } |
| 1431 | |
| 1432 | sp<LayerScreenshot> SurfaceFlinger::createScreenshotSurface( |
| 1433 | const sp<Client>& client, DisplayID display, |
| 1434 | uint32_t w, uint32_t h, uint32_t flags) |
| 1435 | { |
| 1436 | sp<LayerScreenshot> layer = new LayerScreenshot(this, display, client); |
| 1437 | status_t err = layer->capture(); |
| 1438 | if (err != NO_ERROR) { |
| 1439 | layer.clear(); |
| 1440 | LOGW("createScreenshotSurface failed (%s)", strerror(-err)); |
| 1441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | return layer; |
| 1443 | } |
| 1444 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1445 | status_t SurfaceFlinger::removeSurface(const sp<Client>& client, SurfaceID sid) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | { |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1447 | /* |
| 1448 | * called by the window manager, when a surface should be marked for |
| 1449 | * destruction. |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1450 | * |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1451 | * The surface is removed from the current and drawing lists, but placed |
| 1452 | * in the purgatory queue, so it's not destroyed right-away (we need |
| 1453 | * to wait for all client's references to go away first). |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1454 | */ |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1455 | |
Mathias Agopian | 248b5bd | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1456 | status_t err = NAME_NOT_FOUND; |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1457 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1458 | sp<LayerBaseClient> layer = client->getLayerUser(sid); |
Mathias Agopian | 248b5bd | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1459 | if (layer != 0) { |
| 1460 | err = purgatorizeLayer_l(layer); |
| 1461 | if (err == NO_ERROR) { |
Mathias Agopian | 248b5bd | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1462 | setTransactionFlags(eTransactionNeeded); |
| 1463 | } |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1464 | } |
| 1465 | return err; |
| 1466 | } |
| 1467 | |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1468 | status_t SurfaceFlinger::destroySurface(const wp<LayerBaseClient>& layer) |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1469 | { |
Mathias Agopian | 359140c | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1470 | // called by ~ISurface() when all references are gone |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1471 | status_t err = NO_ERROR; |
| 1472 | sp<LayerBaseClient> l(layer.promote()); |
| 1473 | if (l != NULL) { |
| 1474 | Mutex::Autolock _l(mStateLock); |
| 1475 | err = removeLayer_l(l); |
| 1476 | if (err == NAME_NOT_FOUND) { |
| 1477 | // The surface wasn't in the current list, which means it was |
| 1478 | // removed already, which means it is in the purgatory, |
| 1479 | // and need to be removed from there. |
| 1480 | ssize_t idx = mLayerPurgatory.remove(l); |
| 1481 | LOGE_IF(idx < 0, |
| 1482 | "layer=%p is not in the purgatory list", l.get()); |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1483 | } |
Mathias Agopian | 6960811 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1484 | LOGE_IF(err<0 && err != NAME_NOT_FOUND, |
| 1485 | "error removing layer=%p (%s)", l.get(), strerror(-err)); |
| 1486 | } |
| 1487 | return err; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | } |
| 1489 | |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1490 | uint32_t SurfaceFlinger::setClientStateLocked( |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1491 | const sp<Client>& client, |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1492 | const layer_state_t& s) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | uint32_t flags = 0; |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1495 | sp<LayerBaseClient> layer(client->getLayerUser(s.surface)); |
| 1496 | if (layer != 0) { |
| 1497 | const uint32_t what = s.what; |
| 1498 | if (what & ePositionChanged) { |
| 1499 | if (layer->setPosition(s.x, s.y)) |
| 1500 | flags |= eTraversalNeeded; |
| 1501 | } |
| 1502 | if (what & eLayerChanged) { |
| 1503 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 1504 | if (layer->setLayer(s.z)) { |
| 1505 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 1506 | mCurrentState.layersSortedByZ.add(layer); |
| 1507 | // we need traversal (state changed) |
| 1508 | // AND transaction (list changed) |
| 1509 | flags |= eTransactionNeeded|eTraversalNeeded; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | } |
| 1511 | } |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1512 | if (what & eSizeChanged) { |
| 1513 | if (layer->setSize(s.w, s.h)) { |
| 1514 | flags |= eTraversalNeeded; |
| 1515 | mResizeTransationPending = true; |
| 1516 | } |
| 1517 | } |
| 1518 | if (what & eAlphaChanged) { |
| 1519 | if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f))) |
| 1520 | flags |= eTraversalNeeded; |
| 1521 | } |
| 1522 | if (what & eMatrixChanged) { |
| 1523 | if (layer->setMatrix(s.matrix)) |
| 1524 | flags |= eTraversalNeeded; |
| 1525 | } |
| 1526 | if (what & eTransparentRegionChanged) { |
| 1527 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 1528 | flags |= eTraversalNeeded; |
| 1529 | } |
| 1530 | if (what & eVisibilityChanged) { |
| 1531 | if (layer->setFlags(s.flags, s.mask)) |
| 1532 | flags |= eTraversalNeeded; |
| 1533 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | } |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1535 | return flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | void SurfaceFlinger::screenReleased(int dpy) |
| 1539 | { |
| 1540 | // this may be called by a signal handler, we can't do too much in here |
| 1541 | android_atomic_or(eConsoleReleased, &mConsoleSignals); |
| 1542 | signalEvent(); |
| 1543 | } |
| 1544 | |
| 1545 | void SurfaceFlinger::screenAcquired(int dpy) |
| 1546 | { |
| 1547 | // this may be called by a signal handler, we can't do too much in here |
| 1548 | android_atomic_or(eConsoleAcquired, &mConsoleSignals); |
| 1549 | signalEvent(); |
| 1550 | } |
| 1551 | |
| 1552 | status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args) |
| 1553 | { |
Erik Gilling | 94720d7 | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 1554 | const size_t SIZE = 4096; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | char buffer[SIZE]; |
| 1556 | String8 result; |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 1557 | |
| 1558 | if (!PermissionCache::checkCallingPermission(sDump)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | snprintf(buffer, SIZE, "Permission Denial: " |
| 1560 | "can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 1561 | IPCThreadState::self()->getCallingPid(), |
| 1562 | IPCThreadState::self()->getCallingUid()); |
| 1563 | result.append(buffer); |
| 1564 | } else { |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1565 | |
| 1566 | // figure out if we're stuck somewhere |
| 1567 | const nsecs_t now = systemTime(); |
| 1568 | const nsecs_t inSwapBuffers(mDebugInSwapBuffers); |
| 1569 | const nsecs_t inTransaction(mDebugInTransaction); |
| 1570 | nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0; |
| 1571 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 1572 | |
| 1573 | // Try to get the main lock, but don't insist if we can't |
| 1574 | // (this would indicate SF is stuck, but we want to be able to |
| 1575 | // print something in dumpsys). |
| 1576 | int retry = 3; |
| 1577 | while (mStateLock.tryLock()<0 && --retry>=0) { |
| 1578 | usleep(1000000); |
| 1579 | } |
| 1580 | const bool locked(retry >= 0); |
| 1581 | if (!locked) { |
Andreas Huber | e3c0183 | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1582 | snprintf(buffer, SIZE, |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1583 | "SurfaceFlinger appears to be unresponsive, " |
| 1584 | "dumping anyways (no locks held)\n"); |
| 1585 | result.append(buffer); |
| 1586 | } |
| 1587 | |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1588 | /* |
| 1589 | * Dump the visible layer list |
| 1590 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 1592 | const size_t count = currentLayers.size(); |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1593 | snprintf(buffer, SIZE, "Visible layers (count = %d)\n", count); |
| 1594 | result.append(buffer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1596 | const sp<LayerBase>& layer(currentLayers[i]); |
| 1597 | layer->dump(result, buffer, SIZE); |
| 1598 | const Layer::State& s(layer->drawingState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | s.transparentRegion.dump(result, "transparentRegion"); |
| 1600 | layer->transparentRegionScreen.dump(result, "transparentRegionScreen"); |
| 1601 | layer->visibleRegionScreen.dump(result, "visibleRegionScreen"); |
| 1602 | } |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1603 | |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1604 | /* |
| 1605 | * Dump the layers in the purgatory |
| 1606 | */ |
| 1607 | |
| 1608 | const size_t purgatorySize = mLayerPurgatory.size(); |
| 1609 | snprintf(buffer, SIZE, "Purgatory state (%d entries)\n", purgatorySize); |
| 1610 | result.append(buffer); |
| 1611 | for (size_t i=0 ; i<purgatorySize ; i++) { |
| 1612 | const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i)); |
| 1613 | layer->shortDump(result, buffer, SIZE); |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Dump SurfaceFlinger global state |
| 1618 | */ |
| 1619 | |
Mathias Agopian | ab95117 | 2011-07-14 18:01:49 -0700 | [diff] [blame] | 1620 | snprintf(buffer, SIZE, "SurfaceFlinger global state:\n"); |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1621 | result.append(buffer); |
Mathias Agopian | ab95117 | 2011-07-14 18:01:49 -0700 | [diff] [blame] | 1622 | |
| 1623 | const GLExtensions& extensions(GLExtensions::getInstance()); |
| 1624 | snprintf(buffer, SIZE, "GLES: %s, %s, %s\n", |
| 1625 | extensions.getVendor(), |
| 1626 | extensions.getRenderer(), |
| 1627 | extensions.getVersion()); |
| 1628 | result.append(buffer); |
| 1629 | snprintf(buffer, SIZE, "EXTS: %s\n", extensions.getExtension()); |
| 1630 | result.append(buffer); |
| 1631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | mWormholeRegion.dump(result, "WormholeRegion"); |
| 1633 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1634 | snprintf(buffer, SIZE, |
| 1635 | " display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n", |
| 1636 | mFreezeDisplay?"yes":"no", mFreezeCount, |
| 1637 | mCurrentState.orientation, hw.canDraw()); |
| 1638 | result.append(buffer); |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1639 | snprintf(buffer, SIZE, |
| 1640 | " last eglSwapBuffers() time: %f us\n" |
Mathias Agopian | abf88be | 2011-10-20 17:22:38 -0700 | [diff] [blame] | 1641 | " last transaction time : %f us\n" |
| 1642 | " refresh-rate : %f fps\n" |
| 1643 | " x-dpi : %f\n" |
| 1644 | " y-dpi : %f\n", |
| 1645 | mLastSwapBufferTime/1000.0, |
| 1646 | mLastTransactionTime/1000.0, |
| 1647 | hw.getRefreshRate(), |
| 1648 | hw.getDpiX(), |
| 1649 | hw.getDpiY()); |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1650 | result.append(buffer); |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1651 | |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1652 | if (inSwapBuffersDuration || !locked) { |
| 1653 | snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n", |
| 1654 | inSwapBuffersDuration/1000.0); |
| 1655 | result.append(buffer); |
| 1656 | } |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1657 | |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1658 | if (inTransactionDuration || !locked) { |
| 1659 | snprintf(buffer, SIZE, " transaction time: %f us\n", |
| 1660 | inTransactionDuration/1000.0); |
| 1661 | result.append(buffer); |
| 1662 | } |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1663 | |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1664 | /* |
| 1665 | * Dump HWComposer state |
| 1666 | */ |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 1667 | HWComposer& hwc(hw.getHwComposer()); |
| 1668 | snprintf(buffer, SIZE, " h/w composer %s and %s\n", |
| 1669 | hwc.initCheck()==NO_ERROR ? "present" : "not present", |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1670 | (mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled"); |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 1671 | result.append(buffer); |
Mathias Agopian | 5bd1b27 | 2011-09-09 00:49:11 -0700 | [diff] [blame] | 1672 | hwc.dump(result, buffer, SIZE, mVisibleLayersSortedByZ); |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 1673 | |
Mathias Agopian | 06a61e2 | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 1674 | /* |
| 1675 | * Dump gralloc state |
| 1676 | */ |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 1677 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1678 | alloc.dump(result); |
Erik Gilling | 94720d7 | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 1679 | hw.dump(result); |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1680 | |
| 1681 | if (locked) { |
| 1682 | mStateLock.unlock(); |
| 1683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | } |
| 1685 | write(fd, result.string(), result.size()); |
| 1686 | return NO_ERROR; |
| 1687 | } |
| 1688 | |
| 1689 | status_t SurfaceFlinger::onTransact( |
| 1690 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 1691 | { |
| 1692 | switch (code) { |
| 1693 | case CREATE_CONNECTION: |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1694 | case SET_TRANSACTION_STATE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | case SET_ORIENTATION: |
| 1696 | case FREEZE_DISPLAY: |
| 1697 | case UNFREEZE_DISPLAY: |
| 1698 | case BOOT_FINISHED: |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1699 | case TURN_ELECTRON_BEAM_OFF: |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1700 | case TURN_ELECTRON_BEAM_ON: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | { |
| 1702 | // codes that require permission check |
| 1703 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1704 | const int pid = ipc->getCallingPid(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 1705 | const int uid = ipc->getCallingUid(); |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 1706 | if ((uid != AID_GRAPHICS) && |
| 1707 | !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1708 | LOGE("Permission Denial: " |
| 1709 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 1710 | return PERMISSION_DENIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | } |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 1712 | break; |
| 1713 | } |
| 1714 | case CAPTURE_SCREEN: |
| 1715 | { |
| 1716 | // codes that require permission check |
| 1717 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1718 | const int pid = ipc->getCallingPid(); |
| 1719 | const int uid = ipc->getCallingUid(); |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 1720 | if ((uid != AID_GRAPHICS) && |
| 1721 | !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 1722 | LOGE("Permission Denial: " |
| 1723 | "can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 1724 | return PERMISSION_DENIED; |
| 1725 | } |
| 1726 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | } |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 1729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 1731 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | 8c9687a | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 1732 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 1733 | if (UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1734 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1735 | const int pid = ipc->getCallingPid(); |
| 1736 | const int uid = ipc->getCallingUid(); |
| 1737 | LOGE("Permission Denial: " |
| 1738 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | return PERMISSION_DENIED; |
| 1740 | } |
| 1741 | int n; |
| 1742 | switch (code) { |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1743 | case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 1744 | case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1745 | return NO_ERROR; |
| 1746 | case 1002: // SHOW_UPDATES |
| 1747 | n = data.readInt32(); |
| 1748 | mDebugRegion = n ? n : (mDebugRegion ? 0 : 1); |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1749 | invalidateHwcGeometry(); |
| 1750 | repaintEverything(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | return NO_ERROR; |
| 1752 | case 1003: // SHOW_BACKGROUND |
| 1753 | n = data.readInt32(); |
| 1754 | mDebugBackground = n ? 1 : 0; |
| 1755 | return NO_ERROR; |
| 1756 | case 1004:{ // repaint everything |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1757 | repaintEverything(); |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1758 | return NO_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | } |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1760 | case 1005:{ // force transaction |
| 1761 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); |
| 1762 | return NO_ERROR; |
| 1763 | } |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 1764 | case 1006:{ // enable/disable GraphicLog |
| 1765 | int enabled = data.readInt32(); |
| 1766 | GraphicLog::getInstance().setEnabled(enabled); |
| 1767 | return NO_ERROR; |
| 1768 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | case 1007: // set mFreezeCount |
| 1770 | mFreezeCount = data.readInt32(); |
Mathias Agopian | 0e44976 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 1771 | mFreezeDisplayTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1772 | return NO_ERROR; |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1773 | case 1008: // toggle use of hw composer |
| 1774 | n = data.readInt32(); |
| 1775 | mDebugDisableHWC = n ? 1 : 0; |
| 1776 | invalidateHwcGeometry(); |
| 1777 | repaintEverything(); |
| 1778 | return NO_ERROR; |
Mathias Agopian | 2143fe0 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1779 | case 1009: // toggle use of transform hint |
| 1780 | n = data.readInt32(); |
| 1781 | mDebugDisableTransformHint = n ? 1 : 0; |
| 1782 | invalidateHwcGeometry(); |
| 1783 | repaintEverything(); |
| 1784 | return NO_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1785 | case 1010: // interrogate. |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1786 | reply->writeInt32(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | reply->writeInt32(0); |
| 1788 | reply->writeInt32(mDebugRegion); |
| 1789 | reply->writeInt32(mDebugBackground); |
| 1790 | return NO_ERROR; |
| 1791 | case 1013: { |
| 1792 | Mutex::Autolock _l(mStateLock); |
| 1793 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1794 | reply->writeInt32(hw.getPageFlipCount()); |
| 1795 | } |
| 1796 | return NO_ERROR; |
| 1797 | } |
| 1798 | } |
| 1799 | return err; |
| 1800 | } |
| 1801 | |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1802 | void SurfaceFlinger::repaintEverything() { |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1803 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | 6497eab | 2011-10-21 15:18:28 -0700 | [diff] [blame^] | 1804 | const Rect bounds(hw.getBounds()); |
| 1805 | setInvalidateRegion(Region(bounds)); |
Mathias Agopian | 7f76a3c | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 1806 | signalEvent(); |
| 1807 | } |
| 1808 | |
Mathias Agopian | 6497eab | 2011-10-21 15:18:28 -0700 | [diff] [blame^] | 1809 | void SurfaceFlinger::setInvalidateRegion(const Region& reg) { |
| 1810 | Mutex::Autolock _l(mInvalidateLock); |
| 1811 | mInvalidateRegion = reg; |
| 1812 | } |
| 1813 | |
| 1814 | Region SurfaceFlinger::getAndClearInvalidateRegion() { |
| 1815 | Mutex::Autolock _l(mInvalidateLock); |
| 1816 | Region reg(mInvalidateRegion); |
| 1817 | mInvalidateRegion.clear(); |
| 1818 | return reg; |
| 1819 | } |
| 1820 | |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1821 | // --------------------------------------------------------------------------- |
| 1822 | |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1823 | status_t SurfaceFlinger::renderScreenToTexture(DisplayID dpy, |
| 1824 | GLuint* textureName, GLfloat* uOut, GLfloat* vOut) |
| 1825 | { |
| 1826 | Mutex::Autolock _l(mStateLock); |
| 1827 | return renderScreenToTextureLocked(dpy, textureName, uOut, vOut); |
| 1828 | } |
| 1829 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1830 | status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy, |
| 1831 | GLuint* textureName, GLfloat* uOut, GLfloat* vOut) |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1832 | { |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1833 | if (!GLExtensions::getInstance().haveFramebufferObject()) |
| 1834 | return INVALID_OPERATION; |
| 1835 | |
| 1836 | // get screen geometry |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1837 | const DisplayHardware& hw(graphicPlane(dpy).displayHardware()); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1838 | const uint32_t hw_w = hw.getWidth(); |
| 1839 | const uint32_t hw_h = hw.getHeight(); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1840 | GLfloat u = 1; |
| 1841 | GLfloat v = 1; |
| 1842 | |
| 1843 | // make sure to clear all GL error flags |
| 1844 | while ( glGetError() != GL_NO_ERROR ) ; |
| 1845 | |
| 1846 | // create a FBO |
| 1847 | GLuint name, tname; |
| 1848 | glGenTextures(1, &tname); |
| 1849 | glBindTexture(GL_TEXTURE_2D, tname); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1850 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 1851 | hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1852 | if (glGetError() != GL_NO_ERROR) { |
Mathias Agopian | a6cd6d3 | 2010-10-14 12:19:37 -0700 | [diff] [blame] | 1853 | while ( glGetError() != GL_NO_ERROR ) ; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1854 | GLint tw = (2 << (31 - clz(hw_w))); |
| 1855 | GLint th = (2 << (31 - clz(hw_h))); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1856 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 1857 | tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1858 | u = GLfloat(hw_w) / tw; |
| 1859 | v = GLfloat(hw_h) / th; |
| 1860 | } |
| 1861 | glGenFramebuffersOES(1, &name); |
| 1862 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1863 | glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, |
| 1864 | GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 1865 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1866 | // redraw the screen entirely... |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 1867 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 1868 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1869 | glClearColor(0,0,0,1); |
| 1870 | glClear(GL_COLOR_BUFFER_BIT); |
Mathias Agopian | b946a56 | 2011-10-10 19:02:07 -0700 | [diff] [blame] | 1871 | glMatrixMode(GL_MODELVIEW); |
| 1872 | glLoadIdentity(); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1873 | const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ); |
| 1874 | const size_t count = layers.size(); |
| 1875 | for (size_t i=0 ; i<count ; ++i) { |
| 1876 | const sp<LayerBase>& layer(layers[i]); |
| 1877 | layer->drawForSreenShot(); |
| 1878 | } |
| 1879 | |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1880 | hw.compositionComplete(); |
| 1881 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1882 | // back to main framebuffer |
| 1883 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); |
| 1884 | glDisable(GL_SCISSOR_TEST); |
| 1885 | glDeleteFramebuffersOES(1, &name); |
| 1886 | |
| 1887 | *textureName = tname; |
| 1888 | *uOut = u; |
| 1889 | *vOut = v; |
| 1890 | return NO_ERROR; |
| 1891 | } |
| 1892 | |
| 1893 | // --------------------------------------------------------------------------- |
| 1894 | |
| 1895 | status_t SurfaceFlinger::electronBeamOffAnimationImplLocked() |
| 1896 | { |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1897 | // get screen geometry |
| 1898 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1899 | const uint32_t hw_w = hw.getWidth(); |
| 1900 | const uint32_t hw_h = hw.getHeight(); |
Mathias Agopian | b946a56 | 2011-10-10 19:02:07 -0700 | [diff] [blame] | 1901 | const Region screenBounds(hw.getBounds()); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1902 | |
| 1903 | GLfloat u, v; |
| 1904 | GLuint tname; |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1905 | status_t result = renderScreenToTextureLocked(0, &tname, &u, &v); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1906 | if (result != NO_ERROR) { |
| 1907 | return result; |
| 1908 | } |
| 1909 | |
| 1910 | GLfloat vtx[8]; |
Mathias Agopian | b946a56 | 2011-10-10 19:02:07 -0700 | [diff] [blame] | 1911 | const GLfloat texCoords[4][2] = { {0,0}, {0,v}, {u,v}, {u,0} }; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1912 | glBindTexture(GL_TEXTURE_2D, tname); |
| 1913 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 1914 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1915 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1916 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 1917 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 1918 | glVertexPointer(2, GL_FLOAT, 0, vtx); |
| 1919 | |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 1920 | /* |
| 1921 | * Texture coordinate mapping |
| 1922 | * |
| 1923 | * u |
| 1924 | * 1 +----------+---+ |
| 1925 | * | | | | image is inverted |
| 1926 | * | V | | w.r.t. the texture |
| 1927 | * 1-v +----------+ | coordinates |
| 1928 | * | | |
| 1929 | * | | |
| 1930 | * | | |
| 1931 | * 0 +--------------+ |
| 1932 | * 0 1 |
| 1933 | * |
| 1934 | */ |
| 1935 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1936 | class s_curve_interpolator { |
| 1937 | const float nbFrames, s, v; |
| 1938 | public: |
| 1939 | s_curve_interpolator(int nbFrames, float s) |
| 1940 | : nbFrames(1.0f / (nbFrames-1)), s(s), |
| 1941 | v(1.0f + expf(-s + 0.5f*s)) { |
| 1942 | } |
| 1943 | float operator()(int f) { |
| 1944 | const float x = f * nbFrames; |
| 1945 | return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f; |
| 1946 | } |
| 1947 | }; |
| 1948 | |
| 1949 | class v_stretch { |
| 1950 | const GLfloat hw_w, hw_h; |
| 1951 | public: |
| 1952 | v_stretch(uint32_t hw_w, uint32_t hw_h) |
| 1953 | : hw_w(hw_w), hw_h(hw_h) { |
| 1954 | } |
| 1955 | void operator()(GLfloat* vtx, float v) { |
| 1956 | const GLfloat w = hw_w + (hw_w * v); |
| 1957 | const GLfloat h = hw_h - (hw_h * v); |
| 1958 | const GLfloat x = (hw_w - w) * 0.5f; |
| 1959 | const GLfloat y = (hw_h - h) * 0.5f; |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 1960 | vtx[0] = x; vtx[1] = y; |
| 1961 | vtx[2] = x; vtx[3] = y + h; |
| 1962 | vtx[4] = x + w; vtx[5] = y + h; |
| 1963 | vtx[6] = x + w; vtx[7] = y; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1964 | } |
| 1965 | }; |
| 1966 | |
| 1967 | class h_stretch { |
| 1968 | const GLfloat hw_w, hw_h; |
| 1969 | public: |
| 1970 | h_stretch(uint32_t hw_w, uint32_t hw_h) |
| 1971 | : hw_w(hw_w), hw_h(hw_h) { |
| 1972 | } |
| 1973 | void operator()(GLfloat* vtx, float v) { |
| 1974 | const GLfloat w = hw_w - (hw_w * v); |
| 1975 | const GLfloat h = 1.0f; |
| 1976 | const GLfloat x = (hw_w - w) * 0.5f; |
| 1977 | const GLfloat y = (hw_h - h) * 0.5f; |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 1978 | vtx[0] = x; vtx[1] = y; |
| 1979 | vtx[2] = x; vtx[3] = y + h; |
| 1980 | vtx[4] = x + w; vtx[5] = y + h; |
| 1981 | vtx[6] = x + w; vtx[7] = y; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1982 | } |
| 1983 | }; |
| 1984 | |
| 1985 | // the full animation is 24 frames |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 1986 | char value[PROPERTY_VALUE_MAX]; |
| 1987 | property_get("debug.sf.electron_frames", value, "24"); |
| 1988 | int nbFrames = (atoi(value) + 1) >> 1; |
| 1989 | if (nbFrames <= 0) // just in case |
| 1990 | nbFrames = 24; |
| 1991 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 1992 | s_curve_interpolator itr(nbFrames, 7.5f); |
| 1993 | s_curve_interpolator itg(nbFrames, 8.0f); |
| 1994 | s_curve_interpolator itb(nbFrames, 8.5f); |
| 1995 | |
| 1996 | v_stretch vverts(hw_w, hw_h); |
Mathias Agopian | b946a56 | 2011-10-10 19:02:07 -0700 | [diff] [blame] | 1997 | |
| 1998 | glMatrixMode(GL_TEXTURE); |
| 1999 | glLoadIdentity(); |
| 2000 | glMatrixMode(GL_MODELVIEW); |
| 2001 | glLoadIdentity(); |
| 2002 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2003 | glEnable(GL_BLEND); |
| 2004 | glBlendFunc(GL_ONE, GL_ONE); |
| 2005 | for (int i=0 ; i<nbFrames ; i++) { |
| 2006 | float x, y, w, h; |
| 2007 | const float vr = itr(i); |
| 2008 | const float vg = itg(i); |
| 2009 | const float vb = itb(i); |
| 2010 | |
| 2011 | // clear screen |
| 2012 | glColorMask(1,1,1,1); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2013 | glClear(GL_COLOR_BUFFER_BIT); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2014 | glEnable(GL_TEXTURE_2D); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2015 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2016 | // draw the red plane |
| 2017 | vverts(vtx, vr); |
| 2018 | glColorMask(1,0,0,1); |
| 2019 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2020 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2021 | // draw the green plane |
| 2022 | vverts(vtx, vg); |
| 2023 | glColorMask(0,1,0,1); |
| 2024 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2025 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2026 | // draw the blue plane |
| 2027 | vverts(vtx, vb); |
| 2028 | glColorMask(0,0,1,1); |
| 2029 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2030 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2031 | // draw the white highlight (we use the last vertices) |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2032 | glDisable(GL_TEXTURE_2D); |
| 2033 | glColorMask(1,1,1,1); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2034 | glColor4f(vg, vg, vg, 1); |
| 2035 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2036 | hw.flip(screenBounds); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2039 | h_stretch hverts(hw_w, hw_h); |
| 2040 | glDisable(GL_BLEND); |
| 2041 | glDisable(GL_TEXTURE_2D); |
| 2042 | glColorMask(1,1,1,1); |
| 2043 | for (int i=0 ; i<nbFrames ; i++) { |
| 2044 | const float v = itg(i); |
| 2045 | hverts(vtx, v); |
| 2046 | glClear(GL_COLOR_BUFFER_BIT); |
| 2047 | glColor4f(1-v, 1-v, 1-v, 1); |
| 2048 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2049 | hw.flip(screenBounds); |
| 2050 | } |
| 2051 | |
| 2052 | glColorMask(1,1,1,1); |
| 2053 | glEnable(GL_SCISSOR_TEST); |
| 2054 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2055 | glDeleteTextures(1, &tname); |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2056 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 2057 | glDisable(GL_BLEND); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2058 | return NO_ERROR; |
| 2059 | } |
| 2060 | |
| 2061 | status_t SurfaceFlinger::electronBeamOnAnimationImplLocked() |
| 2062 | { |
| 2063 | status_t result = PERMISSION_DENIED; |
| 2064 | |
| 2065 | if (!GLExtensions::getInstance().haveFramebufferObject()) |
| 2066 | return INVALID_OPERATION; |
| 2067 | |
| 2068 | |
| 2069 | // get screen geometry |
| 2070 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 2071 | const uint32_t hw_w = hw.getWidth(); |
| 2072 | const uint32_t hw_h = hw.getHeight(); |
| 2073 | const Region screenBounds(hw.bounds()); |
| 2074 | |
| 2075 | GLfloat u, v; |
| 2076 | GLuint tname; |
| 2077 | result = renderScreenToTextureLocked(0, &tname, &u, &v); |
| 2078 | if (result != NO_ERROR) { |
| 2079 | return result; |
| 2080 | } |
| 2081 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2082 | GLfloat vtx[8]; |
| 2083 | const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} }; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2084 | glBindTexture(GL_TEXTURE_2D, tname); |
| 2085 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 2086 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2087 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 2088 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 2089 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2090 | glVertexPointer(2, GL_FLOAT, 0, vtx); |
| 2091 | |
| 2092 | class s_curve_interpolator { |
| 2093 | const float nbFrames, s, v; |
| 2094 | public: |
| 2095 | s_curve_interpolator(int nbFrames, float s) |
| 2096 | : nbFrames(1.0f / (nbFrames-1)), s(s), |
| 2097 | v(1.0f + expf(-s + 0.5f*s)) { |
| 2098 | } |
| 2099 | float operator()(int f) { |
| 2100 | const float x = f * nbFrames; |
| 2101 | return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f; |
| 2102 | } |
| 2103 | }; |
| 2104 | |
| 2105 | class v_stretch { |
| 2106 | const GLfloat hw_w, hw_h; |
| 2107 | public: |
| 2108 | v_stretch(uint32_t hw_w, uint32_t hw_h) |
| 2109 | : hw_w(hw_w), hw_h(hw_h) { |
| 2110 | } |
| 2111 | void operator()(GLfloat* vtx, float v) { |
| 2112 | const GLfloat w = hw_w + (hw_w * v); |
| 2113 | const GLfloat h = hw_h - (hw_h * v); |
| 2114 | const GLfloat x = (hw_w - w) * 0.5f; |
| 2115 | const GLfloat y = (hw_h - h) * 0.5f; |
| 2116 | vtx[0] = x; vtx[1] = y; |
| 2117 | vtx[2] = x; vtx[3] = y + h; |
| 2118 | vtx[4] = x + w; vtx[5] = y + h; |
| 2119 | vtx[6] = x + w; vtx[7] = y; |
| 2120 | } |
| 2121 | }; |
| 2122 | |
| 2123 | class h_stretch { |
| 2124 | const GLfloat hw_w, hw_h; |
| 2125 | public: |
| 2126 | h_stretch(uint32_t hw_w, uint32_t hw_h) |
| 2127 | : hw_w(hw_w), hw_h(hw_h) { |
| 2128 | } |
| 2129 | void operator()(GLfloat* vtx, float v) { |
| 2130 | const GLfloat w = hw_w - (hw_w * v); |
| 2131 | const GLfloat h = 1.0f; |
| 2132 | const GLfloat x = (hw_w - w) * 0.5f; |
| 2133 | const GLfloat y = (hw_h - h) * 0.5f; |
| 2134 | vtx[0] = x; vtx[1] = y; |
| 2135 | vtx[2] = x; vtx[3] = y + h; |
| 2136 | vtx[4] = x + w; vtx[5] = y + h; |
| 2137 | vtx[6] = x + w; vtx[7] = y; |
| 2138 | } |
| 2139 | }; |
| 2140 | |
Mathias Agopian | dfa08fb | 2010-10-14 12:33:07 -0700 | [diff] [blame] | 2141 | // the full animation is 12 frames |
| 2142 | int nbFrames = 8; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2143 | s_curve_interpolator itr(nbFrames, 7.5f); |
| 2144 | s_curve_interpolator itg(nbFrames, 8.0f); |
| 2145 | s_curve_interpolator itb(nbFrames, 8.5f); |
| 2146 | |
| 2147 | h_stretch hverts(hw_w, hw_h); |
| 2148 | glDisable(GL_BLEND); |
| 2149 | glDisable(GL_TEXTURE_2D); |
| 2150 | glColorMask(1,1,1,1); |
| 2151 | for (int i=nbFrames-1 ; i>=0 ; i--) { |
| 2152 | const float v = itg(i); |
| 2153 | hverts(vtx, v); |
| 2154 | glClear(GL_COLOR_BUFFER_BIT); |
| 2155 | glColor4f(1-v, 1-v, 1-v, 1); |
| 2156 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2157 | hw.flip(screenBounds); |
| 2158 | } |
| 2159 | |
Mathias Agopian | dfa08fb | 2010-10-14 12:33:07 -0700 | [diff] [blame] | 2160 | nbFrames = 4; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2161 | v_stretch vverts(hw_w, hw_h); |
| 2162 | glEnable(GL_BLEND); |
| 2163 | glBlendFunc(GL_ONE, GL_ONE); |
| 2164 | for (int i=nbFrames-1 ; i>=0 ; i--) { |
| 2165 | float x, y, w, h; |
| 2166 | const float vr = itr(i); |
| 2167 | const float vg = itg(i); |
| 2168 | const float vb = itb(i); |
| 2169 | |
| 2170 | // clear screen |
| 2171 | glColorMask(1,1,1,1); |
| 2172 | glClear(GL_COLOR_BUFFER_BIT); |
| 2173 | glEnable(GL_TEXTURE_2D); |
| 2174 | |
| 2175 | // draw the red plane |
| 2176 | vverts(vtx, vr); |
| 2177 | glColorMask(1,0,0,1); |
| 2178 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2179 | |
| 2180 | // draw the green plane |
| 2181 | vverts(vtx, vg); |
| 2182 | glColorMask(0,1,0,1); |
| 2183 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2184 | |
| 2185 | // draw the blue plane |
| 2186 | vverts(vtx, vb); |
| 2187 | glColorMask(0,0,1,1); |
| 2188 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2189 | |
| 2190 | hw.flip(screenBounds); |
| 2191 | } |
| 2192 | |
| 2193 | glColorMask(1,1,1,1); |
| 2194 | glEnable(GL_SCISSOR_TEST); |
| 2195 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2196 | glDeleteTextures(1, &tname); |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2197 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 9044ef0 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 2198 | glDisable(GL_BLEND); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2199 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2200 | return NO_ERROR; |
| 2201 | } |
| 2202 | |
| 2203 | // --------------------------------------------------------------------------- |
| 2204 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2205 | status_t SurfaceFlinger::turnElectronBeamOffImplLocked(int32_t mode) |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2206 | { |
| 2207 | DisplayHardware& hw(graphicPlane(0).editDisplayHardware()); |
| 2208 | if (!hw.canDraw()) { |
| 2209 | // we're already off |
| 2210 | return NO_ERROR; |
| 2211 | } |
Mathias Agopian | 7f97258 | 2011-09-02 12:22:39 -0700 | [diff] [blame] | 2212 | |
| 2213 | // turn off hwc while we're doing the animation |
| 2214 | hw.getHwComposer().disable(); |
| 2215 | // and make sure to turn it back on (if needed) next time we compose |
| 2216 | invalidateHwcGeometry(); |
| 2217 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2218 | if (mode & ISurfaceComposer::eElectronBeamAnimationOff) { |
| 2219 | electronBeamOffAnimationImplLocked(); |
| 2220 | } |
| 2221 | |
| 2222 | // always clear the whole screen at the end of the animation |
| 2223 | glClearColor(0,0,0,1); |
| 2224 | glDisable(GL_SCISSOR_TEST); |
| 2225 | glClear(GL_COLOR_BUFFER_BIT); |
| 2226 | glEnable(GL_SCISSOR_TEST); |
| 2227 | hw.flip( Region(hw.bounds()) ); |
| 2228 | |
Mathias Agopian | a6cd6d3 | 2010-10-14 12:19:37 -0700 | [diff] [blame] | 2229 | return NO_ERROR; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode) |
| 2233 | { |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2234 | class MessageTurnElectronBeamOff : public MessageBase { |
| 2235 | SurfaceFlinger* flinger; |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2236 | int32_t mode; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2237 | status_t result; |
| 2238 | public: |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2239 | MessageTurnElectronBeamOff(SurfaceFlinger* flinger, int32_t mode) |
| 2240 | : flinger(flinger), mode(mode), result(PERMISSION_DENIED) { |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2241 | } |
| 2242 | status_t getResult() const { |
| 2243 | return result; |
| 2244 | } |
| 2245 | virtual bool handler() { |
| 2246 | Mutex::Autolock _l(flinger->mStateLock); |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2247 | result = flinger->turnElectronBeamOffImplLocked(mode); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2248 | return true; |
| 2249 | } |
| 2250 | }; |
| 2251 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2252 | sp<MessageBase> msg = new MessageTurnElectronBeamOff(this, mode); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2253 | status_t res = postMessageSync(msg); |
| 2254 | if (res == NO_ERROR) { |
| 2255 | res = static_cast<MessageTurnElectronBeamOff*>( msg.get() )->getResult(); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2256 | |
| 2257 | // work-around: when the power-manager calls us we activate the |
| 2258 | // animation. eventually, the "on" animation will be called |
| 2259 | // by the power-manager itself |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2260 | mElectronBeamAnimationMode = mode; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2261 | } |
| 2262 | return res; |
| 2263 | } |
| 2264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2265 | // --------------------------------------------------------------------------- |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2266 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2267 | status_t SurfaceFlinger::turnElectronBeamOnImplLocked(int32_t mode) |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2268 | { |
| 2269 | DisplayHardware& hw(graphicPlane(0).editDisplayHardware()); |
| 2270 | if (hw.canDraw()) { |
| 2271 | // we're already on |
| 2272 | return NO_ERROR; |
| 2273 | } |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2274 | if (mode & ISurfaceComposer::eElectronBeamAnimationOn) { |
| 2275 | electronBeamOnAnimationImplLocked(); |
| 2276 | } |
Mathias Agopian | 8b6a054 | 2010-10-14 12:46:24 -0700 | [diff] [blame] | 2277 | |
| 2278 | // make sure to redraw the whole screen when the animation is done |
| 2279 | mDirtyRegion.set(hw.bounds()); |
| 2280 | signalEvent(); |
| 2281 | |
Mathias Agopian | a6cd6d3 | 2010-10-14 12:19:37 -0700 | [diff] [blame] | 2282 | return NO_ERROR; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | status_t SurfaceFlinger::turnElectronBeamOn(int32_t mode) |
| 2286 | { |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2287 | class MessageTurnElectronBeamOn : public MessageBase { |
| 2288 | SurfaceFlinger* flinger; |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2289 | int32_t mode; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2290 | status_t result; |
| 2291 | public: |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2292 | MessageTurnElectronBeamOn(SurfaceFlinger* flinger, int32_t mode) |
| 2293 | : flinger(flinger), mode(mode), result(PERMISSION_DENIED) { |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2294 | } |
| 2295 | status_t getResult() const { |
| 2296 | return result; |
| 2297 | } |
| 2298 | virtual bool handler() { |
| 2299 | Mutex::Autolock _l(flinger->mStateLock); |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2300 | result = flinger->turnElectronBeamOnImplLocked(mode); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2301 | return true; |
| 2302 | } |
| 2303 | }; |
| 2304 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 2305 | postMessageAsync( new MessageTurnElectronBeamOn(this, mode) ); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2306 | return NO_ERROR; |
| 2307 | } |
| 2308 | |
| 2309 | // --------------------------------------------------------------------------- |
| 2310 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2311 | status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy, |
| 2312 | sp<IMemoryHeap>* heap, |
| 2313 | uint32_t* w, uint32_t* h, PixelFormat* f, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2314 | uint32_t sw, uint32_t sh, |
| 2315 | uint32_t minLayerZ, uint32_t maxLayerZ) |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2316 | { |
| 2317 | status_t result = PERMISSION_DENIED; |
| 2318 | |
| 2319 | // only one display supported for now |
| 2320 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 2321 | return BAD_VALUE; |
| 2322 | |
| 2323 | if (!GLExtensions::getInstance().haveFramebufferObject()) |
| 2324 | return INVALID_OPERATION; |
| 2325 | |
| 2326 | // get screen geometry |
| 2327 | const DisplayHardware& hw(graphicPlane(dpy).displayHardware()); |
| 2328 | const uint32_t hw_w = hw.getWidth(); |
| 2329 | const uint32_t hw_h = hw.getHeight(); |
| 2330 | |
| 2331 | if ((sw > hw_w) || (sh > hw_h)) |
| 2332 | return BAD_VALUE; |
| 2333 | |
| 2334 | sw = (!sw) ? hw_w : sw; |
| 2335 | sh = (!sh) ? hw_h : sh; |
| 2336 | const size_t size = sw * sh * 4; |
| 2337 | |
Mathias Agopian | 32ae094 | 2011-03-02 18:45:50 -0800 | [diff] [blame] | 2338 | //LOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d", |
| 2339 | // sw, sh, minLayerZ, maxLayerZ); |
Mathias Agopian | cd2cfb6 | 2011-01-16 14:05:02 -0800 | [diff] [blame] | 2340 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2341 | // make sure to clear all GL error flags |
| 2342 | while ( glGetError() != GL_NO_ERROR ) ; |
| 2343 | |
| 2344 | // create a FBO |
| 2345 | GLuint name, tname; |
| 2346 | glGenRenderbuffersOES(1, &tname); |
| 2347 | glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname); |
| 2348 | glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, sw, sh); |
| 2349 | glGenFramebuffersOES(1, &name); |
| 2350 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); |
| 2351 | glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, |
| 2352 | GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname); |
| 2353 | |
| 2354 | GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); |
Mathias Agopian | cd2cfb6 | 2011-01-16 14:05:02 -0800 | [diff] [blame] | 2355 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2356 | if (status == GL_FRAMEBUFFER_COMPLETE_OES) { |
| 2357 | |
| 2358 | // invert everything, b/c glReadPixel() below will invert the FB |
| 2359 | glViewport(0, 0, sw, sh); |
Mathias Agopian | 1c4e4fc0 | 2010-12-16 18:46:17 -0800 | [diff] [blame] | 2360 | glScissor(0, 0, sw, sh); |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 2361 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2362 | glMatrixMode(GL_PROJECTION); |
| 2363 | glPushMatrix(); |
| 2364 | glLoadIdentity(); |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 2365 | glOrthof(0, hw_w, hw_h, 0, 0, 1); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2366 | glMatrixMode(GL_MODELVIEW); |
| 2367 | |
| 2368 | // redraw the screen entirely... |
| 2369 | glClearColor(0,0,0,1); |
| 2370 | glClear(GL_COLOR_BUFFER_BIT); |
Mathias Agopian | 1c4e4fc0 | 2010-12-16 18:46:17 -0800 | [diff] [blame] | 2371 | |
Jamie Gennis | 830d083 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 2372 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
| 2373 | const size_t count = layers.size(); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2374 | for (size_t i=0 ; i<count ; ++i) { |
| 2375 | const sp<LayerBase>& layer(layers[i]); |
Mathias Agopian | ec49d89 | 2011-08-25 14:36:43 -0700 | [diff] [blame] | 2376 | const uint32_t flags = layer->drawingState().flags; |
| 2377 | if (!(flags & ISurfaceComposer::eLayerHidden)) { |
| 2378 | const uint32_t z = layer->drawingState().z; |
| 2379 | if (z >= minLayerZ && z <= maxLayerZ) { |
| 2380 | layer->drawForSreenShot(); |
| 2381 | } |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2382 | } |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | // XXX: this is needed on tegra |
Mathias Agopian | 3a831d2 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 2386 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2387 | glScissor(0, 0, sw, sh); |
| 2388 | |
| 2389 | // check for errors and return screen capture |
| 2390 | if (glGetError() != GL_NO_ERROR) { |
| 2391 | // error while rendering |
| 2392 | result = INVALID_OPERATION; |
| 2393 | } else { |
| 2394 | // allocate shared memory large enough to hold the |
| 2395 | // screen capture |
| 2396 | sp<MemoryHeapBase> base( |
| 2397 | new MemoryHeapBase(size, 0, "screen-capture") ); |
| 2398 | void* const ptr = base->getBase(); |
| 2399 | if (ptr) { |
| 2400 | // capture the screen with glReadPixels() |
| 2401 | glReadPixels(0, 0, sw, sh, GL_RGBA, GL_UNSIGNED_BYTE, ptr); |
| 2402 | if (glGetError() == GL_NO_ERROR) { |
| 2403 | *heap = base; |
| 2404 | *w = sw; |
| 2405 | *h = sh; |
| 2406 | *f = PIXEL_FORMAT_RGBA_8888; |
| 2407 | result = NO_ERROR; |
| 2408 | } |
| 2409 | } else { |
| 2410 | result = NO_MEMORY; |
| 2411 | } |
| 2412 | } |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2413 | glEnable(GL_SCISSOR_TEST); |
| 2414 | glViewport(0, 0, hw_w, hw_h); |
| 2415 | glMatrixMode(GL_PROJECTION); |
| 2416 | glPopMatrix(); |
| 2417 | glMatrixMode(GL_MODELVIEW); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2418 | } else { |
| 2419 | result = BAD_VALUE; |
| 2420 | } |
| 2421 | |
| 2422 | // release FBO resources |
| 2423 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); |
| 2424 | glDeleteRenderbuffersOES(1, &tname); |
| 2425 | glDeleteFramebuffersOES(1, &name); |
Mathias Agopian | a6b8c1c | 2010-12-15 14:41:59 -0800 | [diff] [blame] | 2426 | |
| 2427 | hw.compositionComplete(); |
| 2428 | |
Mathias Agopian | 32ae094 | 2011-03-02 18:45:50 -0800 | [diff] [blame] | 2429 | // LOGD("screenshot: result = %s", result<0 ? strerror(result) : "OK"); |
Mathias Agopian | cd2cfb6 | 2011-01-16 14:05:02 -0800 | [diff] [blame] | 2430 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2431 | return result; |
| 2432 | } |
| 2433 | |
| 2434 | |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2435 | status_t SurfaceFlinger::captureScreen(DisplayID dpy, |
| 2436 | sp<IMemoryHeap>* heap, |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2437 | uint32_t* width, uint32_t* height, PixelFormat* format, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2438 | uint32_t sw, uint32_t sh, |
| 2439 | uint32_t minLayerZ, uint32_t maxLayerZ) |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2440 | { |
| 2441 | // only one display supported for now |
| 2442 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 2443 | return BAD_VALUE; |
| 2444 | |
| 2445 | if (!GLExtensions::getInstance().haveFramebufferObject()) |
| 2446 | return INVALID_OPERATION; |
| 2447 | |
| 2448 | class MessageCaptureScreen : public MessageBase { |
| 2449 | SurfaceFlinger* flinger; |
| 2450 | DisplayID dpy; |
| 2451 | sp<IMemoryHeap>* heap; |
| 2452 | uint32_t* w; |
| 2453 | uint32_t* h; |
| 2454 | PixelFormat* f; |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2455 | uint32_t sw; |
| 2456 | uint32_t sh; |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2457 | uint32_t minLayerZ; |
| 2458 | uint32_t maxLayerZ; |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2459 | status_t result; |
| 2460 | public: |
| 2461 | MessageCaptureScreen(SurfaceFlinger* flinger, DisplayID dpy, |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2462 | sp<IMemoryHeap>* heap, uint32_t* w, uint32_t* h, PixelFormat* f, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2463 | uint32_t sw, uint32_t sh, |
| 2464 | uint32_t minLayerZ, uint32_t maxLayerZ) |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2465 | : flinger(flinger), dpy(dpy), |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2466 | heap(heap), w(w), h(h), f(f), sw(sw), sh(sh), |
| 2467 | minLayerZ(minLayerZ), maxLayerZ(maxLayerZ), |
| 2468 | result(PERMISSION_DENIED) |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2469 | { |
| 2470 | } |
| 2471 | status_t getResult() const { |
| 2472 | return result; |
| 2473 | } |
| 2474 | virtual bool handler() { |
| 2475 | Mutex::Autolock _l(flinger->mStateLock); |
| 2476 | |
| 2477 | // if we have secure windows, never allow the screen capture |
| 2478 | if (flinger->mSecureFrameBuffer) |
| 2479 | return true; |
| 2480 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2481 | result = flinger->captureScreenImplLocked(dpy, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2482 | heap, w, h, f, sw, sh, minLayerZ, maxLayerZ); |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2483 | |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2484 | return true; |
| 2485 | } |
| 2486 | }; |
| 2487 | |
| 2488 | sp<MessageBase> msg = new MessageCaptureScreen(this, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 2489 | dpy, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ); |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2490 | status_t res = postMessageSync(msg); |
| 2491 | if (res == NO_ERROR) { |
| 2492 | res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult(); |
| 2493 | } |
| 2494 | return res; |
| 2495 | } |
| 2496 | |
| 2497 | // --------------------------------------------------------------------------- |
| 2498 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2499 | sp<Layer> SurfaceFlinger::getLayer(const sp<ISurface>& sur) const |
| 2500 | { |
| 2501 | sp<Layer> result; |
| 2502 | Mutex::Autolock _l(mStateLock); |
| 2503 | result = mLayerMap.valueFor( sur->asBinder() ).promote(); |
| 2504 | return result; |
| 2505 | } |
| 2506 | |
| 2507 | // --------------------------------------------------------------------------- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2509 | Client::Client(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2510 | : mFlinger(flinger), mNameGenerator(1) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | } |
| 2513 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2514 | Client::~Client() |
| 2515 | { |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2516 | const size_t count = mLayers.size(); |
| 2517 | for (size_t i=0 ; i<count ; i++) { |
| 2518 | sp<LayerBaseClient> layer(mLayers.valueAt(i).promote()); |
| 2519 | if (layer != 0) { |
| 2520 | mFlinger->removeLayer(layer); |
| 2521 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2525 | status_t Client::initCheck() const { |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2526 | return NO_ERROR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2528 | |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 2529 | size_t Client::attachLayer(const sp<LayerBaseClient>& layer) |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2530 | { |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 2531 | Mutex::Autolock _l(mLock); |
| 2532 | size_t name = mNameGenerator++; |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2533 | mLayers.add(name, layer); |
| 2534 | return name; |
| 2535 | } |
| 2536 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2537 | void Client::detachLayer(const LayerBaseClient* layer) |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2538 | { |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 2539 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2540 | // we do a linear search here, because this doesn't happen often |
| 2541 | const size_t count = mLayers.size(); |
| 2542 | for (size_t i=0 ; i<count ; i++) { |
| 2543 | if (mLayers.valueAt(i) == layer) { |
| 2544 | mLayers.removeItemsAt(i, 1); |
| 2545 | break; |
| 2546 | } |
| 2547 | } |
| 2548 | } |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 2549 | sp<LayerBaseClient> Client::getLayerUser(int32_t i) const |
| 2550 | { |
| 2551 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2552 | sp<LayerBaseClient> lbc; |
Mathias Agopian | 5fa7ad6 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 2553 | wp<LayerBaseClient> layer(mLayers.valueFor(i)); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2554 | if (layer != 0) { |
| 2555 | lbc = layer.promote(); |
| 2556 | LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i)); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2557 | } |
| 2558 | return lbc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2561 | |
| 2562 | status_t Client::onTransact( |
| 2563 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 2564 | { |
| 2565 | // these must be checked |
| 2566 | IPCThreadState* ipc = IPCThreadState::self(); |
| 2567 | const int pid = ipc->getCallingPid(); |
| 2568 | const int uid = ipc->getCallingUid(); |
| 2569 | const int self_pid = getpid(); |
| 2570 | if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) { |
| 2571 | // we're called from a different process, do the real check |
Mathias Agopian | 0dd593f | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 2572 | if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger)) |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2573 | { |
| 2574 | LOGE("Permission Denial: " |
| 2575 | "can't openGlobalTransaction pid=%d, uid=%d", pid, uid); |
| 2576 | return PERMISSION_DENIED; |
| 2577 | } |
| 2578 | } |
| 2579 | return BnSurfaceComposerClient::onTransact(code, data, reply, flags); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2580 | } |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2581 | |
| 2582 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2583 | sp<ISurface> Client::createSurface( |
Mathias Agopian | 9638e5c | 2011-04-20 14:19:32 -0700 | [diff] [blame] | 2584 | ISurfaceComposerClient::surface_data_t* params, |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2585 | const String8& name, |
| 2586 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | uint32_t flags) |
| 2588 | { |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2589 | /* |
| 2590 | * createSurface must be called from the GL thread so that it can |
| 2591 | * have access to the GL context. |
| 2592 | */ |
| 2593 | |
| 2594 | class MessageCreateSurface : public MessageBase { |
| 2595 | sp<ISurface> result; |
| 2596 | SurfaceFlinger* flinger; |
| 2597 | ISurfaceComposerClient::surface_data_t* params; |
| 2598 | Client* client; |
| 2599 | const String8& name; |
| 2600 | DisplayID display; |
| 2601 | uint32_t w, h; |
| 2602 | PixelFormat format; |
| 2603 | uint32_t flags; |
| 2604 | public: |
| 2605 | MessageCreateSurface(SurfaceFlinger* flinger, |
| 2606 | ISurfaceComposerClient::surface_data_t* params, |
| 2607 | const String8& name, Client* client, |
| 2608 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, |
| 2609 | uint32_t flags) |
| 2610 | : flinger(flinger), params(params), client(client), name(name), |
| 2611 | display(display), w(w), h(h), format(format), flags(flags) |
| 2612 | { |
| 2613 | } |
| 2614 | sp<ISurface> getResult() const { return result; } |
| 2615 | virtual bool handler() { |
| 2616 | result = flinger->createSurface(params, name, client, |
| 2617 | display, w, h, format, flags); |
| 2618 | return true; |
| 2619 | } |
| 2620 | }; |
| 2621 | |
| 2622 | sp<MessageBase> msg = new MessageCreateSurface(mFlinger.get(), |
| 2623 | params, name, this, display, w, h, format, flags); |
| 2624 | mFlinger->postMessageSync(msg); |
| 2625 | return static_cast<MessageCreateSurface*>( msg.get() )->getResult(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | } |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2627 | status_t Client::destroySurface(SurfaceID sid) { |
| 2628 | return mFlinger->removeSurface(this, sid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | |
| 2631 | // --------------------------------------------------------------------------- |
| 2632 | |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 2633 | GraphicBufferAlloc::GraphicBufferAlloc() {} |
| 2634 | |
| 2635 | GraphicBufferAlloc::~GraphicBufferAlloc() {} |
| 2636 | |
| 2637 | sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h, |
Mathias Agopian | eec0f7e | 2011-07-01 14:53:49 -0700 | [diff] [blame] | 2638 | PixelFormat format, uint32_t usage, status_t* error) { |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 2639 | sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage)); |
| 2640 | status_t err = graphicBuffer->initCheck(); |
Mathias Agopian | eec0f7e | 2011-07-01 14:53:49 -0700 | [diff] [blame] | 2641 | *error = err; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2642 | if (err != 0 || graphicBuffer->handle == 0) { |
Mathias Agopian | eec0f7e | 2011-07-01 14:53:49 -0700 | [diff] [blame] | 2643 | if (err == NO_MEMORY) { |
| 2644 | GraphicBuffer::dumpAllocationsToSystemLog(); |
| 2645 | } |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2646 | LOGE("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) " |
| 2647 | "failed (%s), handle=%p", |
| 2648 | w, h, strerror(-err), graphicBuffer->handle); |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 2649 | return 0; |
| 2650 | } |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 2651 | return graphicBuffer; |
| 2652 | } |
| 2653 | |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 2654 | // --------------------------------------------------------------------------- |
| 2655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | GraphicPlane::GraphicPlane() |
| 2657 | : mHw(0) |
| 2658 | { |
| 2659 | } |
| 2660 | |
| 2661 | GraphicPlane::~GraphicPlane() { |
| 2662 | delete mHw; |
| 2663 | } |
| 2664 | |
| 2665 | bool GraphicPlane::initialized() const { |
| 2666 | return mHw ? true : false; |
| 2667 | } |
| 2668 | |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 2669 | int GraphicPlane::getWidth() const { |
| 2670 | return mWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | } |
| 2672 | |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 2673 | int GraphicPlane::getHeight() const { |
| 2674 | return mHeight; |
| 2675 | } |
| 2676 | |
| 2677 | void GraphicPlane::setDisplayHardware(DisplayHardware *hw) |
| 2678 | { |
| 2679 | mHw = hw; |
| 2680 | |
| 2681 | // initialize the display orientation transform. |
| 2682 | // it's a constant that should come from the display driver. |
| 2683 | int displayOrientation = ISurfaceComposer::eOrientationDefault; |
| 2684 | char property[PROPERTY_VALUE_MAX]; |
| 2685 | if (property_get("ro.sf.hwrotation", property, NULL) > 0) { |
| 2686 | //displayOrientation |
| 2687 | switch (atoi(property)) { |
| 2688 | case 90: |
| 2689 | displayOrientation = ISurfaceComposer::eOrientation90; |
| 2690 | break; |
| 2691 | case 270: |
| 2692 | displayOrientation = ISurfaceComposer::eOrientation270; |
| 2693 | break; |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | const float w = hw->getWidth(); |
| 2698 | const float h = hw->getHeight(); |
| 2699 | GraphicPlane::orientationToTransfrom(displayOrientation, w, h, |
| 2700 | &mDisplayTransform); |
| 2701 | if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) { |
| 2702 | mDisplayWidth = h; |
| 2703 | mDisplayHeight = w; |
| 2704 | } else { |
| 2705 | mDisplayWidth = w; |
| 2706 | mDisplayHeight = h; |
| 2707 | } |
| 2708 | |
| 2709 | setOrientation(ISurfaceComposer::eOrientationDefault); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | status_t GraphicPlane::orientationToTransfrom( |
| 2713 | int orientation, int w, int h, Transform* tr) |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2714 | { |
| 2715 | uint32_t flags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | switch (orientation) { |
| 2717 | case ISurfaceComposer::eOrientationDefault: |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2718 | flags = Transform::ROT_0; |
| 2719 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | case ISurfaceComposer::eOrientation90: |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2721 | flags = Transform::ROT_90; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | break; |
| 2723 | case ISurfaceComposer::eOrientation180: |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2724 | flags = Transform::ROT_180; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | break; |
| 2726 | case ISurfaceComposer::eOrientation270: |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2727 | flags = Transform::ROT_270; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | break; |
| 2729 | default: |
| 2730 | return BAD_VALUE; |
| 2731 | } |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2732 | tr->set(flags, w, h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | return NO_ERROR; |
| 2734 | } |
| 2735 | |
| 2736 | status_t GraphicPlane::setOrientation(int orientation) |
| 2737 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | // If the rotation can be handled in hardware, this is where |
| 2739 | // the magic should happen. |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 2740 | |
| 2741 | const DisplayHardware& hw(displayHardware()); |
| 2742 | const float w = mDisplayWidth; |
| 2743 | const float h = mDisplayHeight; |
| 2744 | mWidth = int(w); |
| 2745 | mHeight = int(h); |
| 2746 | |
| 2747 | Transform orientationTransform; |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2748 | GraphicPlane::orientationToTransfrom(orientation, w, h, |
| 2749 | &orientationTransform); |
| 2750 | if (orientation & ISurfaceComposer::eOrientationSwapMask) { |
| 2751 | mWidth = int(h); |
| 2752 | mHeight = int(w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | } |
Mathias Agopian | 8c20ca3 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 2754 | |
Mathias Agopian | 3552f53 | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 2755 | mOrientation = orientation; |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 2756 | mGlobalTransform = mDisplayTransform * orientationTransform; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | return NO_ERROR; |
| 2758 | } |
| 2759 | |
| 2760 | const DisplayHardware& GraphicPlane::displayHardware() const { |
| 2761 | return *mHw; |
| 2762 | } |
| 2763 | |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2764 | DisplayHardware& GraphicPlane::editDisplayHardware() { |
| 2765 | return *mHw; |
| 2766 | } |
| 2767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | const Transform& GraphicPlane::transform() const { |
| 2769 | return mGlobalTransform; |
| 2770 | } |
| 2771 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2772 | EGLDisplay GraphicPlane::getEGLDisplay() const { |
| 2773 | return mHw->getEGLDisplay(); |
| 2774 | } |
| 2775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | // --------------------------------------------------------------------------- |
| 2777 | |
| 2778 | }; // namespace android |