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