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 <stdint.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | #include <math.h> |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 23 | #include <dlfcn.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 24 | |
| 25 | #include <EGL/egl.h> |
| 26 | #include <GLES/gl.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 27 | #include <GLES/glext.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | #include <cutils/log.h> |
| 30 | #include <cutils/properties.h> |
| 31 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> |
| 33 | #include <binder/IServiceManager.h> |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 34 | #include <binder/MemoryHeapBase.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 35 | #include <binder/PermissionCache.h> |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 37 | #include <ui/DisplayInfo.h> |
| 38 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 39 | #include <gui/BitTube.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 40 | #include <gui/BufferQueue.h> |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 41 | #include <gui/GuiConfig.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 42 | #include <gui/IDisplayEventConnection.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 43 | #include <gui/Surface.h> |
Jamie Gennis | 392edd8 | 2012-11-29 23:26:29 -0800 | [diff] [blame] | 44 | #include <gui/GraphicBufferAlloc.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 45 | |
| 46 | #include <ui/GraphicBufferAllocator.h> |
| 47 | #include <ui/PixelFormat.h> |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 48 | #include <ui/UiConfig.h> |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 49 | |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 50 | #include <utils/misc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | #include <utils/String8.h> |
| 52 | #include <utils/String16.h> |
| 53 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 54 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 56 | #include <private/android_filesystem_config.h> |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 57 | #include <private/gui/SyncFeatures.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 59 | #include "Client.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | #include "clz.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 61 | #include "Colorizer.h" |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 62 | #include "DdmConnection.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 63 | #include "DisplayDevice.h" |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 64 | #include "EventThread.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | #include "LayerDim.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 69 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 70 | #include "DisplayHardware/HWComposer.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 71 | #include "DisplayHardware/VirtualDisplaySurface.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 73 | #include "RenderEngine/RenderEngine.h" |
| 74 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | #define DISPLAY_COUNT 1 |
| 76 | |
Mathias Agopian | fee2b46 | 2013-07-03 12:34:01 -0700 | [diff] [blame] | 77 | /* |
| 78 | * DEBUG_SCREENSHOTS: set to true to check that screenshots are not all |
| 79 | * black pixels. |
| 80 | */ |
| 81 | #define DEBUG_SCREENSHOTS false |
| 82 | |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 83 | EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name); |
| 84 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | // --------------------------------------------------------------------------- |
| 87 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 88 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 89 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
| 90 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
| 91 | const String16 sDump("android.permission.DUMP"); |
| 92 | |
| 93 | // --------------------------------------------------------------------------- |
| 94 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | SurfaceFlinger::SurfaceFlinger() |
| 96 | : BnSurfaceComposer(), Thread(false), |
| 97 | mTransactionFlags(0), |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 98 | mTransactionPending(false), |
| 99 | mAnimTransactionPending(false), |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 100 | mLayersRemoved(false), |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 101 | mRepaintEverything(0), |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 102 | mRenderEngine(NULL), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | mBootTime(systemTime()), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | mVisibleRegionsDirty(false), |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 105 | mHwWorkListDirty(false), |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 106 | mAnimCompositionPending(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | mDebugRegion(0), |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 108 | mDebugDDMS(0), |
Mathias Agopian | 73d3ba9 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 109 | mDebugDisableHWC(0), |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 110 | mDebugDisableTransformHint(0), |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 111 | mDebugInSwapBuffers(0), |
| 112 | mLastSwapBufferTime(0), |
| 113 | mDebugInTransaction(0), |
| 114 | mLastTransactionTime(0), |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 115 | mBootFinished(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | { |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 117 | ALOGI("SurfaceFlinger is starting"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
| 119 | // debugging stuff... |
| 120 | char value[PROPERTY_VALUE_MAX]; |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 121 | |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 122 | property_get("ro.bq.gpu_to_cpu_unsupported", value, "0"); |
Mathias Agopian | 50210b9 | 2013-03-21 21:13:21 -0700 | [diff] [blame] | 123 | mGpuToCpuSupported = !atoi(value); |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 124 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | property_get("debug.sf.showupdates", value, "0"); |
| 126 | mDebugRegion = atoi(value); |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 127 | |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 128 | property_get("debug.sf.ddms", value, "0"); |
| 129 | mDebugDDMS = atoi(value); |
| 130 | if (mDebugDDMS) { |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 131 | if (!startDdmConnection()) { |
| 132 | // start failed, and DDMS debugging not enabled |
| 133 | mDebugDDMS = 0; |
| 134 | } |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 135 | } |
Mathias Agopian | c1d359d | 2012-08-04 20:09:03 -0700 | [diff] [blame] | 136 | ALOGI_IF(mDebugRegion, "showupdates enabled"); |
| 137 | ALOGI_IF(mDebugDDMS, "DDMS debugging enabled"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 140 | void SurfaceFlinger::onFirstRef() |
| 141 | { |
| 142 | mEventQueue.init(this); |
| 143 | |
| 144 | run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY); |
| 145 | |
| 146 | // Wait for the main thread to be done with its initialization |
| 147 | mReadyToRunBarrier.wait(); |
| 148 | } |
| 149 | |
| 150 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | SurfaceFlinger::~SurfaceFlinger() |
| 152 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 153 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 154 | eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 155 | eglTerminate(display); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 158 | void SurfaceFlinger::binderDied(const wp<IBinder>& who) |
| 159 | { |
| 160 | // the window manager died on us. prepare its eulogy. |
| 161 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 162 | // restore initial conditions (default device unblank, etc) |
| 163 | initializeDisplays(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 164 | |
| 165 | // restart the boot-animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 166 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 169 | sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 171 | sp<ISurfaceComposerClient> bclient; |
| 172 | sp<Client> client(new Client(this)); |
| 173 | status_t err = client->initCheck(); |
| 174 | if (err == NO_ERROR) { |
| 175 | bclient = client; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | return bclient; |
| 178 | } |
| 179 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 180 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, |
| 181 | bool secure) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 182 | { |
| 183 | class DisplayToken : public BBinder { |
| 184 | sp<SurfaceFlinger> flinger; |
| 185 | virtual ~DisplayToken() { |
| 186 | // no more references, this display must be terminated |
| 187 | Mutex::Autolock _l(flinger->mStateLock); |
| 188 | flinger->mCurrentState.displays.removeItem(this); |
| 189 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 190 | } |
| 191 | public: |
| 192 | DisplayToken(const sp<SurfaceFlinger>& flinger) |
| 193 | : flinger(flinger) { |
| 194 | } |
| 195 | }; |
| 196 | |
| 197 | sp<BBinder> token = new DisplayToken(this); |
| 198 | |
| 199 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 200 | DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL); |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 201 | info.displayName = displayName; |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 202 | info.isSecure = secure; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 203 | mCurrentState.displays.add(token, info); |
| 204 | |
| 205 | return token; |
| 206 | } |
| 207 | |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 208 | void SurfaceFlinger::createBuiltinDisplayLocked(DisplayDevice::DisplayType type) { |
| 209 | ALOGW_IF(mBuiltinDisplays[type], |
| 210 | "Overwriting display token for display type %d", type); |
| 211 | mBuiltinDisplays[type] = new BBinder(); |
| 212 | DisplayDeviceState info(type); |
| 213 | // All non-virtual displays are currently considered secure. |
| 214 | info.isSecure = true; |
| 215 | mCurrentState.displays.add(mBuiltinDisplays[type], info); |
| 216 | } |
| 217 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 218 | sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) { |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 219 | if (uint32_t(id) >= DisplayDevice::NUM_DISPLAY_TYPES) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 220 | ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id); |
| 221 | return NULL; |
| 222 | } |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 223 | return mBuiltinDisplays[id]; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 226 | sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc() |
| 227 | { |
| 228 | sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc()); |
| 229 | return gba; |
| 230 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 231 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | void SurfaceFlinger::bootFinished() |
| 233 | { |
| 234 | const nsecs_t now = systemTime(); |
| 235 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 236 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 237 | mBootFinished = true; |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 238 | |
| 239 | // wait patiently for the window manager death |
| 240 | const String16 name("window"); |
| 241 | sp<IBinder> window(defaultServiceManager()->getService(name)); |
| 242 | if (window != 0) { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 243 | window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 247 | // formerly we would just kill the process, but we now ask it to exit so it |
| 248 | // can choose where to stop the animation. |
| 249 | property_set("service.bootanim.exit", "1"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 252 | void SurfaceFlinger::deleteTextureAsync(GLuint texture) { |
| 253 | class MessageDestroyGLTexture : public MessageBase { |
| 254 | GLuint texture; |
| 255 | public: |
| 256 | MessageDestroyGLTexture(GLuint texture) |
| 257 | : texture(texture) { |
| 258 | } |
| 259 | virtual bool handler() { |
| 260 | glDeleteTextures(1, &texture); |
| 261 | return true; |
| 262 | } |
| 263 | }; |
| 264 | postMessageAsync(new MessageDestroyGLTexture(texture)); |
| 265 | } |
| 266 | |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 267 | status_t SurfaceFlinger::selectConfigForAttribute( |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 268 | EGLDisplay dpy, |
| 269 | EGLint const* attrs, |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 270 | EGLint attribute, EGLint wanted, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 271 | EGLConfig* outConfig) |
| 272 | { |
| 273 | EGLConfig config = NULL; |
| 274 | EGLint numConfigs = -1, n=0; |
| 275 | eglGetConfigs(dpy, NULL, 0, &numConfigs); |
| 276 | EGLConfig* const configs = new EGLConfig[numConfigs]; |
| 277 | eglChooseConfig(dpy, attrs, configs, numConfigs, &n); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 278 | |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 279 | if (n) { |
| 280 | if (attribute != EGL_NONE) { |
| 281 | for (int i=0 ; i<n ; i++) { |
| 282 | EGLint value = 0; |
| 283 | eglGetConfigAttrib(dpy, configs[i], attribute, &value); |
| 284 | if (wanted == value) { |
| 285 | *outConfig = configs[i]; |
| 286 | delete [] configs; |
| 287 | return NO_ERROR; |
| 288 | } |
| 289 | } |
| 290 | } else { |
| 291 | // just pick the first one |
| 292 | *outConfig = configs[0]; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 293 | delete [] configs; |
| 294 | return NO_ERROR; |
| 295 | } |
| 296 | } |
| 297 | delete [] configs; |
| 298 | return NAME_NOT_FOUND; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 301 | class EGLAttributeVector { |
| 302 | struct Attribute; |
| 303 | class Adder; |
| 304 | friend class Adder; |
| 305 | KeyedVector<Attribute, EGLint> mList; |
| 306 | struct Attribute { |
| 307 | Attribute() {}; |
| 308 | Attribute(EGLint v) : v(v) { } |
| 309 | EGLint v; |
| 310 | bool operator < (const Attribute& other) const { |
| 311 | // this places EGL_NONE at the end |
| 312 | EGLint lhs(v); |
| 313 | EGLint rhs(other.v); |
| 314 | if (lhs == EGL_NONE) lhs = 0x7FFFFFFF; |
| 315 | if (rhs == EGL_NONE) rhs = 0x7FFFFFFF; |
| 316 | return lhs < rhs; |
| 317 | } |
| 318 | }; |
| 319 | class Adder { |
| 320 | friend class EGLAttributeVector; |
| 321 | EGLAttributeVector& v; |
| 322 | EGLint attribute; |
| 323 | Adder(EGLAttributeVector& v, EGLint attribute) |
| 324 | : v(v), attribute(attribute) { |
| 325 | } |
| 326 | public: |
| 327 | void operator = (EGLint value) { |
| 328 | if (attribute != EGL_NONE) { |
| 329 | v.mList.add(attribute, value); |
| 330 | } |
| 331 | } |
| 332 | operator EGLint () const { return v.mList[attribute]; } |
| 333 | }; |
| 334 | public: |
| 335 | EGLAttributeVector() { |
| 336 | mList.add(EGL_NONE, EGL_NONE); |
| 337 | } |
| 338 | void remove(EGLint attribute) { |
| 339 | if (attribute != EGL_NONE) { |
| 340 | mList.removeItem(attribute); |
| 341 | } |
| 342 | } |
| 343 | Adder operator [] (EGLint attribute) { |
| 344 | return Adder(*this, attribute); |
| 345 | } |
| 346 | EGLint operator [] (EGLint attribute) const { |
| 347 | return mList[attribute]; |
| 348 | } |
| 349 | // cast-operator to (EGLint const*) |
| 350 | operator EGLint const* () const { return &mList.keyAt(0).v; } |
| 351 | }; |
| 352 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 353 | EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) { |
| 354 | // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if |
| 355 | // it is to be used with WIFI displays |
| 356 | EGLConfig config; |
| 357 | EGLint dummy; |
| 358 | status_t err; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 359 | |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 360 | EGLAttributeVector attribs; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 361 | // TODO: enable ES2 |
| 362 | //attribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; |
| 363 | attribs[EGL_SURFACE_TYPE] = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 364 | attribs[EGL_RECORDABLE_ANDROID] = EGL_TRUE; |
| 365 | attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE; |
| 366 | attribs[EGL_RED_SIZE] = 8; |
| 367 | attribs[EGL_GREEN_SIZE] = 8; |
| 368 | attribs[EGL_BLUE_SIZE] = 8; |
| 369 | |
| 370 | err = selectConfigForAttribute(display, attribs, EGL_NONE, EGL_NONE, &config); |
| 371 | if (!err) |
| 372 | goto success; |
| 373 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 374 | // this didn't work, probably because we're on the emulator... |
| 375 | // try a simplified query |
| 376 | ALOGW("no suitable EGLConfig found, trying a simpler query"); |
| 377 | attribs.remove(EGL_RENDERABLE_TYPE); |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 378 | attribs.remove(EGL_FRAMEBUFFER_TARGET_ANDROID); |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 379 | attribs.remove(EGL_RECORDABLE_ANDROID); |
Mathias Agopian | 722b98f | 2012-09-25 18:24:31 -0700 | [diff] [blame] | 380 | attribs.remove(EGL_RED_SIZE); |
| 381 | attribs.remove(EGL_GREEN_SIZE); |
| 382 | attribs.remove(EGL_BLUE_SIZE); |
| 383 | err = selectConfigForAttribute(display, attribs, |
| 384 | EGL_NATIVE_VISUAL_ID, nativeVisualId, &config); |
Jesse Hall | f21cffa | 2012-09-19 21:00:49 -0700 | [diff] [blame] | 385 | if (!err) |
| 386 | goto success; |
| 387 | |
| 388 | // this EGL is too lame for Android |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 389 | LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up"); |
Jesse Hall | f21cffa | 2012-09-19 21:00:49 -0700 | [diff] [blame] | 390 | return 0; |
| 391 | |
| 392 | success: |
| 393 | if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy)) |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 394 | ALOGW_IF(dummy == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!"); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 395 | return config; |
| 396 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 398 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 399 | status_t SurfaceFlinger::readyToRun() |
| 400 | { |
| 401 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 402 | "Initializing graphics H/W..."); |
| 403 | |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 404 | Mutex::Autolock _l(mStateLock); |
| 405 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 406 | // initialize EGL for the default display |
Jesse Hall | 34a09ba | 2012-07-29 22:35:34 -0700 | [diff] [blame] | 407 | mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 408 | eglInitialize(mEGLDisplay, NULL, NULL); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 409 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 410 | // Initialize the H/W composer object. There may or may not be an |
| 411 | // actual hardware composer underneath. |
| 412 | mHwc = new HWComposer(this, |
| 413 | *static_cast<HWComposer::EventHandler *>(this)); |
| 414 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 415 | // initialize the config and context (can't fail) |
| 416 | mEGLConfig = selectEGLConfig(mEGLDisplay, mHwc->getVisualID()); |
| 417 | |
| 418 | // print some debugging info |
| 419 | EGLint r,g,b,a; |
| 420 | eglGetConfigAttrib(mEGLDisplay, mEGLConfig, EGL_RED_SIZE, &r); |
| 421 | eglGetConfigAttrib(mEGLDisplay, mEGLConfig, EGL_GREEN_SIZE, &g); |
| 422 | eglGetConfigAttrib(mEGLDisplay, mEGLConfig, EGL_BLUE_SIZE, &b); |
| 423 | eglGetConfigAttrib(mEGLDisplay, mEGLConfig, EGL_ALPHA_SIZE, &a); |
| 424 | ALOGI("EGL informations:"); |
| 425 | ALOGI("vendor : %s", eglQueryString(mEGLDisplay, EGL_VENDOR)); |
| 426 | ALOGI("version : %s", eglQueryString(mEGLDisplay, EGL_VERSION)); |
| 427 | ALOGI("extensions: %s", eglQueryString(mEGLDisplay, EGL_EXTENSIONS)); |
| 428 | ALOGI("Client API: %s", eglQueryString(mEGLDisplay, EGL_CLIENT_APIS)?:"Not Supported"); |
| 429 | ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, mEGLConfig); |
| 430 | |
| 431 | // get a RenderEngine for the given display / config (can't fail) |
| 432 | mRenderEngine = RenderEngine::create(mEGLDisplay, mEGLConfig); |
| 433 | |
| 434 | // retrieve the EGL context that was selected/created |
| 435 | mEGLContext = mRenderEngine->getEGLContext(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 436 | |
Mathias Agopian | ed98557 | 2013-03-22 00:24:39 -0700 | [diff] [blame] | 437 | // figure out which format we got |
| 438 | eglGetConfigAttrib(mEGLDisplay, mEGLConfig, |
| 439 | EGL_NATIVE_VISUAL_ID, &mEGLNativeVisualId); |
| 440 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 441 | LOG_ALWAYS_FATAL_IF(mEGLContext == EGL_NO_CONTEXT, |
| 442 | "couldn't create EGLContext"); |
| 443 | |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 444 | // initialize our non-virtual displays |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 445 | for (size_t i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) { |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 446 | DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i); |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 447 | // set-up the displays that are already connected |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 448 | if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) { |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 449 | // All non-virtual displays are currently considered secure. |
| 450 | bool isSecure = true; |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 451 | createBuiltinDisplayLocked(type); |
| 452 | wp<IBinder> token = mBuiltinDisplays[i]; |
| 453 | |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 454 | sp<DisplayDevice> hw = new DisplayDevice(this, |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 455 | type, allocateHwcDisplayId(type), isSecure, token, |
| 456 | new FramebufferSurface(*mHwc, i), |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 457 | mEGLConfig); |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 458 | if (i > DisplayDevice::DISPLAY_PRIMARY) { |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 459 | // FIXME: currently we don't get blank/unblank requests |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 460 | // for displays other than the main display, so we always |
| 461 | // assume a connected display is unblanked. |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 462 | ALOGD("marking display %d as acquired/unblanked", i); |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 463 | hw->acquireScreen(); |
| 464 | } |
| 465 | mDisplays.add(token, hw); |
| 466 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 467 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 468 | |
Mathias Agopian | 028508c | 2012-07-25 21:12:12 -0700 | [diff] [blame] | 469 | // start the EventThread |
| 470 | mEventThread = new EventThread(this); |
| 471 | mEventQueue.setEventThread(mEventThread); |
| 472 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 473 | // initialize our drawing state |
| 474 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 475 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 476 | // We're now ready to accept clients... |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 477 | mReadyToRunBarrier.open(); |
| 478 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 479 | // set initial conditions (e.g. unblank default device) |
| 480 | initializeDisplays(); |
| 481 | |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 482 | // start boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 483 | startBootAnim(); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 484 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | return NO_ERROR; |
| 486 | } |
| 487 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 488 | int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) { |
| 489 | return (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) ? |
| 490 | type : mHwc->allocateDisplayId(); |
| 491 | } |
| 492 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 493 | void SurfaceFlinger::startBootAnim() { |
| 494 | // start boot animation |
| 495 | property_set("service.bootanim.exit", "0"); |
| 496 | property_set("ctl.start", "bootanim"); |
| 497 | } |
| 498 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 499 | size_t SurfaceFlinger::getMaxTextureSize() const { |
| 500 | return mRenderEngine->getMaxTextureSize(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 503 | size_t SurfaceFlinger::getMaxViewportDims() const { |
| 504 | return mRenderEngine->getMaxViewportDims(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 505 | } |
| 506 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 508 | |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 509 | bool SurfaceFlinger::authenticateSurfaceTexture( |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 510 | const sp<IGraphicBufferProducer>& bufferProducer) const { |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 511 | Mutex::Autolock _l(mStateLock); |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 512 | sp<IBinder> surfaceTextureBinder(bufferProducer->asBinder()); |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 513 | return mGraphicBufferProducerList.indexOf(surfaceTextureBinder) >= 0; |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 516 | status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) { |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 517 | int32_t type = NAME_NOT_FOUND; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 518 | for (int i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) { |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 519 | if (display == mBuiltinDisplays[i]) { |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 520 | type = i; |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | if (type < 0) { |
| 526 | return type; |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 527 | } |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 528 | |
| 529 | const HWComposer& hwc(getHwComposer()); |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 530 | float xdpi = hwc.getDpiX(type); |
| 531 | float ydpi = hwc.getDpiY(type); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 532 | |
| 533 | // TODO: Not sure if display density should handled by SF any longer |
| 534 | class Density { |
| 535 | static int getDensityFromProperty(char const* propName) { |
| 536 | char property[PROPERTY_VALUE_MAX]; |
| 537 | int density = 0; |
| 538 | if (property_get(propName, property, NULL) > 0) { |
| 539 | density = atoi(property); |
| 540 | } |
| 541 | return density; |
| 542 | } |
| 543 | public: |
| 544 | static int getEmuDensity() { |
| 545 | return getDensityFromProperty("qemu.sf.lcd_density"); } |
| 546 | static int getBuildDensity() { |
| 547 | return getDensityFromProperty("ro.sf.lcd_density"); } |
| 548 | }; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 549 | |
| 550 | if (type == DisplayDevice::DISPLAY_PRIMARY) { |
| 551 | // The density of the device is provided by a build property |
| 552 | float density = Density::getBuildDensity() / 160.0f; |
| 553 | if (density == 0) { |
| 554 | // the build doesn't provide a density -- this is wrong! |
| 555 | // use xdpi instead |
| 556 | ALOGE("ro.sf.lcd_density must be defined as a build property"); |
| 557 | density = xdpi / 160.0f; |
| 558 | } |
| 559 | if (Density::getEmuDensity()) { |
| 560 | // if "qemu.sf.lcd_density" is specified, it overrides everything |
| 561 | xdpi = ydpi = density = Density::getEmuDensity(); |
| 562 | density /= 160.0f; |
| 563 | } |
| 564 | info->density = density; |
| 565 | |
| 566 | // TODO: this needs to go away (currently needed only by webkit) |
| 567 | sp<const DisplayDevice> hw(getDefaultDisplayDevice()); |
| 568 | info->orientation = hw->getOrientation(); |
| 569 | getPixelFormatInfo(hw->getFormat(), &info->pixelFormatInfo); |
| 570 | } else { |
| 571 | // TODO: where should this value come from? |
| 572 | static const int TV_DENSITY = 213; |
| 573 | info->density = TV_DENSITY / 160.0f; |
| 574 | info->orientation = 0; |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 577 | info->w = hwc.getWidth(type); |
| 578 | info->h = hwc.getHeight(type); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 579 | info->xdpi = xdpi; |
| 580 | info->ydpi = ydpi; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 581 | info->fps = float(1e9 / hwc.getRefreshPeriod(type)); |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 582 | |
| 583 | // All non-virtual displays are currently considered secure. |
| 584 | info->secure = true; |
| 585 | |
Mathias Agopian | 888c822 | 2012-08-04 21:10:38 -0700 | [diff] [blame] | 586 | return NO_ERROR; |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 589 | // ---------------------------------------------------------------------------- |
| 590 | |
| 591 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() { |
Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 592 | return mEventThread->createEventConnection(); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 593 | } |
| 594 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 596 | |
| 597 | void SurfaceFlinger::waitForEvent() { |
| 598 | mEventQueue.waitMessage(); |
| 599 | } |
| 600 | |
| 601 | void SurfaceFlinger::signalTransaction() { |
| 602 | mEventQueue.invalidate(); |
| 603 | } |
| 604 | |
| 605 | void SurfaceFlinger::signalLayerUpdate() { |
| 606 | mEventQueue.invalidate(); |
| 607 | } |
| 608 | |
| 609 | void SurfaceFlinger::signalRefresh() { |
| 610 | mEventQueue.refresh(); |
| 611 | } |
| 612 | |
| 613 | status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg, |
| 614 | nsecs_t reltime, uint32_t flags) { |
| 615 | return mEventQueue.postMessage(msg, reltime); |
| 616 | } |
| 617 | |
| 618 | status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg, |
| 619 | nsecs_t reltime, uint32_t flags) { |
| 620 | status_t res = mEventQueue.postMessage(msg, reltime); |
| 621 | if (res == NO_ERROR) { |
| 622 | msg->wait(); |
| 623 | } |
| 624 | return res; |
| 625 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 627 | bool SurfaceFlinger::threadLoop() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | waitForEvent(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | return true; |
| 630 | } |
| 631 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 632 | void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) { |
Andy McFadden | 43601a2 | 2012-09-11 15:15:13 -0700 | [diff] [blame] | 633 | if (mEventThread == NULL) { |
| 634 | // This is a temporary workaround for b/7145521. A non-null pointer |
| 635 | // does not mean EventThread has finished initializing, so this |
| 636 | // is not a correct fix. |
| 637 | ALOGW("WARNING: EventThread not started, ignoring vsync"); |
| 638 | return; |
| 639 | } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 640 | if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) { |
| 641 | // we should only receive DisplayDevice::DisplayType from the vsync callback |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 642 | mEventThread->onVSyncReceived(type, timestamp); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | void SurfaceFlinger::onHotplugReceived(int type, bool connected) { |
| 647 | if (mEventThread == NULL) { |
| 648 | // This is a temporary workaround for b/7145521. A non-null pointer |
| 649 | // does not mean EventThread has finished initializing, so this |
| 650 | // is not a correct fix. |
| 651 | ALOGW("WARNING: EventThread not started, ignoring hotplug"); |
| 652 | return; |
| 653 | } |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 654 | |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 655 | if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 656 | Mutex::Autolock _l(mStateLock); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 657 | if (connected) { |
| 658 | createBuiltinDisplayLocked((DisplayDevice::DisplayType)type); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 659 | } else { |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 660 | mCurrentState.displays.removeItem(mBuiltinDisplays[type]); |
| 661 | mBuiltinDisplays[type].clear(); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 662 | } |
| 663 | setTransactionFlags(eDisplayTransactionNeeded); |
| 664 | |
Andy McFadden | 9e9689c | 2012-10-10 18:17:51 -0700 | [diff] [blame] | 665 | // Defer EventThread notification until SF has updated mDisplays. |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 666 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Mathias Agopian | 81cd5d3 | 2012-10-04 02:34:38 -0700 | [diff] [blame] | 669 | void SurfaceFlinger::eventControl(int disp, int event, int enabled) { |
| 670 | getHwComposer().eventControl(disp, event, enabled); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 673 | void SurfaceFlinger::onMessageReceived(int32_t what) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 674 | ATRACE_CALL(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 675 | switch (what) { |
Mathias Agopian | 9eb1f05 | 2013-04-10 16:27:17 -0700 | [diff] [blame] | 676 | case MessageQueue::TRANSACTION: |
| 677 | handleMessageTransaction(); |
| 678 | break; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 679 | case MessageQueue::INVALIDATE: |
| 680 | handleMessageTransaction(); |
| 681 | handleMessageInvalidate(); |
| 682 | signalRefresh(); |
| 683 | break; |
| 684 | case MessageQueue::REFRESH: |
| 685 | handleMessageRefresh(); |
| 686 | break; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 690 | void SurfaceFlinger::handleMessageTransaction() { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 691 | uint32_t transactionFlags = peekTransactionFlags(eTransactionMask); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 692 | if (transactionFlags) { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 693 | handleTransaction(transactionFlags); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | void SurfaceFlinger::handleMessageInvalidate() { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 698 | ATRACE_CALL(); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 699 | handlePageFlip(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void SurfaceFlinger::handleMessageRefresh() { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 703 | ATRACE_CALL(); |
| 704 | preComposition(); |
| 705 | rebuildLayerStacks(); |
| 706 | setUpHWComposer(); |
| 707 | doDebugFlashRegions(); |
| 708 | doComposition(); |
| 709 | postComposition(); |
| 710 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 711 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 712 | void SurfaceFlinger::doDebugFlashRegions() |
| 713 | { |
| 714 | // is debugging enabled |
| 715 | if (CC_LIKELY(!mDebugRegion)) |
| 716 | return; |
| 717 | |
| 718 | const bool repaintEverything = mRepaintEverything; |
| 719 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
| 720 | const sp<DisplayDevice>& hw(mDisplays[dpy]); |
| 721 | if (hw->canDraw()) { |
| 722 | // transform the dirty region into this screen's coordinate space |
| 723 | const Region dirtyRegion(hw->getDirtyRegion(repaintEverything)); |
| 724 | if (!dirtyRegion.isEmpty()) { |
| 725 | // redraw the whole screen |
| 726 | doComposeSurfaces(hw, Region(hw->bounds())); |
| 727 | |
| 728 | // and draw the dirty region |
| 729 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 730 | glDisable(GL_TEXTURE_2D); |
| 731 | glDisable(GL_BLEND); |
| 732 | glColor4f(1, 0, 1, 1); |
| 733 | const int32_t height = hw->getHeight(); |
| 734 | Region::const_iterator it = dirtyRegion.begin(); |
| 735 | Region::const_iterator const end = dirtyRegion.end(); |
| 736 | while (it != end) { |
| 737 | const Rect& r = *it++; |
| 738 | GLfloat vertices[][2] = { |
Andy McFadden | 8f06a8c | 2013-01-11 10:24:34 -0800 | [diff] [blame] | 739 | { (GLfloat) r.left, (GLfloat) (height - r.top) }, |
| 740 | { (GLfloat) r.left, (GLfloat) (height - r.bottom) }, |
| 741 | { (GLfloat) r.right, (GLfloat) (height - r.bottom) }, |
| 742 | { (GLfloat) r.right, (GLfloat) (height - r.top) } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 743 | }; |
| 744 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
| 745 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 746 | } |
| 747 | hw->compositionComplete(); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 748 | hw->swapBuffers(getHwComposer()); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | postFramebuffer(); |
| 754 | |
| 755 | if (mDebugRegion > 1) { |
| 756 | usleep(mDebugRegion * 1000); |
| 757 | } |
Mathias Agopian | bb53b0e | 2012-09-24 21:27:29 -0700 | [diff] [blame] | 758 | |
| 759 | HWComposer& hwc(getHwComposer()); |
| 760 | if (hwc.initCheck() == NO_ERROR) { |
| 761 | status_t err = hwc.prepare(); |
| 762 | ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err)); |
| 763 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | void SurfaceFlinger::preComposition() |
| 767 | { |
| 768 | bool needExtraInvalidate = false; |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 769 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
| 770 | const size_t count = layers.size(); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 771 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 772 | if (layers[i]->onPreComposition()) { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 773 | needExtraInvalidate = true; |
| 774 | } |
| 775 | } |
| 776 | if (needExtraInvalidate) { |
| 777 | signalLayerUpdate(); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | void SurfaceFlinger::postComposition() |
| 782 | { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 783 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
| 784 | const size_t count = layers.size(); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 785 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 786 | layers[i]->onPostComposition(); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 787 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 788 | |
| 789 | if (mAnimCompositionPending) { |
| 790 | mAnimCompositionPending = false; |
| 791 | |
| 792 | const HWComposer& hwc = getHwComposer(); |
| 793 | sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY); |
Jesse Hall | a9a1b00 | 2013-02-27 16:39:25 -0800 | [diff] [blame] | 794 | if (presentFence->isValid()) { |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 795 | mAnimFrameTracker.setActualPresentFence(presentFence); |
| 796 | } else { |
| 797 | // The HWC doesn't support present fences, so use the refresh |
| 798 | // timestamp instead. |
| 799 | nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY); |
| 800 | mAnimFrameTracker.setActualPresentTime(presentTime); |
| 801 | } |
| 802 | mAnimFrameTracker.advanceFrame(); |
| 803 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | void SurfaceFlinger::rebuildLayerStacks() { |
| 807 | // rebuild the visible layer list per screen |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 808 | if (CC_UNLIKELY(mVisibleRegionsDirty)) { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 809 | ATRACE_CALL(); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 810 | mVisibleRegionsDirty = false; |
| 811 | invalidateHwcGeometry(); |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 812 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 813 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 814 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 815 | Region opaqueRegion; |
| 816 | Region dirtyRegion; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 817 | Vector< sp<Layer> > layersSortedByZ; |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 818 | const sp<DisplayDevice>& hw(mDisplays[dpy]); |
Mathias Agopian | 7e7ed7f | 2012-08-28 14:20:00 -0700 | [diff] [blame] | 819 | const Transform& tr(hw->getTransform()); |
| 820 | const Rect bounds(hw->getBounds()); |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 821 | if (hw->canDraw()) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 822 | SurfaceFlinger::computeVisibleRegions(layers, |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 823 | hw->getLayerStack(), dirtyRegion, opaqueRegion); |
Mathias Agopian | 7e7ed7f | 2012-08-28 14:20:00 -0700 | [diff] [blame] | 824 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 825 | const size_t count = layers.size(); |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 826 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 827 | const sp<Layer>& layer(layers[i]); |
| 828 | const Layer::State& s(layer->getDrawingState()); |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 829 | if (s.layerStack == hw->getLayerStack()) { |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 830 | Region drawRegion(tr.transform( |
| 831 | layer->visibleNonTransparentRegion)); |
| 832 | drawRegion.andSelf(bounds); |
| 833 | if (!drawRegion.isEmpty()) { |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 834 | layersSortedByZ.add(layer); |
| 835 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 836 | } |
| 837 | } |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 838 | } |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 839 | hw->setVisibleLayersSortedByZ(layersSortedByZ); |
Mathias Agopian | 7e7ed7f | 2012-08-28 14:20:00 -0700 | [diff] [blame] | 840 | hw->undefinedRegion.set(bounds); |
| 841 | hw->undefinedRegion.subtractSelf(tr.transform(opaqueRegion)); |
| 842 | hw->dirtyRegion.orSelf(dirtyRegion); |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 843 | } |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 844 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 845 | } |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 846 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 847 | void SurfaceFlinger::setUpHWComposer() { |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 848 | HWComposer& hwc(getHwComposer()); |
| 849 | if (hwc.initCheck() == NO_ERROR) { |
| 850 | // build the h/w work list |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 851 | if (CC_UNLIKELY(mHwWorkListDirty)) { |
| 852 | mHwWorkListDirty = false; |
| 853 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
| 854 | sp<const DisplayDevice> hw(mDisplays[dpy]); |
| 855 | const int32_t id = hw->getHwcDisplayId(); |
| 856 | if (id >= 0) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 857 | const Vector< sp<Layer> >& currentLayers( |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 858 | hw->getVisibleLayersSortedByZ()); |
| 859 | const size_t count = currentLayers.size(); |
| 860 | if (hwc.createWorkList(id, count) == NO_ERROR) { |
| 861 | HWComposer::LayerListIterator cur = hwc.begin(id); |
| 862 | const HWComposer::LayerListIterator end = hwc.end(id); |
| 863 | for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 864 | const sp<Layer>& layer(currentLayers[i]); |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 865 | layer->setGeometry(hw, *cur); |
| 866 | if (mDebugDisableHWC || mDebugRegion) { |
| 867 | cur->setSkip(true); |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | // set the per-frame data |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 876 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 877 | sp<const DisplayDevice> hw(mDisplays[dpy]); |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 878 | const int32_t id = hw->getHwcDisplayId(); |
| 879 | if (id >= 0) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 880 | const Vector< sp<Layer> >& currentLayers( |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 881 | hw->getVisibleLayersSortedByZ()); |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 882 | const size_t count = currentLayers.size(); |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 883 | HWComposer::LayerListIterator cur = hwc.begin(id); |
| 884 | const HWComposer::LayerListIterator end = hwc.end(id); |
| 885 | for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) { |
| 886 | /* |
| 887 | * update the per-frame h/w composer data for each layer |
| 888 | * and build the transparent region of the FB |
| 889 | */ |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 890 | const sp<Layer>& layer(currentLayers[i]); |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 891 | layer->setPerFrameData(hw, *cur); |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 892 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 893 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 894 | } |
Jamie Gennis | a4310c8 | 2012-09-25 20:26:00 -0700 | [diff] [blame] | 895 | |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 896 | status_t err = hwc.prepare(); |
| 897 | ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err)); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 898 | |
| 899 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
| 900 | sp<const DisplayDevice> hw(mDisplays[dpy]); |
| 901 | hw->prepareFrame(hwc); |
| 902 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 903 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 904 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 905 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 906 | void SurfaceFlinger::doComposition() { |
| 907 | ATRACE_CALL(); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 908 | const bool repaintEverything = android_atomic_and(0, &mRepaintEverything); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 909 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 910 | const sp<DisplayDevice>& hw(mDisplays[dpy]); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 911 | if (hw->canDraw()) { |
| 912 | // transform the dirty region into this screen's coordinate space |
| 913 | const Region dirtyRegion(hw->getDirtyRegion(repaintEverything)); |
Mathias Agopian | 02b9510 | 2012-11-05 17:50:57 -0800 | [diff] [blame] | 914 | |
| 915 | // repaint the framebuffer (if needed) |
| 916 | doDisplayComposition(hw, dirtyRegion); |
| 917 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 918 | hw->dirtyRegion.clear(); |
| 919 | hw->flip(hw->swapRegion); |
| 920 | hw->swapRegion.clear(); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 921 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 922 | // inform the h/w that we're done compositing |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 923 | hw->compositionComplete(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 924 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 925 | postFramebuffer(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 926 | } |
| 927 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | void SurfaceFlinger::postFramebuffer() |
| 929 | { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 930 | ATRACE_CALL(); |
Mathias Agopian | b048cef | 2012-02-04 15:44:04 -0800 | [diff] [blame] | 931 | |
Mathias Agopian | a44b041 | 2011-10-16 18:46:35 -0700 | [diff] [blame] | 932 | const nsecs_t now = systemTime(); |
| 933 | mDebugInSwapBuffers = now; |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 934 | |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 935 | HWComposer& hwc(getHwComposer()); |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 936 | if (hwc.initCheck() == NO_ERROR) { |
Mathias Agopian | 2a23184 | 2012-09-24 18:12:35 -0700 | [diff] [blame] | 937 | if (!hwc.supportsFramebufferTarget()) { |
| 938 | // EGL spec says: |
| 939 | // "surface must be bound to the calling thread's current context, |
| 940 | // for the current rendering API." |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 941 | getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext); |
Mathias Agopian | 2a23184 | 2012-09-24 18:12:35 -0700 | [diff] [blame] | 942 | } |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 943 | hwc.commit(); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 946 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 947 | sp<const DisplayDevice> hw(mDisplays[dpy]); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 948 | const Vector< sp<Layer> >& currentLayers(hw->getVisibleLayersSortedByZ()); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 949 | hw->onSwapBuffersCompleted(hwc); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 950 | const size_t count = currentLayers.size(); |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 951 | int32_t id = hw->getHwcDisplayId(); |
| 952 | if (id >=0 && hwc.initCheck() == NO_ERROR) { |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 953 | HWComposer::LayerListIterator cur = hwc.begin(id); |
| 954 | const HWComposer::LayerListIterator end = hwc.end(id); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 955 | for (size_t i = 0; cur != end && i < count; ++i, ++cur) { |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 956 | currentLayers[i]->onLayerDisplayed(hw, &*cur); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 957 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 958 | } else { |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 959 | for (size_t i = 0; i < count; i++) { |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 960 | currentLayers[i]->onLayerDisplayed(hw, NULL); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 961 | } |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 962 | } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Mathias Agopian | a44b041 | 2011-10-16 18:46:35 -0700 | [diff] [blame] | 965 | mLastSwapBufferTime = systemTime() - now; |
| 966 | mDebugInSwapBuffers = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 969 | void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 971 | ATRACE_CALL(); |
| 972 | |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 973 | // here we keep a copy of the drawing state (that is the state that's |
| 974 | // going to be overwritten by handleTransactionLocked()) outside of |
| 975 | // mStateLock so that the side-effects of the State assignment |
| 976 | // don't happen with mStateLock held (which can cause deadlocks). |
| 977 | State drawingState(mDrawingState); |
| 978 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 979 | Mutex::Autolock _l(mStateLock); |
| 980 | const nsecs_t now = systemTime(); |
| 981 | mDebugInTransaction = now; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 983 | // Here we're guaranteed that some transaction flags are set |
| 984 | // so we can call handleTransactionLocked() unconditionally. |
| 985 | // We call getTransactionFlags(), which will also clear the flags, |
| 986 | // with mStateLock held to guarantee that mCurrentState won't change |
| 987 | // until the transaction is committed. |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 988 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 989 | transactionFlags = getTransactionFlags(eTransactionMask); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 990 | handleTransactionLocked(transactionFlags); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 991 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 992 | mLastTransactionTime = systemTime() - now; |
| 993 | mDebugInTransaction = 0; |
| 994 | invalidateHwcGeometry(); |
| 995 | // here the transaction has been committed |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 998 | void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 999 | { |
| 1000 | const LayerVector& currentLayers(mCurrentState.layersSortedByZ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | const size_t count = currentLayers.size(); |
| 1002 | |
| 1003 | /* |
| 1004 | * Traversal of the children |
| 1005 | * (perform the transaction for each of them if needed) |
| 1006 | */ |
| 1007 | |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1008 | if (transactionFlags & eTraversalNeeded) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1010 | const sp<Layer>& layer(currentLayers[i]); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); |
| 1012 | if (!trFlags) continue; |
| 1013 | |
| 1014 | const uint32_t flags = layer->doTransaction(0); |
| 1015 | if (flags & Layer::eVisibleRegion) |
| 1016 | mVisibleRegionsDirty = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | /* |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1021 | * Perform display own transactions if needed |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | */ |
| 1023 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1024 | if (transactionFlags & eDisplayTransactionNeeded) { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1025 | // here we take advantage of Vector's copy-on-write semantics to |
| 1026 | // improve performance by skipping the transaction entirely when |
| 1027 | // know that the lists are identical |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1028 | const KeyedVector< wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 1029 | const KeyedVector< wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1030 | if (!curr.isIdenticalTo(draw)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | mVisibleRegionsDirty = true; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1032 | const size_t cc = curr.size(); |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1033 | size_t dc = draw.size(); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1034 | |
| 1035 | // find the displays that were removed |
| 1036 | // (ie: in drawing state but not in current state) |
| 1037 | // also handle displays that changed |
| 1038 | // (ie: displays that are in both lists) |
| 1039 | for (size_t i=0 ; i<dc ; i++) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1040 | const ssize_t j = curr.indexOfKey(draw.keyAt(i)); |
| 1041 | if (j < 0) { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1042 | // in drawing state but not in current state |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 1043 | if (!draw[i].isMainDisplay()) { |
Andy McFadden | 27ec573 | 2012-10-02 19:04:45 -0700 | [diff] [blame] | 1044 | // Call makeCurrent() on the primary display so we can |
| 1045 | // be sure that nothing associated with this display |
| 1046 | // is current. |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1047 | const sp<const DisplayDevice> defaultDisplay(getDefaultDisplayDevice()); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1048 | defaultDisplay->makeCurrent(mEGLDisplay, mEGLContext); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1049 | sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i))); |
| 1050 | if (hw != NULL) |
| 1051 | hw->disconnect(getHwComposer()); |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 1052 | if (draw[i].type < DisplayDevice::NUM_DISPLAY_TYPES) |
| 1053 | mEventThread->onHotplugReceived(draw[i].type, false); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1054 | mDisplays.removeItem(draw.keyAt(i)); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1055 | } else { |
| 1056 | ALOGW("trying to remove the main display"); |
| 1057 | } |
| 1058 | } else { |
| 1059 | // this display is in both lists. see if something changed. |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1060 | const DisplayDeviceState& state(curr[j]); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 1061 | const wp<IBinder>& display(curr.keyAt(j)); |
Mathias Agopian | 111b2d8 | 2012-08-16 20:52:17 -0700 | [diff] [blame] | 1062 | if (state.surface->asBinder() != draw[i].surface->asBinder()) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1063 | // changing the surface is like destroying and |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1064 | // recreating the DisplayDevice, so we just remove it |
| 1065 | // from the drawing state, so that it get re-added |
| 1066 | // below. |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1067 | sp<DisplayDevice> hw(getDisplayDevice(display)); |
| 1068 | if (hw != NULL) |
| 1069 | hw->disconnect(getHwComposer()); |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1070 | mDisplays.removeItem(display); |
| 1071 | mDrawingState.displays.removeItemsAt(i); |
| 1072 | dc--; i--; |
| 1073 | // at this point we must loop to the next item |
| 1074 | continue; |
| 1075 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1076 | |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 1077 | const sp<DisplayDevice> disp(getDisplayDevice(display)); |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1078 | if (disp != NULL) { |
| 1079 | if (state.layerStack != draw[i].layerStack) { |
| 1080 | disp->setLayerStack(state.layerStack); |
| 1081 | } |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 1082 | if ((state.orientation != draw[i].orientation) |
| 1083 | || (state.viewport != draw[i].viewport) |
| 1084 | || (state.frame != draw[i].frame)) |
| 1085 | { |
| 1086 | disp->setProjection(state.orientation, |
Jeff Brown | 4fb3999 | 2012-09-07 12:55:10 -0700 | [diff] [blame] | 1087 | state.viewport, state.frame); |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1088 | } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | // find displays that were added |
| 1094 | // (ie: in current state but not in drawing state) |
| 1095 | for (size_t i=0 ; i<cc ; i++) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1096 | if (draw.indexOfKey(curr.keyAt(i)) < 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1097 | const DisplayDeviceState& state(curr[i]); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1098 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1099 | sp<DisplaySurface> dispSurface; |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1100 | int32_t hwcDisplayId = -1; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1101 | if (state.isVirtualDisplay()) { |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1102 | // Virtual displays without a surface are dormant: |
| 1103 | // they have external state (layer stack, projection, |
| 1104 | // etc.) but no internal state (i.e. a DisplayDevice). |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1105 | if (state.surface != NULL) { |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1106 | hwcDisplayId = allocateHwcDisplayId(state.type); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1107 | dispSurface = new VirtualDisplaySurface( |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 1108 | *mHwc, hwcDisplayId, state.surface, |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1109 | state.displayName); |
| 1110 | } |
| 1111 | } else { |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1112 | ALOGE_IF(state.surface!=NULL, |
| 1113 | "adding a supported display, but rendering " |
| 1114 | "surface is provided (%p), ignoring it", |
| 1115 | state.surface.get()); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 1116 | hwcDisplayId = allocateHwcDisplayId(state.type); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1117 | // for supported (by hwc) displays we provide our |
| 1118 | // own rendering surface |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1119 | dispSurface = new FramebufferSurface(*mHwc, state.type); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | const wp<IBinder>& display(curr.keyAt(i)); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1123 | if (dispSurface != NULL) { |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1124 | sp<DisplayDevice> hw = new DisplayDevice(this, |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 1125 | state.type, hwcDisplayId, state.isSecure, |
| 1126 | display, dispSurface, mEGLConfig); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1127 | hw->setLayerStack(state.layerStack); |
| 1128 | hw->setProjection(state.orientation, |
Jeff Brown | 4fb3999 | 2012-09-07 12:55:10 -0700 | [diff] [blame] | 1129 | state.viewport, state.frame); |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 1130 | hw->setDisplayName(state.displayName); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1131 | mDisplays.add(display, hw); |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 1132 | if (state.isVirtualDisplay()) { |
| 1133 | if (hwcDisplayId >= 0) { |
| 1134 | mHwc->setVirtualDisplayProperties(hwcDisplayId, |
| 1135 | hw->getWidth(), hw->getHeight(), |
| 1136 | hw->getFormat()); |
| 1137 | } |
| 1138 | } else { |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 1139 | mEventThread->onHotplugReceived(state.type, true); |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 1140 | } |
Mathias Agopian | 93997a8 | 2012-08-29 17:30:36 -0700 | [diff] [blame] | 1141 | } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1142 | } |
| 1143 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | } |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1145 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 1147 | if (transactionFlags & (eTraversalNeeded|eDisplayTransactionNeeded)) { |
| 1148 | // The transform hint might have changed for some layers |
| 1149 | // (either because a display has changed, or because a layer |
| 1150 | // as changed). |
| 1151 | // |
| 1152 | // Walk through all the layers in currentLayers, |
| 1153 | // and update their transform hint. |
| 1154 | // |
| 1155 | // If a layer is visible only on a single display, then that |
| 1156 | // display is used to calculate the hint, otherwise we use the |
| 1157 | // default display. |
| 1158 | // |
| 1159 | // NOTE: we do this here, rather than in rebuildLayerStacks() so that |
| 1160 | // the hint is set before we acquire a buffer from the surface texture. |
| 1161 | // |
| 1162 | // NOTE: layer transactions have taken place already, so we use their |
| 1163 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 1164 | // happened yet, so we must use the current state layer list |
| 1165 | // (soon to become the drawing state list). |
| 1166 | // |
| 1167 | sp<const DisplayDevice> disp; |
| 1168 | uint32_t currentlayerStack = 0; |
| 1169 | for (size_t i=0; i<count; i++) { |
| 1170 | // NOTE: we rely on the fact that layers are sorted by |
| 1171 | // layerStack first (so we don't have to traverse the list |
| 1172 | // of displays for every layer). |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1173 | const sp<Layer>& layer(currentLayers[i]); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1174 | uint32_t layerStack = layer->getDrawingState().layerStack; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 1175 | if (i==0 || currentlayerStack != layerStack) { |
| 1176 | currentlayerStack = layerStack; |
| 1177 | // figure out if this layerstack is mirrored |
| 1178 | // (more than one display) if so, pick the default display, |
| 1179 | // if not, pick the only display it's on. |
| 1180 | disp.clear(); |
| 1181 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
| 1182 | sp<const DisplayDevice> hw(mDisplays[dpy]); |
| 1183 | if (hw->getLayerStack() == currentlayerStack) { |
| 1184 | if (disp == NULL) { |
| 1185 | disp = hw; |
| 1186 | } else { |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 1187 | disp = NULL; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 1193 | if (disp == NULL) { |
| 1194 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 1195 | // redraw after transform hint changes. See bug 8508397. |
| 1196 | |
| 1197 | // could be null when this layer is using a layerStack |
| 1198 | // that is not visible on any display. Also can occur at |
| 1199 | // screen off/on times. |
| 1200 | disp = getDefaultDisplayDevice(); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 1201 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 1202 | layer->updateTransformHint(disp); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1207 | /* |
| 1208 | * Perform our own transaction if needed |
| 1209 | */ |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1210 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1211 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
| 1212 | if (currentLayers.size() > layers.size()) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1213 | // layers have been added |
| 1214 | mVisibleRegionsDirty = true; |
| 1215 | } |
| 1216 | |
| 1217 | // some layers might have been removed, so |
| 1218 | // we need to update the regions they're exposing. |
| 1219 | if (mLayersRemoved) { |
| 1220 | mLayersRemoved = false; |
| 1221 | mVisibleRegionsDirty = true; |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1222 | const size_t count = layers.size(); |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1223 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1224 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 1225 | if (currentLayers.indexOf(layer) < 0) { |
| 1226 | // this layer is not visible anymore |
| 1227 | // TODO: we could traverse the tree from front to back and |
| 1228 | // compute the actual visible region |
| 1229 | // TODO: we could cache the transformed region |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1230 | const Layer::State& s(layer->getDrawingState()); |
Mathias Agopian | 1501d54 | 2012-09-04 21:04:09 -0700 | [diff] [blame] | 1231 | Region visibleReg = s.transform.transform( |
| 1232 | Region(Rect(s.active.w, s.active.h))); |
| 1233 | invalidateLayerStack(s.layerStack, visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1234 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | commitTransaction(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | void SurfaceFlinger::commitTransaction() |
| 1242 | { |
| 1243 | if (!mLayersPendingRemoval.isEmpty()) { |
| 1244 | // Notify removed layers now that they can't be drawn from |
| 1245 | for (size_t i = 0; i < mLayersPendingRemoval.size(); i++) { |
| 1246 | mLayersPendingRemoval[i]->onRemoved(); |
| 1247 | } |
| 1248 | mLayersPendingRemoval.clear(); |
| 1249 | } |
| 1250 | |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 1251 | // If this transaction is part of a window animation then the next frame |
| 1252 | // we composite should be considered an animation as well. |
| 1253 | mAnimCompositionPending = mAnimTransactionPending; |
| 1254 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1255 | mDrawingState = mCurrentState; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1256 | mTransactionPending = false; |
| 1257 | mAnimTransactionPending = false; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1258 | mTransactionCV.broadcast(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | void SurfaceFlinger::computeVisibleRegions( |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1262 | const LayerVector& currentLayers, uint32_t layerStack, |
| 1263 | Region& outDirtyRegion, Region& outOpaqueRegion) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 1265 | ATRACE_CALL(); |
| 1266 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | Region aboveOpaqueLayers; |
| 1268 | Region aboveCoveredLayers; |
| 1269 | Region dirty; |
| 1270 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1271 | outDirtyRegion.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | |
| 1273 | size_t i = currentLayers.size(); |
| 1274 | while (i--) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1275 | const sp<Layer>& layer = currentLayers[i]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | |
| 1277 | // start with the whole surface at its current location |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1278 | const Layer::State& s(layer->getDrawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 1280 | // only consider the layers on the given layer stack |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1281 | if (s.layerStack != layerStack) |
| 1282 | continue; |
| 1283 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1284 | /* |
| 1285 | * opaqueRegion: area of a surface that is fully opaque. |
| 1286 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | Region opaqueRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1288 | |
| 1289 | /* |
| 1290 | * visibleRegion: area of a surface that is visible on screen |
| 1291 | * and not fully transparent. This is essentially the layer's |
| 1292 | * footprint minus the opaque regions above it. |
| 1293 | * Areas covered by a translucent surface are considered visible. |
| 1294 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | Region visibleRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1296 | |
| 1297 | /* |
| 1298 | * coveredRegion: area of a surface that is covered by all |
| 1299 | * visible regions above it (which includes the translucent areas). |
| 1300 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | Region coveredRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1302 | |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 1303 | /* |
| 1304 | * transparentRegion: area of a surface that is hinted to be completely |
| 1305 | * transparent. This is only used to tell when the layer has no visible |
| 1306 | * non-transparent regions and can be removed from the layer list. It |
| 1307 | * does not affect the visibleRegion of this layer or any layers |
| 1308 | * beneath it. The hint may not be correct if apps don't respect the |
| 1309 | * SurfaceView restrictions (which, sadly, some don't). |
| 1310 | */ |
| 1311 | Region transparentRegion; |
| 1312 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1313 | |
| 1314 | // handle hidden surfaces by setting the visible region to empty |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1315 | if (CC_LIKELY(layer->isVisible())) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1316 | const bool translucent = !layer->isOpaque(); |
Mathias Agopian | 5219a06 | 2013-02-26 16:37:53 -0800 | [diff] [blame] | 1317 | Rect bounds(s.transform.transform(layer->computeBounds())); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | visibleRegion.set(bounds); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1319 | if (!visibleRegion.isEmpty()) { |
| 1320 | // Remove the transparent area from the visible region |
| 1321 | if (translucent) { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1322 | const Transform tr(s.transform); |
| 1323 | if (tr.transformed()) { |
| 1324 | if (tr.preserveRects()) { |
| 1325 | // transform the transparent region |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 1326 | transparentRegion = tr.transform(s.activeTransparentRegion); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1327 | } else { |
| 1328 | // transformation too complex, can't do the |
| 1329 | // transparent region optimization. |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 1330 | transparentRegion.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1331 | } |
| 1332 | } else { |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 1333 | transparentRegion = s.activeTransparentRegion; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1334 | } |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1335 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1337 | // compute the opaque region |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1338 | const int32_t layerOrientation = s.transform.getOrientation(); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1339 | if (s.alpha==255 && !translucent && |
| 1340 | ((layerOrientation & Transform::ROT_INVALID) == false)) { |
| 1341 | // the opaque region is the layer's footprint |
| 1342 | opaqueRegion = visibleRegion; |
| 1343 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1347 | // Clip the covered region to the visible region |
| 1348 | coveredRegion = aboveCoveredLayers.intersect(visibleRegion); |
| 1349 | |
| 1350 | // Update aboveCoveredLayers for next (lower) layer |
| 1351 | aboveCoveredLayers.orSelf(visibleRegion); |
| 1352 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | // subtract the opaque region covered by the layers above us |
| 1354 | visibleRegion.subtractSelf(aboveOpaqueLayers); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | |
| 1356 | // compute this layer's dirty region |
| 1357 | if (layer->contentDirty) { |
| 1358 | // we need to invalidate the whole region |
| 1359 | dirty = visibleRegion; |
| 1360 | // as well, as the old visible region |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1361 | dirty.orSelf(layer->visibleRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | layer->contentDirty = false; |
| 1363 | } else { |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 1364 | /* compute the exposed region: |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1365 | * the exposed region consists of two components: |
| 1366 | * 1) what's VISIBLE now and was COVERED before |
| 1367 | * 2) what's EXPOSED now less what was EXPOSED before |
| 1368 | * |
| 1369 | * note that (1) is conservative, we start with the whole |
| 1370 | * visible region but only keep what used to be covered by |
| 1371 | * something -- which mean it may have been exposed. |
| 1372 | * |
| 1373 | * (2) handles areas that were not covered by anything but got |
| 1374 | * exposed because of a resize. |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 1375 | */ |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1376 | const Region newExposed = visibleRegion - coveredRegion; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1377 | const Region oldVisibleRegion = layer->visibleRegion; |
| 1378 | const Region oldCoveredRegion = layer->coveredRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1379 | const Region oldExposed = oldVisibleRegion - oldCoveredRegion; |
| 1380 | dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1381 | } |
| 1382 | dirty.subtractSelf(aboveOpaqueLayers); |
| 1383 | |
| 1384 | // accumulate to the screen dirty region |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1385 | outDirtyRegion.orSelf(dirty); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 1387 | // Update aboveOpaqueLayers for next (lower) layer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | aboveOpaqueLayers.orSelf(opaqueRegion); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1389 | |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 1390 | // Store the visible region in screen space |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | layer->setVisibleRegion(visibleRegion); |
| 1392 | layer->setCoveredRegion(coveredRegion); |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 1393 | layer->setVisibleNonTransparentRegion( |
| 1394 | visibleRegion.subtract(transparentRegion)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1397 | outOpaqueRegion = aboveOpaqueLayers; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1400 | void SurfaceFlinger::invalidateLayerStack(uint32_t layerStack, |
| 1401 | const Region& dirty) { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1402 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1403 | const sp<DisplayDevice>& hw(mDisplays[dpy]); |
| 1404 | if (hw->getLayerStack() == layerStack) { |
| 1405 | hw->dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1406 | } |
| 1407 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | void SurfaceFlinger::handlePageFlip() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1412 | Region dirtyRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1414 | bool visibleRegions = false; |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1415 | const LayerVector& layers(mDrawingState.layersSortedByZ); |
| 1416 | const size_t count = layers.size(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1417 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1418 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1419 | const Region dirty(layer->latchBuffer(visibleRegions)); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1420 | const Layer::State& s(layer->getDrawingState()); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1421 | invalidateLayerStack(s.layerStack, dirty); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1422 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 1423 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 1424 | mVisibleRegionsDirty |= visibleRegions; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Mathias Agopian | ad456f9 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 1427 | void SurfaceFlinger::invalidateHwcGeometry() |
| 1428 | { |
| 1429 | mHwWorkListDirty = true; |
| 1430 | } |
| 1431 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1432 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1433 | void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw, |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1434 | const Region& inDirtyRegion) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1436 | Region dirtyRegion(inDirtyRegion); |
| 1437 | |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 1438 | // compute the invalid region |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1439 | hw->swapRegion.orSelf(dirtyRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1441 | uint32_t flags = hw->getFlags(); |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 1442 | if (flags & DisplayDevice::SWAP_RECTANGLE) { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 1443 | // we can redraw only what's dirty, but since SWAP_RECTANGLE only |
| 1444 | // takes a rectangle, we must make sure to update that whole |
| 1445 | // rectangle in that case |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1446 | dirtyRegion.set(hw->swapRegion.bounds()); |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 1447 | } else { |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 1448 | if (flags & DisplayDevice::PARTIAL_UPDATES) { |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 1449 | // We need to redraw the rectangle that will be updated |
| 1450 | // (pushed to the framebuffer). |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 1451 | // This is needed because PARTIAL_UPDATES only takes one |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 1452 | // rectangle instead of a region (see DisplayDevice::flip()) |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1453 | dirtyRegion.set(hw->swapRegion.bounds()); |
Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 1454 | } else { |
| 1455 | // we need to redraw everything (the whole screen) |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1456 | dirtyRegion.set(hw->bounds()); |
| 1457 | hw->swapRegion = dirtyRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1461 | doComposeSurfaces(hw, dirtyRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 1463 | // update the swap region and clear the dirty region |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 1464 | hw->swapRegion.orSelf(dirtyRegion); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1465 | |
| 1466 | // swap buffers (presentation) |
| 1467 | hw->swapBuffers(getHwComposer()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1470 | void SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty) |
Mathias Agopian | f384cc3 | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 1471 | { |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1472 | const int32_t id = hw->getHwcDisplayId(); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 1473 | HWComposer& hwc(getHwComposer()); |
Mathias Agopian | 1e26087 | 2012-08-08 18:35:12 -0700 | [diff] [blame] | 1474 | HWComposer::LayerListIterator cur = hwc.begin(id); |
| 1475 | const HWComposer::LayerListIterator end = hwc.end(id); |
Mathias Agopian | cd20eb0 | 2011-09-22 20:57:04 -0700 | [diff] [blame] | 1476 | |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1477 | const bool hasGlesComposition = hwc.hasGlesComposition(id) || (cur==end); |
| 1478 | if (hasGlesComposition) { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1479 | if (!hw->makeCurrent(mEGLDisplay, mEGLContext)) { |
Michael Chock | c8c7109 | 2013-03-04 15:15:46 -0800 | [diff] [blame] | 1480 | ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s", |
| 1481 | hw->getDisplayName().string()); |
| 1482 | return; |
| 1483 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 1484 | |
| 1485 | // set the frame buffer |
| 1486 | glMatrixMode(GL_MODELVIEW); |
| 1487 | glLoadIdentity(); |
| 1488 | |
| 1489 | // Never touch the framebuffer if we don't have any framebuffer layers |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1490 | const bool hasHwcComposition = hwc.hasHwcComposition(id); |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 1491 | if (hasHwcComposition) { |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1492 | // when using overlays, we assume a fully transparent framebuffer |
| 1493 | // NOTE: we could reduce how much we need to clear, for instance |
| 1494 | // remove where there are opaque FB layers. however, on some |
| 1495 | // GPUs doing a "clean slate" glClear might be more efficient. |
| 1496 | // We'll revisit later if needed. |
| 1497 | glClearColor(0, 0, 0, 0); |
| 1498 | glClear(GL_COLOR_BUFFER_BIT); |
| 1499 | } else { |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 1500 | // we start with the whole screen area |
| 1501 | const Region bounds(hw->getBounds()); |
| 1502 | |
| 1503 | // we remove the scissor part |
| 1504 | // we're left with the letterbox region |
| 1505 | // (common case is that letterbox ends-up being empty) |
| 1506 | const Region letterbox(bounds.subtract(hw->getScissor())); |
| 1507 | |
| 1508 | // compute the area to clear |
| 1509 | Region region(hw->undefinedRegion.merge(letterbox)); |
| 1510 | |
| 1511 | // but limit it to the dirty region |
| 1512 | region.andSelf(dirty); |
| 1513 | |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1514 | // screen is already cleared here |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1515 | if (!region.isEmpty()) { |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1516 | // can happen with SurfaceView |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 1517 | drawWormhole(hw, region); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1518 | } |
Mathias Agopian | a2f4e56 | 2012-04-15 23:34:59 -0700 | [diff] [blame] | 1519 | } |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 1520 | |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 1521 | if (hw->getDisplayType() != DisplayDevice::DISPLAY_PRIMARY) { |
| 1522 | // just to be on the safe side, we don't set the |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 1523 | // scissor on the main display. It should never be needed |
| 1524 | // anyways (though in theory it could since the API allows it). |
| 1525 | const Rect& bounds(hw->getBounds()); |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 1526 | const Rect& scissor(hw->getScissor()); |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 1527 | if (scissor != bounds) { |
| 1528 | // scissor doesn't match the screen's dimensions, so we |
| 1529 | // need to clear everything outside of it and enable |
| 1530 | // the GL scissor so we don't draw anything where we shouldn't |
| 1531 | const GLint height = hw->getHeight(); |
| 1532 | glScissor(scissor.left, height - scissor.bottom, |
| 1533 | scissor.getWidth(), scissor.getHeight()); |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 1534 | // enable scissor for this frame |
| 1535 | glEnable(GL_SCISSOR_TEST); |
| 1536 | } |
| 1537 | } |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1538 | } |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 1539 | |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1540 | /* |
| 1541 | * and then, render the layers targeted at the framebuffer |
| 1542 | */ |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 1543 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1544 | const Vector< sp<Layer> >& layers(hw->getVisibleLayersSortedByZ()); |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1545 | const size_t count = layers.size(); |
| 1546 | const Transform& tr = hw->getTransform(); |
| 1547 | if (cur != end) { |
| 1548 | // we're using h/w composer |
| 1549 | for (size_t i=0 ; i<count && cur!=end ; ++i, ++cur) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1550 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1551 | const Region clip(dirty.intersect(tr.transform(layer->visibleRegion))); |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1552 | if (!clip.isEmpty()) { |
| 1553 | switch (cur->getCompositionType()) { |
| 1554 | case HWC_OVERLAY: { |
| 1555 | if ((cur->getHints() & HWC_HINT_CLEAR_FB) |
| 1556 | && i |
| 1557 | && layer->isOpaque() |
| 1558 | && hasGlesComposition) { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1559 | // never clear the very first layer since we're |
| 1560 | // guaranteed the FB is already cleared |
| 1561 | layer->clearWithOpenGL(hw, clip); |
| 1562 | } |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1563 | break; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1564 | } |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1565 | case HWC_FRAMEBUFFER: { |
| 1566 | layer->draw(hw, clip); |
| 1567 | break; |
| 1568 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1569 | case HWC_FRAMEBUFFER_TARGET: { |
| 1570 | // this should not happen as the iterator shouldn't |
| 1571 | // let us get there. |
| 1572 | ALOGW("HWC_FRAMEBUFFER_TARGET found in hwc list (index=%d)", i); |
| 1573 | break; |
| 1574 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1575 | } |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1576 | } |
| 1577 | layer->setAcquireFence(hw, *cur); |
| 1578 | } |
| 1579 | } else { |
| 1580 | // we're not using h/w composer |
| 1581 | for (size_t i=0 ; i<count ; ++i) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1582 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 1583 | const Region clip(dirty.intersect( |
| 1584 | tr.transform(layer->visibleRegion))); |
| 1585 | if (!clip.isEmpty()) { |
| 1586 | layer->draw(hw, clip); |
Jesse Hall | a6b32db | 2012-07-19 16:44:38 -0700 | [diff] [blame] | 1587 | } |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 1588 | } |
| 1589 | } |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 1590 | |
| 1591 | // disable scissor at the end of the frame |
| 1592 | glDisable(GL_SCISSOR_TEST); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 1595 | void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw, |
| 1596 | const Region& region) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | { |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 1598 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1599 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 1600 | glDisable(GL_BLEND); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 1601 | glColor4f(0,0,0,0); |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 1602 | |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 1603 | const int32_t height = hw->getHeight(); |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 1604 | Region::const_iterator it = region.begin(); |
| 1605 | Region::const_iterator const end = region.end(); |
| 1606 | while (it != end) { |
| 1607 | const Rect& r = *it++; |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 1608 | GLfloat vertices[][2] = { |
Andy McFadden | 8f06a8c | 2013-01-11 10:24:34 -0800 | [diff] [blame] | 1609 | { (GLfloat) r.left, (GLfloat) (height - r.top) }, |
| 1610 | { (GLfloat) r.left, (GLfloat) (height - r.bottom) }, |
| 1611 | { (GLfloat) r.right, (GLfloat) (height - r.bottom) }, |
| 1612 | { (GLfloat) r.right, (GLfloat) (height - r.top) } |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 1613 | }; |
| 1614 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 1615 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 1616 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | } |
| 1618 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 1619 | void SurfaceFlinger::addClientLayer(const sp<Client>& client, |
| 1620 | const sp<IBinder>& handle, |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1621 | const sp<IGraphicBufferProducer>& gbc, |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1622 | const sp<Layer>& lbc) |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1623 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1624 | // attach this layer to the client |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 1625 | client->attachLayer(handle, lbc); |
Mathias Agopian | 4f11374 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 1626 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1627 | // add this layer to the current state list |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 1628 | Mutex::Autolock _l(mStateLock); |
| 1629 | mCurrentState.layersSortedByZ.add(lbc); |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1630 | mGraphicBufferProducerList.add(gbc->asBinder()); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1633 | status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | { |
| 1635 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1636 | ssize_t index = mCurrentState.layersSortedByZ.remove(layer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | if (index >= 0) { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1638 | mLayersPendingRemoval.push(layer); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1639 | mLayersRemoved = true; |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1640 | setTransactionFlags(eTransactionNeeded); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | return NO_ERROR; |
| 1642 | } |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1643 | return status_t(index); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 1646 | uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags) |
| 1647 | { |
| 1648 | return android_atomic_release_load(&mTransactionFlags); |
| 1649 | } |
| 1650 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) |
| 1652 | { |
| 1653 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 1654 | } |
| 1655 | |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1656 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | { |
| 1658 | uint32_t old = android_atomic_or(flags, &mTransactionFlags); |
| 1659 | if ((old & flags)==0) { // wake the server up |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1660 | signalTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | } |
| 1662 | return old; |
| 1663 | } |
| 1664 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 1665 | void SurfaceFlinger::setTransactionState( |
| 1666 | const Vector<ComposerState>& state, |
| 1667 | const Vector<DisplayState>& displays, |
| 1668 | uint32_t flags) |
| 1669 | { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 1670 | ATRACE_CALL(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1671 | Mutex::Autolock _l(mStateLock); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 1672 | uint32_t transactionFlags = 0; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1673 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1674 | if (flags & eAnimation) { |
| 1675 | // For window updates that are part of an animation we must wait for |
| 1676 | // previous animation "frames" to be handled. |
| 1677 | while (mAnimTransactionPending) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 1678 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1679 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 1680 | // just in case something goes wrong in SF, return to the |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 1681 | // caller after a few seconds. |
| 1682 | ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out " |
| 1683 | "waiting for previous animation frame"); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1684 | mAnimTransactionPending = false; |
| 1685 | break; |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1690 | size_t count = displays.size(); |
| 1691 | for (size_t i=0 ; i<count ; i++) { |
| 1692 | const DisplayState& s(displays[i]); |
| 1693 | transactionFlags |= setDisplayStateLocked(s); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1696 | count = state.size(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1697 | for (size_t i=0 ; i<count ; i++) { |
| 1698 | const ComposerState& s(state[i]); |
Mathias Agopian | d17e3b5 | 2012-10-22 14:27:45 -0700 | [diff] [blame] | 1699 | // Here we need to check that the interface we're given is indeed |
| 1700 | // one of our own. A malicious client could give us a NULL |
| 1701 | // IInterface, or one of its own or even one of our own but a |
| 1702 | // different type. All these situations would cause us to crash. |
| 1703 | // |
| 1704 | // NOTE: it would be better to use RTTI as we could directly check |
| 1705 | // that we have a Client*. however, RTTI is disabled in Android. |
| 1706 | if (s.client != NULL) { |
| 1707 | sp<IBinder> binder = s.client->asBinder(); |
| 1708 | if (binder != NULL) { |
| 1709 | String16 desc(binder->getInterfaceDescriptor()); |
| 1710 | if (desc == ISurfaceComposerClient::descriptor) { |
| 1711 | sp<Client> client( static_cast<Client *>(s.client.get()) ); |
| 1712 | transactionFlags |= setClientStateLocked(client, s.state); |
| 1713 | } |
| 1714 | } |
| 1715 | } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1716 | } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 1717 | |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 1718 | if (transactionFlags) { |
| 1719 | // this triggers the transaction |
| 1720 | setTransactionFlags(transactionFlags); |
| 1721 | |
| 1722 | // if this is a synchronous transaction, wait for it to take effect |
| 1723 | // before returning. |
| 1724 | if (flags & eSynchronous) { |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1725 | mTransactionPending = true; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 1726 | } |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1727 | if (flags & eAnimation) { |
| 1728 | mAnimTransactionPending = true; |
| 1729 | } |
| 1730 | while (mTransactionPending) { |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 1731 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
| 1732 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 1733 | // just in case something goes wrong in SF, return to the |
| 1734 | // called after a few seconds. |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 1735 | ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out!"); |
| 1736 | mTransactionPending = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 1737 | break; |
| 1738 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1739 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1743 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) |
| 1744 | { |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 1745 | ssize_t dpyIdx = mCurrentState.displays.indexOfKey(s.token); |
| 1746 | if (dpyIdx < 0) |
| 1747 | return 0; |
| 1748 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1749 | uint32_t flags = 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 1750 | DisplayDeviceState& disp(mCurrentState.displays.editValueAt(dpyIdx)); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 1751 | if (disp.isValid()) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1752 | const uint32_t what = s.what; |
| 1753 | if (what & DisplayState::eSurfaceChanged) { |
| 1754 | if (disp.surface->asBinder() != s.surface->asBinder()) { |
| 1755 | disp.surface = s.surface; |
| 1756 | flags |= eDisplayTransactionNeeded; |
| 1757 | } |
| 1758 | } |
| 1759 | if (what & DisplayState::eLayerStackChanged) { |
| 1760 | if (disp.layerStack != s.layerStack) { |
| 1761 | disp.layerStack = s.layerStack; |
| 1762 | flags |= eDisplayTransactionNeeded; |
| 1763 | } |
| 1764 | } |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 1765 | if (what & DisplayState::eDisplayProjectionChanged) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1766 | if (disp.orientation != s.orientation) { |
| 1767 | disp.orientation = s.orientation; |
| 1768 | flags |= eDisplayTransactionNeeded; |
| 1769 | } |
| 1770 | if (disp.frame != s.frame) { |
| 1771 | disp.frame = s.frame; |
| 1772 | flags |= eDisplayTransactionNeeded; |
| 1773 | } |
| 1774 | if (disp.viewport != s.viewport) { |
| 1775 | disp.viewport = s.viewport; |
| 1776 | flags |= eDisplayTransactionNeeded; |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | return flags; |
| 1781 | } |
| 1782 | |
| 1783 | uint32_t SurfaceFlinger::setClientStateLocked( |
| 1784 | const sp<Client>& client, |
| 1785 | const layer_state_t& s) |
| 1786 | { |
| 1787 | uint32_t flags = 0; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1788 | sp<Layer> layer(client->getLayerUser(s.surface)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 1789 | if (layer != 0) { |
| 1790 | const uint32_t what = s.what; |
| 1791 | if (what & layer_state_t::ePositionChanged) { |
| 1792 | if (layer->setPosition(s.x, s.y)) |
| 1793 | flags |= eTraversalNeeded; |
| 1794 | } |
| 1795 | if (what & layer_state_t::eLayerChanged) { |
| 1796 | // NOTE: index needs to be calculated before we update the state |
| 1797 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 1798 | if (layer->setLayer(s.z)) { |
| 1799 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 1800 | mCurrentState.layersSortedByZ.add(layer); |
| 1801 | // we need traversal (state changed) |
| 1802 | // AND transaction (list changed) |
| 1803 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 1804 | } |
| 1805 | } |
| 1806 | if (what & layer_state_t::eSizeChanged) { |
| 1807 | if (layer->setSize(s.w, s.h)) { |
| 1808 | flags |= eTraversalNeeded; |
| 1809 | } |
| 1810 | } |
| 1811 | if (what & layer_state_t::eAlphaChanged) { |
| 1812 | if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f))) |
| 1813 | flags |= eTraversalNeeded; |
| 1814 | } |
| 1815 | if (what & layer_state_t::eMatrixChanged) { |
| 1816 | if (layer->setMatrix(s.matrix)) |
| 1817 | flags |= eTraversalNeeded; |
| 1818 | } |
| 1819 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 1820 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 1821 | flags |= eTraversalNeeded; |
| 1822 | } |
| 1823 | if (what & layer_state_t::eVisibilityChanged) { |
| 1824 | if (layer->setFlags(s.flags, s.mask)) |
| 1825 | flags |= eTraversalNeeded; |
| 1826 | } |
| 1827 | if (what & layer_state_t::eCropChanged) { |
| 1828 | if (layer->setCrop(s.crop)) |
| 1829 | flags |= eTraversalNeeded; |
| 1830 | } |
| 1831 | if (what & layer_state_t::eLayerStackChanged) { |
| 1832 | // NOTE: index needs to be calculated before we update the state |
| 1833 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 1834 | if (layer->setLayerStack(s.layerStack)) { |
| 1835 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 1836 | mCurrentState.layersSortedByZ.add(layer); |
| 1837 | // we need traversal (state changed) |
| 1838 | // AND transaction (list changed) |
| 1839 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | return flags; |
| 1844 | } |
| 1845 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1846 | status_t SurfaceFlinger::createLayer( |
Mathias Agopian | 0ef4e15 | 2011-04-20 14:19:32 -0700 | [diff] [blame] | 1847 | const String8& name, |
| 1848 | const sp<Client>& client, |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1849 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, |
| 1850 | sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1852 | //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string()); |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1853 | if (int32_t(w|h) < 0) { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 1854 | ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)", |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1855 | int(w), int(h)); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1856 | return BAD_VALUE; |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1857 | } |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 1858 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1859 | status_t result = NO_ERROR; |
| 1860 | |
| 1861 | sp<Layer> layer; |
| 1862 | |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 1863 | switch (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 1864 | case ISurfaceComposerClient::eFXSurfaceNormal: |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1865 | result = createNormalLayer(client, |
| 1866 | name, w, h, flags, format, |
| 1867 | handle, gbp, &layer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 1869 | case ISurfaceComposerClient::eFXSurfaceDim: |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1870 | result = createDimLayer(client, |
| 1871 | name, w, h, flags, |
| 1872 | handle, gbp, &layer); |
| 1873 | break; |
| 1874 | default: |
| 1875 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1879 | if (result == NO_ERROR) { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1880 | addClientLayer(client, *handle, *gbp, layer); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 1881 | setTransactionFlags(eTransactionNeeded); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1883 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1886 | status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client, |
| 1887 | const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, |
| 1888 | sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | { |
| 1890 | // initialize the surfaces |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 1891 | switch (format) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | case PIXEL_FORMAT_TRANSPARENT: |
| 1893 | case PIXEL_FORMAT_TRANSLUCENT: |
| 1894 | format = PIXEL_FORMAT_RGBA_8888; |
| 1895 | break; |
| 1896 | case PIXEL_FORMAT_OPAQUE: |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1897 | #ifdef NO_RGBX_8888 |
| 1898 | format = PIXEL_FORMAT_RGB_565; |
| 1899 | #else |
Mathias Agopian | 8f10540 | 2010-04-05 18:01:24 -0700 | [diff] [blame] | 1900 | format = PIXEL_FORMAT_RGBX_8888; |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1901 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | break; |
| 1903 | } |
| 1904 | |
Mathias Agopian | a8f3e4e | 2010-06-30 15:43:47 -0700 | [diff] [blame] | 1905 | #ifdef NO_RGBX_8888 |
| 1906 | if (format == PIXEL_FORMAT_RGBX_8888) |
| 1907 | format = PIXEL_FORMAT_RGBA_8888; |
| 1908 | #endif |
| 1909 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1910 | *outLayer = new Layer(this, client, name, w, h, flags); |
| 1911 | status_t err = (*outLayer)->setBuffers(w, h, format, flags); |
| 1912 | if (err == NO_ERROR) { |
| 1913 | *handle = (*outLayer)->getHandle(); |
| 1914 | *gbp = (*outLayer)->getBufferQueue(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1916 | |
| 1917 | ALOGE_IF(err, "createNormalLayer() failed (%s)", strerror(-err)); |
| 1918 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1921 | status_t SurfaceFlinger::createDimLayer(const sp<Client>& client, |
| 1922 | const String8& name, uint32_t w, uint32_t h, uint32_t flags, |
| 1923 | sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 1925 | *outLayer = new LayerDim(this, client, name, w, h, flags); |
| 1926 | *handle = (*outLayer)->getHandle(); |
| 1927 | *gbp = (*outLayer)->getBufferQueue(); |
| 1928 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 1931 | status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1933 | // called by the window manager when it wants to remove a Layer |
| 1934 | status_t err = NO_ERROR; |
| 1935 | sp<Layer> l(client->getLayerUser(handle)); |
| 1936 | if (l != NULL) { |
| 1937 | err = removeLayer(l); |
| 1938 | ALOGE_IF(err<0 && err != NAME_NOT_FOUND, |
| 1939 | "error removing layer=%p (%s)", l.get(), strerror(-err)); |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1940 | } |
| 1941 | return err; |
| 1942 | } |
| 1943 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1944 | status_t SurfaceFlinger::onLayerDestroyed(const wp<Layer>& layer) |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1945 | { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1946 | // called by ~LayerCleaner() when all references to the IBinder (handle) |
| 1947 | // are gone |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1948 | status_t err = NO_ERROR; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1949 | sp<Layer> l(layer.promote()); |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1950 | if (l != NULL) { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 1951 | err = removeLayer(l); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1952 | ALOGE_IF(err<0 && err != NAME_NOT_FOUND, |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 1953 | "error removing layer=%p (%s)", l.get(), strerror(-err)); |
| 1954 | } |
| 1955 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 1958 | // --------------------------------------------------------------------------- |
| 1959 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 1960 | void SurfaceFlinger::onInitializeDisplays() { |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 1961 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 1962 | Vector<ComposerState> state; |
| 1963 | Vector<DisplayState> displays; |
| 1964 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 1965 | d.what = DisplayState::eDisplayProjectionChanged | |
| 1966 | DisplayState::eLayerStackChanged; |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 1967 | d.token = mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY]; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 1968 | d.layerStack = 0; |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 1969 | d.orientation = DisplayState::eOrientationDefault; |
Jeff Brown | 4c05dd1 | 2012-09-09 00:07:17 -0700 | [diff] [blame] | 1970 | d.frame.makeInvalid(); |
| 1971 | d.viewport.makeInvalid(); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 1972 | displays.add(d); |
| 1973 | setTransactionState(state, displays, 0); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1974 | onScreenAcquired(getDefaultDisplayDevice()); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void SurfaceFlinger::initializeDisplays() { |
| 1978 | class MessageScreenInitialized : public MessageBase { |
| 1979 | SurfaceFlinger* flinger; |
| 1980 | public: |
| 1981 | MessageScreenInitialized(SurfaceFlinger* flinger) : flinger(flinger) { } |
| 1982 | virtual bool handler() { |
| 1983 | flinger->onInitializeDisplays(); |
| 1984 | return true; |
| 1985 | } |
| 1986 | }; |
| 1987 | sp<MessageBase> msg = new MessageScreenInitialized(this); |
| 1988 | postMessageAsync(msg); // we may be called from main thread, use async message |
| 1989 | } |
| 1990 | |
| 1991 | |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 1992 | void SurfaceFlinger::onScreenAcquired(const sp<const DisplayDevice>& hw) { |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 1993 | ALOGD("Screen acquired, type=%d flinger=%p", hw->getDisplayType(), this); |
| 1994 | if (hw->isScreenAcquired()) { |
| 1995 | // this is expected, e.g. when power manager wakes up during boot |
| 1996 | ALOGD(" screen was previously acquired"); |
| 1997 | return; |
| 1998 | } |
| 1999 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2000 | hw->acquireScreen(); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2001 | int32_t type = hw->getDisplayType(); |
| 2002 | if (type < DisplayDevice::NUM_DISPLAY_TYPES) { |
| 2003 | // built-in display, tell the HWC |
| 2004 | getHwComposer().acquire(type); |
| 2005 | |
| 2006 | if (type == DisplayDevice::DISPLAY_PRIMARY) { |
| 2007 | // FIXME: eventthread only knows about the main display right now |
| 2008 | mEventThread->onScreenAcquired(); |
| 2009 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 2010 | } |
Mathias Agopian | 2012830 | 2012-08-13 18:32:13 -0700 | [diff] [blame] | 2011 | mVisibleRegionsDirty = true; |
| 2012 | repaintEverything(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | } |
| 2014 | |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 2015 | void SurfaceFlinger::onScreenReleased(const sp<const DisplayDevice>& hw) { |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2016 | ALOGD("Screen released, type=%d flinger=%p", hw->getDisplayType(), this); |
| 2017 | if (!hw->isScreenAcquired()) { |
| 2018 | ALOGD(" screen was previously released"); |
| 2019 | return; |
| 2020 | } |
| 2021 | |
| 2022 | hw->releaseScreen(); |
| 2023 | int32_t type = hw->getDisplayType(); |
| 2024 | if (type < DisplayDevice::NUM_DISPLAY_TYPES) { |
| 2025 | if (type == DisplayDevice::DISPLAY_PRIMARY) { |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 2026 | // FIXME: eventthread only knows about the main display right now |
| 2027 | mEventThread->onScreenReleased(); |
| 2028 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2029 | |
| 2030 | // built-in display, tell the HWC |
| 2031 | getHwComposer().release(type); |
| 2032 | } |
| 2033 | mVisibleRegionsDirty = true; |
| 2034 | // from this point on, SF will stop drawing on this display |
| 2035 | } |
| 2036 | |
| 2037 | void SurfaceFlinger::unblank(const sp<IBinder>& display) { |
| 2038 | class MessageScreenAcquired : public MessageBase { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2039 | SurfaceFlinger& mFlinger; |
| 2040 | sp<IBinder> mDisplay; |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2041 | public: |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2042 | MessageScreenAcquired(SurfaceFlinger& flinger, |
| 2043 | const sp<IBinder>& disp) : mFlinger(flinger), mDisplay(disp) { } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2044 | virtual bool handler() { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2045 | const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay)); |
| 2046 | if (hw == NULL) { |
| 2047 | ALOGE("Attempt to unblank null display %p", mDisplay.get()); |
| 2048 | } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) { |
| 2049 | ALOGW("Attempt to unblank virtual display"); |
| 2050 | } else { |
| 2051 | mFlinger.onScreenAcquired(hw); |
| 2052 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2053 | return true; |
| 2054 | } |
| 2055 | }; |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2056 | sp<MessageBase> msg = new MessageScreenAcquired(*this, display); |
| 2057 | postMessageSync(msg); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 2060 | void SurfaceFlinger::blank(const sp<IBinder>& display) { |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 2061 | class MessageScreenReleased : public MessageBase { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2062 | SurfaceFlinger& mFlinger; |
| 2063 | sp<IBinder> mDisplay; |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 2064 | public: |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2065 | MessageScreenReleased(SurfaceFlinger& flinger, |
| 2066 | const sp<IBinder>& disp) : mFlinger(flinger), mDisplay(disp) { } |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 2067 | virtual bool handler() { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2068 | const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay)); |
| 2069 | if (hw == NULL) { |
| 2070 | ALOGE("Attempt to blank null display %p", mDisplay.get()); |
| 2071 | } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) { |
| 2072 | ALOGW("Attempt to blank virtual display"); |
| 2073 | } else { |
| 2074 | mFlinger.onScreenReleased(hw); |
| 2075 | } |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 2076 | return true; |
| 2077 | } |
| 2078 | }; |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2079 | sp<MessageBase> msg = new MessageScreenReleased(*this, display); |
| 2080 | postMessageSync(msg); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | // --------------------------------------------------------------------------- |
| 2084 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args) |
| 2086 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | String8 result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 2088 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 2089 | IPCThreadState* ipc = IPCThreadState::self(); |
| 2090 | const int pid = ipc->getCallingPid(); |
| 2091 | const int uid = ipc->getCallingUid(); |
| 2092 | if ((uid != AID_SHELL) && |
| 2093 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2094 | result.appendFormat("Permission Denial: " |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 2095 | "can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | } else { |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 2097 | // Try to get the main lock, but don't insist if we can't |
| 2098 | // (this would indicate SF is stuck, but we want to be able to |
| 2099 | // print something in dumpsys). |
| 2100 | int retry = 3; |
| 2101 | while (mStateLock.tryLock()<0 && --retry>=0) { |
| 2102 | usleep(1000000); |
| 2103 | } |
| 2104 | const bool locked(retry >= 0); |
| 2105 | if (!locked) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2106 | result.append( |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 2107 | "SurfaceFlinger appears to be unresponsive, " |
| 2108 | "dumping anyways (no locks held)\n"); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2111 | bool dumpAll = true; |
| 2112 | size_t index = 0; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2113 | size_t numArgs = args.size(); |
| 2114 | if (numArgs) { |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2115 | if ((index < numArgs) && |
| 2116 | (args[index] == String16("--list"))) { |
| 2117 | index++; |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2118 | listLayersLocked(args, index, result); |
Mathias Agopian | 35aadd6 | 2012-03-08 22:01:51 -0800 | [diff] [blame] | 2119 | dumpAll = false; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | if ((index < numArgs) && |
| 2123 | (args[index] == String16("--latency"))) { |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2124 | index++; |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2125 | dumpStatsLocked(args, index, result); |
Mathias Agopian | 35aadd6 | 2012-03-08 22:01:51 -0800 | [diff] [blame] | 2126 | dumpAll = false; |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2127 | } |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2128 | |
| 2129 | if ((index < numArgs) && |
| 2130 | (args[index] == String16("--latency-clear"))) { |
| 2131 | index++; |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2132 | clearStatsLocked(args, index, result); |
Mathias Agopian | 35aadd6 | 2012-03-08 22:01:51 -0800 | [diff] [blame] | 2133 | dumpAll = false; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2134 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | } |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 2136 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2137 | if (dumpAll) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2138 | dumpAllLocked(args, index, result); |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 2141 | if (locked) { |
| 2142 | mStateLock.unlock(); |
| 2143 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } |
| 2145 | write(fd, result.string(), result.size()); |
| 2146 | return NO_ERROR; |
| 2147 | } |
| 2148 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2149 | void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index, |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2150 | String8& result) const |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2151 | { |
| 2152 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 2153 | const size_t count = currentLayers.size(); |
| 2154 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2155 | const sp<Layer>& layer(currentLayers[i]); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2156 | result.appendFormat("%s\n", layer->getName().string()); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2160 | void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index, |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2161 | String8& result) const |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2162 | { |
| 2163 | String8 name; |
| 2164 | if (index < args.size()) { |
| 2165 | name = String8(args[index]); |
| 2166 | index++; |
| 2167 | } |
| 2168 | |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2169 | const nsecs_t period = |
| 2170 | getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY); |
| 2171 | result.appendFormat("%lld\n", period); |
| 2172 | |
| 2173 | if (name.isEmpty()) { |
| 2174 | mAnimFrameTracker.dump(result); |
| 2175 | } else { |
| 2176 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 2177 | const size_t count = currentLayers.size(); |
| 2178 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2179 | const sp<Layer>& layer(currentLayers[i]); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2180 | if (name == layer->getName()) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2181 | layer->dumpStats(result); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2182 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2187 | void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index, |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2188 | String8& result) |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2189 | { |
| 2190 | String8 name; |
| 2191 | if (index < args.size()) { |
| 2192 | name = String8(args[index]); |
| 2193 | index++; |
| 2194 | } |
| 2195 | |
| 2196 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 2197 | const size_t count = currentLayers.size(); |
| 2198 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2199 | const sp<Layer>& layer(currentLayers[i]); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2200 | if (name.isEmpty() || (name == layer->getName())) { |
| 2201 | layer->clearStats(); |
| 2202 | } |
| 2203 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2204 | |
| 2205 | mAnimFrameTracker.clear(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 2208 | /*static*/ void SurfaceFlinger::appendSfConfigString(String8& result) |
| 2209 | { |
| 2210 | static const char* config = |
| 2211 | " [sf" |
| 2212 | #ifdef NO_RGBX_8888 |
| 2213 | " NO_RGBX_8888" |
| 2214 | #endif |
| 2215 | #ifdef HAS_CONTEXT_PRIORITY |
| 2216 | " HAS_CONTEXT_PRIORITY" |
| 2217 | #endif |
| 2218 | #ifdef NEVER_DEFAULT_TO_ASYNC_MODE |
| 2219 | " NEVER_DEFAULT_TO_ASYNC_MODE" |
| 2220 | #endif |
| 2221 | #ifdef TARGET_DISABLE_TRIPLE_BUFFERING |
| 2222 | " TARGET_DISABLE_TRIPLE_BUFFERING" |
| 2223 | #endif |
| 2224 | "]"; |
| 2225 | result.append(config); |
| 2226 | } |
| 2227 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2228 | void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index, |
| 2229 | String8& result) const |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2230 | { |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2231 | bool colorize = false; |
| 2232 | if (index < args.size() |
| 2233 | && (args[index] == String16("--color"))) { |
| 2234 | colorize = true; |
| 2235 | index++; |
| 2236 | } |
| 2237 | |
| 2238 | Colorizer colorizer(colorize); |
| 2239 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2240 | // figure out if we're stuck somewhere |
| 2241 | const nsecs_t now = systemTime(); |
| 2242 | const nsecs_t inSwapBuffers(mDebugInSwapBuffers); |
| 2243 | const nsecs_t inTransaction(mDebugInTransaction); |
| 2244 | nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0; |
| 2245 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 2246 | |
| 2247 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 2248 | * Dump library configuration. |
| 2249 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2250 | |
| 2251 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 2252 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2253 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 2254 | appendSfConfigString(result); |
| 2255 | appendUiConfigString(result); |
| 2256 | appendGuiConfigString(result); |
| 2257 | result.append("\n"); |
| 2258 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2259 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 2260 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2261 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 2262 | result.append(SyncFeatures::getInstance().toString()); |
| 2263 | result.append("\n"); |
| 2264 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 2265 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2266 | * Dump the visible layer list |
| 2267 | */ |
| 2268 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 2269 | const size_t count = currentLayers.size(); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2270 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2271 | result.appendFormat("Visible layers (count = %d)\n", count); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2272 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2273 | for (size_t i=0 ; i<count ; i++) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2274 | const sp<Layer>& layer(currentLayers[i]); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2275 | layer->dump(result, colorizer); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | /* |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 2279 | * Dump Display state |
| 2280 | */ |
| 2281 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2282 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2283 | result.appendFormat("Displays (%d entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2284 | colorizer.reset(result); |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 2285 | for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) { |
| 2286 | const sp<const DisplayDevice>& hw(mDisplays[dpy]); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2287 | hw->dump(result); |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2291 | * Dump SurfaceFlinger global state |
| 2292 | */ |
| 2293 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2294 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2295 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2296 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2297 | |
Mathias Agopian | 888c822 | 2012-08-04 21:10:38 -0700 | [diff] [blame] | 2298 | HWComposer& hwc(getHwComposer()); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2299 | sp<const DisplayDevice> hw(getDefaultDisplayDevice()); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 2300 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2301 | colorizer.bold(result); |
| 2302 | result.appendFormat("EGL implementation : %s\n", |
| 2303 | eglQueryStringImplementationANDROID(mEGLDisplay, EGL_VERSION)); |
| 2304 | colorizer.reset(result); |
| 2305 | result.appendFormat("%s\n", |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 2306 | eglQueryStringImplementationANDROID(mEGLDisplay, EGL_EXTENSIONS)); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 2307 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 2308 | mRenderEngine->dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2309 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2310 | hw->undefinedRegion.dump(result, "undefinedRegion"); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2311 | result.appendFormat(" orientation=%d, canDraw=%d\n", |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2312 | hw->getOrientation(), hw->canDraw()); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2313 | result.appendFormat( |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2314 | " last eglSwapBuffers() time: %f us\n" |
| 2315 | " last transaction time : %f us\n" |
Mathias Agopian | c95dbdc | 2012-02-05 00:19:27 -0800 | [diff] [blame] | 2316 | " transaction-flags : %08x\n" |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2317 | " refresh-rate : %f fps\n" |
| 2318 | " x-dpi : %f\n" |
Mathias Agopian | ed98557 | 2013-03-22 00:24:39 -0700 | [diff] [blame] | 2319 | " y-dpi : %f\n" |
| 2320 | " EGL_NATIVE_VISUAL_ID : %d\n" |
| 2321 | " gpu_to_cpu_unsupported : %d\n" |
| 2322 | , |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2323 | mLastSwapBufferTime/1000.0, |
| 2324 | mLastTransactionTime/1000.0, |
Mathias Agopian | c95dbdc | 2012-02-05 00:19:27 -0800 | [diff] [blame] | 2325 | mTransactionFlags, |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 2326 | 1e9 / hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY), |
| 2327 | hwc.getDpiX(HWC_DISPLAY_PRIMARY), |
Mathias Agopian | ed98557 | 2013-03-22 00:24:39 -0700 | [diff] [blame] | 2328 | hwc.getDpiY(HWC_DISPLAY_PRIMARY), |
| 2329 | mEGLNativeVisualId, |
| 2330 | !mGpuToCpuSupported); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2331 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2332 | result.appendFormat(" eglSwapBuffers time: %f us\n", |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2333 | inSwapBuffersDuration/1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2334 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2335 | result.appendFormat(" transaction time: %f us\n", |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2336 | inTransactionDuration/1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2337 | |
| 2338 | /* |
| 2339 | * VSYNC state |
| 2340 | */ |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2341 | mEventThread->dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2342 | |
| 2343 | /* |
| 2344 | * Dump HWComposer state |
| 2345 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2346 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2347 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2348 | colorizer.reset(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2349 | result.appendFormat(" h/w composer %s and %s\n", |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2350 | hwc.initCheck()==NO_ERROR ? "present" : "not present", |
| 2351 | (mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled"); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2352 | hwc.dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2353 | |
| 2354 | /* |
| 2355 | * Dump gralloc state |
| 2356 | */ |
| 2357 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 2358 | alloc.dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 2359 | } |
| 2360 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2361 | const Vector< sp<Layer> >& |
Jesse Hall | 48bc05b | 2013-03-21 14:06:52 -0700 | [diff] [blame] | 2362 | SurfaceFlinger::getLayerSortedByZForHwcDisplay(int id) { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 2363 | // Note: mStateLock is held here |
Jesse Hall | 48bc05b | 2013-03-21 14:06:52 -0700 | [diff] [blame] | 2364 | wp<IBinder> dpy; |
| 2365 | for (size_t i=0 ; i<mDisplays.size() ; i++) { |
| 2366 | if (mDisplays.valueAt(i)->getHwcDisplayId() == id) { |
| 2367 | dpy = mDisplays.keyAt(i); |
| 2368 | break; |
| 2369 | } |
| 2370 | } |
| 2371 | if (dpy == NULL) { |
| 2372 | ALOGE("getLayerSortedByZForHwcDisplay: invalid hwc display id %d", id); |
| 2373 | // Just use the primary display so we have something to return |
| 2374 | dpy = getBuiltInDisplay(DisplayDevice::DISPLAY_PRIMARY); |
| 2375 | } |
| 2376 | return getDisplayDevice(dpy)->getVisibleLayersSortedByZ(); |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 2379 | bool SurfaceFlinger::startDdmConnection() |
| 2380 | { |
| 2381 | void* libddmconnection_dso = |
| 2382 | dlopen("libsurfaceflinger_ddmconnection.so", RTLD_NOW); |
| 2383 | if (!libddmconnection_dso) { |
| 2384 | return false; |
| 2385 | } |
| 2386 | void (*DdmConnection_start)(const char* name); |
| 2387 | DdmConnection_start = |
| 2388 | (typeof DdmConnection_start)dlsym(libddmconnection_dso, "DdmConnection_start"); |
| 2389 | if (!DdmConnection_start) { |
| 2390 | dlclose(libddmconnection_dso); |
| 2391 | return false; |
| 2392 | } |
| 2393 | (*DdmConnection_start)(getServiceName()); |
| 2394 | return true; |
| 2395 | } |
| 2396 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | status_t SurfaceFlinger::onTransact( |
| 2398 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 2399 | { |
| 2400 | switch (code) { |
| 2401 | case CREATE_CONNECTION: |
Mathias Agopian | 041a075 | 2013-03-15 18:31:56 -0700 | [diff] [blame] | 2402 | case CREATE_DISPLAY: |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 2403 | case SET_TRANSACTION_STATE: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | case BOOT_FINISHED: |
Colin Cross | 8e53306 | 2012-06-07 13:17:52 -0700 | [diff] [blame] | 2405 | case BLANK: |
| 2406 | case UNBLANK: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | { |
| 2408 | // codes that require permission check |
| 2409 | IPCThreadState* ipc = IPCThreadState::self(); |
| 2410 | const int pid = ipc->getCallingPid(); |
Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 2411 | const int uid = ipc->getCallingUid(); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 2412 | if ((uid != AID_GRAPHICS) && |
| 2413 | !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 2414 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 2415 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 2416 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2418 | break; |
| 2419 | } |
| 2420 | case CAPTURE_SCREEN: |
| 2421 | { |
| 2422 | // codes that require permission check |
| 2423 | IPCThreadState* ipc = IPCThreadState::self(); |
| 2424 | const int pid = ipc->getCallingPid(); |
| 2425 | const int uid = ipc->getCallingUid(); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 2426 | if ((uid != AID_GRAPHICS) && |
| 2427 | !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 2428 | ALOGE("Permission Denial: " |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2429 | "can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 2430 | return PERMISSION_DENIED; |
| 2431 | } |
| 2432 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | } |
| 2434 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2435 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 2437 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 2438 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Glenn Kasten | 99ed224 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 2439 | if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 2440 | IPCThreadState* ipc = IPCThreadState::self(); |
| 2441 | const int pid = ipc->getCallingPid(); |
| 2442 | const int uid = ipc->getCallingUid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 2443 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 2444 | "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] | 2445 | return PERMISSION_DENIED; |
| 2446 | } |
| 2447 | int n; |
| 2448 | switch (code) { |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 2449 | case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 2450 | case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | return NO_ERROR; |
| 2452 | case 1002: // SHOW_UPDATES |
| 2453 | n = data.readInt32(); |
| 2454 | mDebugRegion = n ? n : (mDebugRegion ? 0 : 1); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 2455 | invalidateHwcGeometry(); |
| 2456 | repaintEverything(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | case 1004:{ // repaint everything |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 2459 | repaintEverything(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 2460 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 2462 | case 1005:{ // force transaction |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 2463 | setTransactionFlags( |
| 2464 | eTransactionNeeded| |
| 2465 | eDisplayTransactionNeeded| |
| 2466 | eTraversalNeeded); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 2467 | return NO_ERROR; |
| 2468 | } |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 2469 | case 1006:{ // send empty update |
| 2470 | signalRefresh(); |
| 2471 | return NO_ERROR; |
| 2472 | } |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 2473 | case 1008: // toggle use of hw composer |
| 2474 | n = data.readInt32(); |
| 2475 | mDebugDisableHWC = n ? 1 : 0; |
| 2476 | invalidateHwcGeometry(); |
| 2477 | repaintEverything(); |
| 2478 | return NO_ERROR; |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 2479 | case 1009: // toggle use of transform hint |
| 2480 | n = data.readInt32(); |
| 2481 | mDebugDisableTransformHint = n ? 1 : 0; |
| 2482 | invalidateHwcGeometry(); |
| 2483 | repaintEverything(); |
| 2484 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | case 1010: // interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 2486 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | reply->writeInt32(0); |
| 2488 | reply->writeInt32(mDebugRegion); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 2489 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 2490 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | return NO_ERROR; |
| 2492 | case 1013: { |
| 2493 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2494 | sp<const DisplayDevice> hw(getDefaultDisplayDevice()); |
| 2495 | reply->writeInt32(hw->getPageFlipCount()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | } |
| 2497 | return NO_ERROR; |
| 2498 | } |
| 2499 | } |
| 2500 | return err; |
| 2501 | } |
| 2502 | |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 2503 | void SurfaceFlinger::repaintEverything() { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2504 | android_atomic_or(1, &mRepaintEverything); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2505 | signalTransaction(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Mathias Agopian | 59119e6 | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 2508 | // --------------------------------------------------------------------------- |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2509 | // Capture screen into an IGraphiBufferProducer |
Mathias Agopian | 9daa5c9 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 2510 | // --------------------------------------------------------------------------- |
| 2511 | |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2512 | /* The code below is here to handle b/8734824 |
| 2513 | * |
| 2514 | * We create a IGraphicBufferProducer wrapper that forwards all calls |
| 2515 | * to the calling binder thread, where they are executed. This allows |
| 2516 | * the calling thread to be reused (on the other side) and not |
| 2517 | * depend on having "enough" binder threads to handle the requests. |
| 2518 | * |
| 2519 | */ |
| 2520 | |
| 2521 | class GraphicProducerWrapper : public BBinder, public MessageHandler { |
| 2522 | sp<IGraphicBufferProducer> impl; |
| 2523 | sp<Looper> looper; |
| 2524 | status_t result; |
| 2525 | bool exitPending; |
| 2526 | bool exitRequested; |
| 2527 | mutable Barrier barrier; |
| 2528 | volatile int32_t memoryBarrier; |
| 2529 | uint32_t code; |
| 2530 | Parcel const* data; |
| 2531 | Parcel* reply; |
| 2532 | |
| 2533 | enum { |
| 2534 | MSG_API_CALL, |
| 2535 | MSG_EXIT |
| 2536 | }; |
| 2537 | |
| 2538 | /* |
| 2539 | * this is called by our "fake" BpGraphicBufferProducer. We package the |
| 2540 | * data and reply Parcel and forward them to the calling thread. |
| 2541 | */ |
| 2542 | virtual status_t transact(uint32_t code, |
| 2543 | const Parcel& data, Parcel* reply, uint32_t flags) { |
| 2544 | this->code = code; |
| 2545 | this->data = &data; |
| 2546 | this->reply = reply; |
| 2547 | android_atomic_acquire_store(0, &memoryBarrier); |
| 2548 | if (exitPending) { |
| 2549 | // if we've exited, we run the message synchronously right here |
| 2550 | handleMessage(Message(MSG_API_CALL)); |
| 2551 | } else { |
| 2552 | barrier.close(); |
| 2553 | looper->sendMessage(this, Message(MSG_API_CALL)); |
| 2554 | barrier.wait(); |
| 2555 | } |
| 2556 | return NO_ERROR; |
| 2557 | } |
| 2558 | |
| 2559 | /* |
| 2560 | * here we run on the binder calling thread. All we've got to do is |
| 2561 | * call the real BpGraphicBufferProducer. |
| 2562 | */ |
| 2563 | virtual void handleMessage(const Message& message) { |
| 2564 | android_atomic_release_load(&memoryBarrier); |
| 2565 | if (message.what == MSG_API_CALL) { |
| 2566 | impl->asBinder()->transact(code, data[0], reply); |
| 2567 | barrier.open(); |
| 2568 | } else if (message.what == MSG_EXIT) { |
| 2569 | exitRequested = true; |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | public: |
| 2574 | GraphicProducerWrapper(const sp<IGraphicBufferProducer>& impl) : |
| 2575 | impl(impl), looper(new Looper(true)), result(NO_ERROR), |
| 2576 | exitPending(false), exitRequested(false) { |
| 2577 | } |
| 2578 | |
| 2579 | status_t waitForResponse() { |
| 2580 | do { |
| 2581 | looper->pollOnce(-1); |
| 2582 | } while (!exitRequested); |
| 2583 | return result; |
| 2584 | } |
| 2585 | |
| 2586 | void exit(status_t result) { |
| 2587 | exitPending = true; |
| 2588 | looper->sendMessage(this, Message(MSG_EXIT)); |
| 2589 | } |
| 2590 | }; |
| 2591 | |
| 2592 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2593 | status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display, |
| 2594 | const sp<IGraphicBufferProducer>& producer, |
| 2595 | uint32_t reqWidth, uint32_t reqHeight, |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 2596 | uint32_t minLayerZ, uint32_t maxLayerZ, |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2597 | bool useReadPixels) { |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2598 | |
| 2599 | if (CC_UNLIKELY(display == 0)) |
| 2600 | return BAD_VALUE; |
| 2601 | |
| 2602 | if (CC_UNLIKELY(producer == 0)) |
| 2603 | return BAD_VALUE; |
| 2604 | |
| 2605 | class MessageCaptureScreen : public MessageBase { |
| 2606 | SurfaceFlinger* flinger; |
| 2607 | sp<IBinder> display; |
| 2608 | sp<IGraphicBufferProducer> producer; |
| 2609 | uint32_t reqWidth, reqHeight; |
| 2610 | uint32_t minLayerZ,maxLayerZ; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2611 | bool useReadPixels; |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2612 | status_t result; |
| 2613 | public: |
| 2614 | MessageCaptureScreen(SurfaceFlinger* flinger, |
| 2615 | const sp<IBinder>& display, |
| 2616 | const sp<IGraphicBufferProducer>& producer, |
| 2617 | uint32_t reqWidth, uint32_t reqHeight, |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2618 | uint32_t minLayerZ, uint32_t maxLayerZ, bool useReadPixels) |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2619 | : flinger(flinger), display(display), producer(producer), |
| 2620 | reqWidth(reqWidth), reqHeight(reqHeight), |
| 2621 | minLayerZ(minLayerZ), maxLayerZ(maxLayerZ), |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2622 | useReadPixels(useReadPixels), |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2623 | result(PERMISSION_DENIED) |
| 2624 | { |
| 2625 | } |
| 2626 | status_t getResult() const { |
| 2627 | return result; |
| 2628 | } |
| 2629 | virtual bool handler() { |
| 2630 | Mutex::Autolock _l(flinger->mStateLock); |
| 2631 | sp<const DisplayDevice> hw(flinger->getDisplayDevice(display)); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2632 | bool useReadPixels = this->useReadPixels && !flinger->mGpuToCpuSupported; |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2633 | result = flinger->captureScreenImplLocked(hw, |
| 2634 | producer, reqWidth, reqHeight, minLayerZ, maxLayerZ, |
| 2635 | useReadPixels); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2636 | static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(result); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2637 | return true; |
| 2638 | } |
| 2639 | }; |
| 2640 | |
Mathias Agopian | 9eb1f05 | 2013-04-10 16:27:17 -0700 | [diff] [blame] | 2641 | // make sure to process transactions before screenshots -- a transaction |
| 2642 | // might already be pending but scheduled for VSYNC; this guarantees we |
| 2643 | // will handle it before the screenshot. When VSYNC finally arrives |
| 2644 | // the scheduled transaction will be a no-op. If no transactions are |
| 2645 | // scheduled at this time, this will end-up being a no-op as well. |
| 2646 | mEventQueue.invalidateTransactionNow(); |
| 2647 | |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2648 | // this creates a "fake" BBinder which will serve as a "fake" remote |
| 2649 | // binder to receive the marshaled calls and forward them to the |
| 2650 | // real remote (a BpGraphicBufferProducer) |
| 2651 | sp<GraphicProducerWrapper> wrapper = new GraphicProducerWrapper(producer); |
| 2652 | |
| 2653 | // the asInterface() call below creates our "fake" BpGraphicBufferProducer |
| 2654 | // which does the marshaling work forwards to our "fake remote" above. |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2655 | sp<MessageBase> msg = new MessageCaptureScreen(this, |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2656 | display, IGraphicBufferProducer::asInterface( wrapper ), |
| 2657 | reqWidth, reqHeight, minLayerZ, maxLayerZ, |
| 2658 | useReadPixels); |
| 2659 | |
| 2660 | status_t res = postMessageAsync(msg); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2661 | if (res == NO_ERROR) { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 2662 | res = wrapper->waitForResponse(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2663 | } |
| 2664 | return res; |
| 2665 | } |
| 2666 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2667 | |
| 2668 | void SurfaceFlinger::renderScreenImplLocked( |
| 2669 | const sp<const DisplayDevice>& hw, |
| 2670 | uint32_t reqWidth, uint32_t reqHeight, |
| 2671 | uint32_t minLayerZ, uint32_t maxLayerZ, |
| 2672 | bool yswap) |
| 2673 | { |
| 2674 | ATRACE_CALL(); |
| 2675 | |
| 2676 | // get screen geometry |
| 2677 | const uint32_t hw_w = hw->getWidth(); |
| 2678 | const uint32_t hw_h = hw->getHeight(); |
| 2679 | |
| 2680 | const bool filtering = reqWidth != hw_w || reqWidth != hw_h; |
| 2681 | |
| 2682 | // make sure to clear all GL error flags |
| 2683 | while ( glGetError() != GL_NO_ERROR ) ; |
| 2684 | |
| 2685 | // set-up our viewport |
| 2686 | glViewport(0, 0, reqWidth, reqHeight); |
| 2687 | glMatrixMode(GL_PROJECTION); |
| 2688 | glLoadIdentity(); |
| 2689 | if (yswap) glOrthof(0, hw_w, hw_h, 0, 0, 1); |
| 2690 | else glOrthof(0, hw_w, 0, hw_h, 0, 1); |
| 2691 | glMatrixMode(GL_MODELVIEW); |
| 2692 | glLoadIdentity(); |
| 2693 | |
| 2694 | // redraw the screen entirely... |
| 2695 | glDisable(GL_SCISSOR_TEST); |
| 2696 | glClearColor(0,0,0,1); |
| 2697 | glClear(GL_COLOR_BUFFER_BIT); |
| 2698 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 2699 | glDisable(GL_TEXTURE_2D); |
| 2700 | |
| 2701 | const LayerVector& layers( mDrawingState.layersSortedByZ ); |
| 2702 | const size_t count = layers.size(); |
| 2703 | for (size_t i=0 ; i<count ; ++i) { |
| 2704 | const sp<Layer>& layer(layers[i]); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 2705 | const Layer::State& state(layer->getDrawingState()); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2706 | if (state.layerStack == hw->getLayerStack()) { |
| 2707 | if (state.z >= minLayerZ && state.z <= maxLayerZ) { |
| 2708 | if (layer->isVisible()) { |
| 2709 | if (filtering) layer->setFiltering(true); |
| 2710 | layer->draw(hw); |
| 2711 | if (filtering) layer->setFiltering(false); |
| 2712 | } |
| 2713 | } |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | // compositionComplete is needed for older driver |
| 2718 | hw->compositionComplete(); |
| 2719 | } |
| 2720 | |
| 2721 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2722 | status_t SurfaceFlinger::captureScreenImplLocked( |
| 2723 | const sp<const DisplayDevice>& hw, |
| 2724 | const sp<IGraphicBufferProducer>& producer, |
| 2725 | uint32_t reqWidth, uint32_t reqHeight, |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2726 | uint32_t minLayerZ, uint32_t maxLayerZ, |
| 2727 | bool useReadPixels) |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2728 | { |
| 2729 | ATRACE_CALL(); |
| 2730 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2731 | // get screen geometry |
| 2732 | const uint32_t hw_w = hw->getWidth(); |
| 2733 | const uint32_t hw_h = hw->getHeight(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 2734 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2735 | // if we have secure windows on this display, never allow the screen capture |
| 2736 | if (hw->getSecureLayerVisible()) { |
| 2737 | ALOGW("FB is protected: PERMISSION_DENIED"); |
| 2738 | return PERMISSION_DENIED; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2741 | if ((reqWidth > hw_w) || (reqHeight > hw_h)) { |
| 2742 | ALOGE("size mismatch (%d, %d) > (%d, %d)", |
| 2743 | reqWidth, reqHeight, hw_w, hw_h); |
| 2744 | return BAD_VALUE; |
| 2745 | } |
Mathias Agopian | c1d1b0d | 2011-01-16 14:05:02 -0800 | [diff] [blame] | 2746 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2747 | reqWidth = (!reqWidth) ? hw_w : reqWidth; |
| 2748 | reqHeight = (!reqHeight) ? hw_h : reqHeight; |
| 2749 | |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2750 | // create a surface (because we're a producer, and we need to |
| 2751 | // dequeue/queue a buffer) |
| 2752 | sp<Surface> sur = new Surface(producer); |
| 2753 | ANativeWindow* window = sur.get(); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2754 | |
| 2755 | status_t result = NO_ERROR; |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2756 | if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) == NO_ERROR) { |
| 2757 | uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; |
| 2758 | if (!useReadPixels) { |
| 2759 | usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2762 | int err = 0; |
| 2763 | err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight); |
| 2764 | err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888); |
| 2765 | err |= native_window_set_usage(window, usage); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2766 | |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2767 | if (err == NO_ERROR) { |
| 2768 | ANativeWindowBuffer* buffer; |
| 2769 | /* TODO: Once we have the sync framework everywhere this can use |
| 2770 | * server-side waits on the fence that dequeueBuffer returns. |
| 2771 | */ |
| 2772 | result = native_window_dequeue_buffer_and_wait(window, &buffer); |
| 2773 | if (result == NO_ERROR) { |
| 2774 | // create an EGLImage from the buffer so we can later |
| 2775 | // turn it into a texture |
| 2776 | EGLImageKHR image = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT, |
| 2777 | EGL_NATIVE_BUFFER_ANDROID, buffer, NULL); |
| 2778 | if (image != EGL_NO_IMAGE_KHR) { |
| 2779 | GLuint tname, name; |
| 2780 | if (!useReadPixels) { |
| 2781 | // turn our EGLImage into a texture |
| 2782 | glGenTextures(1, &tname); |
| 2783 | glBindTexture(GL_TEXTURE_2D, tname); |
| 2784 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image); |
| 2785 | // create a Framebuffer Object to render into |
| 2786 | glGenFramebuffersOES(1, &name); |
| 2787 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); |
| 2788 | glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 2789 | GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0); |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2790 | } else { |
| 2791 | // since we're going to use glReadPixels() anyways, |
| 2792 | // use an intermediate renderbuffer instead |
| 2793 | glGenRenderbuffersOES(1, &tname); |
| 2794 | glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname); |
| 2795 | glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, reqWidth, reqHeight); |
| 2796 | // create a FBO to render into |
| 2797 | glGenFramebuffersOES(1, &name); |
| 2798 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, name); |
| 2799 | glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, |
| 2800 | GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname); |
| 2801 | } |
| 2802 | |
| 2803 | GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); |
| 2804 | if (status == GL_FRAMEBUFFER_COMPLETE_OES) { |
| 2805 | // this will in fact render into our dequeued buffer |
| 2806 | // via an FBO, which means we didn't have to create |
| 2807 | // an EGLSurface and therefore we're not |
| 2808 | // dependent on the context's EGLConfig. |
| 2809 | renderScreenImplLocked(hw, reqWidth, reqHeight, |
| 2810 | minLayerZ, maxLayerZ, true); |
| 2811 | |
| 2812 | if (useReadPixels) { |
| 2813 | sp<GraphicBuffer> buf = static_cast<GraphicBuffer*>(buffer); |
| 2814 | void* vaddr; |
| 2815 | if (buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, &vaddr) == NO_ERROR) { |
| 2816 | glReadPixels(0, 0, buffer->stride, reqHeight, |
| 2817 | GL_RGBA, GL_UNSIGNED_BYTE, vaddr); |
Mathias Agopian | fee2b46 | 2013-07-03 12:34:01 -0700 | [diff] [blame] | 2818 | checkScreenshot(buf, vaddr, hw, minLayerZ, maxLayerZ); |
Mathias Agopian | 0aea53f | 2013-04-24 19:03:08 +0200 | [diff] [blame] | 2819 | buf->unlock(); |
| 2820 | } |
| 2821 | } |
| 2822 | } else { |
| 2823 | ALOGE("got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot"); |
| 2824 | result = INVALID_OPERATION; |
| 2825 | } |
| 2826 | |
| 2827 | // back to main framebuffer |
| 2828 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); |
| 2829 | glDeleteFramebuffersOES(1, &name); |
| 2830 | if (!useReadPixels) { |
| 2831 | glDeleteTextures(1, &tname); |
| 2832 | } else { |
| 2833 | glDeleteRenderbuffersOES(1, &tname); |
| 2834 | } |
| 2835 | // destroy our image |
| 2836 | eglDestroyImageKHR(mEGLDisplay, image); |
| 2837 | } else { |
| 2838 | result = BAD_VALUE; |
| 2839 | } |
| 2840 | window->queueBuffer(window, buffer, -1); |
| 2841 | } |
| 2842 | } else { |
| 2843 | result = BAD_VALUE; |
| 2844 | } |
| 2845 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
| 2846 | } |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 2847 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 2848 | hw->setViewportAndProjection(); |
Mathias Agopian | 2be4e8f | 2013-03-06 20:42:56 -0800 | [diff] [blame] | 2849 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 2850 | return result; |
| 2851 | } |
| 2852 | |
Mathias Agopian | fee2b46 | 2013-07-03 12:34:01 -0700 | [diff] [blame] | 2853 | void SurfaceFlinger::checkScreenshot(const sp<GraphicBuffer>& buf, void const* vaddr, |
| 2854 | const sp<const DisplayDevice>& hw, |
| 2855 | uint32_t minLayerZ, uint32_t maxLayerZ) { |
| 2856 | if (DEBUG_SCREENSHOTS) { |
| 2857 | for (ssize_t y=0 ; y<buf->height ; y++) { |
| 2858 | uint32_t const * p = (uint32_t const *)vaddr + y*buf->stride; |
| 2859 | for (ssize_t x=0 ; x<buf->width ; x++) { |
| 2860 | if (p[x] != 0xFF000000) return; |
| 2861 | } |
| 2862 | } |
| 2863 | ALOGE("*** we just took a black screenshot ***\n" |
| 2864 | "requested minz=%d, maxz=%d, layerStack=%d", |
| 2865 | minLayerZ, maxLayerZ, hw->getLayerStack()); |
| 2866 | const LayerVector& layers( mDrawingState.layersSortedByZ ); |
| 2867 | const size_t count = layers.size(); |
| 2868 | for (size_t i=0 ; i<count ; ++i) { |
| 2869 | const sp<Layer>& layer(layers[i]); |
| 2870 | const Layer::State& state(layer->getDrawingState()); |
| 2871 | const bool visible = (state.layerStack == hw->getLayerStack()) |
| 2872 | && (state.z >= minLayerZ && state.z <= maxLayerZ) |
| 2873 | && (layer->isVisible()); |
| 2874 | ALOGE("%c index=%d, name=%s, layerStack=%d, z=%d, visible=%d, flags=%x, alpha=%x", |
| 2875 | visible ? '+' : '-', |
| 2876 | i, layer->getName().string(), state.layerStack, state.z, |
| 2877 | layer->isVisible(), state.flags, state.alpha); |
| 2878 | } |
| 2879 | } |
| 2880 | } |
| 2881 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 2882 | // --------------------------------------------------------------------------- |
| 2883 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 2884 | SurfaceFlinger::LayerVector::LayerVector() { |
| 2885 | } |
| 2886 | |
| 2887 | SurfaceFlinger::LayerVector::LayerVector(const LayerVector& rhs) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2888 | : SortedVector<sp<Layer> >(rhs) { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | int SurfaceFlinger::LayerVector::do_compare(const void* lhs, |
| 2892 | const void* rhs) const |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2893 | { |
Mathias Agopian | be246f8 | 2012-07-31 22:59:38 -0700 | [diff] [blame] | 2894 | // sort layers per layer-stack, then by z-order and finally by sequence |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2895 | const sp<Layer>& l(*reinterpret_cast<const sp<Layer>*>(lhs)); |
| 2896 | const sp<Layer>& r(*reinterpret_cast<const sp<Layer>*>(rhs)); |
Mathias Agopian | be246f8 | 2012-07-31 22:59:38 -0700 | [diff] [blame] | 2897 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 2898 | uint32_t ls = l->getCurrentState().layerStack; |
| 2899 | uint32_t rs = r->getCurrentState().layerStack; |
Mathias Agopian | be246f8 | 2012-07-31 22:59:38 -0700 | [diff] [blame] | 2900 | if (ls != rs) |
| 2901 | return ls - rs; |
| 2902 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 2903 | uint32_t lz = l->getCurrentState().z; |
| 2904 | uint32_t rz = r->getCurrentState().z; |
Mathias Agopian | be246f8 | 2012-07-31 22:59:38 -0700 | [diff] [blame] | 2905 | if (lz != rz) |
| 2906 | return lz - rz; |
| 2907 | |
| 2908 | return l->sequence - r->sequence; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | // --------------------------------------------------------------------------- |
| 2912 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 2913 | SurfaceFlinger::DisplayDeviceState::DisplayDeviceState() |
| 2914 | : type(DisplayDevice::DISPLAY_ID_INVALID) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 2917 | SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type) |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 2918 | : type(type), layerStack(DisplayDevice::NO_LAYER_STACK), orientation(0) { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 2919 | viewport.makeInvalid(); |
| 2920 | frame.makeInvalid(); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | }; // namespace android |