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