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