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