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