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