The Android Open Source Project | edbf3b6 | 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 | edbf3b6 | 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 | a837ba7 | 2009-01-26 11:51:12 -0800 | [diff] [blame] | 24 | #include <limits.h> |
The Android Open Source Project | edbf3b6 | 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 | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> |
| 33 | #include <binder/IServiceManager.h> |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 34 | #include <binder/MemoryHeapBase.h> |
| 35 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include <utils/String8.h> |
| 37 | #include <utils/String16.h> |
| 38 | #include <utils/StopWatch.h> |
| 39 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 40 | #include <ui/GraphicBufferAllocator.h> |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 41 | #include <ui/GraphicLog.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | #include <pixelflinger/pixelflinger.h> |
| 45 | #include <GLES/gl.h> |
| 46 | |
| 47 | #include "clz.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 48 | #include "GLExtensions.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | #include "Layer.h" |
| 50 | #include "LayerBlur.h" |
| 51 | #include "LayerBuffer.h" |
| 52 | #include "LayerDim.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| 55 | #include "DisplayHardware/DisplayHardware.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 56 | #include "DisplayHardware/HWComposer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 58 | /* ideally AID_GRAPHICS would be in a semi-public header |
| 59 | * or there would be a way to map a user/group name to its id |
| 60 | */ |
| 61 | #ifndef AID_GRAPHICS |
| 62 | #define AID_GRAPHICS 1003 |
| 63 | #endif |
| 64 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | #define DISPLAY_COUNT 1 |
| 66 | |
| 67 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | // --------------------------------------------------------------------------- |
| 69 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | SurfaceFlinger::SurfaceFlinger() |
| 71 | : BnSurfaceComposer(), Thread(false), |
| 72 | mTransactionFlags(0), |
| 73 | mTransactionCount(0), |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 74 | mResizeTransationPending(false), |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 75 | mLayersRemoved(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | mBootTime(systemTime()), |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 77 | mHardwareTest("android.permission.HARDWARE_TEST"), |
| 78 | mAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"), |
| 79 | mDump("android.permission.DUMP"), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | mVisibleRegionsDirty(false), |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 81 | mHwWorkListDirty(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | mDeferReleaseConsole(false), |
| 83 | mFreezeDisplay(false), |
| 84 | mFreezeCount(0), |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 85 | mFreezeDisplayTime(0), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | mDebugRegion(0), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | mDebugBackground(0), |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 88 | mDebugInSwapBuffers(0), |
| 89 | mLastSwapBufferTime(0), |
| 90 | mDebugInTransaction(0), |
| 91 | mLastTransactionTime(0), |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 92 | mBootFinished(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | mConsoleSignals(0), |
| 94 | mSecureFrameBuffer(0) |
| 95 | { |
| 96 | init(); |
| 97 | } |
| 98 | |
| 99 | void SurfaceFlinger::init() |
| 100 | { |
| 101 | LOGI("SurfaceFlinger is starting"); |
| 102 | |
| 103 | // debugging stuff... |
| 104 | char value[PROPERTY_VALUE_MAX]; |
| 105 | property_get("debug.sf.showupdates", value, "0"); |
| 106 | mDebugRegion = atoi(value); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | property_get("debug.sf.showbackground", value, "0"); |
| 108 | mDebugBackground = atoi(value); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 110 | LOGI_IF(mDebugRegion, "showupdates enabled"); |
| 111 | LOGI_IF(mDebugBackground, "showbackground enabled"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | SurfaceFlinger::~SurfaceFlinger() |
| 115 | { |
| 116 | glDeleteTextures(1, &mWormholeTexName); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | } |
| 118 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | overlay_control_device_t* SurfaceFlinger::getOverlayEngine() const |
| 120 | { |
| 121 | return graphicPlane(0).displayHardware().getOverlayEngine(); |
| 122 | } |
| 123 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 124 | sp<IMemoryHeap> SurfaceFlinger::getCblk() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | { |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 126 | return mServerHeap; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 129 | sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 131 | sp<ISurfaceComposerClient> bclient; |
| 132 | sp<Client> client(new Client(this)); |
| 133 | status_t err = client->initCheck(); |
| 134 | if (err == NO_ERROR) { |
| 135 | bclient = client; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | return bclient; |
| 138 | } |
| 139 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 140 | sp<ISurfaceComposerClient> SurfaceFlinger::createClientConnection() |
| 141 | { |
| 142 | sp<ISurfaceComposerClient> bclient; |
| 143 | sp<UserClient> client(new UserClient(this)); |
| 144 | status_t err = client->initCheck(); |
| 145 | if (err == NO_ERROR) { |
| 146 | bclient = client; |
| 147 | } |
| 148 | return bclient; |
| 149 | } |
| 150 | |
| 151 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const |
| 153 | { |
| 154 | LOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy); |
| 155 | const GraphicPlane& plane(mGraphicPlanes[dpy]); |
| 156 | return plane; |
| 157 | } |
| 158 | |
| 159 | GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) |
| 160 | { |
| 161 | return const_cast<GraphicPlane&>( |
| 162 | const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy)); |
| 163 | } |
| 164 | |
| 165 | void SurfaceFlinger::bootFinished() |
| 166 | { |
| 167 | const nsecs_t now = systemTime(); |
| 168 | const nsecs_t duration = now - mBootTime; |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 169 | LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 170 | mBootFinished = true; |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 171 | property_set("ctl.stop", "bootanim"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void SurfaceFlinger::onFirstRef() |
| 175 | { |
| 176 | run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY); |
| 177 | |
| 178 | // Wait for the main thread to be done with its initialization |
| 179 | mReadyToRunBarrier.wait(); |
| 180 | } |
| 181 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | static inline uint16_t pack565(int r, int g, int b) { |
| 183 | return (r<<11)|(g<<5)|b; |
| 184 | } |
| 185 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | status_t SurfaceFlinger::readyToRun() |
| 187 | { |
| 188 | LOGI( "SurfaceFlinger's main thread ready to run. " |
| 189 | "Initializing graphics H/W..."); |
| 190 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | // we only support one display currently |
| 192 | int dpy = 0; |
| 193 | |
| 194 | { |
| 195 | // initialize the main display |
| 196 | GraphicPlane& plane(graphicPlane(dpy)); |
| 197 | DisplayHardware* const hw = new DisplayHardware(this, dpy); |
| 198 | plane.setDisplayHardware(hw); |
| 199 | } |
| 200 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 201 | // create the shared control-block |
| 202 | mServerHeap = new MemoryHeapBase(4096, |
| 203 | MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap"); |
| 204 | LOGE_IF(mServerHeap==0, "can't create shared memory dealer"); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 205 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 206 | mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase()); |
| 207 | LOGE_IF(mServerCblk==0, "can't get to shared control block's address"); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 208 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 209 | new(mServerCblk) surface_flinger_cblk_t; |
| 210 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | // initialize primary screen |
| 212 | // (other display should be initialized in the same manner, but |
| 213 | // asynchronously, as they could come and go. None of this is supported |
| 214 | // yet). |
| 215 | const GraphicPlane& plane(graphicPlane(dpy)); |
| 216 | const DisplayHardware& hw = plane.displayHardware(); |
| 217 | const uint32_t w = hw.getWidth(); |
| 218 | const uint32_t h = hw.getHeight(); |
| 219 | const uint32_t f = hw.getFormat(); |
| 220 | hw.makeCurrent(); |
| 221 | |
| 222 | // initialize the shared control block |
| 223 | mServerCblk->connected |= 1<<dpy; |
| 224 | display_cblk_t* dcblk = mServerCblk->displays + dpy; |
| 225 | memset(dcblk, 0, sizeof(display_cblk_t)); |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 226 | dcblk->w = plane.getWidth(); |
| 227 | dcblk->h = plane.getHeight(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | dcblk->format = f; |
| 229 | dcblk->orientation = ISurfaceComposer::eOrientationDefault; |
| 230 | dcblk->xdpi = hw.getDpiX(); |
| 231 | dcblk->ydpi = hw.getDpiY(); |
| 232 | dcblk->fps = hw.getRefreshRate(); |
| 233 | dcblk->density = hw.getDensity(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | |
| 235 | // Initialize OpenGL|ES |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 237 | glPixelStorei(GL_PACK_ALIGNMENT, 4); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | glEnableClientState(GL_VERTEX_ARRAY); |
| 239 | glEnable(GL_SCISSOR_TEST); |
| 240 | glShadeModel(GL_FLAT); |
| 241 | glDisable(GL_DITHER); |
| 242 | glDisable(GL_CULL_FACE); |
| 243 | |
| 244 | const uint16_t g0 = pack565(0x0F,0x1F,0x0F); |
| 245 | const uint16_t g1 = pack565(0x17,0x2f,0x17); |
| 246 | const uint16_t textureData[4] = { g0, g1, g1, g0 }; |
| 247 | glGenTextures(1, &mWormholeTexName); |
| 248 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); |
| 249 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 250 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 251 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 252 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 253 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, |
| 254 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData); |
| 255 | |
| 256 | glViewport(0, 0, w, h); |
| 257 | glMatrixMode(GL_PROJECTION); |
| 258 | glLoadIdentity(); |
| 259 | glOrthof(0, w, h, 0, 0, 1); |
| 260 | |
| 261 | LayerDim::initDimmer(this, w, h); |
| 262 | |
| 263 | mReadyToRunBarrier.open(); |
| 264 | |
| 265 | /* |
| 266 | * We're now ready to accept clients... |
| 267 | */ |
| 268 | |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 269 | // start boot animation |
| 270 | property_set("ctl.start", "bootanim"); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | return NO_ERROR; |
| 273 | } |
| 274 | |
| 275 | // ---------------------------------------------------------------------------- |
| 276 | #if 0 |
| 277 | #pragma mark - |
| 278 | #pragma mark Events Handler |
| 279 | #endif |
| 280 | |
| 281 | void SurfaceFlinger::waitForEvent() |
| 282 | { |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 283 | while (true) { |
| 284 | nsecs_t timeout = -1; |
Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 285 | const nsecs_t freezeDisplayTimeout = ms2ns(5000); |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 286 | if (UNLIKELY(isFrozen())) { |
| 287 | // wait 5 seconds |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 288 | const nsecs_t now = systemTime(); |
| 289 | if (mFreezeDisplayTime == 0) { |
| 290 | mFreezeDisplayTime = now; |
| 291 | } |
| 292 | nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime); |
| 293 | timeout = waitTime>0 ? waitTime : 0; |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 294 | } |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 295 | |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 296 | sp<MessageBase> msg = mEventQueue.waitMessage(timeout); |
Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 297 | |
| 298 | // see if we timed out |
| 299 | if (isFrozen()) { |
| 300 | const nsecs_t now = systemTime(); |
| 301 | nsecs_t frozenTime = (now - mFreezeDisplayTime); |
| 302 | if (frozenTime >= freezeDisplayTimeout) { |
| 303 | // we timed out and are still frozen |
| 304 | LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d", |
| 305 | mFreezeDisplay, mFreezeCount); |
| 306 | mFreezeDisplayTime = 0; |
| 307 | mFreezeCount = 0; |
| 308 | mFreezeDisplay = false; |
| 309 | } |
| 310 | } |
| 311 | |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 312 | if (msg != 0) { |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 313 | switch (msg->what) { |
| 314 | case MessageQueue::INVALIDATE: |
| 315 | // invalidate message, just return to the main loop |
| 316 | return; |
| 317 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | void SurfaceFlinger::signalEvent() { |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 323 | mEventQueue.invalidate(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void SurfaceFlinger::signal() const { |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 327 | // this is the IPC call |
| 328 | const_cast<SurfaceFlinger*>(this)->signalEvent(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 331 | status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg, |
| 332 | nsecs_t reltime, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | { |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 334 | return mEventQueue.postMessage(msg, reltime, flags); |
| 335 | } |
| 336 | |
| 337 | status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg, |
| 338 | nsecs_t reltime, uint32_t flags) |
| 339 | { |
| 340 | status_t res = mEventQueue.postMessage(msg, reltime, flags); |
| 341 | if (res == NO_ERROR) { |
| 342 | msg->wait(); |
| 343 | } |
| 344 | return res; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // ---------------------------------------------------------------------------- |
| 348 | #if 0 |
| 349 | #pragma mark - |
| 350 | #pragma mark Main loop |
| 351 | #endif |
| 352 | |
| 353 | bool SurfaceFlinger::threadLoop() |
| 354 | { |
| 355 | waitForEvent(); |
| 356 | |
| 357 | // check for transactions |
| 358 | if (UNLIKELY(mConsoleSignals)) { |
| 359 | handleConsoleEvents(); |
| 360 | } |
| 361 | |
| 362 | if (LIKELY(mTransactionCount == 0)) { |
| 363 | // if we're in a global transaction, don't do anything. |
| 364 | const uint32_t mask = eTransactionNeeded | eTraversalNeeded; |
| 365 | uint32_t transactionFlags = getTransactionFlags(mask); |
| 366 | if (LIKELY(transactionFlags)) { |
| 367 | handleTransaction(transactionFlags); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // post surfaces (if needed) |
| 372 | handlePageFlip(); |
| 373 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 374 | if (UNLIKELY(mHwWorkListDirty)) { |
| 375 | // build the h/w work list |
| 376 | handleWorkList(); |
| 377 | } |
| 378 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | 8a77baa | 2009-09-27 22:47:27 -0700 | [diff] [blame] | 380 | if (LIKELY(hw.canDraw() && !isFrozen())) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | // repaint the framebuffer (if needed) |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 382 | |
| 383 | const int index = hw.getCurrentBufferIndex(); |
| 384 | GraphicLog& logger(GraphicLog::getInstance()); |
| 385 | |
| 386 | logger.log(GraphicLog::SF_REPAINT, index); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | handleRepaint(); |
| 388 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 389 | // inform the h/w that we're done compositing |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 390 | logger.log(GraphicLog::SF_COMPOSITION_COMPLETE, index); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 391 | hw.compositionComplete(); |
| 392 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 393 | logger.log(GraphicLog::SF_SWAP_BUFFERS, index); |
Antti Hatala | 8392b50 | 2010-09-08 06:37:14 -0700 | [diff] [blame] | 394 | postFramebuffer(); |
| 395 | |
Mathias Agopian | c479e18 | 2010-09-15 12:29:18 -0700 | [diff] [blame^] | 396 | logger.log(GraphicLog::SF_UNLOCK_CLIENTS, index); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | unlockClients(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 399 | logger.log(GraphicLog::SF_REPAINT_DONE, index); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | } else { |
| 401 | // pretend we did the post |
| 402 | unlockClients(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | usleep(16667); // 60 fps period |
| 404 | } |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | void SurfaceFlinger::postFramebuffer() |
| 409 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | if (!mInvalidRegion.isEmpty()) { |
| 411 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 412 | const nsecs_t now = systemTime(); |
| 413 | mDebugInSwapBuffers = now; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | hw.flip(mInvalidRegion); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 415 | mLastSwapBufferTime = systemTime() - now; |
| 416 | mDebugInSwapBuffers = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | mInvalidRegion.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | void SurfaceFlinger::handleConsoleEvents() |
| 422 | { |
| 423 | // something to do with the console |
| 424 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); |
| 425 | |
| 426 | int what = android_atomic_and(0, &mConsoleSignals); |
| 427 | if (what & eConsoleAcquired) { |
| 428 | hw.acquireScreen(); |
| 429 | } |
| 430 | |
| 431 | if (mDeferReleaseConsole && hw.canDraw()) { |
Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 432 | // We got the release signal before the acquire signal |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | mDeferReleaseConsole = false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | hw.releaseScreen(); |
| 435 | } |
| 436 | |
| 437 | if (what & eConsoleReleased) { |
| 438 | if (hw.canDraw()) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | hw.releaseScreen(); |
| 440 | } else { |
| 441 | mDeferReleaseConsole = true; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | mDirtyRegion.set(hw.bounds()); |
| 446 | } |
| 447 | |
| 448 | void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) |
| 449 | { |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 450 | Vector< sp<LayerBase> > ditchedLayers; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 452 | /* |
| 453 | * Perform and commit the transaction |
| 454 | */ |
| 455 | |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 456 | { // scope for the lock |
| 457 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 458 | const nsecs_t now = systemTime(); |
| 459 | mDebugInTransaction = now; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 460 | handleTransactionLocked(transactionFlags, ditchedLayers); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 461 | mLastTransactionTime = systemTime() - now; |
| 462 | mDebugInTransaction = 0; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 463 | mHwWorkListDirty = true; |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 464 | // here the transaction has been committed |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 467 | /* |
| 468 | * Clean-up all layers that went away |
| 469 | * (do this without the lock held) |
| 470 | */ |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 471 | |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 472 | const size_t count = ditchedLayers.size(); |
| 473 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 0852e67 | 2009-09-04 19:50:23 -0700 | [diff] [blame] | 474 | if (ditchedLayers[i] != 0) { |
| 475 | //LOGD("ditching layer %p", ditchedLayers[i].get()); |
| 476 | ditchedLayers[i]->ditch(); |
| 477 | } |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
| 481 | void SurfaceFlinger::handleTransactionLocked( |
| 482 | uint32_t transactionFlags, Vector< sp<LayerBase> >& ditchedLayers) |
| 483 | { |
| 484 | const LayerVector& currentLayers(mCurrentState.layersSortedByZ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | const size_t count = currentLayers.size(); |
| 486 | |
| 487 | /* |
| 488 | * Traversal of the children |
| 489 | * (perform the transaction for each of them if needed) |
| 490 | */ |
| 491 | |
| 492 | const bool layersNeedTransaction = transactionFlags & eTraversalNeeded; |
| 493 | if (layersNeedTransaction) { |
| 494 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 495 | const sp<LayerBase>& layer = currentLayers[i]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); |
| 497 | if (!trFlags) continue; |
| 498 | |
| 499 | const uint32_t flags = layer->doTransaction(0); |
| 500 | if (flags & Layer::eVisibleRegion) |
| 501 | mVisibleRegionsDirty = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Perform our own transaction if needed |
| 507 | */ |
| 508 | |
| 509 | if (transactionFlags & eTransactionNeeded) { |
| 510 | if (mCurrentState.orientation != mDrawingState.orientation) { |
| 511 | // the orientation has changed, recompute all visible regions |
| 512 | // and invalidate everything. |
| 513 | |
| 514 | const int dpy = 0; |
| 515 | const int orientation = mCurrentState.orientation; |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 516 | const uint32_t type = mCurrentState.orientationType; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | GraphicPlane& plane(graphicPlane(dpy)); |
| 518 | plane.setOrientation(orientation); |
| 519 | |
| 520 | // update the shared control block |
| 521 | const DisplayHardware& hw(plane.displayHardware()); |
| 522 | volatile display_cblk_t* dcblk = mServerCblk->displays + dpy; |
| 523 | dcblk->orientation = orientation; |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 524 | dcblk->w = plane.getWidth(); |
| 525 | dcblk->h = plane.getHeight(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | |
| 527 | mVisibleRegionsDirty = true; |
| 528 | mDirtyRegion.set(hw.bounds()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) { |
| 532 | // freezing or unfreezing the display -> trigger animation if needed |
| 533 | mFreezeDisplay = mCurrentState.freezeDisplay; |
Mathias Agopian | 064e1e6 | 2010-03-01 17:51:17 -0800 | [diff] [blame] | 534 | if (mFreezeDisplay) |
| 535 | mFreezeDisplayTime = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 538 | if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) { |
| 539 | // layers have been added |
| 540 | mVisibleRegionsDirty = true; |
| 541 | } |
| 542 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | // some layers might have been removed, so |
| 544 | // we need to update the regions they're exposing. |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 545 | if (mLayersRemoved) { |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 546 | mLayersRemoved = false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | mVisibleRegionsDirty = true; |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 548 | const LayerVector& previousLayers(mDrawingState.layersSortedByZ); |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 549 | const size_t count = previousLayers.size(); |
| 550 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 551 | const sp<LayerBase>& layer(previousLayers[i]); |
| 552 | if (currentLayers.indexOf( layer ) < 0) { |
| 553 | // this layer is not visible anymore |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 554 | ditchedLayers.add(layer); |
Mathias Agopian | 5d7126b | 2009-07-28 14:20:21 -0700 | [diff] [blame] | 555 | mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | commitTransaction(); |
| 562 | } |
| 563 | |
| 564 | sp<FreezeLock> SurfaceFlinger::getFreezeLock() const |
| 565 | { |
| 566 | return new FreezeLock(const_cast<SurfaceFlinger *>(this)); |
| 567 | } |
| 568 | |
| 569 | void SurfaceFlinger::computeVisibleRegions( |
| 570 | LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion) |
| 571 | { |
| 572 | const GraphicPlane& plane(graphicPlane(0)); |
| 573 | const Transform& planeTransform(plane.transform()); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 574 | const DisplayHardware& hw(plane.displayHardware()); |
| 575 | const Region screenRegion(hw.bounds()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | |
| 577 | Region aboveOpaqueLayers; |
| 578 | Region aboveCoveredLayers; |
| 579 | Region dirty; |
| 580 | |
| 581 | bool secureFrameBuffer = false; |
| 582 | |
| 583 | size_t i = currentLayers.size(); |
| 584 | while (i--) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 585 | const sp<LayerBase>& layer = currentLayers[i]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | layer->validateVisibility(planeTransform); |
| 587 | |
| 588 | // start with the whole surface at its current location |
Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 589 | const Layer::State& s(layer->drawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 591 | /* |
| 592 | * opaqueRegion: area of a surface that is fully opaque. |
| 593 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | Region opaqueRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * visibleRegion: area of a surface that is visible on screen |
| 598 | * and not fully transparent. This is essentially the layer's |
| 599 | * footprint minus the opaque regions above it. |
| 600 | * Areas covered by a translucent surface are considered visible. |
| 601 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | Region visibleRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * coveredRegion: area of a surface that is covered by all |
| 606 | * visible regions above it (which includes the translucent areas). |
| 607 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | Region coveredRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 609 | |
| 610 | |
| 611 | // handle hidden surfaces by setting the visible region to empty |
Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 612 | if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | const bool translucent = layer->needsBlending(); |
Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 614 | const Rect bounds(layer->visibleBounds()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | visibleRegion.set(bounds); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 616 | visibleRegion.andSelf(screenRegion); |
| 617 | if (!visibleRegion.isEmpty()) { |
| 618 | // Remove the transparent area from the visible region |
| 619 | if (translucent) { |
| 620 | visibleRegion.subtractSelf(layer->transparentRegionScreen); |
| 621 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 623 | // compute the opaque region |
| 624 | const int32_t layerOrientation = layer->getOrientation(); |
| 625 | if (s.alpha==255 && !translucent && |
| 626 | ((layerOrientation & Transform::ROT_INVALID) == false)) { |
| 627 | // the opaque region is the layer's footprint |
| 628 | opaqueRegion = visibleRegion; |
| 629 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 633 | // Clip the covered region to the visible region |
| 634 | coveredRegion = aboveCoveredLayers.intersect(visibleRegion); |
| 635 | |
| 636 | // Update aboveCoveredLayers for next (lower) layer |
| 637 | aboveCoveredLayers.orSelf(visibleRegion); |
| 638 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | // subtract the opaque region covered by the layers above us |
| 640 | visibleRegion.subtractSelf(aboveOpaqueLayers); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | |
| 642 | // compute this layer's dirty region |
| 643 | if (layer->contentDirty) { |
| 644 | // we need to invalidate the whole region |
| 645 | dirty = visibleRegion; |
| 646 | // as well, as the old visible region |
| 647 | dirty.orSelf(layer->visibleRegionScreen); |
| 648 | layer->contentDirty = false; |
| 649 | } else { |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 650 | /* compute the exposed region: |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 651 | * the exposed region consists of two components: |
| 652 | * 1) what's VISIBLE now and was COVERED before |
| 653 | * 2) what's EXPOSED now less what was EXPOSED before |
| 654 | * |
| 655 | * note that (1) is conservative, we start with the whole |
| 656 | * visible region but only keep what used to be covered by |
| 657 | * something -- which mean it may have been exposed. |
| 658 | * |
| 659 | * (2) handles areas that were not covered by anything but got |
| 660 | * exposed because of a resize. |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 661 | */ |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 662 | const Region newExposed = visibleRegion - coveredRegion; |
| 663 | const Region oldVisibleRegion = layer->visibleRegionScreen; |
| 664 | const Region oldCoveredRegion = layer->coveredRegionScreen; |
| 665 | const Region oldExposed = oldVisibleRegion - oldCoveredRegion; |
| 666 | dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | } |
| 668 | dirty.subtractSelf(aboveOpaqueLayers); |
| 669 | |
| 670 | // accumulate to the screen dirty region |
| 671 | dirtyRegion.orSelf(dirty); |
| 672 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 673 | // Update aboveOpaqueLayers for next (lower) layer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | aboveOpaqueLayers.orSelf(opaqueRegion); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 675 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | // Store the visible region is screen space |
| 677 | layer->setVisibleRegion(visibleRegion); |
| 678 | layer->setCoveredRegion(coveredRegion); |
| 679 | |
Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 680 | // If a secure layer is partially visible, lock-down the screen! |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | if (layer->isSecure() && !visibleRegion.isEmpty()) { |
| 682 | secureFrameBuffer = true; |
| 683 | } |
| 684 | } |
| 685 | |
Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 686 | // invalidate the areas where a layer was removed |
| 687 | dirtyRegion.orSelf(mDirtyRegionRemovedLayer); |
| 688 | mDirtyRegionRemovedLayer.clear(); |
| 689 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | mSecureFrameBuffer = secureFrameBuffer; |
| 691 | opaqueRegion = aboveOpaqueLayers; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void SurfaceFlinger::commitTransaction() |
| 696 | { |
| 697 | mDrawingState = mCurrentState; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 698 | mResizeTransationPending = false; |
| 699 | mTransactionCV.broadcast(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void SurfaceFlinger::handlePageFlip() |
| 703 | { |
| 704 | bool visibleRegions = mVisibleRegionsDirty; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 705 | LayerVector& currentLayers( |
| 706 | const_cast<LayerVector&>(mDrawingState.layersSortedByZ)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | visibleRegions |= lockPageFlip(currentLayers); |
| 708 | |
| 709 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); |
| 710 | const Region screenRegion(hw.bounds()); |
| 711 | if (visibleRegions) { |
| 712 | Region opaqueRegion; |
| 713 | computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion); |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 714 | |
| 715 | /* |
| 716 | * rebuild the visible layer list |
| 717 | */ |
| 718 | mVisibleLayersSortedByZ.clear(); |
| 719 | const LayerVector& currentLayers(mDrawingState.layersSortedByZ); |
| 720 | size_t count = currentLayers.size(); |
| 721 | mVisibleLayersSortedByZ.setCapacity(count); |
| 722 | for (size_t i=0 ; i<count ; i++) { |
| 723 | if (!currentLayers[i]->visibleRegionScreen.isEmpty()) |
| 724 | mVisibleLayersSortedByZ.add(currentLayers[i]); |
| 725 | } |
| 726 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | mWormholeRegion = screenRegion.subtract(opaqueRegion); |
| 728 | mVisibleRegionsDirty = false; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 729 | mHwWorkListDirty = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | unlockPageFlip(currentLayers); |
| 733 | mDirtyRegion.andSelf(screenRegion); |
| 734 | } |
| 735 | |
| 736 | bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers) |
| 737 | { |
| 738 | bool recomputeVisibleRegions = false; |
| 739 | size_t count = currentLayers.size(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 740 | sp<LayerBase> const* layers = currentLayers.array(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 742 | const sp<LayerBase>& layer(layers[i]); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | layer->lockPageFlip(recomputeVisibleRegions); |
| 744 | } |
| 745 | return recomputeVisibleRegions; |
| 746 | } |
| 747 | |
| 748 | void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers) |
| 749 | { |
| 750 | const GraphicPlane& plane(graphicPlane(0)); |
| 751 | const Transform& planeTransform(plane.transform()); |
| 752 | size_t count = currentLayers.size(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 753 | sp<LayerBase> const* layers = currentLayers.array(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 755 | const sp<LayerBase>& layer(layers[i]); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | layer->unlockPageFlip(planeTransform, mDirtyRegion); |
| 757 | } |
| 758 | } |
| 759 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 760 | void SurfaceFlinger::handleWorkList() |
| 761 | { |
| 762 | mHwWorkListDirty = false; |
| 763 | HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer()); |
| 764 | if (hwc.initCheck() == NO_ERROR) { |
| 765 | const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ); |
| 766 | const size_t count = currentLayers.size(); |
| 767 | hwc.createWorkList(count); |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 768 | hwc_layer_t* const cur(hwc.getLayers()); |
| 769 | for (size_t i=0 ; cur && i<count ; i++) { |
| 770 | currentLayers[i]->setGeometry(&cur[i]); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 774 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | void SurfaceFlinger::handleRepaint() |
| 776 | { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 777 | // compute the invalid region |
| 778 | mInvalidRegion.orSelf(mDirtyRegion); |
| 779 | if (mInvalidRegion.isEmpty()) { |
| 780 | // nothing to do |
| 781 | return; |
| 782 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | |
| 784 | if (UNLIKELY(mDebugRegion)) { |
| 785 | debugFlashRegions(); |
| 786 | } |
| 787 | |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 788 | // set the frame buffer |
| 789 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 790 | glMatrixMode(GL_MODELVIEW); |
| 791 | glLoadIdentity(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | |
| 793 | uint32_t flags = hw.getFlags(); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 794 | if ((flags & DisplayHardware::SWAP_RECTANGLE) || |
| 795 | (flags & DisplayHardware::BUFFER_PRESERVED)) |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 796 | { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 797 | // we can redraw only what's dirty, but since SWAP_RECTANGLE only |
| 798 | // takes a rectangle, we must make sure to update that whole |
| 799 | // rectangle in that case |
| 800 | if (flags & DisplayHardware::SWAP_RECTANGLE) { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 801 | // TODO: we really should be able to pass a region to |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 802 | // SWAP_RECTANGLE so that we don't have to redraw all this. |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | mDirtyRegion.set(mInvalidRegion.bounds()); |
| 804 | } else { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 805 | // in the BUFFER_PRESERVED case, obviously, we can update only |
| 806 | // what's needed and nothing more. |
| 807 | // NOTE: this is NOT a common case, as preserving the backbuffer |
| 808 | // is costly and usually involves copying the whole update back. |
| 809 | } |
| 810 | } else { |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 811 | if (flags & DisplayHardware::PARTIAL_UPDATES) { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 812 | // We need to redraw the rectangle that will be updated |
| 813 | // (pushed to the framebuffer). |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 814 | // This is needed because PARTIAL_UPDATES only takes one |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 815 | // rectangle instead of a region (see DisplayHardware::flip()) |
| 816 | mDirtyRegion.set(mInvalidRegion.bounds()); |
| 817 | } else { |
| 818 | // we need to redraw everything (the whole screen) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | mDirtyRegion.set(hw.bounds()); |
| 820 | mInvalidRegion = mDirtyRegion; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // compose all surfaces |
| 825 | composeSurfaces(mDirtyRegion); |
| 826 | |
| 827 | // clear the dirty regions |
| 828 | mDirtyRegion.clear(); |
| 829 | } |
| 830 | |
| 831 | void SurfaceFlinger::composeSurfaces(const Region& dirty) |
| 832 | { |
| 833 | if (UNLIKELY(!mWormholeRegion.isEmpty())) { |
| 834 | // should never happen unless the window manager has a bug |
| 835 | // draw something... |
| 836 | drawWormhole(); |
| 837 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 838 | |
| 839 | status_t err = NO_ERROR; |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 840 | const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ); |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 841 | size_t count = layers.size(); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 842 | |
| 843 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 844 | HWComposer& hwc(hw.getHwComposer()); |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 845 | hwc_layer_t* const cur(hwc.getLayers()); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 846 | |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 847 | LOGE_IF(cur && hwc.getNumLayers() != count, |
| 848 | "HAL number of layers (%d) doesn't match surfaceflinger (%d)", |
| 849 | hwc.getNumLayers(), count); |
| 850 | |
| 851 | // just to be extra-safe, use the smallest count |
Erik Gilling | 24925bf | 2010-08-12 23:21:40 -0700 | [diff] [blame] | 852 | if (hwc.initCheck() == NO_ERROR) { |
| 853 | count = count < hwc.getNumLayers() ? count : hwc.getNumLayers(); |
| 854 | } |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 855 | |
| 856 | /* |
| 857 | * update the per-frame h/w composer data for each layer |
| 858 | * and build the transparent region of the FB |
| 859 | */ |
| 860 | Region transparent; |
| 861 | if (cur) { |
| 862 | for (size_t i=0 ; i<count ; i++) { |
| 863 | const sp<LayerBase>& layer(layers[i]); |
| 864 | layer->setPerFrameData(&cur[i]); |
| 865 | if (cur[i].hints & HWC_HINT_CLEAR_FB) { |
| 866 | if (!(layer->needsBlending())) { |
| 867 | transparent.orSelf(layer->visibleRegionScreen); |
| 868 | } |
| 869 | } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 870 | } |
| 871 | err = hwc.prepare(); |
| 872 | LOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err)); |
| 873 | } |
| 874 | |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 875 | /* |
| 876 | * clear the area of the FB that need to be transparent |
| 877 | */ |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 878 | transparent.andSelf(dirty); |
| 879 | if (!transparent.isEmpty()) { |
| 880 | glClearColor(0,0,0,0); |
| 881 | Region::const_iterator it = transparent.begin(); |
| 882 | Region::const_iterator const end = transparent.end(); |
| 883 | const int32_t height = hw.getHeight(); |
| 884 | while (it != end) { |
| 885 | const Rect& r(*it++); |
| 886 | const GLint sy = height - (r.top + r.height()); |
| 887 | glScissor(r.left, sy, r.width(), r.height()); |
| 888 | glClear(GL_COLOR_BUFFER_BIT); |
| 889 | } |
| 890 | } |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 891 | |
| 892 | |
| 893 | /* |
| 894 | * and then, render the layers targeted at the framebuffer |
| 895 | */ |
| 896 | for (size_t i=0 ; i<count ; i++) { |
| 897 | if (cur) { |
Antti Hatala | 586a0de | 2010-09-09 02:32:30 -0700 | [diff] [blame] | 898 | if ((cur[i].compositionType != HWC_FRAMEBUFFER) && |
| 899 | !(cur[i].flags & HWC_SKIP_LAYER)) { |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 900 | // skip layers handled by the HAL |
| 901 | continue; |
| 902 | } |
| 903 | } |
| 904 | const sp<LayerBase>& layer(layers[i]); |
| 905 | const Region clip(dirty.intersect(layer->visibleRegionScreen)); |
| 906 | if (!clip.isEmpty()) { |
| 907 | layer->draw(clip); |
| 908 | } |
| 909 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | void SurfaceFlinger::unlockClients() |
| 913 | { |
| 914 | const LayerVector& drawingLayers(mDrawingState.layersSortedByZ); |
| 915 | const size_t count = drawingLayers.size(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 916 | sp<LayerBase> const* const layers = drawingLayers.array(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | for (size_t i=0 ; i<count ; ++i) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 918 | const sp<LayerBase>& layer = layers[i]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | layer->finishPageFlip(); |
| 920 | } |
| 921 | } |
| 922 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | void SurfaceFlinger::debugFlashRegions() |
| 924 | { |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 925 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 926 | const uint32_t flags = hw.getFlags(); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 927 | |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 928 | if (!((flags & DisplayHardware::SWAP_RECTANGLE) || |
| 929 | (flags & DisplayHardware::BUFFER_PRESERVED))) { |
| 930 | const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ? |
| 931 | mDirtyRegion.bounds() : hw.bounds()); |
| 932 | composeSurfaces(repaint); |
| 933 | } |
| 934 | |
| 935 | TextureManager::deactivateTextures(); |
| 936 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | glDisable(GL_BLEND); |
| 938 | glDisable(GL_DITHER); |
| 939 | glDisable(GL_SCISSOR_TEST); |
| 940 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 941 | static int toggle = 0; |
| 942 | toggle = 1 - toggle; |
| 943 | if (toggle) { |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 944 | glColor4f(1, 0, 1, 1); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 945 | } else { |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 946 | glColor4f(1, 1, 0, 1); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 947 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 949 | Region::const_iterator it = mDirtyRegion.begin(); |
| 950 | Region::const_iterator const end = mDirtyRegion.end(); |
| 951 | while (it != end) { |
| 952 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | GLfloat vertices[][2] = { |
| 954 | { r.left, r.top }, |
| 955 | { r.left, r.bottom }, |
| 956 | { r.right, r.bottom }, |
| 957 | { r.right, r.top } |
| 958 | }; |
| 959 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
| 960 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 961 | } |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 962 | |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 963 | if (mInvalidRegion.isEmpty()) { |
| 964 | mDirtyRegion.dump("mDirtyRegion"); |
| 965 | mInvalidRegion.dump("mInvalidRegion"); |
| 966 | } |
| 967 | hw.flip(mInvalidRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | |
| 969 | if (mDebugRegion > 1) |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 970 | usleep(mDebugRegion * 1000); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | |
| 972 | glEnable(GL_SCISSOR_TEST); |
| 973 | //mDirtyRegion.dump("mDirtyRegion"); |
| 974 | } |
| 975 | |
| 976 | void SurfaceFlinger::drawWormhole() const |
| 977 | { |
| 978 | const Region region(mWormholeRegion.intersect(mDirtyRegion)); |
| 979 | if (region.isEmpty()) |
| 980 | return; |
| 981 | |
| 982 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 983 | const int32_t width = hw.getWidth(); |
| 984 | const int32_t height = hw.getHeight(); |
| 985 | |
| 986 | glDisable(GL_BLEND); |
| 987 | glDisable(GL_DITHER); |
| 988 | |
| 989 | if (LIKELY(!mDebugBackground)) { |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 990 | glClearColor(0,0,0,0); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 991 | Region::const_iterator it = region.begin(); |
| 992 | Region::const_iterator const end = region.end(); |
| 993 | while (it != end) { |
| 994 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | const GLint sy = height - (r.top + r.height()); |
| 996 | glScissor(r.left, sy, r.width(), r.height()); |
| 997 | glClear(GL_COLOR_BUFFER_BIT); |
| 998 | } |
| 999 | } else { |
| 1000 | const GLshort vertices[][2] = { { 0, 0 }, { width, 0 }, |
| 1001 | { width, height }, { 0, height } }; |
| 1002 | const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } }; |
| 1003 | glVertexPointer(2, GL_SHORT, 0, vertices); |
| 1004 | glTexCoordPointer(2, GL_SHORT, 0, tcoords); |
| 1005 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1006 | #if defined(GL_OES_texture_external) |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 1007 | if (GLExtensions::getInstance().haveTextureExternal()) { |
| 1008 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 1009 | } |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 1010 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | glEnable(GL_TEXTURE_2D); |
| 1012 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); |
| 1013 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 1014 | glMatrixMode(GL_TEXTURE); |
| 1015 | glLoadIdentity(); |
| 1016 | glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 1017 | Region::const_iterator it = region.begin(); |
| 1018 | Region::const_iterator const end = region.end(); |
| 1019 | while (it != end) { |
| 1020 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | const GLint sy = height - (r.top + r.height()); |
| 1022 | glScissor(r.left, sy, r.width(), r.height()); |
| 1023 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 1024 | } |
| 1025 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | void SurfaceFlinger::debugShowFPS() const |
| 1030 | { |
| 1031 | static int mFrameCount; |
| 1032 | static int mLastFrameCount = 0; |
| 1033 | static nsecs_t mLastFpsTime = 0; |
| 1034 | static float mFps = 0; |
| 1035 | mFrameCount++; |
| 1036 | nsecs_t now = systemTime(); |
| 1037 | nsecs_t diff = now - mLastFpsTime; |
| 1038 | if (diff > ms2ns(250)) { |
| 1039 | mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; |
| 1040 | mLastFpsTime = now; |
| 1041 | mLastFrameCount = mFrameCount; |
| 1042 | } |
| 1043 | // XXX: mFPS has the value we want |
| 1044 | } |
| 1045 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1046 | status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | { |
| 1048 | Mutex::Autolock _l(mStateLock); |
| 1049 | addLayer_l(layer); |
| 1050 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); |
| 1051 | return NO_ERROR; |
| 1052 | } |
| 1053 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1054 | status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer) |
| 1055 | { |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 1056 | ssize_t i = mCurrentState.layersSortedByZ.add(layer); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1057 | return (i < 0) ? status_t(i) : status_t(NO_ERROR); |
| 1058 | } |
| 1059 | |
| 1060 | ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client, |
| 1061 | const sp<LayerBaseClient>& lbc) |
| 1062 | { |
| 1063 | Mutex::Autolock _l(mStateLock); |
| 1064 | |
| 1065 | // attach this layer to the client |
| 1066 | ssize_t name = client->attachLayer(lbc); |
| 1067 | |
| 1068 | // add this layer to the current state list |
| 1069 | addLayer_l(lbc); |
| 1070 | |
| 1071 | return name; |
| 1072 | } |
| 1073 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1074 | status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | { |
| 1076 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1077 | status_t err = purgatorizeLayer_l(layer); |
| 1078 | if (err == NO_ERROR) |
| 1079 | setTransactionFlags(eTransactionNeeded); |
| 1080 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1083 | status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1085 | sp<LayerBaseClient> lbc(layerBase->getLayerBaseClient()); |
| 1086 | if (lbc != 0) { |
| 1087 | mLayerMap.removeItem( lbc->getSurface()->asBinder() ); |
| 1088 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase); |
| 1090 | if (index >= 0) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1091 | mLayersRemoved = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | return NO_ERROR; |
| 1093 | } |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1094 | return status_t(index); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1097 | status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase) |
| 1098 | { |
Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1099 | // remove the layer from the main list (through a transaction). |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1100 | ssize_t err = removeLayer_l(layerBase); |
Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1101 | |
Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 1102 | layerBase->onRemoved(); |
| 1103 | |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1104 | // it's possible that we don't find a layer, because it might |
| 1105 | // have been destroyed already -- this is not technically an error |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1106 | // from the user because there is a race between Client::destroySurface(), |
| 1107 | // ~Client() and ~ISurface(). |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1108 | return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err; |
| 1109 | } |
| 1110 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1111 | status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1113 | layer->forceVisibilityTransaction(); |
| 1114 | setTransactionFlags(eTraversalNeeded); |
| 1115 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) |
| 1119 | { |
| 1120 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 1121 | } |
| 1122 | |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1123 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | { |
| 1125 | uint32_t old = android_atomic_or(flags, &mTransactionFlags); |
| 1126 | if ((old & flags)==0) { // wake the server up |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1127 | signalEvent(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
| 1129 | return old; |
| 1130 | } |
| 1131 | |
| 1132 | void SurfaceFlinger::openGlobalTransaction() |
| 1133 | { |
| 1134 | android_atomic_inc(&mTransactionCount); |
| 1135 | } |
| 1136 | |
| 1137 | void SurfaceFlinger::closeGlobalTransaction() |
| 1138 | { |
| 1139 | if (android_atomic_dec(&mTransactionCount) == 1) { |
| 1140 | signalEvent(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1141 | |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1142 | // if there is a transaction with a resize, wait for it to |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1143 | // take effect before returning. |
| 1144 | Mutex::Autolock _l(mStateLock); |
| 1145 | while (mResizeTransationPending) { |
Mathias Agopian | 448f015 | 2009-09-30 14:42:13 -0700 | [diff] [blame] | 1146 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
| 1147 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 1148 | // just in case something goes wrong in SF, return to the |
| 1149 | // called after a few seconds. |
| 1150 | LOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!"); |
| 1151 | mResizeTransationPending = false; |
| 1152 | break; |
| 1153 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1154 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags) |
| 1159 | { |
| 1160 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1161 | return BAD_VALUE; |
| 1162 | |
| 1163 | Mutex::Autolock _l(mStateLock); |
| 1164 | mCurrentState.freezeDisplay = 1; |
| 1165 | setTransactionFlags(eTransactionNeeded); |
| 1166 | |
| 1167 | // flags is intended to communicate some sort of animation behavior |
Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1168 | // (for instance fading) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | return NO_ERROR; |
| 1170 | } |
| 1171 | |
| 1172 | status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags) |
| 1173 | { |
| 1174 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1175 | return BAD_VALUE; |
| 1176 | |
| 1177 | Mutex::Autolock _l(mStateLock); |
| 1178 | mCurrentState.freezeDisplay = 0; |
| 1179 | setTransactionFlags(eTransactionNeeded); |
| 1180 | |
| 1181 | // flags is intended to communicate some sort of animation behavior |
Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1182 | // (for instance fading) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | return NO_ERROR; |
| 1184 | } |
| 1185 | |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1186 | int SurfaceFlinger::setOrientation(DisplayID dpy, |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 1187 | int orientation, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | { |
| 1189 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) |
| 1190 | return BAD_VALUE; |
| 1191 | |
| 1192 | Mutex::Autolock _l(mStateLock); |
| 1193 | if (mCurrentState.orientation != orientation) { |
| 1194 | if (uint32_t(orientation)<=eOrientation270 || orientation==42) { |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 1195 | mCurrentState.orientationType = flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | mCurrentState.orientation = orientation; |
| 1197 | setTransactionFlags(eTransactionNeeded); |
| 1198 | mTransactionCV.wait(mStateLock); |
| 1199 | } else { |
| 1200 | orientation = BAD_VALUE; |
| 1201 | } |
| 1202 | } |
| 1203 | return orientation; |
| 1204 | } |
| 1205 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1206 | sp<ISurface> SurfaceFlinger::createSurface(const sp<Client>& client, int pid, |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 1207 | const String8& name, ISurfaceComposerClient::surface_data_t* params, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | DisplayID d, uint32_t w, uint32_t h, PixelFormat format, |
| 1209 | uint32_t flags) |
| 1210 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1211 | sp<LayerBaseClient> layer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | sp<LayerBaseClient::Surface> surfaceHandle; |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1213 | |
| 1214 | if (int32_t(w|h) < 0) { |
| 1215 | LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)", |
| 1216 | int(w), int(h)); |
| 1217 | return surfaceHandle; |
| 1218 | } |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1219 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | //LOGD("createSurface for pid %d (%d x %d)", pid, w, h); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1221 | sp<Layer> normalLayer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | switch (flags & eFXSurfaceMask) { |
| 1223 | case eFXSurfaceNormal: |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1224 | #if HAS_PUSH_BUFFERS |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | if (UNLIKELY(flags & ePushBuffers)) { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1226 | layer = createPushBuffersSurface(client, d, w, h, flags); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1227 | } else |
| 1228 | #endif |
| 1229 | { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1230 | normalLayer = createNormalSurface(client, d, w, h, flags, format); |
| 1231 | layer = normalLayer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } |
| 1233 | break; |
| 1234 | case eFXSurfaceBlur: |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1235 | layer = createBlurSurface(client, d, w, h, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | break; |
| 1237 | case eFXSurfaceDim: |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1238 | layer = createDimSurface(client, d, w, h, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | break; |
| 1240 | } |
| 1241 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1242 | if (layer != 0) { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1243 | layer->initStates(w, h, flags); |
Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 1244 | layer->setName(name); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1245 | ssize_t token = addClientLayer(client, layer); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1246 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | surfaceHandle = layer->getSurface(); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1248 | if (surfaceHandle != 0) { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1249 | params->token = token; |
Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1250 | params->identity = surfaceHandle->getIdentity(); |
| 1251 | params->width = w; |
| 1252 | params->height = h; |
| 1253 | params->format = format; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1254 | if (normalLayer != 0) { |
| 1255 | Mutex::Autolock _l(mStateLock); |
| 1256 | mLayerMap.add(surfaceHandle->asBinder(), normalLayer); |
| 1257 | } |
Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1258 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1259 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1260 | setTransactionFlags(eTransactionNeeded); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | return surfaceHandle; |
| 1264 | } |
| 1265 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1266 | sp<Layer> SurfaceFlinger::createNormalSurface( |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1267 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1268 | uint32_t w, uint32_t h, uint32_t flags, |
Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1269 | PixelFormat& format) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | { |
| 1271 | // initialize the surfaces |
| 1272 | switch (format) { // TODO: take h/w into account |
| 1273 | case PIXEL_FORMAT_TRANSPARENT: |
| 1274 | case PIXEL_FORMAT_TRANSLUCENT: |
| 1275 | format = PIXEL_FORMAT_RGBA_8888; |
| 1276 | break; |
| 1277 | case PIXEL_FORMAT_OPAQUE: |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1278 | #ifdef NO_RGBX_8888 |
| 1279 | format = PIXEL_FORMAT_RGB_565; |
| 1280 | #else |
Mathias Agopian | 8f10540 | 2010-04-05 18:01:24 -0700 | [diff] [blame] | 1281 | format = PIXEL_FORMAT_RGBX_8888; |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1282 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | break; |
| 1284 | } |
| 1285 | |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1286 | #ifdef NO_RGBX_8888 |
| 1287 | if (format == PIXEL_FORMAT_RGBX_8888) |
| 1288 | format = PIXEL_FORMAT_RGBA_8888; |
| 1289 | #endif |
| 1290 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1291 | sp<Layer> layer = new Layer(this, display, client); |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1292 | status_t err = layer->setBuffers(w, h, format, flags); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1293 | if (LIKELY(err != NO_ERROR)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err)); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1295 | layer.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | } |
| 1297 | return layer; |
| 1298 | } |
| 1299 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1300 | sp<LayerBlur> SurfaceFlinger::createBlurSurface( |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1301 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1302 | uint32_t w, uint32_t h, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1304 | sp<LayerBlur> layer = new LayerBlur(this, display, client); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | layer->initStates(w, h, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | return layer; |
| 1307 | } |
| 1308 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1309 | sp<LayerDim> SurfaceFlinger::createDimSurface( |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1310 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1311 | uint32_t w, uint32_t h, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1313 | sp<LayerDim> layer = new LayerDim(this, display, client); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | layer->initStates(w, h, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | return layer; |
| 1316 | } |
| 1317 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1318 | sp<LayerBuffer> SurfaceFlinger::createPushBuffersSurface( |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1319 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1320 | uint32_t w, uint32_t h, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1322 | sp<LayerBuffer> layer = new LayerBuffer(this, display, client); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | layer->initStates(w, h, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | return layer; |
| 1325 | } |
| 1326 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1327 | status_t SurfaceFlinger::removeSurface(const sp<Client>& client, SurfaceID sid) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1329 | /* |
| 1330 | * called by the window manager, when a surface should be marked for |
| 1331 | * destruction. |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1332 | * |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1333 | * The surface is removed from the current and drawing lists, but placed |
| 1334 | * in the purgatory queue, so it's not destroyed right-away (we need |
| 1335 | * to wait for all client's references to go away first). |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1336 | */ |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1337 | |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1338 | status_t err = NAME_NOT_FOUND; |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1339 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1340 | sp<LayerBaseClient> layer = client->getLayerUser(sid); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1341 | if (layer != 0) { |
| 1342 | err = purgatorizeLayer_l(layer); |
| 1343 | if (err == NO_ERROR) { |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1344 | setTransactionFlags(eTransactionNeeded); |
| 1345 | } |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1346 | } |
| 1347 | return err; |
| 1348 | } |
| 1349 | |
| 1350 | status_t SurfaceFlinger::destroySurface(const sp<LayerBaseClient>& layer) |
| 1351 | { |
Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1352 | // called by ~ISurface() when all references are gone |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1353 | |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1354 | class MessageDestroySurface : public MessageBase { |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1355 | SurfaceFlinger* flinger; |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1356 | sp<LayerBaseClient> layer; |
| 1357 | public: |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1358 | MessageDestroySurface( |
| 1359 | SurfaceFlinger* flinger, const sp<LayerBaseClient>& layer) |
| 1360 | : flinger(flinger), layer(layer) { } |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1361 | virtual bool handler() { |
Mathias Agopian | cd8c5e2 | 2009-06-19 16:24:02 -0700 | [diff] [blame] | 1362 | sp<LayerBaseClient> l(layer); |
| 1363 | layer.clear(); // clear it outside of the lock; |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1364 | Mutex::Autolock _l(flinger->mStateLock); |
Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1365 | /* |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1366 | * remove the layer from the current list -- chances are that it's |
| 1367 | * not in the list anyway, because it should have been removed |
| 1368 | * already upon request of the client (eg: window manager). |
Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1369 | * However, a buggy client could have not done that. |
| 1370 | * Since we know we don't have any more clients, we don't need |
| 1371 | * to use the purgatory. |
| 1372 | */ |
Mathias Agopian | cd8c5e2 | 2009-06-19 16:24:02 -0700 | [diff] [blame] | 1373 | status_t err = flinger->removeLayer_l(l); |
Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1374 | LOGE_IF(err<0 && err != NAME_NOT_FOUND, |
| 1375 | "error removing layer=%p (%s)", l.get(), strerror(-err)); |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1376 | return true; |
| 1377 | } |
| 1378 | }; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1379 | |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1380 | postMessageAsync( new MessageDestroySurface(this, layer) ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1381 | return NO_ERROR; |
| 1382 | } |
| 1383 | |
| 1384 | status_t SurfaceFlinger::setClientState( |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1385 | const sp<Client>& client, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | int32_t count, |
| 1387 | const layer_state_t* states) |
| 1388 | { |
| 1389 | Mutex::Autolock _l(mStateLock); |
| 1390 | uint32_t flags = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | for (int i=0 ; i<count ; i++) { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1392 | const layer_state_t& s(states[i]); |
| 1393 | sp<LayerBaseClient> layer(client->getLayerUser(s.surface)); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1394 | if (layer != 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | const uint32_t what = s.what; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | if (what & ePositionChanged) { |
| 1397 | if (layer->setPosition(s.x, s.y)) |
| 1398 | flags |= eTraversalNeeded; |
| 1399 | } |
| 1400 | if (what & eLayerChanged) { |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 1401 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | if (layer->setLayer(s.z)) { |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 1403 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 1404 | mCurrentState.layersSortedByZ.add(layer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | // we need traversal (state changed) |
| 1406 | // AND transaction (list changed) |
| 1407 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 1408 | } |
| 1409 | } |
| 1410 | if (what & eSizeChanged) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1411 | if (layer->setSize(s.w, s.h)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | flags |= eTraversalNeeded; |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1413 | mResizeTransationPending = true; |
| 1414 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | } |
| 1416 | if (what & eAlphaChanged) { |
| 1417 | if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f))) |
| 1418 | flags |= eTraversalNeeded; |
| 1419 | } |
| 1420 | if (what & eMatrixChanged) { |
| 1421 | if (layer->setMatrix(s.matrix)) |
| 1422 | flags |= eTraversalNeeded; |
| 1423 | } |
| 1424 | if (what & eTransparentRegionChanged) { |
| 1425 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 1426 | flags |= eTraversalNeeded; |
| 1427 | } |
| 1428 | if (what & eVisibilityChanged) { |
| 1429 | if (layer->setFlags(s.flags, s.mask)) |
| 1430 | flags |= eTraversalNeeded; |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | if (flags) { |
| 1435 | setTransactionFlags(flags); |
| 1436 | } |
| 1437 | return NO_ERROR; |
| 1438 | } |
| 1439 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | void SurfaceFlinger::screenReleased(int dpy) |
| 1441 | { |
| 1442 | // this may be called by a signal handler, we can't do too much in here |
| 1443 | android_atomic_or(eConsoleReleased, &mConsoleSignals); |
| 1444 | signalEvent(); |
| 1445 | } |
| 1446 | |
| 1447 | void SurfaceFlinger::screenAcquired(int dpy) |
| 1448 | { |
| 1449 | // this may be called by a signal handler, we can't do too much in here |
| 1450 | android_atomic_or(eConsoleAcquired, &mConsoleSignals); |
| 1451 | signalEvent(); |
| 1452 | } |
| 1453 | |
| 1454 | status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args) |
| 1455 | { |
| 1456 | const size_t SIZE = 1024; |
| 1457 | char buffer[SIZE]; |
| 1458 | String8 result; |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1459 | if (!mDump.checkCalling()) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | snprintf(buffer, SIZE, "Permission Denial: " |
| 1461 | "can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 1462 | IPCThreadState::self()->getCallingPid(), |
| 1463 | IPCThreadState::self()->getCallingUid()); |
| 1464 | result.append(buffer); |
| 1465 | } else { |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1466 | |
| 1467 | // figure out if we're stuck somewhere |
| 1468 | const nsecs_t now = systemTime(); |
| 1469 | const nsecs_t inSwapBuffers(mDebugInSwapBuffers); |
| 1470 | const nsecs_t inTransaction(mDebugInTransaction); |
| 1471 | nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0; |
| 1472 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 1473 | |
| 1474 | // Try to get the main lock, but don't insist if we can't |
| 1475 | // (this would indicate SF is stuck, but we want to be able to |
| 1476 | // print something in dumpsys). |
| 1477 | int retry = 3; |
| 1478 | while (mStateLock.tryLock()<0 && --retry>=0) { |
| 1479 | usleep(1000000); |
| 1480 | } |
| 1481 | const bool locked(retry >= 0); |
| 1482 | if (!locked) { |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1483 | snprintf(buffer, SIZE, |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1484 | "SurfaceFlinger appears to be unresponsive, " |
| 1485 | "dumping anyways (no locks held)\n"); |
| 1486 | result.append(buffer); |
| 1487 | } |
| 1488 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 1490 | const size_t count = currentLayers.size(); |
| 1491 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1492 | const sp<LayerBase>& layer(currentLayers[i]); |
| 1493 | layer->dump(result, buffer, SIZE); |
| 1494 | const Layer::State& s(layer->drawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | s.transparentRegion.dump(result, "transparentRegion"); |
| 1496 | layer->transparentRegionScreen.dump(result, "transparentRegionScreen"); |
| 1497 | layer->visibleRegionScreen.dump(result, "visibleRegionScreen"); |
| 1498 | } |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1499 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | mWormholeRegion.dump(result, "WormholeRegion"); |
| 1501 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1502 | snprintf(buffer, SIZE, |
| 1503 | " display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n", |
| 1504 | mFreezeDisplay?"yes":"no", mFreezeCount, |
| 1505 | mCurrentState.orientation, hw.canDraw()); |
| 1506 | result.append(buffer); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1507 | snprintf(buffer, SIZE, |
| 1508 | " last eglSwapBuffers() time: %f us\n" |
| 1509 | " last transaction time : %f us\n", |
| 1510 | mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0); |
| 1511 | result.append(buffer); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1512 | |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1513 | if (inSwapBuffersDuration || !locked) { |
| 1514 | snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n", |
| 1515 | inSwapBuffersDuration/1000.0); |
| 1516 | result.append(buffer); |
| 1517 | } |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1518 | |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1519 | if (inTransactionDuration || !locked) { |
| 1520 | snprintf(buffer, SIZE, " transaction time: %f us\n", |
| 1521 | inTransactionDuration/1000.0); |
| 1522 | result.append(buffer); |
| 1523 | } |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 1524 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 1525 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1526 | alloc.dump(result); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1527 | |
| 1528 | if (locked) { |
| 1529 | mStateLock.unlock(); |
| 1530 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | } |
| 1532 | write(fd, result.string(), result.size()); |
| 1533 | return NO_ERROR; |
| 1534 | } |
| 1535 | |
| 1536 | status_t SurfaceFlinger::onTransact( |
| 1537 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 1538 | { |
| 1539 | switch (code) { |
| 1540 | case CREATE_CONNECTION: |
| 1541 | case OPEN_GLOBAL_TRANSACTION: |
| 1542 | case CLOSE_GLOBAL_TRANSACTION: |
| 1543 | case SET_ORIENTATION: |
| 1544 | case FREEZE_DISPLAY: |
| 1545 | case UNFREEZE_DISPLAY: |
| 1546 | case BOOT_FINISHED: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | { |
| 1548 | // codes that require permission check |
| 1549 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1550 | const int pid = ipc->getCallingPid(); |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 1551 | const int uid = ipc->getCallingUid(); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1552 | if ((uid != AID_GRAPHICS) && !mAccessSurfaceFlinger.check(pid, uid)) { |
| 1553 | LOGE("Permission Denial: " |
| 1554 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 1555 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 1560 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 1561 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1562 | if (UNLIKELY(!mHardwareTest.checkCalling())) { |
| 1563 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1564 | const int pid = ipc->getCallingPid(); |
| 1565 | const int uid = ipc->getCallingUid(); |
| 1566 | LOGE("Permission Denial: " |
| 1567 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | return PERMISSION_DENIED; |
| 1569 | } |
| 1570 | int n; |
| 1571 | switch (code) { |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1572 | case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 1573 | case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | return NO_ERROR; |
| 1575 | case 1002: // SHOW_UPDATES |
| 1576 | n = data.readInt32(); |
| 1577 | mDebugRegion = n ? n : (mDebugRegion ? 0 : 1); |
| 1578 | return NO_ERROR; |
| 1579 | case 1003: // SHOW_BACKGROUND |
| 1580 | n = data.readInt32(); |
| 1581 | mDebugBackground = n ? 1 : 0; |
| 1582 | return NO_ERROR; |
| 1583 | case 1004:{ // repaint everything |
| 1584 | Mutex::Autolock _l(mStateLock); |
| 1585 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1586 | mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe |
| 1587 | signalEvent(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1588 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1590 | case 1005:{ // force transaction |
| 1591 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); |
| 1592 | return NO_ERROR; |
| 1593 | } |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 1594 | case 1006:{ // enable/disable GraphicLog |
| 1595 | int enabled = data.readInt32(); |
| 1596 | GraphicLog::getInstance().setEnabled(enabled); |
| 1597 | return NO_ERROR; |
| 1598 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | case 1007: // set mFreezeCount |
| 1600 | mFreezeCount = data.readInt32(); |
Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 1601 | mFreezeDisplayTime = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | return NO_ERROR; |
| 1603 | case 1010: // interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1604 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | reply->writeInt32(0); |
| 1606 | reply->writeInt32(mDebugRegion); |
| 1607 | reply->writeInt32(mDebugBackground); |
| 1608 | return NO_ERROR; |
| 1609 | case 1013: { |
| 1610 | Mutex::Autolock _l(mStateLock); |
| 1611 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 1612 | reply->writeInt32(hw.getPageFlipCount()); |
| 1613 | } |
| 1614 | return NO_ERROR; |
| 1615 | } |
| 1616 | } |
| 1617 | return err; |
| 1618 | } |
| 1619 | |
| 1620 | // --------------------------------------------------------------------------- |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1621 | |
| 1622 | sp<Layer> SurfaceFlinger::getLayer(const sp<ISurface>& sur) const |
| 1623 | { |
| 1624 | sp<Layer> result; |
| 1625 | Mutex::Autolock _l(mStateLock); |
| 1626 | result = mLayerMap.valueFor( sur->asBinder() ).promote(); |
| 1627 | return result; |
| 1628 | } |
| 1629 | |
| 1630 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1632 | Client::Client(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1633 | : mFlinger(flinger), mNameGenerator(1) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | } |
| 1636 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1637 | Client::~Client() |
| 1638 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1639 | const size_t count = mLayers.size(); |
| 1640 | for (size_t i=0 ; i<count ; i++) { |
| 1641 | sp<LayerBaseClient> layer(mLayers.valueAt(i).promote()); |
| 1642 | if (layer != 0) { |
| 1643 | mFlinger->removeLayer(layer); |
| 1644 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1648 | status_t Client::initCheck() const { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1649 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1651 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1652 | ssize_t Client::attachLayer(const sp<LayerBaseClient>& layer) |
| 1653 | { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1654 | int32_t name = android_atomic_inc(&mNameGenerator); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1655 | mLayers.add(name, layer); |
| 1656 | return name; |
| 1657 | } |
| 1658 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1659 | void Client::detachLayer(const LayerBaseClient* layer) |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1660 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1661 | // we do a linear search here, because this doesn't happen often |
| 1662 | const size_t count = mLayers.size(); |
| 1663 | for (size_t i=0 ; i<count ; i++) { |
| 1664 | if (mLayers.valueAt(i) == layer) { |
| 1665 | mLayers.removeItemsAt(i, 1); |
| 1666 | break; |
| 1667 | } |
| 1668 | } |
| 1669 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1670 | sp<LayerBaseClient> Client::getLayerUser(int32_t i) const { |
| 1671 | sp<LayerBaseClient> lbc; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1672 | const wp<LayerBaseClient>& layer(mLayers.valueFor(i)); |
| 1673 | if (layer != 0) { |
| 1674 | lbc = layer.promote(); |
| 1675 | LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i)); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1676 | } |
| 1677 | return lbc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | } |
| 1679 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1680 | sp<IMemoryHeap> Client::getControlBlock() const { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1681 | return 0; |
| 1682 | } |
| 1683 | ssize_t Client::getTokenForSurface(const sp<ISurface>& sur) const { |
| 1684 | return -1; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1686 | sp<ISurface> Client::createSurface( |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1687 | ISurfaceComposerClient::surface_data_t* params, int pid, |
| 1688 | const String8& name, |
| 1689 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1690 | uint32_t flags) |
| 1691 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1692 | return mFlinger->createSurface(this, pid, name, params, |
| 1693 | display, w, h, format, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1695 | status_t Client::destroySurface(SurfaceID sid) { |
| 1696 | return mFlinger->removeSurface(this, sid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1698 | status_t Client::setState(int32_t count, const layer_state_t* states) { |
| 1699 | return mFlinger->setClientState(this, count, states); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | // --------------------------------------------------------------------------- |
| 1703 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1704 | UserClient::UserClient(const sp<SurfaceFlinger>& flinger) |
| 1705 | : ctrlblk(0), mBitmap(0), mFlinger(flinger) |
| 1706 | { |
| 1707 | const int pgsize = getpagesize(); |
| 1708 | const int cblksize = ((sizeof(SharedClient)+(pgsize-1))&~(pgsize-1)); |
| 1709 | |
| 1710 | mCblkHeap = new MemoryHeapBase(cblksize, 0, |
| 1711 | "SurfaceFlinger Client control-block"); |
| 1712 | |
| 1713 | ctrlblk = static_cast<SharedClient *>(mCblkHeap->getBase()); |
| 1714 | if (ctrlblk) { // construct the shared structure in-place. |
| 1715 | new(ctrlblk) SharedClient; |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | UserClient::~UserClient() |
| 1720 | { |
| 1721 | if (ctrlblk) { |
| 1722 | ctrlblk->~SharedClient(); // destroy our shared-structure. |
| 1723 | } |
| 1724 | |
| 1725 | /* |
| 1726 | * When a UserClient dies, it's unclear what to do exactly. |
| 1727 | * We could go ahead and destroy all surfaces linked to that client |
| 1728 | * however, it wouldn't be fair to the main Client |
| 1729 | * (usually the the window-manager), which might want to re-target |
| 1730 | * the layer to another UserClient. |
| 1731 | * I think the best is to do nothing, or not much; in most cases the |
| 1732 | * WM itself will go ahead and clean things up when it detects a client of |
| 1733 | * his has died. |
| 1734 | * The remaining question is what to display? currently we keep |
| 1735 | * just keep the current buffer. |
| 1736 | */ |
| 1737 | } |
| 1738 | |
| 1739 | status_t UserClient::initCheck() const { |
| 1740 | return ctrlblk == 0 ? NO_INIT : NO_ERROR; |
| 1741 | } |
| 1742 | |
| 1743 | void UserClient::detachLayer(const Layer* layer) |
| 1744 | { |
| 1745 | int32_t name = layer->getToken(); |
| 1746 | if (name >= 0) { |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 1747 | int32_t mask = 1LU<<name; |
| 1748 | if ((android_atomic_and(~mask, &mBitmap) & mask) == 0) { |
| 1749 | LOGW("token %d wasn't marked as used %08x", name, int(mBitmap)); |
| 1750 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | sp<IMemoryHeap> UserClient::getControlBlock() const { |
| 1755 | return mCblkHeap; |
| 1756 | } |
| 1757 | |
| 1758 | ssize_t UserClient::getTokenForSurface(const sp<ISurface>& sur) const |
| 1759 | { |
| 1760 | int32_t name = NAME_NOT_FOUND; |
| 1761 | sp<Layer> layer(mFlinger->getLayer(sur)); |
Jamie Gennis | 89c2dd2 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 1762 | if (layer == 0) { |
| 1763 | return name; |
| 1764 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1765 | |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 1766 | // if this layer already has a token, just return it |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1767 | name = layer->getToken(); |
Jamie Gennis | 89c2dd2 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 1768 | if ((name >= 0) && (layer->getClient() == this)) { |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 1769 | return name; |
Jamie Gennis | 89c2dd2 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 1770 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1771 | |
| 1772 | name = 0; |
| 1773 | do { |
| 1774 | int32_t mask = 1LU<<name; |
| 1775 | if ((android_atomic_or(mask, &mBitmap) & mask) == 0) { |
| 1776 | // we found and locked that name |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 1777 | status_t err = layer->setToken( |
| 1778 | const_cast<UserClient*>(this), ctrlblk, name); |
| 1779 | if (err != NO_ERROR) { |
| 1780 | // free the name |
| 1781 | android_atomic_and(~mask, &mBitmap); |
| 1782 | name = err; |
| 1783 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1784 | break; |
| 1785 | } |
| 1786 | if (++name > 31) |
| 1787 | name = NO_MEMORY; |
| 1788 | } while(name >= 0); |
| 1789 | |
Mathias Agopian | 53503a9 | 2010-06-08 15:40:56 -0700 | [diff] [blame] | 1790 | //LOGD("getTokenForSurface(%p) => %d (client=%p, bitmap=%08lx)", |
| 1791 | // sur->asBinder().get(), name, this, mBitmap); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 1792 | return name; |
| 1793 | } |
| 1794 | |
| 1795 | sp<ISurface> UserClient::createSurface( |
| 1796 | ISurfaceComposerClient::surface_data_t* params, int pid, |
| 1797 | const String8& name, |
| 1798 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, |
| 1799 | uint32_t flags) { |
| 1800 | return 0; |
| 1801 | } |
| 1802 | status_t UserClient::destroySurface(SurfaceID sid) { |
| 1803 | return INVALID_OPERATION; |
| 1804 | } |
| 1805 | status_t UserClient::setState(int32_t count, const layer_state_t* states) { |
| 1806 | return INVALID_OPERATION; |
| 1807 | } |
| 1808 | |
| 1809 | // --------------------------------------------------------------------------- |
| 1810 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | GraphicPlane::GraphicPlane() |
| 1812 | : mHw(0) |
| 1813 | { |
| 1814 | } |
| 1815 | |
| 1816 | GraphicPlane::~GraphicPlane() { |
| 1817 | delete mHw; |
| 1818 | } |
| 1819 | |
| 1820 | bool GraphicPlane::initialized() const { |
| 1821 | return mHw ? true : false; |
| 1822 | } |
| 1823 | |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 1824 | int GraphicPlane::getWidth() const { |
| 1825 | return mWidth; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 1828 | int GraphicPlane::getHeight() const { |
| 1829 | return mHeight; |
| 1830 | } |
| 1831 | |
| 1832 | void GraphicPlane::setDisplayHardware(DisplayHardware *hw) |
| 1833 | { |
| 1834 | mHw = hw; |
| 1835 | |
| 1836 | // initialize the display orientation transform. |
| 1837 | // it's a constant that should come from the display driver. |
| 1838 | int displayOrientation = ISurfaceComposer::eOrientationDefault; |
| 1839 | char property[PROPERTY_VALUE_MAX]; |
| 1840 | if (property_get("ro.sf.hwrotation", property, NULL) > 0) { |
| 1841 | //displayOrientation |
| 1842 | switch (atoi(property)) { |
| 1843 | case 90: |
| 1844 | displayOrientation = ISurfaceComposer::eOrientation90; |
| 1845 | break; |
| 1846 | case 270: |
| 1847 | displayOrientation = ISurfaceComposer::eOrientation270; |
| 1848 | break; |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | const float w = hw->getWidth(); |
| 1853 | const float h = hw->getHeight(); |
| 1854 | GraphicPlane::orientationToTransfrom(displayOrientation, w, h, |
| 1855 | &mDisplayTransform); |
| 1856 | if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) { |
| 1857 | mDisplayWidth = h; |
| 1858 | mDisplayHeight = w; |
| 1859 | } else { |
| 1860 | mDisplayWidth = w; |
| 1861 | mDisplayHeight = h; |
| 1862 | } |
| 1863 | |
| 1864 | setOrientation(ISurfaceComposer::eOrientationDefault); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | status_t GraphicPlane::orientationToTransfrom( |
| 1868 | int orientation, int w, int h, Transform* tr) |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1869 | { |
| 1870 | uint32_t flags = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | switch (orientation) { |
| 1872 | case ISurfaceComposer::eOrientationDefault: |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1873 | flags = Transform::ROT_0; |
| 1874 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | case ISurfaceComposer::eOrientation90: |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1876 | flags = Transform::ROT_90; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | break; |
| 1878 | case ISurfaceComposer::eOrientation180: |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1879 | flags = Transform::ROT_180; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | break; |
| 1881 | case ISurfaceComposer::eOrientation270: |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1882 | flags = Transform::ROT_270; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | break; |
| 1884 | default: |
| 1885 | return BAD_VALUE; |
| 1886 | } |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1887 | tr->set(flags, w, h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | return NO_ERROR; |
| 1889 | } |
| 1890 | |
| 1891 | status_t GraphicPlane::setOrientation(int orientation) |
| 1892 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | // If the rotation can be handled in hardware, this is where |
| 1894 | // the magic should happen. |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 1895 | |
| 1896 | const DisplayHardware& hw(displayHardware()); |
| 1897 | const float w = mDisplayWidth; |
| 1898 | const float h = mDisplayHeight; |
| 1899 | mWidth = int(w); |
| 1900 | mHeight = int(h); |
| 1901 | |
| 1902 | Transform orientationTransform; |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1903 | GraphicPlane::orientationToTransfrom(orientation, w, h, |
| 1904 | &orientationTransform); |
| 1905 | if (orientation & ISurfaceComposer::eOrientationSwapMask) { |
| 1906 | mWidth = int(h); |
| 1907 | mHeight = int(w); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | } |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 1909 | |
Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 1910 | mOrientation = orientation; |
Mathias Agopian | 2b92d89 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 1911 | mGlobalTransform = mDisplayTransform * orientationTransform; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | return NO_ERROR; |
| 1913 | } |
| 1914 | |
| 1915 | const DisplayHardware& GraphicPlane::displayHardware() const { |
| 1916 | return *mHw; |
| 1917 | } |
| 1918 | |
| 1919 | const Transform& GraphicPlane::transform() const { |
| 1920 | return mGlobalTransform; |
| 1921 | } |
| 1922 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1923 | EGLDisplay GraphicPlane::getEGLDisplay() const { |
| 1924 | return mHw->getEGLDisplay(); |
| 1925 | } |
| 1926 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | // --------------------------------------------------------------------------- |
| 1928 | |
| 1929 | }; // namespace android |