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