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