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