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 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 19 | |
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> |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 22 | #include <dlfcn.h> |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 23 | |
| 24 | #include <algorithm> |
| 25 | #include <cinttypes> |
| 26 | #include <cmath> |
| 27 | #include <cstdint> |
| 28 | #include <functional> |
| 29 | #include <mutex> |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 30 | #include <optional> |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 31 | #include <unordered_map> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 32 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include <cutils/properties.h> |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 34 | #include <log/log.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 36 | #include <binder/IPCThreadState.h> |
| 37 | #include <binder/IServiceManager.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 38 | #include <binder/PermissionCache.h> |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 39 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 40 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 41 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 42 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 43 | #include <compositionengine/Layer.h> |
| 44 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 45 | #include <compositionengine/RenderSurface.h> |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 46 | #include <compositionengine/impl/LayerCompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 47 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 48 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 49 | #include <dvr/vr_flinger.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 50 | #include <gui/BufferQueue.h> |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 51 | #include <gui/GuiConfig.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 52 | #include <gui/IDisplayEventConnection.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 53 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 54 | #include <gui/LayerDebugInfo.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 55 | #include <gui/Surface.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 56 | #include <input/IInputFlinger.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 57 | #include <renderengine/RenderEngine.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 58 | #include <ui/ColorSpace.h> |
| 59 | #include <ui/DebugUtils.h> |
| 60 | #include <ui/DisplayInfo.h> |
| 61 | #include <ui/DisplayStatInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 62 | #include <ui/GraphicBufferAllocator.h> |
| 63 | #include <ui/PixelFormat.h> |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 64 | #include <ui/UiConfig.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 66 | #include <utils/String16.h> |
| 67 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 68 | #include <utils/Timers.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 69 | #include <utils/Trace.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 70 | #include <utils/misc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 72 | #include <private/android_filesystem_config.h> |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 73 | #include <private/gui/SyncFeatures.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 75 | #include "BufferLayer.h" |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 76 | #include "BufferQueueLayer.h" |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 77 | #include "BufferStateLayer.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 78 | #include "Client.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 79 | #include "ColorLayer.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 80 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 81 | #include "ContainerLayer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 82 | #include "DisplayDevice.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | #include "Layer.h" |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 84 | #include "LayerVector.h" |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 85 | #include "MonitoredProducer.h" |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 86 | #include "NativeWindowSurface.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 87 | #include "StartPropertySetThread.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | #include "SurfaceFlinger.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 89 | #include "SurfaceInterceptor.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 91 | #include "DisplayHardware/ComposerHal.h" |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 92 | #include "DisplayHardware/DisplayIdentification.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 93 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 94 | #include "DisplayHardware/HWComposer.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 95 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 96 | #include "Effects/Daltonizer.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 97 | #include "Scheduler/DispSync.h" |
Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 98 | #include "Scheduler/DispSyncSource.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 99 | #include "Scheduler/EventControlThread.h" |
| 100 | #include "Scheduler/EventThread.h" |
Ana Krulec | 4745445 | 2018-08-14 11:04:14 -0700 | [diff] [blame] | 101 | #include "Scheduler/InjectVSyncSource.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 102 | #include "Scheduler/MessageQueue.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 103 | #include "Scheduler/Scheduler.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 104 | #include "TimeStats/TimeStats.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 105 | |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 106 | #include <cutils/compiler.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 107 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 108 | #include "android-base/stringprintf.h" |
| 109 | |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 110 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 111 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 112 | #include <android/hardware/configstore/1.1/types.h> |
Jaesoo Lee | 4351857 | 2017-01-23 19:03:16 +0900 | [diff] [blame] | 113 | #include <configstore/Utils.h> |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 114 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 115 | #include <layerproto/LayerProtoParser.h> |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 116 | #include "SurfaceFlingerProperties.h" |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 117 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | namespace android { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 119 | |
Jaesoo Lee | 4351857 | 2017-01-23 19:03:16 +0900 | [diff] [blame] | 120 | using namespace android::hardware::configstore; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 121 | using namespace android::hardware::configstore::V1_0; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 122 | using namespace android::sysprop; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 123 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 124 | using base::StringAppendF; |
Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 125 | using ui::ColorMode; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 126 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 127 | using ui::DisplayPrimaries; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 128 | using ui::Hdr; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 129 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 130 | |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 131 | using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; |
| 132 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 133 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 134 | |
| 135 | #pragma clang diagnostic push |
| 136 | #pragma clang diagnostic error "-Wswitch-enum" |
| 137 | |
| 138 | bool isWideColorMode(const ColorMode colorMode) { |
| 139 | switch (colorMode) { |
| 140 | case ColorMode::DISPLAY_P3: |
| 141 | case ColorMode::ADOBE_RGB: |
| 142 | case ColorMode::DCI_P3: |
| 143 | case ColorMode::BT2020: |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 144 | case ColorMode::DISPLAY_BT2020: |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 145 | case ColorMode::BT2100_PQ: |
| 146 | case ColorMode::BT2100_HLG: |
| 147 | return true; |
| 148 | case ColorMode::NATIVE: |
| 149 | case ColorMode::STANDARD_BT601_625: |
| 150 | case ColorMode::STANDARD_BT601_625_UNADJUSTED: |
| 151 | case ColorMode::STANDARD_BT601_525: |
| 152 | case ColorMode::STANDARD_BT601_525_UNADJUSTED: |
| 153 | case ColorMode::STANDARD_BT709: |
| 154 | case ColorMode::SRGB: |
| 155 | return false; |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 160 | ui::Transform::orientation_flags fromSurfaceComposerRotation(ISurfaceComposer::Rotation rotation) { |
| 161 | switch (rotation) { |
| 162 | case ISurfaceComposer::eRotateNone: |
| 163 | return ui::Transform::ROT_0; |
| 164 | case ISurfaceComposer::eRotate90: |
| 165 | return ui::Transform::ROT_90; |
| 166 | case ISurfaceComposer::eRotate180: |
| 167 | return ui::Transform::ROT_180; |
| 168 | case ISurfaceComposer::eRotate270: |
| 169 | return ui::Transform::ROT_270; |
| 170 | } |
| 171 | ALOGE("Invalid rotation passed to captureScreen(): %d\n", rotation); |
| 172 | return ui::Transform::ROT_0; |
| 173 | } |
| 174 | |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 175 | #pragma clang diagnostic pop |
| 176 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 177 | class ConditionalLock { |
| 178 | public: |
| 179 | ConditionalLock(Mutex& mutex, bool lock) : mMutex(mutex), mLocked(lock) { |
| 180 | if (lock) { |
| 181 | mMutex.lock(); |
| 182 | } |
| 183 | } |
| 184 | ~ConditionalLock() { if (mLocked) mMutex.unlock(); } |
| 185 | private: |
| 186 | Mutex& mMutex; |
| 187 | bool mLocked; |
| 188 | }; |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 189 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 190 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 191 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 192 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 193 | } |
| 194 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 195 | } // namespace anonymous |
| 196 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | // --------------------------------------------------------------------------- |
| 198 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 199 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 200 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
| 201 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
| 202 | const String16 sDump("android.permission.DUMP"); |
| 203 | |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 204 | constexpr float kDefaultRefreshRate = 60.f; |
| 205 | constexpr float kPerformanceRefreshRate = 90.f; |
| 206 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 207 | // --------------------------------------------------------------------------- |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 208 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 209 | bool SurfaceFlinger::useHwcForRgbToYuv; |
Fabien Sanglard | c8e387e | 2017-03-10 10:30:28 -0800 | [diff] [blame] | 210 | uint64_t SurfaceFlinger::maxVirtualDisplaySize; |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 211 | bool SurfaceFlinger::hasSyncFramework; |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 212 | bool SurfaceFlinger::useVrFlinger; |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 213 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 214 | bool SurfaceFlinger::hasWideColorDisplay; |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 215 | int SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientationDefault; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 216 | bool SurfaceFlinger::useColorManagement; |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 217 | bool SurfaceFlinger::useContextPriority; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 218 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 219 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 220 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 221 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 222 | |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 223 | std::string getHwcServiceName() { |
| 224 | char value[PROPERTY_VALUE_MAX] = {}; |
| 225 | property_get("debug.sf.hwc_service_name", value, "default"); |
| 226 | ALOGI("Using HWComposer service: '%s'", value); |
| 227 | return std::string(value); |
| 228 | } |
| 229 | |
| 230 | bool useTrebleTestingOverride() { |
| 231 | char value[PROPERTY_VALUE_MAX] = {}; |
| 232 | property_get("debug.sf.treble_testing_override", value, "false"); |
| 233 | ALOGI("Treble testing override: '%s'", value); |
| 234 | return std::string(value) == "true"; |
| 235 | } |
| 236 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 237 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 238 | switch(displayColorSetting) { |
| 239 | case DisplayColorSetting::MANAGED: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 240 | return std::string("Managed"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 241 | case DisplayColorSetting::UNMANAGED: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 242 | return std::string("Unmanaged"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 243 | case DisplayColorSetting::ENHANCED: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 244 | return std::string("Enhanced"); |
| 245 | default: |
| 246 | return std::string("Unknown ") + |
| 247 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 248 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 249 | } |
| 250 | |
David Sodman | bc81528 | 2017-11-05 18:57:52 -0800 | [diff] [blame] | 251 | SurfaceFlingerBE::SurfaceFlingerBE() |
| 252 | : mHwcServiceName(getHwcServiceName()), |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 253 | mFrameBuckets(), |
| 254 | mTotalTime(0), |
| 255 | mLastSwapTime(0), |
David Sodman | bc81528 | 2017-11-05 18:57:52 -0800 | [diff] [blame] | 256 | mComposerSequenceId(0) { |
| 257 | } |
| 258 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 259 | SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory, |
| 260 | SurfaceFlinger::SkipInitializationTag) |
Lloyd Pique | 12eb423 | 2018-01-17 11:54:43 -0800 | [diff] [blame] | 261 | : BnSurfaceComposer(), |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 262 | mFactory(factory), |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 263 | mTransactionPending(false), |
| 264 | mAnimTransactionPending(false), |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 265 | mLayersRemoved(false), |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 266 | mLayersAdded(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | mBootTime(systemTime()), |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 268 | mPhaseOffsets{getFactory().createPhaseOffsets()}, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | mVisibleRegionsDirty(false), |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 270 | mGeometryInvalid(false), |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 271 | mAnimCompositionPending(false), |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 272 | mBootStage(BootStage::BOOTLOADER), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | mDebugRegion(0), |
Mathias Agopian | 73d3ba9 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 274 | mDebugDisableHWC(0), |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 275 | mDebugDisableTransformHint(0), |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 276 | mDebugEnableProtectedContent(false), |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 277 | mDebugInTransaction(0), |
| 278 | mLastTransactionTime(0), |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 279 | mForceFullDamage(false), |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 280 | mTimeStats(factory.createTimeStats()), |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 281 | mRefreshStartTime(0), |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 282 | mHasPoweredOff(false), |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 283 | mNumLayers(0), |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 284 | mVrFlingerRequestsDisplay(false), |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 285 | mMainThreadId(std::this_thread::get_id()), |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 286 | mCompositionEngine{getFactory().createCompositionEngine()} { |
| 287 | mSetInputWindowsListener = new SetInputWindowsListener(this); |
| 288 | } |
Lloyd Pique | ac648ee | 2018-01-17 13:42:24 -0800 | [diff] [blame] | 289 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 290 | SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory) |
| 291 | : SurfaceFlinger(factory, SkipInitialization) { |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 292 | ALOGI("SurfaceFlinger is starting"); |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 293 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 294 | hasSyncFramework = running_without_sync_framework(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 296 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 297 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 298 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 299 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 300 | maxVirtualDisplaySize = max_virtual_display_dimension(0); |
Fabien Sanglard | c8e387e | 2017-03-10 10:30:28 -0800 | [diff] [blame] | 301 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 302 | // Vr flinger is only enabled on Daydream ready devices. |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 303 | useVrFlinger = use_vr_flinger(false); |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 304 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 305 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 306 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 307 | hasWideColorDisplay = has_wide_color_display(false); |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 308 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 309 | useColorManagement = use_color_management(false); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 310 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 311 | mDefaultCompositionDataspace = |
| 312 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 313 | mWideColorGamutCompositionDataspace = |
| 314 | static_cast<ui::Dataspace>(wcg_composition_dataspace(Dataspace::V0_SRGB)); |
| 315 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 316 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 317 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 318 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 319 | wideColorGamutCompositionPixelFormat = |
| 320 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 321 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 322 | useContextPriority = use_context_priority(true); |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 323 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 324 | auto tmpPrimaryDisplayOrientation = primary_display_orientation( |
| 325 | SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_0); |
| 326 | switch (tmpPrimaryDisplayOrientation) { |
| 327 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_90: |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 328 | SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation90; |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 329 | break; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 330 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_180: |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 331 | SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation180; |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 332 | break; |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 333 | case SurfaceFlingerProperties::primary_display_orientation_values::ORIENTATION_270: |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 334 | SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientation270; |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 335 | break; |
| 336 | default: |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 337 | SurfaceFlinger::primaryDisplayOrientation = DisplayState::eOrientationDefault; |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 338 | break; |
| 339 | } |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 340 | ALOGV("Primary Display Orientation is set to %2d.", SurfaceFlinger::primaryDisplayOrientation); |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 341 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 342 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 343 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | // debugging stuff... |
| 345 | char value[PROPERTY_VALUE_MAX]; |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 346 | |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 347 | property_get("ro.bq.gpu_to_cpu_unsupported", value, "0"); |
Mathias Agopian | 50210b9 | 2013-03-21 21:13:21 -0700 | [diff] [blame] | 348 | mGpuToCpuSupported = !atoi(value); |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 349 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | property_get("debug.sf.showupdates", value, "0"); |
| 351 | mDebugRegion = atoi(value); |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 352 | |
Mathias Agopian | c1d359d | 2012-08-04 20:09:03 -0700 | [diff] [blame] | 353 | ALOGI_IF(mDebugRegion, "showupdates enabled"); |
Orion Hodson | 34397da | 2019-02-04 09:36:10 +0000 | [diff] [blame] | 354 | |
| 355 | // DDMS debugging deprecated (b/120782499) |
| 356 | property_get("debug.sf.ddms", value, "0"); |
| 357 | int debugDdms = atoi(value); |
| 358 | ALOGI_IF(debugDdms, "DDMS debugging not supported"); |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 359 | |
| 360 | property_get("debug.sf.disable_backpressure", value, "0"); |
| 361 | mPropagateBackpressure = !atoi(value); |
| 362 | ALOGI_IF(!mPropagateBackpressure, "Disabling backpressure propagation"); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 363 | |
Fabien Sanglard | 642b23d | 2017-02-09 12:29:39 -0800 | [diff] [blame] | 364 | property_get("debug.sf.enable_hwc_vds", value, "0"); |
| 365 | mUseHwcVirtualDisplays = atoi(value); |
Chia-I Wu | 11d1061 | 2018-06-21 15:41:13 +0800 | [diff] [blame] | 366 | ALOGI_IF(mUseHwcVirtualDisplays, "Enabling HWC virtual displays"); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 367 | |
Yiwei Zhang | b770ed3 | 2018-12-17 17:44:28 -0800 | [diff] [blame] | 368 | property_get("ro.sf.disable_triple_buffer", value, "0"); |
Fabien Sanglard | c65dafa | 2017-02-07 14:06:39 -0800 | [diff] [blame] | 369 | mLayerTripleBufferingDisabled = atoi(value); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 370 | ALOGI_IF(mLayerTripleBufferingDisabled, "Disabling Triple Buffering"); |
Romain Guy | 3054f00 | 2017-06-05 18:38:53 -0700 | [diff] [blame] | 371 | |
Yiwei Zhang | 243b378 | 2018-05-15 17:40:04 -0700 | [diff] [blame] | 372 | const size_t defaultListSize = MAX_LAYERS; |
Dan Stoza | 0a0158c | 2018-03-16 13:38:54 -0700 | [diff] [blame] | 373 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 374 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
| 375 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 376 | property_get("debug.sf.use_90Hz", value, "0"); |
| 377 | mUse90Hz = atoi(value); |
Ady Abraham | c3e2131 | 2019-02-07 14:30:23 -0800 | [diff] [blame] | 378 | |
Ana Krulec | ba13ab3 | 2019-02-20 14:14:12 -0800 | [diff] [blame] | 379 | property_get("debug.sf.use_smart_90_for_video", value, "0"); |
| 380 | mUseSmart90ForVideo = atoi(value); |
| 381 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 382 | property_get("debug.sf.luma_sampling", value, "1"); |
| 383 | mLumaSampling = atoi(value); |
| 384 | |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 385 | const auto [early, gl, late] = mPhaseOffsets->getCurrentOffsets(); |
| 386 | mVsyncModulator.setPhaseOffsets(early, gl, late); |
Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 387 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 388 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 389 | // but since /data may be encrypted, we need to wait until after vold |
| 390 | // comes online to attempt to read the property. The property is |
| 391 | // instead read after the boot animation |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 392 | |
| 393 | if (useTrebleTestingOverride()) { |
| 394 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 395 | // services that are not listed in the manifests. Considered |
| 396 | // deriving the setting from the set service name, but it |
| 397 | // would be brittle if the name that's not 'default' is used |
| 398 | // for production purposes later on. |
| 399 | setenv("TREBLE_TESTING_OVERRIDE", "true", true); |
| 400 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 403 | void SurfaceFlinger::onFirstRef() |
| 404 | { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 405 | mEventQueue->init(this); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 406 | } |
| 407 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | SurfaceFlinger::~SurfaceFlinger() |
| 409 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 412 | void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */) |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 413 | { |
| 414 | // the window manager died on us. prepare its eulogy. |
| 415 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 416 | // restore initial conditions (default device unblank, etc) |
| 417 | initializeDisplays(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 418 | |
| 419 | // restart the boot-animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 420 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 423 | static sp<ISurfaceComposerClient> initClient(const sp<Client>& client) { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 424 | status_t err = client->initCheck(); |
| 425 | if (err == NO_ERROR) { |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 426 | return client; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 428 | return nullptr; |
| 429 | } |
| 430 | |
| 431 | sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() { |
| 432 | return initClient(new Client(this)); |
| 433 | } |
| 434 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 435 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, |
| 436 | bool secure) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 437 | { |
| 438 | class DisplayToken : public BBinder { |
| 439 | sp<SurfaceFlinger> flinger; |
| 440 | virtual ~DisplayToken() { |
| 441 | // no more references, this display must be terminated |
| 442 | Mutex::Autolock _l(flinger->mStateLock); |
| 443 | flinger->mCurrentState.displays.removeItem(this); |
| 444 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 445 | } |
| 446 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 447 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 448 | : flinger(flinger) { |
| 449 | } |
| 450 | }; |
| 451 | |
| 452 | sp<BBinder> token = new DisplayToken(this); |
| 453 | |
| 454 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 455 | // Display ID is assigned when virtual display is allocated by HWC. |
| 456 | DisplayDeviceState state; |
| 457 | state.isSecure = secure; |
| 458 | state.displayName = displayName; |
| 459 | mCurrentState.displays.add(token, state); |
| 460 | mInterceptor->saveDisplayCreation(state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 461 | return token; |
| 462 | } |
| 463 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 464 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 465 | Mutex::Autolock _l(mStateLock); |
| 466 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 467 | ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
| 468 | if (index < 0) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 469 | ALOGE("destroyDisplay: Invalid display token %p", displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 473 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
| 474 | if (!state.isVirtual()) { |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 475 | ALOGE("destroyDisplay called for non-virtual display"); |
| 476 | return; |
| 477 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 478 | mInterceptor->saveDisplayDeletion(state.sequenceId); |
| 479 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 480 | setTransactionFlags(eDisplayTransactionNeeded); |
| 481 | } |
| 482 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 483 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIds() const { |
| 484 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 485 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 486 | const auto internalDisplayId = getInternalDisplayIdLocked(); |
| 487 | if (!internalDisplayId) { |
| 488 | return {}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 491 | std::vector<PhysicalDisplayId> displayIds; |
| 492 | displayIds.reserve(mPhysicalDisplayTokens.size()); |
| 493 | displayIds.push_back(internalDisplayId->value); |
| 494 | |
| 495 | for (const auto& [id, token] : mPhysicalDisplayTokens) { |
| 496 | if (id != *internalDisplayId) { |
| 497 | displayIds.push_back(id.value); |
| 498 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 499 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 500 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 501 | return displayIds; |
| 502 | } |
| 503 | |
| 504 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 505 | Mutex::Autolock lock(mStateLock); |
| 506 | return getPhysicalDisplayTokenLocked(DisplayId{displayId}); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 509 | status_t SurfaceFlinger::getColorManagement(bool* outGetColorManagement) const { |
| 510 | if (!outGetColorManagement) { |
| 511 | return BAD_VALUE; |
| 512 | } |
| 513 | *outGetColorManagement = useColorManagement; |
| 514 | return NO_ERROR; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 517 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 518 | return mCompositionEngine->getHwComposer(); |
| 519 | } |
| 520 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 521 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
| 522 | return mCompositionEngine->getRenderEngine(); |
| 523 | } |
| 524 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 525 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 526 | return *mCompositionEngine.get(); |
| 527 | } |
| 528 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | void SurfaceFlinger::bootFinished() |
| 530 | { |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 531 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 532 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 533 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | const nsecs_t now = systemTime(); |
| 535 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 536 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 537 | |
| 538 | // wait patiently for the window manager death |
| 539 | const String16 name("window"); |
| 540 | sp<IBinder> window(defaultServiceManager()->getService(name)); |
| 541 | if (window != 0) { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 542 | window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 543 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 544 | sp<IBinder> input(defaultServiceManager()->getService( |
| 545 | String16("inputflinger"))); |
| 546 | if (input == nullptr) { |
| 547 | ALOGE("Failed to link to input service"); |
| 548 | } else { |
| 549 | mInputFlinger = interface_cast<IInputFlinger>(input); |
| 550 | } |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 551 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 552 | if (mVrFlinger) { |
| 553 | mVrFlinger->OnBootFinished(); |
| 554 | } |
| 555 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 556 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 557 | // formerly we would just kill the process, but we now ask it to exit so it |
| 558 | // can choose where to stop the animation. |
| 559 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 560 | |
| 561 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 562 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 563 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 564 | |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 565 | postMessageAsync(new LambdaMessage([this]() NO_THREAD_SAFETY_ANALYSIS { |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 566 | readPersistentProperties(); |
| 567 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 568 | |
| 569 | // TODO(b/122905403): Once the display policy is completely integrated, this flag should go |
| 570 | // away and it should be controlled by flipping the switch in setting. The switch in |
| 571 | // settings should only be available to P19 devices, if they are opted into 90Hz fishfood. |
| 572 | // The boot must be complete before we can set the active config. |
| 573 | |
| 574 | if (mUse90Hz) { |
| 575 | mPhaseOffsets->setRefreshRateType( |
| 576 | scheduler::RefreshRateConfigs::RefreshRateType::PERFORMANCE); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 577 | setRefreshRateTo(RefreshRateType::PERFORMANCE, ConfigEvent::None); |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 578 | } else { |
| 579 | mPhaseOffsets->setRefreshRateType( |
| 580 | scheduler::RefreshRateConfigs::RefreshRateType::DEFAULT); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 581 | setRefreshRateTo(RefreshRateType::DEFAULT, ConfigEvent::None); |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 582 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 583 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 586 | uint32_t SurfaceFlinger::getNewTexture() { |
| 587 | { |
| 588 | std::lock_guard lock(mTexturePoolMutex); |
| 589 | if (!mTexturePool.empty()) { |
| 590 | uint32_t name = mTexturePool.back(); |
| 591 | mTexturePool.pop_back(); |
| 592 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
| 593 | return name; |
| 594 | } |
| 595 | |
| 596 | // The pool was too small, so increase it for the future |
| 597 | ++mTexturePoolSize; |
| 598 | } |
| 599 | |
| 600 | // The pool was empty, so we need to get a new texture name directly using a |
| 601 | // blocking call to the main thread |
| 602 | uint32_t name = 0; |
| 603 | postMessageSync(new LambdaMessage([&]() { getRenderEngine().genTextures(1, &name); })); |
| 604 | return name; |
| 605 | } |
| 606 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 607 | void SurfaceFlinger::deleteTextureAsync(uint32_t texture) { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 608 | postMessageAsync(new LambdaMessage([=] { getRenderEngine().deleteTextures(1, &texture); })); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 611 | // Do not call property_set on main thread which will be blocked by init |
| 612 | // Use StartPropertySetThread instead. |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 613 | void SurfaceFlinger::init() { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 614 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 615 | "Initializing graphics H/W..."); |
| 616 | |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 617 | ALOGI("Phase offset NS: %" PRId64 "", mPhaseOffsets->getCurrentAppOffset()); |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 618 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 619 | Mutex::Autolock _l(mStateLock); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 620 | // start the EventThread |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 621 | mScheduler = |
| 622 | getFactory().createScheduler([this](bool enabled) { setPrimaryVsyncEnabled(enabled); }); |
| 623 | auto resyncCallback = |
| 624 | mScheduler->makeResyncCallback(std::bind(&SurfaceFlinger::getVsyncPeriod, this)); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 625 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 626 | mAppConnectionHandle = |
| 627 | mScheduler->createConnection("app", mPhaseOffsets->getCurrentAppOffset(), |
| 628 | resyncCallback, |
| 629 | impl::EventThread::InterceptVSyncsCallback()); |
| 630 | mSfConnectionHandle = mScheduler->createConnection("sf", mPhaseOffsets->getCurrentSfOffset(), |
| 631 | resyncCallback, [this](nsecs_t timestamp) { |
| 632 | mInterceptor->saveVSyncEvent(timestamp); |
| 633 | }); |
| 634 | |
| 635 | mEventQueue->setEventConnection(mScheduler->getEventConnection(mSfConnectionHandle)); |
| 636 | mVsyncModulator.setSchedulerAndHandles(mScheduler.get(), mAppConnectionHandle.get(), |
| 637 | mSfConnectionHandle.get()); |
| 638 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 639 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 640 | int32_t renderEngineFeature = 0; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 641 | renderEngineFeature |= (useColorManagement ? |
| 642 | renderengine::RenderEngine::USE_COLOR_MANAGEMENT : 0); |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 643 | renderEngineFeature |= (useContextPriority ? |
| 644 | renderengine::RenderEngine::USE_HIGH_PRIORITY_CONTEXT : 0); |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 645 | |
| 646 | // TODO(b/77156734): We need to stop casting and use HAL types when possible. |
Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 647 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 648 | mCompositionEngine->setRenderEngine( |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 649 | renderengine::RenderEngine::create(static_cast<int32_t>(defaultCompositionPixelFormat), |
Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 650 | renderEngineFeature, maxFrameBufferAcquiredBuffers)); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 651 | |
| 652 | LOG_ALWAYS_FATAL_IF(mVrFlingerRequestsDisplay, |
| 653 | "Starting with vr flinger active is not currently supported."); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 654 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(getBE().mHwcServiceName)); |
| 655 | mCompositionEngine->getHwComposer().registerCallback(this, getBE().mComposerSequenceId); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 656 | // Process any initial hotplug and resulting display changes. |
| 657 | processDisplayHotplugEventsLocked(); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 658 | const auto display = getDefaultDisplayDeviceLocked(); |
| 659 | LOG_ALWAYS_FATAL_IF(!display, "Missing internal display after registering composer callback."); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 660 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(*display->getId()), |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 661 | "Internal display is disconnected."); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 662 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 663 | if (useVrFlinger) { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 664 | auto vrFlingerRequestDisplayCallback = [this](bool requestDisplay) { |
Steven Thomas | be6cbae | 2017-09-28 15:30:23 -0700 | [diff] [blame] | 665 | // This callback is called from the vr flinger dispatch thread. We |
| 666 | // need to call signalTransaction(), which requires holding |
| 667 | // mStateLock when we're not on the main thread. Acquiring |
| 668 | // mStateLock from the vr flinger dispatch thread might trigger a |
| 669 | // deadlock in surface flinger (see b/66916578), so post a message |
| 670 | // to be handled on the main thread instead. |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 671 | postMessageAsync(new LambdaMessage([=] { |
Steven Thomas | be6cbae | 2017-09-28 15:30:23 -0700 | [diff] [blame] | 672 | ALOGI("VR request display mode: requestDisplay=%d", requestDisplay); |
| 673 | mVrFlingerRequestsDisplay = requestDisplay; |
| 674 | signalTransaction(); |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 675 | })); |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 676 | }; |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 677 | mVrFlinger = dvr::VrFlinger::Create(getHwComposer().getComposer(), |
| 678 | getHwComposer() |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 679 | .fromPhysicalDisplayId(*display->getId()) |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 680 | .value_or(0), |
| 681 | vrFlingerRequestDisplayCallback); |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 682 | if (!mVrFlinger) { |
| 683 | ALOGE("Failed to start vrflinger"); |
| 684 | } |
| 685 | } |
| 686 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 687 | // initialize our drawing state |
| 688 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 689 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 690 | // set initial conditions (e.g. unblank default device) |
| 691 | initializeDisplays(); |
| 692 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 693 | getRenderEngine().primeCache(); |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 694 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 695 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 696 | |
| 697 | const bool presentFenceReliable = |
| 698 | !getHwComposer().hasCapability(HWC2::Capability::PresentFenceIsNotReliable); |
| 699 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 700 | |
| 701 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 702 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 703 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | |
Kevin DuBois | 3623313 | 2019-02-19 14:08:55 -0800 | [diff] [blame] | 705 | if (mUse90Hz) { |
| 706 | mScheduler->setExpiredIdleTimerCallback([this] { |
| 707 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 708 | setRefreshRateTo(RefreshRateType::DEFAULT, ConfigEvent::None); |
Kevin DuBois | 3623313 | 2019-02-19 14:08:55 -0800 | [diff] [blame] | 709 | }); |
| 710 | mScheduler->setResetIdleTimerCallback([this] { |
| 711 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 712 | setRefreshRateTo(RefreshRateType::PERFORMANCE, ConfigEvent::None); |
Kevin DuBois | 3623313 | 2019-02-19 14:08:55 -0800 | [diff] [blame] | 713 | }); |
| 714 | } |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 715 | mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(getHwComposer().getConfigs( |
| 716 | *display->getId()), |
| 717 | mTimeStats); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 718 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 719 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 722 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 723 | Mutex::Autolock _l(mStateLock); |
| 724 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 725 | char value[PROPERTY_VALUE_MAX]; |
| 726 | |
| 727 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 728 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 729 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 730 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 731 | |
| 732 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 733 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 734 | |
| 735 | property_get("persist.sys.sf.color_mode", value, "0"); |
| 736 | mForceColorMode = static_cast<ColorMode>(atoi(value)); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 739 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 740 | // Start boot animation service by setting a property mailbox |
| 741 | // if property setting thread is already running, Start() will be just a NOP |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 742 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 743 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 744 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 745 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 746 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 749 | size_t SurfaceFlinger::getMaxTextureSize() const { |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 750 | return getRenderEngine().getMaxTextureSize(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 753 | size_t SurfaceFlinger::getMaxViewportDims() const { |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 754 | return getRenderEngine().getMaxViewportDims(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 755 | } |
| 756 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 758 | |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 759 | bool SurfaceFlinger::authenticateSurfaceTexture( |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 760 | const sp<IGraphicBufferProducer>& bufferProducer) const { |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 761 | Mutex::Autolock _l(mStateLock); |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 762 | return authenticateSurfaceTextureLocked(bufferProducer); |
| 763 | } |
| 764 | |
| 765 | bool SurfaceFlinger::authenticateSurfaceTextureLocked( |
| 766 | const sp<IGraphicBufferProducer>& bufferProducer) const { |
Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 767 | sp<IBinder> surfaceTextureBinder(IInterface::asBinder(bufferProducer)); |
Dan Stoza | 101d8dc | 2018-02-27 15:42:25 -0800 | [diff] [blame] | 768 | return mGraphicBufferProducerList.count(surfaceTextureBinder.get()) > 0; |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 771 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 772 | std::vector<FrameEvent>* outSupported) const { |
| 773 | *outSupported = { |
| 774 | FrameEvent::REQUESTED_PRESENT, |
| 775 | FrameEvent::ACQUIRE, |
| 776 | FrameEvent::LATCH, |
| 777 | FrameEvent::FIRST_REFRESH_START, |
| 778 | FrameEvent::LAST_REFRESH_START, |
| 779 | FrameEvent::GPU_COMPOSITION_DONE, |
| 780 | FrameEvent::DEQUEUE_READY, |
| 781 | FrameEvent::RELEASE, |
| 782 | }; |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 783 | ConditionalLock _l(mStateLock, |
| 784 | std::this_thread::get_id() != mMainThreadId); |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 785 | if (!getHwComposer().hasCapability( |
| 786 | HWC2::Capability::PresentFenceIsNotReliable)) { |
| 787 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 788 | } |
| 789 | return NO_ERROR; |
| 790 | } |
| 791 | |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 792 | status_t SurfaceFlinger::getDisplayConfigsLocked(const sp<IBinder>& displayToken, |
| 793 | Vector<DisplayInfo>* configs) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 794 | if (!displayToken || !configs) { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 795 | return BAD_VALUE; |
| 796 | } |
| 797 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 798 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 799 | if (!displayId) { |
| 800 | return NAME_NOT_FOUND; |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 801 | } |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 802 | |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 803 | // TODO: Not sure if display density should handled by SF any longer |
| 804 | class Density { |
Hernan Liatis | 5756893 | 2018-08-16 17:07:08 -0700 | [diff] [blame] | 805 | static float getDensityFromProperty(char const* propName) { |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 806 | char property[PROPERTY_VALUE_MAX]; |
Hernan Liatis | 5756893 | 2018-08-16 17:07:08 -0700 | [diff] [blame] | 807 | float density = 0.0f; |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 808 | if (property_get(propName, property, nullptr) > 0) { |
Hernan Liatis | 5756893 | 2018-08-16 17:07:08 -0700 | [diff] [blame] | 809 | density = strtof(property, nullptr); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 810 | } |
| 811 | return density; |
| 812 | } |
| 813 | public: |
Hernan Liatis | 5756893 | 2018-08-16 17:07:08 -0700 | [diff] [blame] | 814 | static float getEmuDensity() { |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 815 | return getDensityFromProperty("qemu.sf.lcd_density"); } |
Hernan Liatis | 5756893 | 2018-08-16 17:07:08 -0700 | [diff] [blame] | 816 | static float getBuildDensity() { |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 817 | return getDensityFromProperty("ro.sf.lcd_density"); } |
| 818 | }; |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 819 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 820 | configs->clear(); |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 821 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 822 | for (const auto& hwConfig : getHwComposer().getConfigs(*displayId)) { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 823 | DisplayInfo info = DisplayInfo(); |
| 824 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 825 | float xdpi = hwConfig->getDpiX(); |
| 826 | float ydpi = hwConfig->getDpiY(); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 827 | |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 828 | info.w = hwConfig->getWidth(); |
| 829 | info.h = hwConfig->getHeight(); |
| 830 | // Default display viewport to display width and height |
| 831 | info.viewportW = info.w; |
| 832 | info.viewportH = info.h; |
| 833 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 834 | if (displayId == getInternalDisplayIdLocked()) { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 835 | // The density of the device is provided by a build property |
| 836 | float density = Density::getBuildDensity() / 160.0f; |
| 837 | if (density == 0) { |
| 838 | // the build doesn't provide a density -- this is wrong! |
| 839 | // use xdpi instead |
| 840 | ALOGE("ro.sf.lcd_density must be defined as a build property"); |
| 841 | density = xdpi / 160.0f; |
| 842 | } |
| 843 | if (Density::getEmuDensity()) { |
| 844 | // if "qemu.sf.lcd_density" is specified, it overrides everything |
| 845 | xdpi = ydpi = density = Density::getEmuDensity(); |
| 846 | density /= 160.0f; |
| 847 | } |
| 848 | info.density = density; |
| 849 | |
| 850 | // TODO: this needs to go away (currently needed only by webkit) |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 851 | const auto display = getDefaultDisplayDeviceLocked(); |
| 852 | info.orientation = display ? display->getOrientation() : 0; |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 853 | |
| 854 | // This is for screenrecord |
| 855 | const Rect viewport = display->getViewport(); |
| 856 | if (viewport.isValid()) { |
| 857 | info.viewportW = uint32_t(viewport.getWidth()); |
| 858 | info.viewportH = uint32_t(viewport.getHeight()); |
| 859 | } |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 860 | } else { |
| 861 | // TODO: where should this value come from? |
| 862 | static const int TV_DENSITY = 213; |
| 863 | info.density = TV_DENSITY / 160.0f; |
| 864 | info.orientation = 0; |
| 865 | } |
| 866 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 867 | info.xdpi = xdpi; |
| 868 | info.ydpi = ydpi; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 869 | info.fps = 1e9 / hwConfig->getVsyncPeriod(); |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 870 | info.appVsyncOffset = mPhaseOffsets->getCurrentAppOffset(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 871 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 872 | // This is how far in advance a buffer must be queued for |
| 873 | // presentation at a given time. If you want a buffer to appear |
| 874 | // on the screen at time N, you must submit the buffer before |
| 875 | // (N - presentationDeadline). |
| 876 | // |
| 877 | // Normally it's one full refresh period (to give SF a chance to |
| 878 | // latch the buffer), but this can be reduced by configuring a |
| 879 | // DispSync offset. Any additional delays introduced by the hardware |
| 880 | // composer or panel must be accounted for here. |
| 881 | // |
| 882 | // We add an additional 1ms to allow for processing time and |
| 883 | // differences between the ideal and actual refresh rate. |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 884 | info.presentationDeadline = |
| 885 | hwConfig->getVsyncPeriod() - mPhaseOffsets->getCurrentSfOffset() + 1000000; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 886 | |
| 887 | // All non-virtual displays are currently considered secure. |
| 888 | info.secure = true; |
| 889 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 890 | if (displayId == getInternalDisplayIdLocked() && |
Chia-I Wu | 304d9cd | 2018-08-27 14:38:14 -0700 | [diff] [blame] | 891 | primaryDisplayOrientation & DisplayState::eOrientationSwapMask) { |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 892 | std::swap(info.w, info.h); |
| 893 | } |
| 894 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 895 | configs->push_back(info); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 898 | return NO_ERROR; |
| 899 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 900 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 901 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>&, DisplayStatInfo* stats) { |
| 902 | if (!stats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 903 | return BAD_VALUE; |
| 904 | } |
| 905 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 906 | mScheduler->getDisplayStatInfo(stats); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 907 | return NO_ERROR; |
| 908 | } |
| 909 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 910 | int SurfaceFlinger::getActiveConfig(const sp<IBinder>& displayToken) { |
| 911 | const auto display = getDisplayDevice(displayToken); |
| 912 | if (!display) { |
| 913 | ALOGE("getActiveConfig: Invalid display token %p", displayToken.get()); |
Jinguang Dong | 9f8b9ae | 2016-11-29 13:55:57 +0800 | [diff] [blame] | 914 | return BAD_VALUE; |
| 915 | } |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 916 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 917 | return display->getActiveConfig(); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 918 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 919 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 920 | void SurfaceFlinger::setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode, |
| 921 | ConfigEvent event) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 922 | ATRACE_CALL(); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 923 | |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 924 | Vector<DisplayInfo> configs; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 925 | // Lock is acquired by setRefreshRateTo. |
| 926 | getDisplayConfigsLocked(displayToken, &configs); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 927 | if (mode < 0 || mode >= static_cast<int>(configs.size())) { |
| 928 | ALOGE("Attempt to set active config %d for display with %zu configs", mode, configs.size()); |
| 929 | return; |
| 930 | } |
| 931 | |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 932 | // Lock is acquired by setRefreshRateTo. |
| 933 | const auto display = getDisplayDeviceLocked(displayToken); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 934 | if (!display) { |
| 935 | ALOGE("Attempt to set active config %d for invalid display token %p", mode, |
| 936 | displayToken.get()); |
| 937 | return; |
| 938 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 939 | if (display->isVirtual()) { |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 940 | ALOGW("Attempt to set active config %d for virtual display", mode); |
| 941 | return; |
| 942 | } |
| 943 | int currentDisplayPowerMode = display->getPowerMode(); |
| 944 | if (currentDisplayPowerMode != HWC_POWER_MODE_NORMAL) { |
| 945 | // Don't change active config when in AoD. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 946 | return; |
| 947 | } |
| 948 | |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 949 | // Don't check against the current mode yet. Worst case we set the desired |
Ady Abraham | 9360a22 | 2019-02-27 17:05:30 -0800 | [diff] [blame] | 950 | // config twice. However event generation config might have changed so we need to update it |
| 951 | // accordingly |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 952 | std::lock_guard<std::mutex> lock(mActiveConfigLock); |
Ady Abraham | 9360a22 | 2019-02-27 17:05:30 -0800 | [diff] [blame] | 953 | const ConfigEvent desiredConfig = mDesiredActiveConfig.event | event; |
| 954 | mDesiredActiveConfig = ActiveConfigInfo{mode, displayToken, desiredConfig}; |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 955 | |
| 956 | if (!mDesiredActiveConfigChanged) { |
| 957 | // This is the first time we set the desired |
| 958 | mScheduler->pauseVsyncCallback(mAppConnectionHandle, true); |
| 959 | |
| 960 | // This will trigger HWC refresh without resetting the idle timer. |
| 961 | repaintEverythingForHWC(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 962 | } |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 963 | mDesiredActiveConfigChanged = true; |
| 964 | ATRACE_INT("DesiredActiveConfigChanged", mDesiredActiveConfigChanged); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int mode) { |
| 968 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 969 | |
| 970 | std::vector<int32_t> allowedConfig; |
| 971 | allowedConfig.push_back(mode); |
| 972 | |
| 973 | return setAllowedDisplayConfigs(displayToken, allowedConfig); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 974 | } |
| 975 | |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 976 | void SurfaceFlinger::setActiveConfigInternal() { |
| 977 | ATRACE_CALL(); |
| 978 | |
| 979 | std::lock_guard<std::mutex> lock(mActiveConfigLock); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 980 | mRefreshRateStats->setConfigMode(mUpcomingActiveConfig.configId); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 981 | |
| 982 | const auto display = getDisplayDeviceLocked(mUpcomingActiveConfig.displayToken); |
| 983 | display->setActiveConfig(mUpcomingActiveConfig.configId); |
| 984 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 985 | mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 986 | ATRACE_INT("ActiveConfigMode", mUpcomingActiveConfig.configId); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 987 | if (mUpcomingActiveConfig.event != ConfigEvent::None) { |
| 988 | mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value, |
| 989 | mUpcomingActiveConfig.configId); |
| 990 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 993 | bool SurfaceFlinger::performSetActiveConfig() NO_THREAD_SAFETY_ANALYSIS { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 994 | ATRACE_CALL(); |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 995 | // we may be in the process of changing the active state |
| 996 | if (mWaitForNextInvalidate) { |
| 997 | mWaitForNextInvalidate = false; |
| 998 | |
| 999 | repaintEverythingForHWC(); |
| 1000 | // We do not want to give another frame to HWC while we are transitioning. |
| 1001 | return true; |
| 1002 | } |
| 1003 | |
| 1004 | if (mCheckPendingFence) { |
| 1005 | if (mPreviousPresentFence != Fence::NO_FENCE && |
| 1006 | (mPreviousPresentFence->getStatus() == Fence::Status::Unsignaled)) { |
| 1007 | // fence has not signaled yet. wait for the next invalidate |
| 1008 | repaintEverythingForHWC(); |
| 1009 | return true; |
| 1010 | } |
| 1011 | |
| 1012 | // We received the present fence from the HWC, so we assume it successfully updated |
| 1013 | // the config, hence we update SF. |
| 1014 | mCheckPendingFence = false; |
| 1015 | setActiveConfigInternal(); |
| 1016 | } |
| 1017 | |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1018 | // Store the local variable to release the lock. |
| 1019 | ActiveConfigInfo desiredActiveConfig; |
| 1020 | { |
| 1021 | std::lock_guard<std::mutex> lock(mActiveConfigLock); |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 1022 | if (!mDesiredActiveConfigChanged) { |
| 1023 | return false; |
| 1024 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1025 | desiredActiveConfig = mDesiredActiveConfig; |
| 1026 | } |
| 1027 | |
| 1028 | const auto display = getDisplayDevice(desiredActiveConfig.displayToken); |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 1029 | if (!display || display->getActiveConfig() == desiredActiveConfig.configId) { |
| 1030 | // display is not valid or we are already in the requested mode |
| 1031 | // on both cases there is nothing left to do |
| 1032 | std::lock_guard<std::mutex> lock(mActiveConfigLock); |
| 1033 | mScheduler->pauseVsyncCallback(mAppConnectionHandle, false); |
| 1034 | mDesiredActiveConfigChanged = false; |
| 1035 | ATRACE_INT("DesiredActiveConfigChanged", mDesiredActiveConfigChanged); |
| 1036 | return false; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1037 | } |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 1038 | |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1039 | // Desired active config was set, it is different than the config currently in use, however |
| 1040 | // allowed configs might have change by the time we process the refresh. |
| 1041 | // Make sure the desired config is still allowed |
| 1042 | if (!isConfigAllowed(*display->getId(), desiredActiveConfig.configId)) { |
| 1043 | std::lock_guard<std::mutex> lock(mActiveConfigLock); |
| 1044 | mDesiredActiveConfig.configId = display->getActiveConfig(); |
| 1045 | return false; |
| 1046 | } |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 1047 | mUpcomingActiveConfig = desiredActiveConfig; |
| 1048 | const auto displayId = display->getId(); |
| 1049 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 1050 | |
| 1051 | ATRACE_INT("ActiveConfigModeHWC", mUpcomingActiveConfig.configId); |
| 1052 | getHwComposer().setActiveConfig(*displayId, mUpcomingActiveConfig.configId); |
| 1053 | |
| 1054 | // we need to submit an empty frame to HWC to start the process |
| 1055 | mWaitForNextInvalidate = true; |
| 1056 | mCheckPendingFence = true; |
| 1057 | |
| 1058 | return false; |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1059 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1060 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1061 | status_t SurfaceFlinger::getDisplayColorModes(const sp<IBinder>& displayToken, |
| 1062 | Vector<ColorMode>* outColorModes) { |
| 1063 | if (!displayToken || !outColorModes) { |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1064 | return BAD_VALUE; |
| 1065 | } |
| 1066 | |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 1067 | std::vector<ColorMode> modes; |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 1068 | { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1069 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 1070 | |
| 1071 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1072 | if (!displayId) { |
| 1073 | return NAME_NOT_FOUND; |
| 1074 | } |
| 1075 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1076 | modes = getHwComposer().getColorModes(*displayId); |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 1077 | } |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1078 | outColorModes->clear(); |
| 1079 | std::copy(modes.cbegin(), modes.cend(), std::back_inserter(*outColorModes)); |
| 1080 | |
| 1081 | return NO_ERROR; |
| 1082 | } |
| 1083 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1084 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
| 1085 | ui::DisplayPrimaries &primaries) { |
| 1086 | if (!displayToken) { |
| 1087 | return BAD_VALUE; |
| 1088 | } |
| 1089 | |
| 1090 | // Currently we only support this API for a single internal display. |
| 1091 | if (getInternalDisplayToken() != displayToken) { |
| 1092 | return BAD_VALUE; |
| 1093 | } |
| 1094 | |
| 1095 | memcpy(&primaries, &mInternalDisplayPrimaries, sizeof(ui::DisplayPrimaries)); |
| 1096 | return NO_ERROR; |
| 1097 | } |
| 1098 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1099 | ColorMode SurfaceFlinger::getActiveColorMode(const sp<IBinder>& displayToken) { |
| 1100 | if (const auto display = getDisplayDevice(displayToken)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1101 | return display->getCompositionDisplay()->getState().colorMode; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1102 | } |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 1103 | return static_cast<ColorMode>(BAD_VALUE); |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1106 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ColorMode mode) { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 1107 | postMessageSync(new LambdaMessage([&] { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1108 | Vector<ColorMode> modes; |
| 1109 | getDisplayColorModes(displayToken, &modes); |
| 1110 | bool exists = std::find(std::begin(modes), std::end(modes), mode) != std::end(modes); |
| 1111 | if (mode < ColorMode::NATIVE || !exists) { |
| 1112 | ALOGE("Attempt to set invalid active color mode %s (%d) for display token %p", |
| 1113 | decodeColorMode(mode).c_str(), mode, displayToken.get()); |
| 1114 | return; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1115 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1116 | const auto display = getDisplayDevice(displayToken); |
| 1117 | if (!display) { |
| 1118 | ALOGE("Attempt to set active color mode %s (%d) for invalid display token %p", |
| 1119 | decodeColorMode(mode).c_str(), mode, displayToken.get()); |
| 1120 | } else if (display->isVirtual()) { |
| 1121 | ALOGW("Attempt to set active color mode %s (%d) for virtual display", |
| 1122 | decodeColorMode(mode).c_str(), mode); |
| 1123 | } else { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1124 | display->getCompositionDisplay()->setColorMode(mode, Dataspace::UNKNOWN, |
| 1125 | RenderIntent::COLORIMETRIC); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1126 | } |
| 1127 | })); |
| 1128 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1129 | return NO_ERROR; |
| 1130 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1131 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1132 | status_t SurfaceFlinger::clearAnimationFrameStats() { |
| 1133 | Mutex::Autolock _l(mStateLock); |
| 1134 | mAnimFrameTracker.clearStats(); |
| 1135 | return NO_ERROR; |
| 1136 | } |
| 1137 | |
| 1138 | status_t SurfaceFlinger::getAnimationFrameStats(FrameStats* outStats) const { |
| 1139 | Mutex::Autolock _l(mStateLock); |
| 1140 | mAnimFrameTracker.getStats(outStats); |
| 1141 | return NO_ERROR; |
| 1142 | } |
| 1143 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1144 | status_t SurfaceFlinger::getHdrCapabilities(const sp<IBinder>& displayToken, |
| 1145 | HdrCapabilities* outCapabilities) const { |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 1146 | Mutex::Autolock _l(mStateLock); |
| 1147 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1148 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1149 | if (!display) { |
| 1150 | ALOGE("getHdrCapabilities: Invalid display token %p", displayToken.get()); |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 1151 | return BAD_VALUE; |
| 1152 | } |
| 1153 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 1154 | // At this point the DisplayDeivce should already be set up, |
| 1155 | // meaning the luminance information is already queried from |
| 1156 | // hardware composer and stored properly. |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1157 | const HdrCapabilities& capabilities = display->getHdrCapabilities(); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 1158 | *outCapabilities = HdrCapabilities(capabilities.getSupportedHdrTypes(), |
| 1159 | capabilities.getDesiredMaxLuminance(), |
| 1160 | capabilities.getDesiredMaxAverageLuminance(), |
| 1161 | capabilities.getDesiredMinLuminance()); |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 1162 | |
| 1163 | return NO_ERROR; |
| 1164 | } |
| 1165 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1166 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1167 | ui::PixelFormat* outFormat, |
| 1168 | ui::Dataspace* outDataspace, |
| 1169 | uint8_t* outComponentMask) const { |
| 1170 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1171 | return BAD_VALUE; |
| 1172 | } |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1173 | const auto display = getDisplayDevice(displayToken); |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1174 | if (!display || !display->getId()) { |
| 1175 | ALOGE("getDisplayedContentSamplingAttributes: Bad display token: %p", display.get()); |
| 1176 | return BAD_VALUE; |
| 1177 | } |
| 1178 | return getHwComposer().getDisplayedContentSamplingAttributes(*display->getId(), outFormat, |
| 1179 | outDataspace, outComponentMask); |
| 1180 | } |
| 1181 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1182 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1183 | bool enable, uint8_t componentMask, |
| 1184 | uint64_t maxFrames) const { |
| 1185 | const auto display = getDisplayDevice(displayToken); |
| 1186 | if (!display || !display->getId()) { |
| 1187 | ALOGE("setDisplayContentSamplingEnabled: Bad display token: %p", display.get()); |
| 1188 | return BAD_VALUE; |
| 1189 | } |
| 1190 | |
| 1191 | return getHwComposer().setDisplayContentSamplingEnabled(*display->getId(), enable, |
| 1192 | componentMask, maxFrames); |
| 1193 | } |
| 1194 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1195 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1196 | uint64_t maxFrames, uint64_t timestamp, |
| 1197 | DisplayedFrameStats* outStats) const { |
| 1198 | const auto display = getDisplayDevice(displayToken); |
| 1199 | if (!display || !display->getId()) { |
| 1200 | ALOGE("getDisplayContentSample: Bad display token: %p", displayToken.get()); |
| 1201 | return BAD_VALUE; |
| 1202 | } |
| 1203 | |
| 1204 | return getHwComposer().getDisplayedContentSample(*display->getId(), maxFrames, timestamp, |
| 1205 | outStats); |
| 1206 | } |
| 1207 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1208 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1209 | if (!outSupported) { |
| 1210 | return BAD_VALUE; |
| 1211 | } |
| 1212 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1213 | return NO_ERROR; |
| 1214 | } |
| 1215 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1216 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1217 | bool* outIsWideColorDisplay) const { |
| 1218 | if (!displayToken || !outIsWideColorDisplay) { |
| 1219 | return BAD_VALUE; |
| 1220 | } |
| 1221 | Mutex::Autolock _l(mStateLock); |
| 1222 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1223 | if (!display) { |
| 1224 | return BAD_VALUE; |
| 1225 | } |
| 1226 | *outIsWideColorDisplay = display->hasWideColorGamut(); |
| 1227 | return NO_ERROR; |
| 1228 | } |
| 1229 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1230 | status_t SurfaceFlinger::enableVSyncInjections(bool enable) { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 1231 | postMessageSync(new LambdaMessage([&] { |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1232 | Mutex::Autolock _l(mStateLock); |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1233 | |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1234 | if (mInjectVSyncs == enable) { |
| 1235 | return; |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1236 | } |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1237 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1238 | auto resyncCallback = |
| 1239 | mScheduler->makeResyncCallback(std::bind(&SurfaceFlinger::getVsyncPeriod, this)); |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 1240 | |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 1241 | // TODO(akrulec): Part of the Injector should be refactored, so that it |
| 1242 | // can be passed to Scheduler. |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1243 | if (enable) { |
| 1244 | ALOGV("VSync Injections enabled"); |
| 1245 | if (mVSyncInjector.get() == nullptr) { |
Lloyd Pique | e83f931 | 2018-02-01 12:53:17 -0800 | [diff] [blame] | 1246 | mVSyncInjector = std::make_unique<InjectVSyncSource>(); |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 1247 | mInjectorEventThread = std::make_unique< |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 1248 | impl::EventThread>(mVSyncInjector.get(), |
Lloyd Pique | 24b0a48 | 2018-03-09 18:52:26 -0800 | [diff] [blame] | 1249 | impl::EventThread::InterceptVSyncsCallback(), |
| 1250 | "injEventThread"); |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1251 | } |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 1252 | mEventQueue->setEventThread(mInjectorEventThread.get(), std::move(resyncCallback)); |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1253 | } else { |
| 1254 | ALOGV("VSync Injections disabled"); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1255 | mEventQueue->setEventThread(mScheduler->getEventThread(mSfConnectionHandle), |
| 1256 | std::move(resyncCallback)); |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1259 | mInjectVSyncs = enable; |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 1260 | })); |
| 1261 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1262 | return NO_ERROR; |
| 1263 | } |
| 1264 | |
| 1265 | status_t SurfaceFlinger::injectVSync(nsecs_t when) { |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 1266 | Mutex::Autolock _l(mStateLock); |
| 1267 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1268 | if (!mInjectVSyncs) { |
| 1269 | ALOGE("VSync Injections not enabled"); |
| 1270 | return BAD_VALUE; |
| 1271 | } |
| 1272 | if (mInjectVSyncs && mInjectorEventThread.get() != nullptr) { |
| 1273 | ALOGV("Injecting VSync inside SurfaceFlinger"); |
| 1274 | mVSyncInjector->onInjectSyncEvent(when); |
| 1275 | } |
| 1276 | return NO_ERROR; |
| 1277 | } |
| 1278 | |
Lloyd Pique | 755e319 | 2018-01-31 16:46:15 -0800 | [diff] [blame] | 1279 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const |
| 1280 | NO_THREAD_SAFETY_ANALYSIS { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1281 | // Try to acquire a lock for 1s, fail gracefully |
| 1282 | const status_t err = mStateLock.timedLock(s2ns(1)); |
| 1283 | const bool locked = (err == NO_ERROR); |
| 1284 | if (!locked) { |
| 1285 | ALOGE("LayerDebugInfo: SurfaceFlinger unresponsive (%s [%d]) - exit", strerror(-err), err); |
| 1286 | return TIMED_OUT; |
| 1287 | } |
| 1288 | |
| 1289 | outLayers->clear(); |
| 1290 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
| 1291 | outLayers->push_back(layer->getLayerDebugInfo()); |
| 1292 | }); |
| 1293 | |
| 1294 | mStateLock.unlock(); |
| 1295 | return NO_ERROR; |
| 1296 | } |
| 1297 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1298 | status_t SurfaceFlinger::getCompositionPreference( |
| 1299 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1300 | Dataspace* outWideColorGamutDataspace, |
| 1301 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1302 | *outDataspace = mDefaultCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1303 | *outPixelFormat = defaultCompositionPixelFormat; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1304 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1305 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1306 | return NO_ERROR; |
| 1307 | } |
| 1308 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1309 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1310 | const sp<IBinder>& stopLayerHandle, |
| 1311 | const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1312 | if (!listener || samplingArea == Rect::INVALID_RECT) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1313 | return BAD_VALUE; |
| 1314 | } |
| 1315 | mRegionSamplingThread->addListener(samplingArea, stopLayerHandle, listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1316 | return NO_ERROR; |
| 1317 | } |
| 1318 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1319 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1320 | if (!listener) { |
| 1321 | return BAD_VALUE; |
| 1322 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1323 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1324 | return NO_ERROR; |
| 1325 | } |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 1326 | // ---------------------------------------------------------------------------- |
| 1327 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 1328 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
| 1329 | ISurfaceComposer::VsyncSource vsyncSource) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1330 | auto resyncCallback = mScheduler->makeResyncCallback([this] { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1331 | Mutex::Autolock lock(mStateLock); |
| 1332 | return getVsyncPeriod(); |
| 1333 | }); |
Dominik Laskowski | f654d57 | 2018-12-20 11:03:06 -0800 | [diff] [blame] | 1334 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1335 | const auto& handle = |
| 1336 | vsyncSource == eVsyncSourceSurfaceFlinger ? mSfConnectionHandle : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1337 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1338 | return mScheduler->createDisplayEventConnection(handle, std::move(resyncCallback)); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1342 | |
| 1343 | void SurfaceFlinger::waitForEvent() { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1344 | mEventQueue->waitMessage(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | void SurfaceFlinger::signalTransaction() { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1348 | mEventQueue->invalidate(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | void SurfaceFlinger::signalLayerUpdate() { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1352 | mEventQueue->invalidate(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | void SurfaceFlinger::signalRefresh() { |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 1356 | mRefreshPending = true; |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1357 | mEventQueue->refresh(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 1361 | nsecs_t reltime, uint32_t /* flags */) { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1362 | return mEventQueue->postMessage(msg, reltime); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 1366 | nsecs_t reltime, uint32_t /* flags */) { |
Lloyd Pique | 3fcdef1 | 2018-01-22 17:14:00 -0800 | [diff] [blame] | 1367 | status_t res = mEventQueue->postMessage(msg, reltime); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1368 | if (res == NO_ERROR) { |
| 1369 | msg->wait(); |
| 1370 | } |
| 1371 | return res; |
| 1372 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1373 | |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 1374 | void SurfaceFlinger::run() { |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 1375 | do { |
| 1376 | waitForEvent(); |
| 1377 | } while (true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1380 | nsecs_t SurfaceFlinger::getVsyncPeriod() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1381 | const auto displayId = getInternalDisplayIdLocked(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1382 | if (!displayId || !getHwComposer().isConnected(*displayId)) { |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
| 1386 | const auto config = getHwComposer().getActiveConfig(*displayId); |
| 1387 | return config ? config->getVsyncPeriod() : 0; |
| 1388 | } |
| 1389 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1390 | void SurfaceFlinger::onVsyncReceived(int32_t sequenceId, hwc2_display_t hwcDisplayId, |
| 1391 | int64_t timestamp) { |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1392 | ATRACE_NAME("SF onVsync"); |
| 1393 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1394 | Mutex::Autolock lock(mStateLock); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1395 | // Ignore any vsyncs from a previous hardware composer. |
David Sodman | 105b7dc | 2017-11-04 20:28:14 -0700 | [diff] [blame] | 1396 | if (sequenceId != getBE().mComposerSequenceId) { |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1397 | return; |
| 1398 | } |
| 1399 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1400 | if (!getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1401 | return; |
| 1402 | } |
| 1403 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1404 | if (hwcDisplayId != getHwComposer().getInternalHwcDisplayId()) { |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1405 | // For now, we don't do anything with external display vsyncs. |
| 1406 | return; |
| 1407 | } |
| 1408 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1409 | mScheduler->addResyncSample(timestamp); |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1412 | void SurfaceFlinger::getCompositorTiming(CompositorTiming* compositorTiming) { |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1413 | std::lock_guard<std::mutex> lock(getBE().mCompositorTimingLock); |
| 1414 | *compositorTiming = getBE().mCompositorTiming; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1415 | } |
| 1416 | |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1417 | bool SurfaceFlinger::isConfigAllowed(const DisplayId& displayId, int32_t config) { |
| 1418 | std::lock_guard lock(mAllowedConfigsLock); |
| 1419 | |
| 1420 | // if allowed configs are not set yet for this display, every config is considered allowed |
| 1421 | if (mAllowedConfigs.find(displayId) == mAllowedConfigs.end()) { |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
| 1425 | return mAllowedConfigs[displayId]->isConfigAllowed(config); |
| 1426 | } |
| 1427 | |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1428 | void SurfaceFlinger::setRefreshRateTo(RefreshRateType refreshRate, ConfigEvent event) { |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1429 | mPhaseOffsets->setRefreshRateType(refreshRate); |
| 1430 | |
| 1431 | const auto [early, gl, late] = mPhaseOffsets->getCurrentOffsets(); |
| 1432 | mVsyncModulator.setPhaseOffsets(early, gl, late); |
| 1433 | |
| 1434 | if (mBootStage != BootStage::FINISHED) { |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1435 | return; |
| 1436 | } |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1437 | |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1438 | // TODO(b/113612090): There should be a message queue flush here. Because this esentially |
| 1439 | // runs on a mainthread, we cannot call postMessageSync. This can be resolved in a better |
| 1440 | // manner, once the setActiveConfig is synchronous, and is executed at a known time in a |
| 1441 | // refresh cycle. |
| 1442 | |
| 1443 | // Don't do any updating if the current fps is the same as the new one. |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1444 | const nsecs_t currentVsyncPeriod = getVsyncPeriod(); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1445 | if (currentVsyncPeriod == 0) { |
| 1446 | return; |
| 1447 | } |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1448 | |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1449 | // TODO(b/113612090): Consider having an enum value for correct refresh rates, rather than |
| 1450 | // floating numbers. |
| 1451 | const float currentFps = 1e9 / currentVsyncPeriod; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1452 | const float newFps = refreshRate == RefreshRateType::PERFORMANCE ? kPerformanceRefreshRate |
| 1453 | : kDefaultRefreshRate; |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1454 | if (std::abs(currentFps - newFps) <= 1) { |
| 1455 | return; |
| 1456 | } |
| 1457 | |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1458 | const auto displayId = getInternalDisplayIdLocked(); |
| 1459 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 1460 | |
| 1461 | auto configs = getHwComposer().getConfigs(*displayId); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1462 | for (int i = 0; i < configs.size(); i++) { |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1463 | if (!isConfigAllowed(*displayId, i)) { |
| 1464 | ALOGV("Skipping config %d as it is not part of allowed configs", i); |
| 1465 | continue; |
| 1466 | } |
| 1467 | |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1468 | const nsecs_t vsyncPeriod = configs.at(i)->getVsyncPeriod(); |
| 1469 | if (vsyncPeriod == 0) { |
| 1470 | continue; |
| 1471 | } |
| 1472 | const float fps = 1e9 / vsyncPeriod; |
| 1473 | // TODO(b/113612090): There should be a better way at determining which config |
| 1474 | // has the right refresh rate. |
| 1475 | if (std::abs(fps - newFps) <= 1) { |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1476 | setDesiredActiveConfig(getInternalDisplayTokenLocked(), i, event); |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | } |
| 1480 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1481 | void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hwc2_display_t hwcDisplayId, |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 1482 | HWC2::Connection connection) { |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1483 | ALOGV("%s(%d, %" PRIu64 ", %s)", __FUNCTION__, sequenceId, hwcDisplayId, |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 1484 | connection == HWC2::Connection::Connected ? "connected" : "disconnected"); |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1485 | |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 1486 | // Ignore events that do not have the right sequenceId. |
| 1487 | if (sequenceId != getBE().mComposerSequenceId) { |
| 1488 | return; |
| 1489 | } |
| 1490 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1491 | // Only lock if we're not on the main thread. This function is normally |
| 1492 | // called on a hwbinder thread, but for the primary display it's called on |
| 1493 | // the main thread with the state lock already held, so don't attempt to |
| 1494 | // acquire it here. |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 1495 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1496 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1497 | mPendingHotplugEvents.emplace_back(HotplugEvent{hwcDisplayId, connection}); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 1498 | |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 1499 | if (std::this_thread::get_id() == mMainThreadId) { |
| 1500 | // Process all pending hot plug events immediately if we are on the main thread. |
| 1501 | processDisplayHotplugEventsLocked(); |
| 1502 | } |
| 1503 | |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 1504 | setTransactionFlags(eDisplayTransactionNeeded); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1507 | void SurfaceFlinger::onRefreshReceived(int sequenceId, hwc2_display_t /*hwcDisplayId*/) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1508 | Mutex::Autolock lock(mStateLock); |
David Sodman | 105b7dc | 2017-11-04 20:28:14 -0700 | [diff] [blame] | 1509 | if (sequenceId != getBE().mComposerSequenceId) { |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1510 | return; |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1511 | } |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 1512 | repaintEverythingForHWC(); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1515 | void SurfaceFlinger::setPrimaryVsyncEnabled(bool enabled) { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 1516 | ATRACE_CALL(); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1517 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1518 | if (const auto displayId = getInternalDisplayIdLocked()) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1519 | getHwComposer().setVsyncEnabled(*displayId, |
| 1520 | enabled ? HWC2::Vsync::Enable : HWC2::Vsync::Disable); |
| 1521 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1524 | // Note: it is assumed the caller holds |mStateLock| when this is called |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1525 | void SurfaceFlinger::resetDisplayState() { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1526 | mScheduler->disableHardwareVsync(true); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1527 | // Clear the drawing state so that the logic inside of |
| 1528 | // handleTransactionLocked will fire. It will determine the delta between |
| 1529 | // mCurrentState and mDrawingState and re-apply all changes when we make the |
| 1530 | // transition. |
| 1531 | mDrawingState.displays.clear(); |
| 1532 | mDisplays.clear(); |
| 1533 | } |
| 1534 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 1535 | void SurfaceFlinger::updateVrFlinger() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1536 | ATRACE_CALL(); |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 1537 | if (!mVrFlinger) |
| 1538 | return; |
| 1539 | bool vrFlingerRequestsDisplay = mVrFlingerRequestsDisplay; |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 1540 | if (vrFlingerRequestsDisplay == getHwComposer().isUsingVrComposer()) { |
Mark Urbanus | 209beca | 2017-02-23 11:16:04 -0800 | [diff] [blame] | 1541 | return; |
| 1542 | } |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1543 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 1544 | if (vrFlingerRequestsDisplay && !getHwComposer().getComposer()->isRemote()) { |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1545 | ALOGE("Vr flinger is only supported for remote hardware composer" |
| 1546 | " service connections. Ignoring request to transition to vr" |
| 1547 | " flinger."); |
| 1548 | mVrFlingerRequestsDisplay = false; |
| 1549 | return; |
Mark Urbanus | 209beca | 2017-02-23 11:16:04 -0800 | [diff] [blame] | 1550 | } |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1551 | |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1552 | Mutex::Autolock _l(mStateLock); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1553 | |
Steven Thomas | 0123ac6 | 2018-07-12 11:32:34 -0700 | [diff] [blame] | 1554 | sp<DisplayDevice> display = getDefaultDisplayDeviceLocked(); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 1555 | LOG_ALWAYS_FATAL_IF(!display); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 1556 | |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 1557 | const int currentDisplayPowerMode = display->getPowerMode(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 1558 | |
| 1559 | // Clear out all the output layers from the composition engine for all |
| 1560 | // displays before destroying the hardware composer interface. This ensures |
| 1561 | // any HWC layers are destroyed through that interface before it becomes |
| 1562 | // invalid. |
| 1563 | for (const auto& [token, displayDevice] : mDisplays) { |
| 1564 | displayDevice->getCompositionDisplay()->setOutputLayersOrderedByZ( |
| 1565 | compositionengine::Output::OutputLayers()); |
| 1566 | } |
| 1567 | |
Steven Thomas | 0123ac6 | 2018-07-12 11:32:34 -0700 | [diff] [blame] | 1568 | // This DisplayDevice will no longer be relevant once resetDisplayState() is |
| 1569 | // called below. Clear the reference now so we don't accidentally use it |
| 1570 | // later. |
| 1571 | display.clear(); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1572 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1573 | if (!vrFlingerRequestsDisplay) { |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1574 | mVrFlinger->SeizeDisplayOwnership(); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1575 | } |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1576 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1577 | resetDisplayState(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 1578 | // Delete the current instance before creating the new one |
| 1579 | mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>()); |
| 1580 | mCompositionEngine->setHwComposer(getFactory().createHWComposer( |
| 1581 | vrFlingerRequestsDisplay ? "vr" : getBE().mHwcServiceName)); |
| 1582 | getHwComposer().registerCallback(this, ++getBE().mComposerSequenceId); |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1583 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 1584 | LOG_ALWAYS_FATAL_IF(!getHwComposer().getComposer()->isRemote(), |
David Sodman | 105b7dc | 2017-11-04 20:28:14 -0700 | [diff] [blame] | 1585 | "Switched to non-remote hardware composer"); |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1586 | |
| 1587 | if (vrFlingerRequestsDisplay) { |
| 1588 | mVrFlinger->GrantDisplayOwnership(); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1589 | } |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1590 | |
| 1591 | mVisibleRegionsDirty = true; |
| 1592 | invalidateHwcGeometry(); |
| 1593 | |
Alex Sakhartchouk | 096cb99 | 2017-06-05 10:37:57 -0400 | [diff] [blame] | 1594 | // Re-enable default display. |
Steven Thomas | 0123ac6 | 2018-07-12 11:32:34 -0700 | [diff] [blame] | 1595 | display = getDefaultDisplayDeviceLocked(); |
| 1596 | LOG_ALWAYS_FATAL_IF(!display); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 1597 | setPowerModeInternal(display, currentDisplayPowerMode); |
Alex Sakhartchouk | 096cb99 | 2017-06-05 10:37:57 -0400 | [diff] [blame] | 1598 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1599 | // Reset the timing values to account for the period of the swapped in HWC |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1600 | const nsecs_t vsyncPeriod = getVsyncPeriod(); |
| 1601 | mAnimFrameTracker.setDisplayRefreshPeriod(vsyncPeriod); |
Alex Sakhartchouk | 096cb99 | 2017-06-05 10:37:57 -0400 | [diff] [blame] | 1602 | |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1603 | // The present fences returned from vr_hwc are not an accurate |
| 1604 | // representation of vsync times. |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1605 | mScheduler->setIgnorePresentFences(getHwComposer().isUsingVrComposer() || !hasSyncFramework); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1606 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 1607 | // Use phase of 0 since phase is not known. |
| 1608 | // Use latency of 0, which will snap to the ideal latency. |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1609 | DisplayStatInfo stats{0 /* vsyncTime */, vsyncPeriod}; |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1610 | setCompositorTimingSnapped(stats, 0); |
Stephen Kiazyk | 82386cd | 2017-04-14 13:43:29 -0700 | [diff] [blame] | 1611 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1612 | mScheduler->resyncToHardwareVsync(false, vsyncPeriod); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1613 | |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 1614 | mRepaintEverything = true; |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1615 | setTransactionFlags(eDisplayTransactionNeeded); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1618 | void SurfaceFlinger::onMessageReceived(int32_t what) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1619 | ATRACE_CALL(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1620 | switch (what) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1621 | case MessageQueue::INVALIDATE: { |
Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 1622 | if (performSetActiveConfig()) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1623 | break; |
| 1624 | } |
| 1625 | |
Ana Krulec | ba13ab3 | 2019-02-20 14:14:12 -0800 | [diff] [blame] | 1626 | if (mUse90Hz && mUseSmart90ForVideo) { |
| 1627 | // This call is made each time SF wakes up and creates a new frame. It is part |
| 1628 | // of video detection feature. |
| 1629 | mScheduler->incrementFrameCounter(); |
| 1630 | } |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1631 | bool frameMissed = mPreviousPresentFence != Fence::NO_FENCE && |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1632 | (mPreviousPresentFence->getStatus() == Fence::Status::Unsignaled); |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1633 | bool hwcFrameMissed = !mHadClientComposition && frameMissed; |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1634 | if (frameMissed) { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1635 | ATRACE_INT("FrameMissed", static_cast<int>(frameMissed)); |
| 1636 | mFrameMissedCount++; |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 1637 | mTimeStats->incrementMissedFrames(); |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1638 | } |
| 1639 | // For now, only propagate backpressure when missing a hwc frame. |
| 1640 | if (hwcFrameMissed) { |
Yiwei Zhang | 621f9d4 | 2018-05-07 10:40:55 -0700 | [diff] [blame] | 1641 | if (mPropagateBackpressure) { |
| 1642 | signalLayerUpdate(); |
| 1643 | break; |
| 1644 | } |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1645 | } |
Dan Stoza | 5018288 | 2016-07-08 12:02:20 -0700 | [diff] [blame] | 1646 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 1647 | // Now that we're going to make it to the handleMessageTransaction() |
| 1648 | // call below it's safe to call updateVrFlinger(), which will |
| 1649 | // potentially trigger a display handoff. |
| 1650 | updateVrFlinger(); |
| 1651 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1652 | bool refreshNeeded = handleMessageTransaction(); |
| 1653 | refreshNeeded |= handleMessageInvalidate(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 1654 | |
| 1655 | updateCursorAsync(); |
| 1656 | updateInputFlinger(); |
| 1657 | |
Dan Stoza | 5878444 | 2014-12-02 16:58:17 -0800 | [diff] [blame] | 1658 | refreshNeeded |= mRepaintEverything; |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 1659 | if (refreshNeeded && CC_LIKELY(mBootStage != BootStage::BOOTLOADER)) { |
Dan Stoza | 5878444 | 2014-12-02 16:58:17 -0800 | [diff] [blame] | 1660 | // Signal a refresh if a transaction modified the window state, |
| 1661 | // a new buffer was latched, or if HWC has requested a full |
| 1662 | // repaint |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1663 | signalRefresh(); |
| 1664 | } |
| 1665 | break; |
| 1666 | } |
| 1667 | case MessageQueue::REFRESH: { |
| 1668 | handleMessageRefresh(); |
| 1669 | break; |
| 1670 | } |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1671 | } |
| 1672 | } |
| 1673 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1674 | bool SurfaceFlinger::handleMessageTransaction() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1675 | ATRACE_CALL(); |
Fabien Sanglard | c8251eb | 2016-12-07 13:59:48 -0800 | [diff] [blame] | 1676 | uint32_t transactionFlags = peekTransactionFlags(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 1677 | |
| 1678 | // Apply any ready transactions in the queues if there are still transactions that have not been |
| 1679 | // applied, wake up during the next vsync period and check again |
| 1680 | bool transactionNeeded = false; |
| 1681 | if (!flushTransactionQueues()) { |
| 1682 | transactionNeeded = true; |
| 1683 | } |
| 1684 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1685 | if (transactionFlags) { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 1686 | handleTransaction(transactionFlags); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1687 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 1688 | |
| 1689 | if (transactionNeeded) { |
| 1690 | setTransactionFlags(eTransactionNeeded); |
| 1691 | } |
| 1692 | |
| 1693 | return transactionFlags; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1696 | void SurfaceFlinger::handleMessageRefresh() { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1697 | ATRACE_CALL(); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 1698 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 1699 | mRefreshPending = false; |
| 1700 | |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 1701 | const bool repaintEverything = mRepaintEverything.exchange(false); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1702 | preComposition(); |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 1703 | rebuildLayerStacks(); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1704 | calculateWorkingSet(); |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1705 | for (const auto& [token, display] : mDisplays) { |
| 1706 | beginFrame(display); |
| 1707 | prepareFrame(display); |
| 1708 | doDebugFlashRegions(display, repaintEverything); |
| 1709 | doComposition(display, repaintEverything); |
| 1710 | } |
| 1711 | |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 1712 | doTracing("handleRefresh"); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 1713 | logLayerStats(); |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1714 | |
| 1715 | postFrame(); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1716 | postComposition(); |
Dan Stoza | 05dacfb | 2016-07-01 13:33:38 -0700 | [diff] [blame] | 1717 | |
Dan Stoza | bfbffeb | 2016-07-21 14:49:33 -0700 | [diff] [blame] | 1718 | mHadClientComposition = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1719 | for (const auto& [token, displayDevice] : mDisplays) { |
| 1720 | auto display = displayDevice->getCompositionDisplay(); |
| 1721 | const auto displayId = display->getId(); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 1722 | mHadClientComposition = |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1723 | mHadClientComposition || getHwComposer().hasClientComposition(displayId); |
Dan Stoza | bfbffeb | 2016-07-21 14:49:33 -0700 | [diff] [blame] | 1724 | } |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1725 | |
Jorim Jaggi | 9053521 | 2018-05-23 23:44:06 +0200 | [diff] [blame] | 1726 | mVsyncModulator.onRefreshed(mHadClientComposition); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 1727 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 1728 | mLayersWithQueuedFrames.clear(); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1729 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1730 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1731 | |
| 1732 | bool SurfaceFlinger::handleMessageInvalidate() { |
| 1733 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 1734 | bool refreshNeeded = handlePageFlip(); |
| 1735 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 1736 | if (mVisibleRegionsDirty) { |
| 1737 | computeLayerBounds(); |
| 1738 | } |
| 1739 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 1740 | for (auto& layer : mLayersPendingRefresh) { |
| 1741 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 1742 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 1743 | invalidateLayerStack(layer, visibleReg); |
| 1744 | } |
| 1745 | mLayersPendingRefresh.clear(); |
| 1746 | return refreshNeeded; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1749 | void SurfaceFlinger::calculateWorkingSet() { |
| 1750 | ATRACE_CALL(); |
| 1751 | ALOGV(__FUNCTION__); |
| 1752 | |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1753 | // build the h/w work list |
| 1754 | if (CC_UNLIKELY(mGeometryInvalid)) { |
| 1755 | mGeometryInvalid = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1756 | for (const auto& [token, displayDevice] : mDisplays) { |
| 1757 | auto display = displayDevice->getCompositionDisplay(); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1758 | const auto displayId = display->getId(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1759 | if (!displayId) { |
| 1760 | continue; |
| 1761 | } |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1762 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1763 | const Vector<sp<Layer>>& currentLayers = displayDevice->getVisibleLayersSortedByZ(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1764 | for (size_t i = 0; i < currentLayers.size(); i++) { |
| 1765 | const auto& layer = currentLayers[i]; |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1766 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1767 | if (!layer->hasHwcLayer(displayDevice)) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 1768 | layer->forceClientComposition(displayDevice); |
| 1769 | continue; |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1770 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1771 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1772 | layer->setGeometry(displayDevice, i); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1773 | if (mDebugDisableHWC || mDebugRegion) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1774 | layer->forceClientComposition(displayDevice); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1775 | } |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | // Set the per-frame data |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1781 | for (const auto& [token, displayDevice] : mDisplays) { |
| 1782 | auto display = displayDevice->getCompositionDisplay(); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1783 | const auto displayId = display->getId(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1784 | if (!displayId) { |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1785 | continue; |
| 1786 | } |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 1787 | auto* profile = display->getDisplayColorProfile(); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1788 | |
| 1789 | if (mDrawingState.colorMatrixChanged) { |
| 1790 | display->setColorTransform(mDrawingState.colorMatrix); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1791 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1792 | for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) { |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1793 | if (layer->isHdrY410()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1794 | layer->forceClientComposition(displayDevice); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1795 | } else if ((layer->getDataSpace() == Dataspace::BT2020_PQ || |
| 1796 | layer->getDataSpace() == Dataspace::BT2020_ITU_PQ) && |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 1797 | !profile->hasHDR10Support()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1798 | layer->forceClientComposition(displayDevice); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1799 | } else if ((layer->getDataSpace() == Dataspace::BT2020_HLG || |
| 1800 | layer->getDataSpace() == Dataspace::BT2020_ITU_HLG) && |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 1801 | !profile->hasHLGSupport()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1802 | layer->forceClientComposition(displayDevice); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1805 | // TODO(b/111562338) remove when composer 2.3 is shipped. |
| 1806 | if (layer->hasColorTransform()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1807 | layer->forceClientComposition(displayDevice); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1810 | if (layer->getRoundedCornerState().radius > 0.0f) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1811 | layer->forceClientComposition(displayDevice); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1814 | if (layer->getForceClientComposition(displayDevice)) { |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1815 | ALOGV("[%s] Requesting Client composition", layer->getName().string()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1816 | layer->setCompositionType(displayDevice, |
| 1817 | Hwc2::IComposerClient::Composition::CLIENT); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1818 | continue; |
| 1819 | } |
| 1820 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1821 | const auto& displayState = display->getState(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1822 | layer->setPerFrameData(displayDevice, displayState.transform, displayState.viewport, |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1823 | displayDevice->getSupportedPerFrameMetadata()); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 1826 | if (useColorManagement) { |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1827 | ColorMode colorMode; |
| 1828 | Dataspace dataSpace; |
| 1829 | RenderIntent renderIntent; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1830 | pickColorMode(displayDevice, &colorMode, &dataSpace, &renderIntent); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1831 | display->setColorMode(colorMode, dataSpace, renderIntent); |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | mDrawingState.colorMatrixChanged = false; |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 1836 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1837 | for (const auto& [token, displayDevice] : mDisplays) { |
| 1838 | auto display = displayDevice->getCompositionDisplay(); |
| 1839 | for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) { |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 1840 | auto& layerState = layer->getCompositionLayer()->editState().frontEnd; |
| 1841 | layerState.compositionType = static_cast<Hwc2::IComposerClient::Composition>( |
| 1842 | layer->getCompositionType(displayDevice)); |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 1843 | } |
| 1844 | } |
David Sodman | 79bba0e | 2018-08-05 18:07:49 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1847 | void SurfaceFlinger::doDebugFlashRegions(const sp<DisplayDevice>& displayDevice, |
| 1848 | bool repaintEverything) { |
| 1849 | auto display = displayDevice->getCompositionDisplay(); |
| 1850 | const auto& displayState = display->getState(); |
| 1851 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1852 | // is debugging enabled |
| 1853 | if (CC_LIKELY(!mDebugRegion)) |
| 1854 | return; |
| 1855 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1856 | if (displayState.isEnabled) { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1857 | // transform the dirty region into this screen's coordinate space |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1858 | const Region dirtyRegion = display->getDirtyRegion(repaintEverything); |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1859 | if (!dirtyRegion.isEmpty()) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1860 | base::unique_fd readyFence; |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 1861 | // redraw the whole screen |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1862 | doComposeSurfaces(displayDevice, dirtyRegion, &readyFence); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1863 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1864 | display->getRenderSurface()->queueBuffer(std::move(readyFence)); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1868 | postFramebuffer(displayDevice); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1869 | |
| 1870 | if (mDebugRegion > 1) { |
| 1871 | usleep(mDebugRegion * 1000); |
| 1872 | } |
Mathias Agopian | bb53b0e | 2012-09-24 21:27:29 -0700 | [diff] [blame] | 1873 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1874 | prepareFrame(displayDevice); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 1877 | void SurfaceFlinger::doTracing(const char* where) { |
| 1878 | ATRACE_CALL(); |
| 1879 | ATRACE_NAME(where); |
| 1880 | if (CC_UNLIKELY(mTracing.isEnabled())) { |
Jorim Jaggi | 8e0af36 | 2017-11-14 16:28:28 +0100 | [diff] [blame] | 1881 | mTracing.traceLayers(where, dumpProtoInfo(LayerVector::StateSet::Drawing)); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 1885 | void SurfaceFlinger::logLayerStats() { |
| 1886 | ATRACE_CALL(); |
| 1887 | if (CC_UNLIKELY(mLayerStats.isEnabled())) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 1888 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1889 | if (display->isPrimary()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1890 | mLayerStats.logLayerStats(dumpVisibleLayersProtoInfo(display)); |
Dominik Laskowski | 63165dc | 2018-05-25 18:36:52 -0700 | [diff] [blame] | 1891 | return; |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 1892 | } |
| 1893 | } |
Dominik Laskowski | 63165dc | 2018-05-25 18:36:52 -0700 | [diff] [blame] | 1894 | |
| 1895 | ALOGE("logLayerStats: no primary display"); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1899 | void SurfaceFlinger::preComposition() |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1900 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1901 | ATRACE_CALL(); |
| 1902 | ALOGV("preComposition"); |
| 1903 | |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1904 | mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 1905 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1906 | bool needExtraInvalidate = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 1907 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1908 | if (layer->onPreComposition(mRefreshStartTime)) { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1909 | needExtraInvalidate = true; |
| 1910 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 1911 | }); |
| 1912 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1913 | if (needExtraInvalidate) { |
| 1914 | signalLayerUpdate(); |
| 1915 | } |
| 1916 | } |
| 1917 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1918 | void SurfaceFlinger::updateCompositorTiming(const DisplayStatInfo& stats, nsecs_t compositeTime, |
| 1919 | std::shared_ptr<FenceTime>& presentFenceTime) { |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1920 | // Update queue of past composite+present times and determine the |
| 1921 | // most recently known composite to present latency. |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1922 | getBE().mCompositePresentTimes.push({compositeTime, presentFenceTime}); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1923 | nsecs_t compositeToPresentLatency = -1; |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1924 | while (!getBE().mCompositePresentTimes.empty()) { |
| 1925 | SurfaceFlingerBE::CompositePresentTime& cpt = getBE().mCompositePresentTimes.front(); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1926 | // Cached values should have been updated before calling this method, |
| 1927 | // which helps avoid duplicate syscalls. |
| 1928 | nsecs_t displayTime = cpt.display->getCachedSignalTime(); |
| 1929 | if (displayTime == Fence::SIGNAL_TIME_PENDING) { |
| 1930 | break; |
| 1931 | } |
| 1932 | compositeToPresentLatency = displayTime - cpt.composite; |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1933 | getBE().mCompositePresentTimes.pop(); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | // Don't let mCompositePresentTimes grow unbounded, just in case. |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1937 | while (getBE().mCompositePresentTimes.size() > 16) { |
| 1938 | getBE().mCompositePresentTimes.pop(); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1941 | setCompositorTimingSnapped(stats, compositeToPresentLatency); |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1944 | void SurfaceFlinger::setCompositorTimingSnapped(const DisplayStatInfo& stats, |
| 1945 | nsecs_t compositeToPresentLatency) { |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1946 | // Integer division and modulo round toward 0 not -inf, so we need to |
| 1947 | // treat negative and positive offsets differently. |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 1948 | nsecs_t idealLatency = (mPhaseOffsets->getCurrentSfOffset() > 0) |
| 1949 | ? (stats.vsyncPeriod - (mPhaseOffsets->getCurrentSfOffset() % stats.vsyncPeriod)) |
| 1950 | : ((-mPhaseOffsets->getCurrentSfOffset()) % stats.vsyncPeriod); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1951 | |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 1952 | // Just in case mPhaseOffsets->getCurrentSfOffset() == -vsyncInterval. |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 1953 | if (idealLatency <= 0) { |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1954 | idealLatency = stats.vsyncPeriod; |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 1955 | } |
| 1956 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1957 | // Snap the latency to a value that removes scheduling jitter from the |
| 1958 | // composition and present times, which often have >1ms of jitter. |
| 1959 | // Reducing jitter is important if an app attempts to extrapolate |
| 1960 | // something (such as user input) to an accurate diasplay time. |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 1961 | // Snapping also allows an app to precisely calculate mPhaseOffsets->getCurrentSfOffset() |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1962 | // with (presentLatency % interval). |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1963 | nsecs_t bias = stats.vsyncPeriod / 2; |
| 1964 | int64_t extraVsyncs = (compositeToPresentLatency - idealLatency + bias) / stats.vsyncPeriod; |
| 1965 | nsecs_t snappedCompositeToPresentLatency = |
| 1966 | (extraVsyncs > 0) ? idealLatency + (extraVsyncs * stats.vsyncPeriod) : idealLatency; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1967 | |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1968 | std::lock_guard<std::mutex> lock(getBE().mCompositorTimingLock); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 1969 | getBE().mCompositorTiming.deadline = stats.vsyncTime - idealLatency; |
| 1970 | getBE().mCompositorTiming.interval = stats.vsyncPeriod; |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 1971 | getBE().mCompositorTiming.presentLatency = snappedCompositeToPresentLatency; |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 1974 | void SurfaceFlinger::postComposition() |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 1975 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1976 | ATRACE_CALL(); |
| 1977 | ALOGV("postComposition"); |
| 1978 | |
Brian Anderson | 3546a3f | 2016-07-14 11:51:14 -0700 | [diff] [blame] | 1979 | // Release any buffers which were replaced this frame |
Brian Anderson | f638686 | 2016-10-31 16:34:13 -0700 | [diff] [blame] | 1980 | nsecs_t dequeueReadyTime = systemTime(); |
Brian Anderson | 3546a3f | 2016-07-14 11:51:14 -0700 | [diff] [blame] | 1981 | for (auto& layer : mLayersWithQueuedFrames) { |
Brian Anderson | f638686 | 2016-10-31 16:34:13 -0700 | [diff] [blame] | 1982 | layer->releasePendingBuffer(dequeueReadyTime); |
Brian Anderson | 3546a3f | 2016-07-14 11:51:14 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Stephen Kiazyk | 7d3dcb9 | 2017-04-05 16:46:49 -0700 | [diff] [blame] | 1985 | // |mStateLock| not needed as we are on the main thread |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1986 | const auto displayDevice = getDefaultDisplayDeviceLocked(); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1987 | |
David Sodman | 73beded | 2017-11-15 11:56:06 -0800 | [diff] [blame] | 1988 | getBE().mGlCompositionDoneTimeline.updateSignalTimes(); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1989 | std::shared_ptr<FenceTime> glCompositionDoneFenceTime; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1990 | if (displayDevice && getHwComposer().hasClientComposition(displayDevice->getId())) { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1991 | glCompositionDoneFenceTime = |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 1992 | std::make_shared<FenceTime>(displayDevice->getCompositionDisplay() |
| 1993 | ->getRenderSurface() |
| 1994 | ->getClientTargetAcquireFence()); |
David Sodman | 73beded | 2017-11-15 11:56:06 -0800 | [diff] [blame] | 1995 | getBE().mGlCompositionDoneTimeline.push(glCompositionDoneFenceTime); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1996 | } else { |
| 1997 | glCompositionDoneFenceTime = FenceTime::NO_FENCE; |
| 1998 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1999 | |
David Sodman | 73beded | 2017-11-15 11:56:06 -0800 | [diff] [blame] | 2000 | getBE().mDisplayTimeline.updateSignalTimes(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2001 | mPreviousPresentFence = displayDevice ? getHwComposer().getPresentFence(*displayDevice->getId()) |
| 2002 | : Fence::NO_FENCE; |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 2003 | auto presentFenceTime = std::make_shared<FenceTime>(mPreviousPresentFence); |
David Sodman | 73beded | 2017-11-15 11:56:06 -0800 | [diff] [blame] | 2004 | getBE().mDisplayTimeline.push(presentFenceTime); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2005 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 2006 | DisplayStatInfo stats; |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2007 | mScheduler->getDisplayStatInfo(&stats); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2008 | |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2009 | // We use the mRefreshStartTime which might be sampled a little later than |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2010 | // when we started doing work for this frame, but that should be okay |
| 2011 | // since updateCompositorTiming has snapping logic. |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 2012 | updateCompositorTiming(stats, mRefreshStartTime, presentFenceTime); |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 2013 | CompositorTiming compositorTiming; |
| 2014 | { |
David Sodman | 99974d2 | 2017-11-28 12:04:33 -0800 | [diff] [blame] | 2015 | std::lock_guard<std::mutex> lock(getBE().mCompositorTimingLock); |
| 2016 | compositorTiming = getBE().mCompositorTiming; |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 2017 | } |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2018 | |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2019 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2020 | bool frameLatched = |
| 2021 | layer->onPostComposition(displayDevice->getId(), glCompositionDoneFenceTime, |
| 2022 | presentFenceTime, compositorTiming); |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 2023 | if (frameLatched) { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2024 | recordBufferingStats(layer->getName().string(), |
| 2025 | layer->getOccupancyHistory(false)); |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 2026 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2027 | }); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2028 | |
Brian Anderson | fbc80ae | 2017-05-26 16:23:54 -0700 | [diff] [blame] | 2029 | if (presentFenceTime->isValid()) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2030 | mScheduler->addPresentFence(presentFenceTime); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 2033 | if (!hasSyncFramework) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2034 | if (displayDevice && getHwComposer().isConnected(*displayDevice->getId()) && |
| 2035 | displayDevice->isPoweredOn()) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2036 | mScheduler->enableHardwareVsync(); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2040 | if (mAnimCompositionPending) { |
| 2041 | mAnimCompositionPending = false; |
| 2042 | |
Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 2043 | if (presentFenceTime->isValid()) { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2044 | mAnimFrameTracker.setActualPresentFence( |
Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 2045 | std::move(presentFenceTime)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2046 | } else if (displayDevice && getHwComposer().isConnected(*displayDevice->getId())) { |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2047 | // The HWC doesn't support present fences, so use the refresh |
| 2048 | // timestamp instead. |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2049 | const nsecs_t presentTime = |
| 2050 | getHwComposer().getRefreshTimestamp(*displayDevice->getId()); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2051 | mAnimFrameTracker.setActualPresentTime(presentTime); |
| 2052 | } |
| 2053 | mAnimFrameTracker.advanceFrame(); |
| 2054 | } |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2055 | |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 2056 | mTimeStats->incrementTotalFrames(); |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 2057 | if (mHadClientComposition) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 2058 | mTimeStats->incrementClientCompositionFrames(); |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 2061 | mTimeStats->setPresentFenceGlobal(presentFenceTime); |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 2062 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2063 | if (displayDevice && getHwComposer().isConnected(*displayDevice->getId()) && |
| 2064 | !displayDevice->isPoweredOn()) { |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2065 | return; |
| 2066 | } |
| 2067 | |
| 2068 | nsecs_t currentTime = systemTime(); |
| 2069 | if (mHasPoweredOff) { |
| 2070 | mHasPoweredOff = false; |
| 2071 | } else { |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 2072 | nsecs_t elapsedTime = currentTime - getBE().mLastSwapTime; |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 2073 | size_t numPeriods = static_cast<size_t>(elapsedTime / stats.vsyncPeriod); |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 2074 | if (numPeriods < SurfaceFlingerBE::NUM_BUCKETS - 1) { |
| 2075 | getBE().mFrameBuckets[numPeriods] += elapsedTime; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2076 | } else { |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 2077 | getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] += elapsedTime; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2078 | } |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 2079 | getBE().mTotalTime += elapsedTime; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2080 | } |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 2081 | getBE().mLastSwapTime = currentTime; |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2082 | |
| 2083 | { |
| 2084 | std::lock_guard lock(mTexturePoolMutex); |
| 2085 | const size_t refillCount = mTexturePoolSize - mTexturePool.size(); |
| 2086 | if (refillCount > 0) { |
| 2087 | const size_t offset = mTexturePool.size(); |
| 2088 | mTexturePool.resize(mTexturePoolSize); |
| 2089 | getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset); |
| 2090 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
| 2091 | } |
| 2092 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 2093 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2094 | mTransactionCompletedThread.addPresentFence(mPreviousPresentFence); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 2095 | mTransactionCompletedThread.sendCallbacks(); |
Ady Abraham | 8164d48 | 2019-01-11 14:47:59 -0800 | [diff] [blame] | 2096 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 2097 | if (mLumaSampling) { |
| 2098 | mRegionSamplingThread->sampleNow(); |
| 2099 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2102 | void SurfaceFlinger::computeLayerBounds() { |
| 2103 | for (const auto& pair : mDisplays) { |
| 2104 | const auto& displayDevice = pair.second; |
| 2105 | const auto display = displayDevice->getCompositionDisplay(); |
| 2106 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 2107 | // only consider the layers on the given layer stack |
| 2108 | if (!display->belongsInOutput(layer->getLayerStack(), layer->getPrimaryDisplayOnly())) { |
Vishnu Nair | 01ace76 | 2019-02-12 14:25:24 -0800 | [diff] [blame] | 2109 | continue; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | layer->computeBounds(displayDevice->getViewport().toFloatRect(), ui::Transform()); |
| 2113 | } |
| 2114 | } |
| 2115 | } |
| 2116 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2117 | void SurfaceFlinger::rebuildLayerStacks() { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2118 | ATRACE_CALL(); |
| 2119 | ALOGV("rebuildLayerStacks"); |
| 2120 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2121 | // rebuild the visible layer list per screen |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2122 | if (CC_UNLIKELY(mVisibleRegionsDirty)) { |
Siarhei Vishniakou | fc2589e | 2017-09-21 15:35:13 -0700 | [diff] [blame] | 2123 | ATRACE_NAME("rebuildLayerStacks VR Dirty"); |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2124 | mVisibleRegionsDirty = false; |
| 2125 | invalidateHwcGeometry(); |
Fabien Sanglard | 3beb711 | 2017-02-24 17:33:52 -0800 | [diff] [blame] | 2126 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2127 | for (const auto& pair : mDisplays) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2128 | const auto& displayDevice = pair.second; |
| 2129 | auto display = displayDevice->getCompositionDisplay(); |
| 2130 | const auto& displayState = display->getState(); |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2131 | Region opaqueRegion; |
| 2132 | Region dirtyRegion; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 2133 | compositionengine::Output::OutputLayers layersSortedByZ; |
| 2134 | Vector<sp<Layer>> deprecated_layersSortedByZ; |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2135 | Vector<sp<Layer>> layersNeedingFences; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2136 | const ui::Transform& tr = displayState.transform; |
| 2137 | const Rect bounds = displayState.bounds; |
| 2138 | if (displayState.isEnabled) { |
| 2139 | computeVisibleRegions(displayDevice, dirtyRegion, opaqueRegion); |
Fabien Sanglard | 3beb711 | 2017-02-24 17:33:52 -0800 | [diff] [blame] | 2140 | |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2141 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 2142 | auto compositionLayer = layer->getCompositionLayer(); |
| 2143 | if (compositionLayer == nullptr) { |
| 2144 | return; |
| 2145 | } |
| 2146 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2147 | const auto displayId = displayDevice->getId(); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 2148 | sp<compositionengine::LayerFE> layerFE = compositionLayer->getLayerFE(); |
| 2149 | LOG_ALWAYS_FATAL_IF(layerFE.get() == nullptr); |
| 2150 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 2151 | bool needsOutputLayer = false; |
| 2152 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 2153 | if (display->belongsInOutput(layer->getLayerStack(), |
| 2154 | layer->getPrimaryDisplayOnly())) { |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2155 | Region drawRegion(tr.transform( |
| 2156 | layer->visibleNonTransparentRegion)); |
| 2157 | drawRegion.andSelf(bounds); |
| 2158 | if (!drawRegion.isEmpty()) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 2159 | needsOutputLayer = true; |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2160 | } |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2161 | } |
| 2162 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 2163 | if (needsOutputLayer) { |
| 2164 | layersSortedByZ.emplace_back( |
| 2165 | display->getOrCreateOutputLayer(displayId, compositionLayer, |
| 2166 | layerFE)); |
| 2167 | deprecated_layersSortedByZ.add(layer); |
| 2168 | |
| 2169 | auto& outputLayerState = layersSortedByZ.back()->editState(); |
| 2170 | outputLayerState.visibleRegion = |
| 2171 | tr.transform(layer->visibleRegion.intersect(displayState.viewport)); |
| 2172 | } else if (displayId) { |
| 2173 | // For layers that are being removed from a HWC display, |
| 2174 | // and that have queued frames, add them to a a list of |
| 2175 | // released layers so we can properly set a fence. |
| 2176 | bool hasExistingOutputLayer = |
| 2177 | display->getOutputLayerForLayer(compositionLayer.get()) != nullptr; |
| 2178 | bool hasQueuedFrames = std::find(mLayersWithQueuedFrames.cbegin(), |
| 2179 | mLayersWithQueuedFrames.cend(), |
| 2180 | layer) != mLayersWithQueuedFrames.cend(); |
| 2181 | |
| 2182 | if (hasExistingOutputLayer && hasQueuedFrames) { |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2183 | layersNeedingFences.add(layer); |
| 2184 | } |
Fabien Sanglard | 3beb711 | 2017-02-24 17:33:52 -0800 | [diff] [blame] | 2185 | } |
Jeff Sharkey | 7648811 | 2017-02-27 14:15:18 -0700 | [diff] [blame] | 2186 | }); |
| 2187 | } |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 2188 | |
| 2189 | display->setOutputLayersOrderedByZ(std::move(layersSortedByZ)); |
| 2190 | |
| 2191 | displayDevice->setVisibleLayersSortedByZ(deprecated_layersSortedByZ); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2192 | displayDevice->setLayersNeedingFences(layersNeedingFences); |
| 2193 | |
| 2194 | Region undefinedRegion{bounds}; |
| 2195 | undefinedRegion.subtractSelf(tr.transform(opaqueRegion)); |
| 2196 | |
| 2197 | display->editState().undefinedRegion = undefinedRegion; |
| 2198 | display->editState().dirtyRegion.orSelf(dirtyRegion); |
Fabien Sanglard | 3beb711 | 2017-02-24 17:33:52 -0800 | [diff] [blame] | 2199 | } |
Fabien Sanglard | 3beb711 | 2017-02-24 17:33:52 -0800 | [diff] [blame] | 2200 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2201 | } |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 2202 | |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2203 | // Returns a data space that fits all visible layers. The returned data space |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2204 | // can only be one of |
Chia-I Wu | 7a28ecb | 2018-05-04 10:38:39 -0700 | [diff] [blame] | 2205 | // - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced) |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2206 | // - Dataspace::DISPLAY_P3 |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 2207 | // - Dataspace::DISPLAY_BT2020 |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2208 | // The returned HDR data space is one of |
| 2209 | // - Dataspace::UNKNOWN |
| 2210 | // - Dataspace::BT2020_HLG |
| 2211 | // - Dataspace::BT2020_PQ |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2212 | Dataspace SurfaceFlinger::getBestDataspace(const sp<const DisplayDevice>& display, |
| 2213 | Dataspace* outHdrDataSpace) const { |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 2214 | Dataspace bestDataSpace = Dataspace::V0_SRGB; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2215 | *outHdrDataSpace = Dataspace::UNKNOWN; |
| 2216 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2217 | for (const auto& layer : display->getVisibleLayersSortedByZ()) { |
Chia-I Wu | 01591c9 | 2018-05-22 12:03:00 -0700 | [diff] [blame] | 2218 | switch (layer->getDataSpace()) { |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2219 | case Dataspace::V0_SCRGB: |
| 2220 | case Dataspace::V0_SCRGB_LINEAR: |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 2221 | case Dataspace::BT2020: |
| 2222 | case Dataspace::BT2020_ITU: |
| 2223 | case Dataspace::BT2020_LINEAR: |
| 2224 | case Dataspace::DISPLAY_BT2020: |
| 2225 | bestDataSpace = Dataspace::DISPLAY_BT2020; |
| 2226 | break; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2227 | case Dataspace::DISPLAY_P3: |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 2228 | bestDataSpace = Dataspace::DISPLAY_P3; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2229 | break; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2230 | case Dataspace::BT2020_PQ: |
| 2231 | case Dataspace::BT2020_ITU_PQ: |
Peiyong Lin | f6eb766 | 2019-02-05 15:39:15 -0800 | [diff] [blame] | 2232 | bestDataSpace = Dataspace::DISPLAY_P3; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2233 | *outHdrDataSpace = Dataspace::BT2020_PQ; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2234 | break; |
Peiyong Lin | f59a719 | 2018-04-25 11:19:31 -0700 | [diff] [blame] | 2235 | case Dataspace::BT2020_HLG: |
| 2236 | case Dataspace::BT2020_ITU_HLG: |
Peiyong Lin | f6eb766 | 2019-02-05 15:39:15 -0800 | [diff] [blame] | 2237 | bestDataSpace = Dataspace::DISPLAY_P3; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2238 | // When there's mixed PQ content and HLG content, we set the HDR |
| 2239 | // data space to be BT2020_PQ and convert HLG to PQ. |
| 2240 | if (*outHdrDataSpace == Dataspace::UNKNOWN) { |
| 2241 | *outHdrDataSpace = Dataspace::BT2020_HLG; |
Peiyong Lin | f59a719 | 2018-04-25 11:19:31 -0700 | [diff] [blame] | 2242 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2243 | break; |
| 2244 | default: |
| 2245 | break; |
| 2246 | } |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 2247 | } |
| 2248 | |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2249 | return bestDataSpace; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 2250 | } |
| 2251 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2252 | // Pick the ColorMode / Dataspace for the display device. |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2253 | void SurfaceFlinger::pickColorMode(const sp<DisplayDevice>& display, ColorMode* outMode, |
| 2254 | Dataspace* outDataSpace, RenderIntent* outRenderIntent) const { |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2255 | if (mDisplayColorSetting == DisplayColorSetting::UNMANAGED) { |
| 2256 | *outMode = ColorMode::NATIVE; |
| 2257 | *outDataSpace = Dataspace::UNKNOWN; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2258 | *outRenderIntent = RenderIntent::COLORIMETRIC; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2259 | return; |
Chia-I Wu | 5c6e463 | 2018-01-11 08:54:38 -0800 | [diff] [blame] | 2260 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 2261 | |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2262 | Dataspace hdrDataSpace; |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2263 | Dataspace bestDataSpace = getBestDataspace(display, &hdrDataSpace); |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2264 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 2265 | auto* profile = display->getCompositionDisplay()->getDisplayColorProfile(); |
| 2266 | |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 2267 | switch (mForceColorMode) { |
| 2268 | case ColorMode::SRGB: |
| 2269 | bestDataSpace = Dataspace::V0_SRGB; |
| 2270 | break; |
| 2271 | case ColorMode::DISPLAY_P3: |
| 2272 | bestDataSpace = Dataspace::DISPLAY_P3; |
| 2273 | break; |
| 2274 | default: |
| 2275 | break; |
| 2276 | } |
| 2277 | |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 2278 | // respect hdrDataSpace only when there is no legacy HDR support |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 2279 | const bool isHdr = |
| 2280 | hdrDataSpace != Dataspace::UNKNOWN && !profile->hasLegacyHdrSupport(hdrDataSpace); |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 2281 | if (isHdr) { |
| 2282 | bestDataSpace = hdrDataSpace; |
| 2283 | } |
| 2284 | |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 2285 | RenderIntent intent; |
| 2286 | switch (mDisplayColorSetting) { |
| 2287 | case DisplayColorSetting::MANAGED: |
| 2288 | case DisplayColorSetting::UNMANAGED: |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 2289 | intent = isHdr ? RenderIntent::TONE_MAP_COLORIMETRIC : RenderIntent::COLORIMETRIC; |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 2290 | break; |
| 2291 | case DisplayColorSetting::ENHANCED: |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 2292 | intent = isHdr ? RenderIntent::TONE_MAP_ENHANCE : RenderIntent::ENHANCE; |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 2293 | break; |
| 2294 | default: // vendor display color setting |
| 2295 | intent = static_cast<RenderIntent>(mDisplayColorSetting); |
| 2296 | break; |
| 2297 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 2298 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 2299 | profile->getBestColorMode(bestDataSpace, intent, outDataSpace, outMode, outRenderIntent); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 2300 | } |
| 2301 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2302 | void SurfaceFlinger::beginFrame(const sp<DisplayDevice>& displayDevice) { |
| 2303 | auto display = displayDevice->getCompositionDisplay(); |
| 2304 | const auto& displayState = display->getState(); |
| 2305 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 2306 | bool dirty = !display->getDirtyRegion(false).isEmpty(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2307 | bool empty = displayDevice->getVisibleLayersSortedByZ().size() == 0; |
| 2308 | bool wasEmpty = !displayState.lastCompositionHadVisibleLayers; |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2309 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2310 | // If nothing has changed (!dirty), don't recompose. |
| 2311 | // If something changed, but we don't currently have any visible layers, |
| 2312 | // and didn't when we last did a composition, then skip it this time. |
| 2313 | // The second rule does two things: |
| 2314 | // - When all layers are removed from a display, we'll emit one black |
| 2315 | // frame, then nothing more until we get new layers. |
| 2316 | // - When a display is created with a private layer stack, we won't |
| 2317 | // emit any black frames until a layer is added to the layer stack. |
| 2318 | bool mustRecompose = dirty && !(empty && wasEmpty); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2319 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2320 | const char flagPrefix[] = {'-', '+'}; |
| 2321 | static_cast<void>(flagPrefix); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2322 | ALOGV_IF(displayDevice->isVirtual(), "%s: %s composition for %s (%cdirty %cempty %cwasEmpty)", |
| 2323 | __FUNCTION__, mustRecompose ? "doing" : "skipping", |
| 2324 | displayDevice->getDebugName().c_str(), flagPrefix[dirty], flagPrefix[empty], |
| 2325 | flagPrefix[wasEmpty]); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2326 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2327 | display->getRenderSurface()->beginFrame(mustRecompose); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2328 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2329 | if (mustRecompose) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2330 | display->editState().lastCompositionHadVisibleLayers = !empty; |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2334 | void SurfaceFlinger::prepareFrame(const sp<DisplayDevice>& displayDevice) { |
| 2335 | auto display = displayDevice->getCompositionDisplay(); |
| 2336 | const auto& displayState = display->getState(); |
| 2337 | |
| 2338 | if (!displayState.isEnabled) { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2339 | return; |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2340 | } |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2341 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2342 | status_t result = display->getRenderSurface()->prepareFrame(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2343 | ALOGE_IF(result != NO_ERROR, "prepareFrame failed for %s: %d (%s)", |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2344 | displayDevice->getDebugName().c_str(), result, strerror(-result)); |
David Sodman | 2b40636 | 2017-12-15 13:33:47 -0800 | [diff] [blame] | 2345 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 2346 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2347 | void SurfaceFlinger::doComposition(const sp<DisplayDevice>& displayDevice, bool repaintEverything) { |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2348 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2349 | ALOGV("doComposition"); |
| 2350 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2351 | auto display = displayDevice->getCompositionDisplay(); |
| 2352 | const auto& displayState = display->getState(); |
| 2353 | |
| 2354 | if (displayState.isEnabled) { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2355 | // transform the dirty region into this screen's coordinate space |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 2356 | const Region dirtyRegion = display->getDirtyRegion(repaintEverything); |
Mathias Agopian | 02b9510 | 2012-11-05 17:50:57 -0800 | [diff] [blame] | 2357 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2358 | // repaint the framebuffer (if needed) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2359 | doDisplayComposition(displayDevice, dirtyRegion); |
Mathias Agopian | 02b9510 | 2012-11-05 17:50:57 -0800 | [diff] [blame] | 2360 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2361 | display->editState().dirtyRegion.clear(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2362 | display->getRenderSurface()->flip(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2363 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2364 | postFramebuffer(displayDevice); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2367 | void SurfaceFlinger::postFrame() |
| 2368 | { |
| 2369 | // |mStateLock| not needed as we are on the main thread |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2370 | const auto display = getDefaultDisplayDeviceLocked(); |
| 2371 | if (display && getHwComposer().isConnected(*display->getId())) { |
| 2372 | uint32_t flipCount = display->getPageFlipCount(); |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2373 | if (flipCount % LOG_FRAME_STATS_PERIOD == 0) { |
| 2374 | logFrameStats(); |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2379 | void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 2380 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2381 | ALOGV("postFramebuffer"); |
Mathias Agopian | b048cef | 2012-02-04 15:44:04 -0800 | [diff] [blame] | 2382 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2383 | auto display = displayDevice->getCompositionDisplay(); |
| 2384 | const auto& displayState = display->getState(); |
| 2385 | const auto displayId = display->getId(); |
| 2386 | |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2387 | mPostFramebufferTime = systemTime(); |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 2388 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2389 | if (displayState.isEnabled) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2390 | if (displayId) { |
| 2391 | getHwComposer().presentAndGetReleaseFences(*displayId); |
Mathias Agopian | 2a23184 | 2012-09-24 18:12:35 -0700 | [diff] [blame] | 2392 | } |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2393 | display->getRenderSurface()->onPresentDisplayCompleted(); |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2394 | for (auto& layer : display->getOutputLayersOrderedByZ()) { |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 2395 | sp<Fence> releaseFence = Fence::NO_FENCE; |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2396 | bool usedClientComposition = true; |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 2397 | |
Chia-I Wu | 7b54959 | 2017-11-15 09:14:57 -0800 | [diff] [blame] | 2398 | // The layer buffer from the previous frame (if any) is released |
| 2399 | // by HWC only when the release fence from this frame (if any) is |
| 2400 | // signaled. Always get the release fence from HWC first. |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2401 | if (layer->getState().hwc) { |
| 2402 | const auto& hwcState = *layer->getState().hwc; |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2403 | releaseFence = |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2404 | getHwComposer().getLayerReleaseFence(*displayId, hwcState.hwcLayer.get()); |
| 2405 | usedClientComposition = |
| 2406 | hwcState.hwcCompositionType == Hwc2::IComposerClient::Composition::CLIENT; |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 2407 | } |
Chia-I Wu | 7b54959 | 2017-11-15 09:14:57 -0800 | [diff] [blame] | 2408 | |
| 2409 | // If the layer was client composited in the previous frame, we |
| 2410 | // need to merge with the previous client target acquire fence. |
| 2411 | // Since we do not track that, always merge with the current |
| 2412 | // client target acquire fence when it is available, even though |
| 2413 | // this is suboptimal. |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2414 | if (usedClientComposition) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2415 | releaseFence = |
| 2416 | Fence::merge("LayerRelease", releaseFence, |
| 2417 | display->getRenderSurface()->getClientTargetAcquireFence()); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 2418 | } |
Chia-I Wu | 7b54959 | 2017-11-15 09:14:57 -0800 | [diff] [blame] | 2419 | |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2420 | layer->getLayerFE().onLayerDisplayed(releaseFence); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2421 | } |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2422 | |
| 2423 | // We've got a list of layers needing fences, that are disjoint with |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2424 | // display->getVisibleLayersSortedByZ. The best we can do is to |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2425 | // supply them with the present fence. |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2426 | if (!displayDevice->getLayersNeedingFences().isEmpty()) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2427 | sp<Fence> presentFence = |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 2428 | displayId ? getHwComposer().getPresentFence(*displayId) : Fence::NO_FENCE; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2429 | for (auto& layer : displayDevice->getLayersNeedingFences()) { |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 2430 | layer->getCompositionLayer()->getLayerFE()->onLayerDisplayed(presentFence); |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2434 | if (displayId) { |
| 2435 | getHwComposer().clearReleaseFences(*displayId); |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 2436 | } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 2437 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2440 | void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 2442 | ATRACE_CALL(); |
| 2443 | |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 2444 | // here we keep a copy of the drawing state (that is the state that's |
| 2445 | // going to be overwritten by handleTransactionLocked()) outside of |
| 2446 | // mStateLock so that the side-effects of the State assignment |
| 2447 | // don't happen with mStateLock held (which can cause deadlocks). |
| 2448 | State drawingState(mDrawingState); |
| 2449 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 2450 | Mutex::Autolock _l(mStateLock); |
| 2451 | const nsecs_t now = systemTime(); |
| 2452 | mDebugInTransaction = now; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 2454 | // Here we're guaranteed that some transaction flags are set |
| 2455 | // so we can call handleTransactionLocked() unconditionally. |
| 2456 | // We call getTransactionFlags(), which will also clear the flags, |
| 2457 | // with mStateLock held to guarantee that mCurrentState won't change |
| 2458 | // until the transaction is committed. |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 2459 | |
Jorim Jaggi | f15c3be | 2018-04-12 12:56:58 +0100 | [diff] [blame] | 2460 | mVsyncModulator.onTransactionHandled(); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 2461 | transactionFlags = getTransactionFlags(eTransactionMask); |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2462 | handleTransactionLocked(transactionFlags); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 2463 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 2464 | mLastTransactionTime = systemTime() - now; |
| 2465 | mDebugInTransaction = 0; |
| 2466 | invalidateHwcGeometry(); |
| 2467 | // here the transaction has been committed |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2470 | void SurfaceFlinger::processDisplayHotplugEventsLocked() { |
| 2471 | for (const auto& event : mPendingHotplugEvents) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2472 | const std::optional<DisplayIdentificationInfo> info = |
| 2473 | getHwComposer().onHotplug(event.hwcDisplayId, event.connection); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2474 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2475 | if (!info) { |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2476 | continue; |
| 2477 | } |
| 2478 | |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2479 | if (event.connection == HWC2::Connection::Connected) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2480 | if (!mPhysicalDisplayTokens.count(info->id)) { |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 2481 | ALOGV("Creating display %s", to_string(info->id).c_str()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2482 | mPhysicalDisplayTokens[info->id] = new BBinder(); |
| 2483 | DisplayDeviceState state; |
| 2484 | state.displayId = info->id; |
| 2485 | state.isSecure = true; // All physical displays are currently considered secure. |
| 2486 | state.displayName = info->name; |
| 2487 | mCurrentState.displays.add(mPhysicalDisplayTokens[info->id], state); |
| 2488 | mInterceptor->saveDisplayCreation(state); |
Steven Thomas | eb6d205 | 2018-03-20 15:40:48 -0700 | [diff] [blame] | 2489 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2490 | } else { |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 2491 | ALOGV("Removing display %s", to_string(info->id).c_str()); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2492 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2493 | ssize_t index = mCurrentState.displays.indexOfKey(mPhysicalDisplayTokens[info->id]); |
| 2494 | if (index >= 0) { |
| 2495 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
| 2496 | mInterceptor->saveDisplayDeletion(state.sequenceId); |
| 2497 | mCurrentState.displays.removeItemsAt(index); |
Lloyd Pique | fcd8661 | 2017-12-14 17:15:36 -0800 | [diff] [blame] | 2498 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2499 | mPhysicalDisplayTokens.erase(info->id); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | processDisplayChangesLocked(); |
| 2503 | } |
| 2504 | |
| 2505 | mPendingHotplugEvents.clear(); |
| 2506 | } |
| 2507 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2508 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2509 | mScheduler->hotplugReceived(mAppConnectionHandle, displayId, connected); |
| 2510 | mScheduler->hotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2513 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2514 | const wp<IBinder>& displayToken, const std::optional<DisplayId>& displayId, |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 2515 | const DisplayDeviceState& state, const sp<compositionengine::DisplaySurface>& dispSurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2516 | const sp<IGraphicBufferProducer>& producer) { |
| 2517 | DisplayDeviceCreationArgs creationArgs(this, displayToken, displayId); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 2518 | creationArgs.sequenceId = state.sequenceId; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2519 | creationArgs.isVirtual = state.isVirtual(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2520 | creationArgs.isSecure = state.isSecure; |
| 2521 | creationArgs.displaySurface = dispSurface; |
| 2522 | creationArgs.hasWideColorGamut = false; |
| 2523 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2524 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2525 | const bool isInternalDisplay = displayId && displayId == getInternalDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2526 | creationArgs.isPrimary = isInternalDisplay; |
| 2527 | |
| 2528 | if (useColorManagement && displayId) { |
| 2529 | std::vector<ColorMode> modes = getHwComposer().getColorModes(*displayId); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2530 | for (ColorMode colorMode : modes) { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 2531 | if (isWideColorMode(colorMode)) { |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2532 | creationArgs.hasWideColorGamut = true; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2533 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2534 | |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 2535 | std::vector<RenderIntent> renderIntents = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2536 | getHwComposer().getRenderIntents(*displayId, colorMode); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2537 | creationArgs.hwcColorModes.emplace(colorMode, renderIntents); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2538 | } |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 2539 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2540 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2541 | if (displayId) { |
| 2542 | getHwComposer().getHdrCapabilities(*displayId, &creationArgs.hdrCapabilities); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2543 | creationArgs.supportedPerFrameMetadata = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2544 | getHwComposer().getSupportedPerFrameMetadata(*displayId); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 2545 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2546 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 2547 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2548 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2549 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2550 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2551 | // Make sure that composition can never be stalled by a virtual display |
| 2552 | // consumer that isn't processing buffers fast enough. We have to do this |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 2553 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 2554 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2555 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 2556 | } |
| 2557 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2558 | creationArgs.displayInstallOrientation = |
| 2559 | isInternalDisplay ? primaryDisplayOrientation : DisplayState::eOrientationDefault; |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 2560 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2561 | // virtual displays are always considered enabled |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2562 | creationArgs.initialPowerMode = state.isVirtual() ? HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2563 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 2564 | sp<DisplayDevice> display = getFactory().createDisplayDevice(std::move(creationArgs)); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2565 | |
| 2566 | if (maxFrameBufferAcquiredBuffers >= 3) { |
| 2567 | nativeWindowSurface->preallocateBuffers(); |
| 2568 | } |
| 2569 | |
| 2570 | ColorMode defaultColorMode = ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2571 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2572 | if (display->hasWideColorGamut()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2573 | defaultColorMode = ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 2574 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2575 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2576 | display->getCompositionDisplay()->setColorMode(defaultColorMode, defaultDataSpace, |
| 2577 | RenderIntent::COLORIMETRIC); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2578 | if (!state.isVirtual()) { |
| 2579 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 2580 | display->setActiveConfig(getHwComposer().getActiveConfigIndex(*displayId)); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 2581 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2582 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2583 | display->setLayerStack(state.layerStack); |
| 2584 | display->setProjection(state.orientation, state.viewport, state.frame); |
| 2585 | display->setDisplayName(state.displayName); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2586 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2587 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2588 | } |
| 2589 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2590 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 2591 | // here we take advantage of Vector's copy-on-write semantics to |
| 2592 | // improve performance by skipping the transaction entirely when |
| 2593 | // know that the lists are identical |
| 2594 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 2595 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 2596 | if (!curr.isIdenticalTo(draw)) { |
| 2597 | mVisibleRegionsDirty = true; |
| 2598 | const size_t cc = curr.size(); |
| 2599 | size_t dc = draw.size(); |
| 2600 | |
| 2601 | // find the displays that were removed |
| 2602 | // (ie: in drawing state but not in current state) |
| 2603 | // also handle displays that changed |
| 2604 | // (ie: displays that are in both lists) |
| 2605 | for (size_t i = 0; i < dc;) { |
| 2606 | const ssize_t j = curr.indexOfKey(draw.keyAt(i)); |
| 2607 | if (j < 0) { |
| 2608 | // in drawing state but not in current state |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2609 | if (const auto display = getDisplayDeviceLocked(draw.keyAt(i))) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2610 | // Save display ID before disconnecting. |
| 2611 | const auto displayId = display->getId(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 2612 | display->disconnect(); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2613 | |
| 2614 | if (!display->isVirtual()) { |
| 2615 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 2616 | dispatchDisplayHotplugEvent(displayId->value, false); |
| 2617 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2618 | } |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2619 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2620 | mDisplays.erase(draw.keyAt(i)); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2621 | } else { |
| 2622 | // this display is in both lists. see if something changed. |
| 2623 | const DisplayDeviceState& state(curr[j]); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2624 | const wp<IBinder>& displayToken = curr.keyAt(j); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2625 | const sp<IBinder> state_binder = IInterface::asBinder(state.surface); |
| 2626 | const sp<IBinder> draw_binder = IInterface::asBinder(draw[i].surface); |
| 2627 | if (state_binder != draw_binder) { |
| 2628 | // changing the surface is like destroying and |
| 2629 | // recreating the DisplayDevice, so we just remove it |
| 2630 | // from the drawing state, so that it get re-added |
| 2631 | // below. |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2632 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 2633 | display->disconnect(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2634 | } |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2635 | mDisplays.erase(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2636 | mDrawingState.displays.removeItemsAt(i); |
| 2637 | dc--; |
| 2638 | // at this point we must loop to the next item |
| 2639 | continue; |
| 2640 | } |
| 2641 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2642 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2643 | if (state.layerStack != draw[i].layerStack) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2644 | display->setLayerStack(state.layerStack); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2645 | } |
| 2646 | if ((state.orientation != draw[i].orientation) || |
| 2647 | (state.viewport != draw[i].viewport) || (state.frame != draw[i].frame)) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2648 | display->setProjection(state.orientation, state.viewport, state.frame); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2649 | } |
| 2650 | if (state.width != draw[i].width || state.height != draw[i].height) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2651 | display->setDisplaySize(state.width, state.height); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | } |
| 2655 | ++i; |
| 2656 | } |
| 2657 | |
| 2658 | // find displays that were added |
| 2659 | // (ie: in current state but not in drawing state) |
| 2660 | for (size_t i = 0; i < cc; i++) { |
| 2661 | if (draw.indexOfKey(curr.keyAt(i)) < 0) { |
| 2662 | const DisplayDeviceState& state(curr[i]); |
| 2663 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 2664 | sp<compositionengine::DisplaySurface> dispSurface; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2665 | sp<IGraphicBufferProducer> producer; |
| 2666 | sp<IGraphicBufferProducer> bqProducer; |
| 2667 | sp<IGraphicBufferConsumer> bqConsumer; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 2668 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, false); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2669 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2670 | std::optional<DisplayId> displayId; |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 2671 | if (state.isVirtual()) { |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2672 | // Virtual displays without a surface are dormant: |
| 2673 | // they have external state (layer stack, projection, |
| 2674 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 2675 | if (state.surface != nullptr) { |
| 2676 | // Allow VR composer to use virtual displays. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2677 | if (mUseHwcVirtualDisplays || getHwComposer().isUsingVrComposer()) { |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2678 | int width = 0; |
| 2679 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &width); |
| 2680 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
| 2681 | int height = 0; |
| 2682 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &height); |
| 2683 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
| 2684 | int intFormat = 0; |
| 2685 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &intFormat); |
| 2686 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 2687 | auto format = static_cast<ui::PixelFormat>(intFormat); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2688 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2689 | displayId = |
| 2690 | getHwComposer().allocateVirtualDisplay(width, height, &format); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | // TODO: Plumb requested format back up to consumer |
| 2694 | |
| 2695 | sp<VirtualDisplaySurface> vds = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2696 | new VirtualDisplaySurface(getHwComposer(), displayId, state.surface, |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2697 | bqProducer, bqConsumer, |
| 2698 | state.displayName); |
| 2699 | |
| 2700 | dispSurface = vds; |
| 2701 | producer = vds; |
| 2702 | } |
| 2703 | } else { |
| 2704 | ALOGE_IF(state.surface != nullptr, |
| 2705 | "adding a supported display, but rendering " |
| 2706 | "surface is provided (%p), ignoring it", |
| 2707 | state.surface.get()); |
| 2708 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2709 | displayId = state.displayId; |
| 2710 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 2711 | dispSurface = new FramebufferSurface(getHwComposer(), *displayId, bqConsumer); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2712 | producer = bqProducer; |
| 2713 | } |
| 2714 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2715 | const wp<IBinder>& displayToken = curr.keyAt(i); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2716 | if (dispSurface != nullptr) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2717 | mDisplays.emplace(displayToken, |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 2718 | setupNewDisplayDeviceInternal(displayToken, displayId, state, |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2719 | dispSurface, producer)); |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 2720 | if (!state.isVirtual()) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2721 | LOG_ALWAYS_FATAL_IF(!displayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2722 | dispatchDisplayHotplugEvent(displayId->value, true); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2723 | } |
| 2724 | } |
| 2725 | } |
| 2726 | } |
| 2727 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2728 | |
| 2729 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2730 | } |
| 2731 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2732 | void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 2733 | { |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 2734 | // Notify all layers of available frames |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2735 | mCurrentState.traverseInZOrder([](Layer* layer) { |
| 2736 | layer->notifyAvailableFrames(); |
| 2737 | }); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 2738 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | /* |
| 2740 | * Traversal of the children |
| 2741 | * (perform the transaction for each of them if needed) |
| 2742 | */ |
| 2743 | |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2744 | if (transactionFlags & eTraversalNeeded) { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2745 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2747 | if (!trFlags) return; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | |
| 2749 | const uint32_t flags = layer->doTransaction(0); |
| 2750 | if (flags & Layer::eVisibleRegion) |
| 2751 | mVisibleRegionsDirty = true; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2752 | |
| 2753 | if (flags & Layer::eInputInfoChanged) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2754 | mInputInfoChanged = true; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2755 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2756 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | /* |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2760 | * Perform display own transactions if needed |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | */ |
| 2762 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 2763 | if (transactionFlags & eDisplayTransactionNeeded) { |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 2764 | processDisplayChangesLocked(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2765 | processDisplayHotplugEventsLocked(); |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2766 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 2768 | if (transactionFlags & (eDisplayLayerStackChanged|eDisplayTransactionNeeded)) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2769 | // The transform hint might have changed for some layers |
| 2770 | // (either because a display has changed, or because a layer |
| 2771 | // as changed). |
| 2772 | // |
| 2773 | // Walk through all the layers in currentLayers, |
| 2774 | // and update their transform hint. |
| 2775 | // |
| 2776 | // If a layer is visible only on a single display, then that |
| 2777 | // display is used to calculate the hint, otherwise we use the |
| 2778 | // default display. |
| 2779 | // |
| 2780 | // NOTE: we do this here, rather than in rebuildLayerStacks() so that |
| 2781 | // the hint is set before we acquire a buffer from the surface texture. |
| 2782 | // |
| 2783 | // NOTE: layer transactions have taken place already, so we use their |
| 2784 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 2785 | // happened yet, so we must use the current state layer list |
| 2786 | // (soon to become the drawing state list). |
| 2787 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2788 | sp<const DisplayDevice> hintDisplay; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2789 | uint32_t currentlayerStack = 0; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2790 | bool first = true; |
| 2791 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2792 | // NOTE: we rely on the fact that layers are sorted by |
| 2793 | // layerStack first (so we don't have to traverse the list |
| 2794 | // of displays for every layer). |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2795 | uint32_t layerStack = layer->getLayerStack(); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2796 | if (first || currentlayerStack != layerStack) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2797 | currentlayerStack = layerStack; |
| 2798 | // figure out if this layerstack is mirrored |
| 2799 | // (more than one display) if so, pick the default display, |
| 2800 | // if not, pick the only display it's on. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2801 | hintDisplay = nullptr; |
| 2802 | for (const auto& [token, display] : mDisplays) { |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 2803 | if (display->getCompositionDisplay() |
| 2804 | ->belongsInOutput(layer->getLayerStack(), |
| 2805 | layer->getPrimaryDisplayOnly())) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2806 | if (hintDisplay) { |
| 2807 | hintDisplay = nullptr; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2808 | break; |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2809 | } else { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2810 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 2815 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2816 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 2817 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 2818 | // redraw after transform hint changes. See bug 8508397. |
Robert Carr | 56a0b9a | 2017-12-04 16:06:13 -0800 | [diff] [blame] | 2819 | |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 2820 | // could be null when this layer is using a layerStack |
| 2821 | // that is not visible on any display. Also can occur at |
| 2822 | // screen off/on times. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2823 | hintDisplay = getDefaultDisplayDeviceLocked(); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2824 | } |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 2825 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2826 | // could be null if there is no display available at all to get |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 2827 | // the transform hint from. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2828 | if (hintDisplay) { |
| 2829 | layer->updateTransformHint(hintDisplay); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 2830 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2831 | |
| 2832 | first = false; |
| 2833 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2837 | /* |
| 2838 | * Perform our own transaction if needed |
| 2839 | */ |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2840 | |
| 2841 | if (mLayersAdded) { |
| 2842 | mLayersAdded = false; |
| 2843 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2844 | mVisibleRegionsDirty = true; |
| 2845 | } |
| 2846 | |
| 2847 | // some layers might have been removed, so |
| 2848 | // we need to update the regions they're exposing. |
| 2849 | if (mLayersRemoved) { |
| 2850 | mLayersRemoved = false; |
| 2851 | mVisibleRegionsDirty = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2852 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2853 | if (mLayersPendingRemoval.indexOf(layer) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 2854 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2855 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2856 | visibleReg.set(layer->getScreenBounds()); |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 2857 | invalidateLayerStack(layer, visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 2858 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2859 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | } |
| 2861 | |
Vishnu Nair | ec0ab38 | 2019-02-13 15:32:56 -0800 | [diff] [blame] | 2862 | commitInputWindowCommands(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | commitTransaction(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2866 | void SurfaceFlinger::updateInputFlinger() { |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2867 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2868 | if (!mInputFlinger) { |
Vishnu Nair | de19f85 | 2018-12-18 16:11:53 -0800 | [diff] [blame] | 2869 | return; |
| 2870 | } |
| 2871 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2872 | if (mVisibleRegionsDirty || mInputInfoChanged) { |
| 2873 | mInputInfoChanged = false; |
| 2874 | updateInputWindowInfo(); |
chaviw | 95ef3c4 | 2019-02-14 10:55:09 -0800 | [diff] [blame] | 2875 | } else if (mInputWindowCommands.syncInputWindows) { |
| 2876 | // If the caller requested to sync input windows, but there are no |
| 2877 | // changes to input windows, notify immediately. |
| 2878 | setInputWindowsFinished(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | executeInputWindowCommands(); |
| 2882 | } |
| 2883 | |
| 2884 | void SurfaceFlinger::updateInputWindowInfo() { |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2885 | Vector<InputWindowInfo> inputHandles; |
| 2886 | |
| 2887 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 2888 | if (layer->hasInput()) { |
Vishnu Nair | 51625fa | 2018-12-06 13:54:33 -0800 | [diff] [blame] | 2889 | // When calculating the screen bounds we ignore the transparent region since it may |
| 2890 | // result in an unwanted offset. |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 2891 | inputHandles.add(layer->fillInputInfo()); |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2892 | } |
| 2893 | }); |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 2894 | |
| 2895 | mInputFlinger->setInputWindows(inputHandles, |
| 2896 | mInputWindowCommands.syncInputWindows ? mSetInputWindowsListener |
| 2897 | : nullptr); |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
Vishnu Nair | ec0ab38 | 2019-02-13 15:32:56 -0800 | [diff] [blame] | 2900 | void SurfaceFlinger::commitInputWindowCommands() { |
| 2901 | mInputWindowCommands.merge(mPendingInputWindowCommands); |
| 2902 | mPendingInputWindowCommands.clear(); |
| 2903 | } |
| 2904 | |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 2905 | void SurfaceFlinger::executeInputWindowCommands() { |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 2906 | for (const auto& transferTouchFocusCommand : mInputWindowCommands.transferTouchFocusCommands) { |
| 2907 | if (transferTouchFocusCommand.fromToken != nullptr && |
| 2908 | transferTouchFocusCommand.toToken != nullptr && |
| 2909 | transferTouchFocusCommand.fromToken != transferTouchFocusCommand.toToken) { |
| 2910 | mInputFlinger->transferTouchFocus(transferTouchFocusCommand.fromToken, |
| 2911 | transferTouchFocusCommand.toToken); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | mInputWindowCommands.clear(); |
| 2916 | } |
| 2917 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 2918 | void SurfaceFlinger::updateCursorAsync() |
| 2919 | { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 2920 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2921 | if (!display->getId()) { |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 2922 | continue; |
| 2923 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2924 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2925 | for (auto& layer : display->getVisibleLayersSortedByZ()) { |
| 2926 | layer->updateCursorPosition(display); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 2927 | } |
| 2928 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 2931 | void SurfaceFlinger::latchAndReleaseBuffer(const sp<Layer>& layer) { |
| 2932 | if (layer->hasReadyFrame()) { |
Robert Carr | a062923 | 2019-02-07 15:28:54 -0800 | [diff] [blame] | 2933 | bool ignored = false; |
Alec Mouri | 56e538f | 2019-01-14 15:22:01 -0800 | [diff] [blame] | 2934 | layer->latchBuffer(ignored, systemTime()); |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 2935 | } |
| 2936 | layer->releasePendingBuffer(systemTime()); |
| 2937 | } |
| 2938 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2939 | void SurfaceFlinger::commitTransaction() |
| 2940 | { |
Steve Pfetsch | 598f6d5 | 2016-10-25 21:47:58 +0000 | [diff] [blame] | 2941 | if (!mLayersPendingRemoval.isEmpty()) { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2942 | // Notify removed layers now that they can't be drawn from |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2943 | for (const auto& l : mLayersPendingRemoval) { |
| 2944 | recordBufferingStats(l->getName().string(), |
| 2945 | l->getOccupancyHistory(true)); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2946 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 2947 | // Ensure any buffers set to display on any children are released. |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2948 | if (l->isRemovedFromCurrentState()) { |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 2949 | latchAndReleaseBuffer(l); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2950 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2951 | } |
| 2952 | mLayersPendingRemoval.clear(); |
| 2953 | } |
| 2954 | |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2955 | // If this transaction is part of a window animation then the next frame |
| 2956 | // we composite should be considered an animation as well. |
| 2957 | mAnimCompositionPending = mAnimTransactionPending; |
| 2958 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2959 | mDrawingState = mCurrentState; |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 2960 | // clear the "changed" flags in current state |
| 2961 | mCurrentState.colorMatrixChanged = false; |
| 2962 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2963 | mDrawingState.traverseInZOrder([](Layer* layer) { |
| 2964 | layer->commitChildList(); |
| 2965 | }); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 2966 | mTransactionPending = false; |
| 2967 | mAnimTransactionPending = false; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2968 | mTransactionCV.broadcast(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | } |
| 2970 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2971 | void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice, |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2972 | Region& outDirtyRegion, Region& outOpaqueRegion) { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 2973 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2974 | ALOGV("computeVisibleRegions"); |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 2975 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2976 | auto display = displayDevice->getCompositionDisplay(); |
| 2977 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | Region aboveOpaqueLayers; |
| 2979 | Region aboveCoveredLayers; |
| 2980 | Region dirty; |
| 2981 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2982 | outDirtyRegion.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2984 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2985 | // start with the whole surface at its current location |
| 2986 | const Layer::State& s(layer->getDrawingState()); |
| 2987 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 2988 | // only consider the layers on the given layer stack |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 2989 | if (!display->belongsInOutput(layer->getLayerStack(), layer->getPrimaryDisplayOnly())) { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 2990 | return; |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2991 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 2992 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 2993 | /* |
| 2994 | * opaqueRegion: area of a surface that is fully opaque. |
| 2995 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | Region opaqueRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 2997 | |
| 2998 | /* |
| 2999 | * visibleRegion: area of a surface that is visible on screen |
| 3000 | * and not fully transparent. This is essentially the layer's |
| 3001 | * footprint minus the opaque regions above it. |
| 3002 | * Areas covered by a translucent surface are considered visible. |
| 3003 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | Region visibleRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3005 | |
| 3006 | /* |
| 3007 | * coveredRegion: area of a surface that is covered by all |
| 3008 | * visible regions above it (which includes the translucent areas). |
| 3009 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | Region coveredRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3011 | |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 3012 | /* |
| 3013 | * transparentRegion: area of a surface that is hinted to be completely |
| 3014 | * transparent. This is only used to tell when the layer has no visible |
| 3015 | * non-transparent regions and can be removed from the layer list. It |
| 3016 | * does not affect the visibleRegion of this layer or any layers |
| 3017 | * beneath it. The hint may not be correct if apps don't respect the |
| 3018 | * SurfaceView restrictions (which, sadly, some don't). |
| 3019 | */ |
| 3020 | Region transparentRegion; |
| 3021 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3022 | |
| 3023 | // handle hidden surfaces by setting the visible region to empty |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 3024 | if (CC_LIKELY(layer->isVisible())) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 3025 | const bool translucent = !layer->isOpaque(s); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3026 | Rect bounds(layer->getScreenBounds()); |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3027 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | visibleRegion.set(bounds); |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 3029 | ui::Transform tr = layer->getTransform(); |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3030 | if (!visibleRegion.isEmpty()) { |
| 3031 | // Remove the transparent area from the visible region |
| 3032 | if (translucent) { |
Dan Stoza | 22f7fc4 | 2016-05-10 16:19:53 -0700 | [diff] [blame] | 3033 | if (tr.preserveRects()) { |
| 3034 | // transform the transparent region |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 3035 | transparentRegion = tr.transform(layer->getActiveTransparentRegion(s)); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3036 | } else { |
Dan Stoza | 22f7fc4 | 2016-05-10 16:19:53 -0700 | [diff] [blame] | 3037 | // transformation too complex, can't do the |
| 3038 | // transparent region optimization. |
| 3039 | transparentRegion.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3040 | } |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3041 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3043 | // compute the opaque region |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3044 | const int32_t layerOrientation = tr.getOrientation(); |
Jorim Jaggi | 039bbb8 | 2017-09-06 18:12:05 +0200 | [diff] [blame] | 3045 | if (layer->getAlpha() == 1.0f && !translucent && |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 3046 | layer->getRoundedCornerState().radius == 0.0f && |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 3047 | ((layerOrientation & ui::Transform::ROT_INVALID) == false)) { |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3048 | // the opaque region is the layer's footprint |
| 3049 | opaqueRegion = visibleRegion; |
| 3050 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | } |
| 3052 | } |
| 3053 | |
Robert Carr | e5f4f69 | 2018-01-12 13:12:28 -0800 | [diff] [blame] | 3054 | if (visibleRegion.isEmpty()) { |
| 3055 | layer->clearVisibilityRegions(); |
| 3056 | return; |
| 3057 | } |
| 3058 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3059 | // Clip the covered region to the visible region |
| 3060 | coveredRegion = aboveCoveredLayers.intersect(visibleRegion); |
| 3061 | |
| 3062 | // Update aboveCoveredLayers for next (lower) layer |
| 3063 | aboveCoveredLayers.orSelf(visibleRegion); |
| 3064 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | // subtract the opaque region covered by the layers above us |
| 3066 | visibleRegion.subtractSelf(aboveOpaqueLayers); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | |
| 3068 | // compute this layer's dirty region |
| 3069 | if (layer->contentDirty) { |
| 3070 | // we need to invalidate the whole region |
| 3071 | dirty = visibleRegion; |
| 3072 | // as well, as the old visible region |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3073 | dirty.orSelf(layer->visibleRegion); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | layer->contentDirty = false; |
| 3075 | } else { |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 3076 | /* compute the exposed region: |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3077 | * the exposed region consists of two components: |
| 3078 | * 1) what's VISIBLE now and was COVERED before |
| 3079 | * 2) what's EXPOSED now less what was EXPOSED before |
| 3080 | * |
| 3081 | * note that (1) is conservative, we start with the whole |
| 3082 | * visible region but only keep what used to be covered by |
| 3083 | * something -- which mean it may have been exposed. |
| 3084 | * |
| 3085 | * (2) handles areas that were not covered by anything but got |
| 3086 | * exposed because of a resize. |
Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 3087 | */ |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3088 | const Region newExposed = visibleRegion - coveredRegion; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3089 | const Region oldVisibleRegion = layer->visibleRegion; |
| 3090 | const Region oldCoveredRegion = layer->coveredRegion; |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3091 | const Region oldExposed = oldVisibleRegion - oldCoveredRegion; |
| 3092 | dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | } |
| 3094 | dirty.subtractSelf(aboveOpaqueLayers); |
| 3095 | |
| 3096 | // accumulate to the screen dirty region |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 3097 | outDirtyRegion.orSelf(dirty); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3098 | |
Mathias Agopian | ab02873 | 2010-03-16 16:41:46 -0700 | [diff] [blame] | 3099 | // Update aboveOpaqueLayers for next (lower) layer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | aboveOpaqueLayers.orSelf(opaqueRegion); |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 3101 | |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 3102 | // Store the visible region in screen space |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | layer->setVisibleRegion(visibleRegion); |
| 3104 | layer->setCoveredRegion(coveredRegion); |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 3105 | layer->setVisibleNonTransparentRegion( |
| 3106 | visibleRegion.subtract(transparentRegion)); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3107 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 3109 | outOpaqueRegion = aboveOpaqueLayers; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | } |
| 3111 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 3112 | void SurfaceFlinger::invalidateLayerStack(const sp<const Layer>& layer, const Region& dirty) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3113 | for (const auto& [token, displayDevice] : mDisplays) { |
| 3114 | auto display = displayDevice->getCompositionDisplay(); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 3115 | if (display->belongsInOutput(layer->getLayerStack(), layer->getPrimaryDisplayOnly())) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3116 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 3117 | } |
| 3118 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3121 | bool SurfaceFlinger::handlePageFlip() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3123 | ALOGV("handlePageFlip"); |
| 3124 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 3125 | nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3127 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3128 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3129 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 3130 | |
| 3131 | // Store the set of layers that need updates. This set must not change as |
| 3132 | // buffers are being latched, as this could result in a deadlock. |
| 3133 | // Example: Two producers share the same command stream and: |
| 3134 | // 1.) Layer 0 is latched |
| 3135 | // 2.) Layer 0 gets a new frame |
| 3136 | // 2.) Layer 1 gets a new frame |
| 3137 | // 3.) Layer 1 is latched. |
| 3138 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 3139 | // second frame. But layer 0's second frame could be waiting on display. |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3140 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 3141 | if (layer->hasReadyFrame()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3142 | frameQueued = true; |
Ady Abraham | c3e2131 | 2019-02-07 14:30:23 -0800 | [diff] [blame] | 3143 | nsecs_t expectedPresentTime; |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 3144 | expectedPresentTime = mScheduler->expectedPresentTime(); |
Ana Krulec | 010d219 | 2018-10-08 06:29:54 -0700 | [diff] [blame] | 3145 | if (layer->shouldPresentNow(expectedPresentTime)) { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3146 | mLayersWithQueuedFrames.push_back(layer); |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 3147 | } else { |
| 3148 | layer->useEmptyDamage(); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3149 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 3150 | } else { |
| 3151 | layer->useEmptyDamage(); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3152 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3153 | }); |
| 3154 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 3155 | if (!mLayersWithQueuedFrames.empty()) { |
| 3156 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 3157 | // writes to Layer current state. See also b/119481871 |
| 3158 | Mutex::Autolock lock(mStateLock); |
| 3159 | |
| 3160 | for (auto& layer : mLayersWithQueuedFrames) { |
Alec Mouri | 56e538f | 2019-01-14 15:22:01 -0800 | [diff] [blame] | 3161 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3162 | mLayersPendingRefresh.push_back(layer); |
| 3163 | } |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 3164 | layer->useSurfaceDamage(); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 3165 | if (layer->isBufferLatched()) { |
| 3166 | newDataLatched = true; |
| 3167 | } |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3168 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3169 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 3170 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 3171 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3172 | |
| 3173 | // If we will need to wake up at some time in the future to deal with a |
| 3174 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 3175 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 3176 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3177 | signalLayerUpdate(); |
| 3178 | } |
| 3179 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 3180 | // enter boot animation on first buffer latch |
| 3181 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 3182 | ALOGI("Enter boot animation"); |
| 3183 | mBootStage = BootStage::BOOTANIMATION; |
| 3184 | } |
| 3185 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3186 | // Only continue with the refresh if there is actually new work to do |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3187 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | } |
| 3189 | |
Mathias Agopian | ad456f9 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 3190 | void SurfaceFlinger::invalidateHwcGeometry() |
| 3191 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3192 | mGeometryInvalid = true; |
Mathias Agopian | ad456f9 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 3193 | } |
| 3194 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3195 | void SurfaceFlinger::doDisplayComposition(const sp<DisplayDevice>& displayDevice, |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3196 | const Region& inDirtyRegion) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3197 | auto display = displayDevice->getCompositionDisplay(); |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 3198 | // We only need to actually compose the display if: |
| 3199 | // 1) It is being handled by hardware composer, which may need this to |
| 3200 | // keep its virtual display state machine in sync, or |
| 3201 | // 2) There is work to be done (the dirty region isn't empty) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3202 | if (!displayDevice->getId() && inDirtyRegion.isEmpty()) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3203 | ALOGV("Skipping display composition"); |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 3204 | return; |
| 3205 | } |
| 3206 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3207 | ALOGV("doDisplayComposition"); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3208 | base::unique_fd readyFence; |
| 3209 | if (!doComposeSurfaces(displayDevice, Region::INVALID_REGION, &readyFence)) return; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 3210 | |
| 3211 | // swap buffers (presentation) |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3212 | display->getRenderSurface()->queueBuffer(std::move(readyFence)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | } |
| 3214 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3215 | bool SurfaceFlinger::doComposeSurfaces(const sp<DisplayDevice>& displayDevice, |
| 3216 | const Region& debugRegion, base::unique_fd* readyFence) { |
Alec Mouri | 820c740 | 2019-01-23 13:02:39 -0800 | [diff] [blame] | 3217 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3218 | ALOGV("doComposeSurfaces"); |
Mathias Agopian | cd20eb0 | 2011-09-22 20:57:04 -0700 | [diff] [blame] | 3219 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3220 | auto display = displayDevice->getCompositionDisplay(); |
| 3221 | const auto& displayState = display->getState(); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 3222 | const auto displayId = display->getId(); |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3223 | auto& renderEngine = getRenderEngine(); |
| 3224 | const bool supportProtectedContent = |
| 3225 | mDebugEnableProtectedContent && renderEngine.supportsProtectedContent(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3226 | |
| 3227 | const Region bounds(displayState.bounds); |
| 3228 | const DisplayRenderArea renderArea(displayDevice); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 3229 | const bool hasClientComposition = getHwComposer().hasClientComposition(displayId); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3230 | ATRACE_INT("hasClientComposition", hasClientComposition); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 3231 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3232 | mat4 colorMatrix; |
Chia-I Wu | 8e50e69 | 2018-05-04 10:12:37 -0700 | [diff] [blame] | 3233 | bool applyColorMatrix = false; |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 3234 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3235 | renderengine::DisplaySettings clientCompositionDisplay; |
| 3236 | std::vector<renderengine::LayerSettings> clientCompositionLayers; |
| 3237 | sp<GraphicBuffer> buf; |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 3238 | base::unique_fd fd; |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3239 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3240 | if (hasClientComposition) { |
| 3241 | ALOGV("hasClientComposition"); |
| 3242 | |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3243 | if (displayDevice->isPrimary() && supportProtectedContent) { |
| 3244 | bool needsProtected = false; |
| 3245 | for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) { |
| 3246 | // If the layer is a protected layer, mark protected context is needed. |
| 3247 | if (layer->isProtected()) { |
| 3248 | needsProtected = true; |
| 3249 | break; |
| 3250 | } |
| 3251 | } |
| 3252 | if (needsProtected != renderEngine.isProtected() && |
| 3253 | renderEngine.useProtectedContext(needsProtected)) { |
| 3254 | display->getRenderSurface()->setProtected(needsProtected); |
| 3255 | } |
| 3256 | } |
| 3257 | |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 3258 | buf = display->getRenderSurface()->dequeueBuffer(&fd); |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3259 | |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3260 | if (buf == nullptr) { |
| 3261 | ALOGW("Dequeuing buffer for display [%s] failed, bailing out of " |
| 3262 | "client composition for this frame", |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3263 | displayDevice->getDisplayName().c_str()); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3264 | return false; |
| 3265 | } |
| 3266 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3267 | clientCompositionDisplay.physicalDisplay = displayState.scissor; |
| 3268 | clientCompositionDisplay.clip = displayState.scissor; |
| 3269 | const ui::Transform& displayTransform = displayState.transform; |
| 3270 | mat4 m; |
| 3271 | m[0][0] = displayTransform[0][0]; |
| 3272 | m[0][1] = displayTransform[0][1]; |
| 3273 | m[0][3] = displayTransform[0][2]; |
| 3274 | m[1][0] = displayTransform[1][0]; |
| 3275 | m[1][1] = displayTransform[1][1]; |
| 3276 | m[1][3] = displayTransform[1][2]; |
| 3277 | m[3][0] = displayTransform[2][0]; |
| 3278 | m[3][1] = displayTransform[2][1]; |
| 3279 | m[3][3] = displayTransform[2][2]; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3280 | clientCompositionDisplay.globalTransform = m; |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3281 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 3282 | const auto* profile = display->getDisplayColorProfile(); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 3283 | Dataspace outputDataspace = Dataspace::UNKNOWN; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 3284 | if (profile->hasWideColorGamut()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3285 | outputDataspace = displayState.dataspace; |
Chia-I Wu | 69bf10f | 2018-02-20 13:04:50 -0800 | [diff] [blame] | 3286 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3287 | clientCompositionDisplay.outputDataspace = outputDataspace; |
| 3288 | clientCompositionDisplay.maxLuminance = |
| 3289 | profile->getHdrCapabilities().getDesiredMaxLuminance(); |
Chia-I Wu | 69bf10f | 2018-02-20 13:04:50 -0800 | [diff] [blame] | 3290 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 3291 | const bool hasDeviceComposition = getHwComposer().hasDeviceComposition(displayId); |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3292 | const bool skipClientColorTransform = |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 3293 | getHwComposer() |
| 3294 | .hasDisplayCapability(displayId, |
| 3295 | HWC2::DisplayCapability::SkipClientColorTransform); |
Chia-I Wu | 8e50e69 | 2018-05-04 10:12:37 -0700 | [diff] [blame] | 3296 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3297 | // Compute the global color transform matrix. |
Chia-I Wu | 8e50e69 | 2018-05-04 10:12:37 -0700 | [diff] [blame] | 3298 | applyColorMatrix = !hasDeviceComposition && !skipClientColorTransform; |
| 3299 | if (applyColorMatrix) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3300 | clientCompositionDisplay.colorTransform = colorMatrix; |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 3301 | } |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 3302 | } |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 3303 | |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 3304 | /* |
| 3305 | * and then, render the layers targeted at the framebuffer |
| 3306 | */ |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 3307 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3308 | ALOGV("Rendering client layers"); |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3309 | bool firstLayer = true; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3310 | Region clearRegion = Region::INVALID_REGION; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3311 | for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3312 | const Region viewportRegion(displayState.viewport); |
| 3313 | const Region clip(viewportRegion.intersect(layer->visibleRegion)); |
David Sodman | c1498e6 | 2018-09-12 14:36:26 -0700 | [diff] [blame] | 3314 | ALOGV("Layer: %s", layer->getName().string()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 3315 | ALOGV(" Composition type: %s", toString(layer->getCompositionType(displayDevice)).c_str()); |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3316 | if (!clip.isEmpty()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 3317 | switch (layer->getCompositionType(displayDevice)) { |
| 3318 | case Hwc2::IComposerClient::Composition::CURSOR: |
| 3319 | case Hwc2::IComposerClient::Composition::DEVICE: |
| 3320 | case Hwc2::IComposerClient::Composition::SIDEBAND: |
| 3321 | case Hwc2::IComposerClient::Composition::SOLID_COLOR: { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3322 | LOG_ALWAYS_FATAL_IF(!displayId); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 3323 | const Layer::State& state(layer->getDrawingState()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 3324 | if (layer->getClearClientTarget(displayDevice) && !firstLayer && |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 3325 | layer->isOpaque(state) && (layer->getAlpha() == 1.0f) && |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 3326 | layer->getRoundedCornerState().radius == 0.0f && hasClientComposition) { |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3327 | // never clear the very first layer since we're |
| 3328 | // guaranteed the FB is already cleared |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3329 | renderengine::LayerSettings layerSettings; |
| 3330 | Region dummyRegion; |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3331 | bool prepared = |
| 3332 | layer->prepareClientLayer(renderArea, clip, dummyRegion, |
| 3333 | supportProtectedContent, layerSettings); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3334 | |
| 3335 | if (prepared) { |
| 3336 | layerSettings.source.buffer.buffer = nullptr; |
| 3337 | layerSettings.source.solidColor = half3(0.0, 0.0, 0.0); |
| 3338 | layerSettings.alpha = half(0.0); |
| 3339 | layerSettings.disableBlending = true; |
| 3340 | clientCompositionLayers.push_back(layerSettings); |
| 3341 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3342 | } |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3343 | break; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3344 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 3345 | case Hwc2::IComposerClient::Composition::CLIENT: { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3346 | renderengine::LayerSettings layerSettings; |
| 3347 | bool prepared = |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3348 | layer->prepareClientLayer(renderArea, clip, clearRegion, |
| 3349 | supportProtectedContent, layerSettings); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3350 | if (prepared) { |
| 3351 | clientCompositionLayers.push_back(layerSettings); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3352 | } |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3353 | break; |
| 3354 | } |
| 3355 | default: |
| 3356 | break; |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 3357 | } |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3358 | } else { |
| 3359 | ALOGV(" Skipping for empty clip"); |
Mathias Agopian | 85d751c | 2012-08-29 16:59:24 -0700 | [diff] [blame] | 3360 | } |
Chia-I Wu | 5e9a43e | 2018-05-03 14:27:39 -0700 | [diff] [blame] | 3361 | firstLayer = false; |
Mathias Agopian | 4b2ba53 | 2012-03-29 12:23:51 -0700 | [diff] [blame] | 3362 | } |
Mathias Agopian | f45c510 | 2012-10-24 16:29:17 -0700 | [diff] [blame] | 3363 | |
Alec Mouri | 820c740 | 2019-01-23 13:02:39 -0800 | [diff] [blame] | 3364 | // Perform some cleanup steps if we used client composition. |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3365 | if (hasClientComposition) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3366 | clientCompositionDisplay.clearRegion = clearRegion; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame^] | 3367 | |
| 3368 | // We boost GPU frequency here because there will be color spaces conversion |
| 3369 | // and it's expensive. We boost the GPU frequency so that GPU composition can |
| 3370 | // finish in time. We must reset GPU frequency afterwards, because high frequency |
| 3371 | // consumes extra battery. |
| 3372 | const bool expensiveRenderingExpected = |
| 3373 | clientCompositionDisplay.outputDataspace == Dataspace::DISPLAY_P3; |
| 3374 | if (expensiveRenderingExpected && displayId) { |
| 3375 | mPowerAdvisor.setExpensiveRenderingExpected(*displayId, true); |
| 3376 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 3377 | if (!debugRegion.isEmpty()) { |
| 3378 | Region::const_iterator it = debugRegion.begin(); |
| 3379 | Region::const_iterator end = debugRegion.end(); |
| 3380 | while (it != end) { |
| 3381 | const Rect& rect = *it++; |
| 3382 | renderengine::LayerSettings layerSettings; |
| 3383 | layerSettings.source.buffer.buffer = nullptr; |
| 3384 | layerSettings.source.solidColor = half3(1.0, 0.0, 1.0); |
| 3385 | layerSettings.geometry.boundaries = rect.toFloatRect(); |
| 3386 | layerSettings.alpha = half(1.0); |
| 3387 | clientCompositionLayers.push_back(layerSettings); |
| 3388 | } |
| 3389 | } |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 3390 | renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers, |
| 3391 | buf->getNativeBuffer(), std::move(fd), readyFence); |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame^] | 3392 | if (expensiveRenderingExpected && displayId) { |
| 3393 | mPowerAdvisor.setExpensiveRenderingExpected(*displayId, false); |
| 3394 | } |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 3395 | } |
Michael Lentine | 3f121fc | 2014-10-01 11:17:28 -0700 | [diff] [blame] | 3396 | return true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
Chia-I Wu | 28e3a25 | 2018-09-07 12:05:02 -0700 | [diff] [blame] | 3399 | void SurfaceFlinger::drawWormhole(const Region& region) const { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 3400 | auto& engine(getRenderEngine()); |
Chia-I Wu | 28e3a25 | 2018-09-07 12:05:02 -0700 | [diff] [blame] | 3401 | engine.fillRegionWithColor(region, 0, 0, 0, 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | } |
| 3403 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3404 | status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 3405 | const sp<IBinder>& handle, |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 3406 | const sp<IGraphicBufferProducer>& gbc, |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3407 | const sp<Layer>& lbc, |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 3408 | const sp<Layer>& parent, |
| 3409 | bool addToCurrentState) |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 3410 | { |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3411 | // add this layer to the current state list |
| 3412 | { |
| 3413 | Mutex::Autolock _l(mStateLock); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3414 | if (mNumLayers >= MAX_LAYERS) { |
Courtney Goeltzenleuchter | ab702f5 | 2017-04-19 15:14:02 -0600 | [diff] [blame] | 3415 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers, |
| 3416 | MAX_LAYERS); |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3417 | return NO_MEMORY; |
| 3418 | } |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 3419 | if (parent == nullptr && addToCurrentState) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3420 | mCurrentState.layersSortedByZ.add(lbc); |
chaviw | ac84185 | 2019-01-16 16:04:43 -0800 | [diff] [blame] | 3421 | } else if (parent == nullptr) { |
| 3422 | lbc->onRemovedFromCurrentState(); |
| 3423 | } else if (parent->isRemovedFromCurrentState()) { |
| 3424 | parent->addChild(lbc); |
| 3425 | lbc->onRemovedFromCurrentState(); |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 3426 | } else { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3427 | parent->addChild(lbc); |
| 3428 | } |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 3429 | |
Yiwei Zhang | 243b378 | 2018-05-15 17:40:04 -0700 | [diff] [blame] | 3430 | if (gbc != nullptr) { |
| 3431 | mGraphicBufferProducerList.insert(IInterface::asBinder(gbc).get()); |
| 3432 | LOG_ALWAYS_FATAL_IF(mGraphicBufferProducerList.size() > |
| 3433 | mMaxGraphicBufferProducerListSize, |
| 3434 | "Suspected IGBP leak: %zu IGBPs (%zu max), %zu Layers", |
| 3435 | mGraphicBufferProducerList.size(), |
| 3436 | mMaxGraphicBufferProducerListSize, mNumLayers); |
| 3437 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3438 | mLayersAdded = true; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 3441 | // attach this layer to the client |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 3442 | client->attachLayer(handle, lbc); |
Mathias Agopian | 4f11374 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 3443 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3444 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
Fabien Sanglard | c8251eb | 2016-12-07 13:59:48 -0800 | [diff] [blame] | 3447 | uint32_t SurfaceFlinger::peekTransactionFlags() { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 3448 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 3451 | uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 3452 | return mTransactionFlags.fetch_and(~flags) & flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | } |
| 3454 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 3455 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags) { |
Ana Krulec | 7ecce8c | 2018-10-12 13:44:41 -0700 | [diff] [blame] | 3456 | return setTransactionFlags(flags, Scheduler::TransactionStart::NORMAL); |
Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags, |
Ana Krulec | 7ecce8c | 2018-10-12 13:44:41 -0700 | [diff] [blame] | 3460 | Scheduler::TransactionStart transactionStart) { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 3461 | uint32_t old = mTransactionFlags.fetch_or(flags); |
Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 3462 | mVsyncModulator.setTransactionStart(transactionStart); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3463 | if ((old & flags)==0) { // wake the server up |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 3464 | signalTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3465 | } |
| 3466 | return old; |
| 3467 | } |
| 3468 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3469 | bool SurfaceFlinger::flushTransactionQueues() { |
| 3470 | Mutex::Autolock _l(mStateLock); |
| 3471 | auto it = mTransactionQueues.begin(); |
| 3472 | while (it != mTransactionQueues.end()) { |
| 3473 | auto& [applyToken, transactionQueue] = *it; |
| 3474 | |
| 3475 | while (!transactionQueue.empty()) { |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3476 | const auto& [states, displays, flags, desiredPresentTime, privileged] = |
| 3477 | transactionQueue.front(); |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3478 | if (!transactionIsReadyToBeApplied(desiredPresentTime, states)) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3479 | break; |
| 3480 | } |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3481 | applyTransactionState(states, displays, flags, mPendingInputWindowCommands, privileged); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3482 | transactionQueue.pop(); |
| 3483 | } |
| 3484 | |
| 3485 | it = (transactionQueue.empty()) ? mTransactionQueues.erase(it) : std::next(it, 1); |
| 3486 | } |
| 3487 | return mTransactionQueues.empty(); |
| 3488 | } |
| 3489 | |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3490 | bool SurfaceFlinger::containsAnyInvalidClientState(const Vector<ComposerState>& states) { |
| 3491 | for (const ComposerState& state : states) { |
| 3492 | // Here we need to check that the interface we're given is indeed |
| 3493 | // one of our own. A malicious client could give us a nullptr |
| 3494 | // IInterface, or one of its own or even one of our own but a |
| 3495 | // different type. All these situations would cause us to crash. |
| 3496 | if (state.client == nullptr) { |
| 3497 | return true; |
| 3498 | } |
| 3499 | |
| 3500 | sp<IBinder> binder = IInterface::asBinder(state.client); |
| 3501 | if (binder == nullptr) { |
| 3502 | return true; |
| 3503 | } |
| 3504 | |
| 3505 | if (binder->queryLocalInterface(ISurfaceComposerClient::descriptor) == nullptr) { |
| 3506 | return true; |
| 3507 | } |
| 3508 | } |
| 3509 | return false; |
| 3510 | } |
| 3511 | |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3512 | bool SurfaceFlinger::transactionIsReadyToBeApplied(int64_t desiredPresentTime, |
| 3513 | const Vector<ComposerState>& states) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 3514 | nsecs_t expectedPresentTime = mScheduler->expectedPresentTime(); |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3515 | // Do not present if the desiredPresentTime has not passed unless it is more than one second |
| 3516 | // in the future. We ignore timestamps more than 1 second in the future for stability reasons. |
| 3517 | if (desiredPresentTime >= 0 && desiredPresentTime >= expectedPresentTime && |
| 3518 | desiredPresentTime < expectedPresentTime + s2ns(1)) { |
| 3519 | return false; |
| 3520 | } |
| 3521 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3522 | for (const ComposerState& state : states) { |
| 3523 | const layer_state_t& s = state.state; |
| 3524 | if (!(s.what & layer_state_t::eAcquireFenceChanged)) { |
| 3525 | continue; |
| 3526 | } |
| 3527 | if (s.acquireFence && s.acquireFence->getStatus() == Fence::Status::Unsignaled) { |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3528 | return false; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3529 | } |
| 3530 | } |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3531 | return true; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& states, |
| 3535 | const Vector<DisplayState>& displays, uint32_t flags, |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 3536 | const sp<IBinder>& applyToken, |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3537 | const InputWindowCommands& inputWindowCommands, |
| 3538 | int64_t desiredPresentTime) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 3539 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3540 | |
| 3541 | bool privileged = callingThreadHasUnscopedSurfaceFlingerAccess(); |
| 3542 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 3543 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3544 | |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3545 | if (containsAnyInvalidClientState(states)) { |
| 3546 | return; |
| 3547 | } |
| 3548 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3549 | // If its TransactionQueue already has a pending TransactionState or if it is pending |
| 3550 | if (mTransactionQueues.find(applyToken) != mTransactionQueues.end() || |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3551 | !transactionIsReadyToBeApplied(desiredPresentTime, states)) { |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3552 | mTransactionQueues[applyToken].emplace(states, displays, flags, desiredPresentTime, |
| 3553 | privileged); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3554 | setTransactionFlags(eTransactionNeeded); |
| 3555 | return; |
| 3556 | } |
| 3557 | |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3558 | applyTransactionState(states, displays, flags, inputWindowCommands, privileged); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | void SurfaceFlinger::applyTransactionState(const Vector<ComposerState>& states, |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 3562 | const Vector<DisplayState>& displays, uint32_t flags, |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3563 | const InputWindowCommands& inputWindowCommands, |
| 3564 | bool privileged) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3565 | uint32_t transactionFlags = 0; |
| 3566 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3567 | if (flags & eAnimation) { |
| 3568 | // For window updates that are part of an animation we must wait for |
| 3569 | // previous animation "frames" to be handled. |
| 3570 | while (mAnimTransactionPending) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 3571 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3572 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 3573 | // just in case something goes wrong in SF, return to the |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 3574 | // caller after a few seconds. |
| 3575 | ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out " |
| 3576 | "waiting for previous animation frame"); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3577 | mAnimTransactionPending = false; |
| 3578 | break; |
| 3579 | } |
| 3580 | } |
| 3581 | } |
| 3582 | |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3583 | for (const DisplayState& display : displays) { |
| 3584 | transactionFlags |= setDisplayStateLocked(display); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 3587 | uint32_t clientStateFlags = 0; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3588 | for (const ComposerState& state : states) { |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3589 | clientStateFlags |= setClientStateLocked(state, privileged); |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3590 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 3591 | // If the state doesn't require a traversal and there are callbacks, send them now |
| 3592 | if (!(clientStateFlags & eTraversalNeeded)) { |
| 3593 | mTransactionCompletedThread.sendCallbacks(); |
| 3594 | } |
| 3595 | transactionFlags |= clientStateFlags; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3596 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 3597 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
| 3598 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 3599 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 3600 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 3601 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 3602 | // transaction for empty animation transactions. |
| 3603 | if (transactionFlags == 0 && |
| 3604 | ((flags & eSynchronous) || (flags & eAnimation))) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 3605 | transactionFlags = eTransactionNeeded; |
| 3606 | } |
| 3607 | |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3608 | if (transactionFlags) { |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 3609 | if (mInterceptor->isEnabled()) { |
| 3610 | mInterceptor->saveTransaction(states, mCurrentState.displays, displays, flags); |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 3611 | } |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 3612 | |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3613 | // this triggers the transaction |
Ana Krulec | 7ecce8c | 2018-10-12 13:44:41 -0700 | [diff] [blame] | 3614 | const auto start = (flags & eEarlyWakeup) ? Scheduler::TransactionStart::EARLY |
| 3615 | : Scheduler::TransactionStart::NORMAL; |
Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 3616 | setTransactionFlags(transactionFlags, start); |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3617 | |
| 3618 | // if this is a synchronous transaction, wait for it to take effect |
| 3619 | // before returning. |
| 3620 | if (flags & eSynchronous) { |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3621 | mTransactionPending = true; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3622 | } |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3623 | if (flags & eAnimation) { |
| 3624 | mAnimTransactionPending = true; |
| 3625 | } |
chaviw | 95ef3c4 | 2019-02-14 10:55:09 -0800 | [diff] [blame] | 3626 | |
| 3627 | mPendingSyncInputWindows = mPendingInputWindowCommands.syncInputWindows; |
| 3628 | while (mTransactionPending || mPendingSyncInputWindows) { |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3629 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); |
| 3630 | if (CC_UNLIKELY(err != NO_ERROR)) { |
| 3631 | // just in case something goes wrong in SF, return to the |
| 3632 | // called after a few seconds. |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 3633 | ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out!"); |
| 3634 | mTransactionPending = false; |
chaviw | 95ef3c4 | 2019-02-14 10:55:09 -0800 | [diff] [blame] | 3635 | mPendingSyncInputWindows = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 3636 | break; |
| 3637 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 3638 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 3642 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 3643 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 3644 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 3645 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3646 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 3647 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 3648 | |
| 3649 | const uint32_t what = s.what; |
| 3650 | if (what & DisplayState::eSurfaceChanged) { |
| 3651 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 3652 | state.surface = s.surface; |
| 3653 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 3654 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3655 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 3656 | if (what & DisplayState::eLayerStackChanged) { |
| 3657 | if (state.layerStack != s.layerStack) { |
| 3658 | state.layerStack = s.layerStack; |
| 3659 | flags |= eDisplayTransactionNeeded; |
| 3660 | } |
| 3661 | } |
| 3662 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 3663 | if (state.orientation != s.orientation) { |
| 3664 | state.orientation = s.orientation; |
| 3665 | flags |= eDisplayTransactionNeeded; |
| 3666 | } |
| 3667 | if (state.frame != s.frame) { |
| 3668 | state.frame = s.frame; |
| 3669 | flags |= eDisplayTransactionNeeded; |
| 3670 | } |
| 3671 | if (state.viewport != s.viewport) { |
| 3672 | state.viewport = s.viewport; |
| 3673 | flags |= eDisplayTransactionNeeded; |
| 3674 | } |
| 3675 | } |
| 3676 | if (what & DisplayState::eDisplaySizeChanged) { |
| 3677 | if (state.width != s.width) { |
| 3678 | state.width = s.width; |
| 3679 | flags |= eDisplayTransactionNeeded; |
| 3680 | } |
| 3681 | if (state.height != s.height) { |
| 3682 | state.height = s.height; |
| 3683 | flags |= eDisplayTransactionNeeded; |
| 3684 | } |
| 3685 | } |
| 3686 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3687 | return flags; |
| 3688 | } |
| 3689 | |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3690 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess() { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 3691 | IPCThreadState* ipc = IPCThreadState::self(); |
| 3692 | const int pid = ipc->getCallingPid(); |
| 3693 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 3694 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 3695 | !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 3696 | return false; |
| 3697 | } |
| 3698 | return true; |
| 3699 | } |
| 3700 | |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3701 | uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState, |
| 3702 | bool privileged) { |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 3703 | const layer_state_t& s = composerState.state; |
| 3704 | sp<Client> client(static_cast<Client*>(composerState.client.get())); |
| 3705 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 3706 | sp<Layer> layer(client->getLayerUser(s.surface)); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3707 | if (layer == nullptr) { |
| 3708 | return 0; |
| 3709 | } |
| 3710 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3711 | uint32_t flags = 0; |
| 3712 | |
Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 3713 | const uint64_t what = s.what; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3714 | bool geometryAppliesWithResize = |
| 3715 | what & layer_state_t::eGeometryAppliesWithResize; |
Jorim Jaggi | dba3273 | 2018-05-28 17:43:52 +0200 | [diff] [blame] | 3716 | |
| 3717 | // If we are deferring transaction, make sure to push the pending state, as otherwise the |
| 3718 | // pending state will also be deferred. |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3719 | if (what & layer_state_t::eDeferTransaction_legacy) { |
Jorim Jaggi | dba3273 | 2018-05-28 17:43:52 +0200 | [diff] [blame] | 3720 | layer->pushPendingState(); |
| 3721 | } |
| 3722 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3723 | if (what & layer_state_t::ePositionChanged) { |
| 3724 | if (layer->setPosition(s.x, s.y, !geometryAppliesWithResize)) { |
| 3725 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3726 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3727 | } |
| 3728 | if (what & layer_state_t::eLayerChanged) { |
| 3729 | // NOTE: index needs to be calculated before we update the state |
| 3730 | const auto& p = layer->getParent(); |
| 3731 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 3732 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3733 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3734 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 3735 | mCurrentState.layersSortedByZ.add(layer); |
| 3736 | // we need traversal (state changed) |
| 3737 | // AND transaction (list changed) |
| 3738 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 3739 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3740 | } else { |
| 3741 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3742 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 3743 | } |
| 3744 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3745 | } |
| 3746 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3747 | // NOTE: index needs to be calculated before we update the state |
| 3748 | const auto& p = layer->getParent(); |
| 3749 | if (p == nullptr) { |
| 3750 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 3751 | if (layer->setRelativeLayer(s.relativeLayerHandle, s.z) && idx >= 0) { |
| 3752 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 3753 | mCurrentState.layersSortedByZ.add(layer); |
| 3754 | // we need traversal (state changed) |
| 3755 | // AND transaction (list changed) |
| 3756 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 3757 | } |
| 3758 | } else { |
| 3759 | if (p->setChildRelativeLayer(layer, s.relativeLayerHandle, s.z)) { |
| 3760 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 3761 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3762 | } |
| 3763 | } |
| 3764 | if (what & layer_state_t::eSizeChanged) { |
| 3765 | if (layer->setSize(s.w, s.h)) { |
| 3766 | flags |= eTraversalNeeded; |
| 3767 | } |
| 3768 | } |
| 3769 | if (what & layer_state_t::eAlphaChanged) { |
| 3770 | if (layer->setAlpha(s.alpha)) |
| 3771 | flags |= eTraversalNeeded; |
| 3772 | } |
| 3773 | if (what & layer_state_t::eColorChanged) { |
| 3774 | if (layer->setColor(s.color)) |
| 3775 | flags |= eTraversalNeeded; |
| 3776 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3777 | if (what & layer_state_t::eColorTransformChanged) { |
| 3778 | if (layer->setColorTransform(s.colorTransform)) { |
| 3779 | flags |= eTraversalNeeded; |
| 3780 | } |
| 3781 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 3782 | if (what & layer_state_t::eBackgroundColorChanged) { |
| 3783 | if (layer->setBackgroundColor(s.color, s.bgColorAlpha, s.bgColorDataspace)) { |
| 3784 | flags |= eTraversalNeeded; |
| 3785 | } |
| 3786 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3787 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 3788 | // TODO: b/109894387 |
| 3789 | // |
| 3790 | // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary |
| 3791 | // rotation. To see the problem observe that if we have a square parent, and a child |
| 3792 | // of the same size, then we rotate the child 45 degrees around it's center, the child |
| 3793 | // must now be cropped to a non rectangular 8 sided region. |
| 3794 | // |
| 3795 | // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is |
| 3796 | // private API, and the WindowManager only uses rotation in one case, which is on a top |
| 3797 | // level layer in which cropping is not an issue. |
| 3798 | // |
| 3799 | // However given that abuse of rotation matrices could lead to surfaces extending outside |
| 3800 | // of cropped areas, we need to prevent non-root clients without permission ACCESS_SURFACE_FLINGER |
| 3801 | // (a.k.a. everyone except WindowManager and tests) from setting non rectangle preserving |
| 3802 | // transformations. |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3803 | if (layer->setMatrix(s.matrix, privileged)) |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3804 | flags |= eTraversalNeeded; |
| 3805 | } |
| 3806 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 3807 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 3808 | flags |= eTraversalNeeded; |
| 3809 | } |
| 3810 | if (what & layer_state_t::eFlagsChanged) { |
| 3811 | if (layer->setFlags(s.flags, s.mask)) |
| 3812 | flags |= eTraversalNeeded; |
| 3813 | } |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3814 | if (what & layer_state_t::eCropChanged_legacy) { |
| 3815 | if (layer->setCrop_legacy(s.crop_legacy, !geometryAppliesWithResize)) |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3816 | flags |= eTraversalNeeded; |
| 3817 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 3818 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 3819 | if (layer->setCornerRadius(s.cornerRadius)) |
| 3820 | flags |= eTraversalNeeded; |
| 3821 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3822 | if (what & layer_state_t::eLayerStackChanged) { |
| 3823 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 3824 | // We only allow setting layer stacks for top level layers, |
| 3825 | // everything else inherits layer stack from its parent. |
| 3826 | if (layer->hasParent()) { |
| 3827 | ALOGE("Attempt to set layer stack on layer with parent (%s) is invalid", |
| 3828 | layer->getName().string()); |
| 3829 | } else if (idx < 0) { |
| 3830 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
| 3831 | "that also does not appear in the top level layer list. Something" |
| 3832 | " has gone wrong.", layer->getName().string()); |
| 3833 | } else if (layer->setLayerStack(s.layerStack)) { |
| 3834 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 3835 | mCurrentState.layersSortedByZ.add(layer); |
| 3836 | // we need traversal (state changed) |
| 3837 | // AND transaction (list changed) |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3838 | flags |= eTransactionNeeded|eTraversalNeeded|eDisplayLayerStackChanged; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3841 | if (what & layer_state_t::eDeferTransaction_legacy) { |
| 3842 | if (s.barrierHandle_legacy != nullptr) { |
| 3843 | layer->deferTransactionUntil_legacy(s.barrierHandle_legacy, s.frameNumber_legacy); |
| 3844 | } else if (s.barrierGbp_legacy != nullptr) { |
| 3845 | const sp<IGraphicBufferProducer>& gbp = s.barrierGbp_legacy; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3846 | if (authenticateSurfaceTextureLocked(gbp)) { |
| 3847 | const auto& otherLayer = |
| 3848 | (static_cast<MonitoredProducer*>(gbp.get()))->getLayer(); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3849 | layer->deferTransactionUntil_legacy(otherLayer, s.frameNumber_legacy); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3850 | } else { |
| 3851 | ALOGE("Attempt to defer transaction to to an" |
| 3852 | " unrecognized GraphicBufferProducer"); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 3853 | } |
| 3854 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3855 | // We don't trigger a traversal here because if no other state is |
| 3856 | // changed, we don't want this to cause any more work |
| 3857 | } |
| 3858 | if (what & layer_state_t::eReparent) { |
chaviw | 8ea97bb | 2017-11-29 10:05:15 -0800 | [diff] [blame] | 3859 | bool hadParent = layer->hasParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3860 | if (layer->reparent(s.parentHandleForChild)) { |
chaviw | 8ea97bb | 2017-11-29 10:05:15 -0800 | [diff] [blame] | 3861 | if (!hadParent) { |
| 3862 | mCurrentState.layersSortedByZ.remove(layer); |
| 3863 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3864 | flags |= eTransactionNeeded|eTraversalNeeded; |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3865 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3866 | } |
| 3867 | if (what & layer_state_t::eReparentChildren) { |
| 3868 | if (layer->reparentChildren(s.reparentHandle)) { |
| 3869 | flags |= eTransactionNeeded|eTraversalNeeded; |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 3870 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3871 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 3872 | if (what & layer_state_t::eDetachChildren) { |
| 3873 | layer->detachChildren(); |
| 3874 | } |
| 3875 | if (what & layer_state_t::eOverrideScalingModeChanged) { |
| 3876 | layer->setOverrideScalingMode(s.overrideScalingMode); |
| 3877 | // We don't trigger a traversal here because if no other state is |
| 3878 | // changed, we don't want this to cause any more work |
| 3879 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 3880 | if (what & layer_state_t::eTransformChanged) { |
| 3881 | if (layer->setTransform(s.transform)) flags |= eTraversalNeeded; |
| 3882 | } |
| 3883 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 3884 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 3885 | flags |= eTraversalNeeded; |
| 3886 | } |
| 3887 | if (what & layer_state_t::eCropChanged) { |
| 3888 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 3889 | } |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3890 | if (what & layer_state_t::eFrameChanged) { |
| 3891 | if (layer->setFrame(s.frame)) flags |= eTraversalNeeded; |
| 3892 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 3893 | if (what & layer_state_t::eAcquireFenceChanged) { |
| 3894 | if (layer->setAcquireFence(s.acquireFence)) flags |= eTraversalNeeded; |
| 3895 | } |
| 3896 | if (what & layer_state_t::eDataspaceChanged) { |
| 3897 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 3898 | } |
| 3899 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 3900 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 3901 | } |
| 3902 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 3903 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 3904 | } |
| 3905 | if (what & layer_state_t::eApiChanged) { |
| 3906 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 3907 | } |
| 3908 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 3909 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 3910 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3911 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | 11ac201 | 2019-01-22 09:05:25 -0800 | [diff] [blame] | 3912 | if (callingThreadHasUnscopedSurfaceFlingerAccess()) { |
| 3913 | layer->setInputInfo(s.inputInfo); |
| 3914 | flags |= eTraversalNeeded; |
| 3915 | } else { |
| 3916 | ALOGE("Attempt to update InputWindowInfo without permission ACCESS_SURFACE_FLINGER"); |
| 3917 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3918 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 3919 | if (what & layer_state_t::eMetadataChanged) { |
| 3920 | if (layer->setMetadata(s.metadata)) flags |= eTraversalNeeded; |
| 3921 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 3922 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 3923 | if ((what & layer_state_t::eListenerCallbacksChanged) && (!s.listenerCallbacks.empty())) { |
| 3924 | mTransactionCompletedThread.run(); |
| 3925 | for (const auto& [listener, callbackIds] : s.listenerCallbacks) { |
| 3926 | callbackHandles.emplace_back(new CallbackHandle(listener, callbackIds, s.surface)); |
| 3927 | } |
| 3928 | } |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 3929 | |
| 3930 | if (what & layer_state_t::eBufferChanged) { |
| 3931 | // Add the new buffer to the cache. This should always come before eCachedBufferChanged. |
| 3932 | BufferStateLayerCache::getInstance().add(s.cachedBuffer.token, s.cachedBuffer.bufferId, |
| 3933 | s.buffer); |
| 3934 | } |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 3935 | if (what & layer_state_t::eCachedBufferChanged) { |
| 3936 | sp<GraphicBuffer> buffer = |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 3937 | BufferStateLayerCache::getInstance().get(s.cachedBuffer.token, |
| 3938 | s.cachedBuffer.bufferId); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 3939 | if (layer->setBuffer(buffer)) flags |= eTraversalNeeded; |
| 3940 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 3941 | if (layer->setTransactionCompletedListeners(callbackHandles)) flags |= eTraversalNeeded; |
| 3942 | // Do not put anything that updates layer state or modifies flags after |
| 3943 | // setTransactionCompletedListener |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 3944 | return flags; |
| 3945 | } |
| 3946 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 3947 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
| 3948 | uint32_t flags = 0; |
| 3949 | if (!inputWindowCommands.transferTouchFocusCommands.empty()) { |
| 3950 | flags |= eTraversalNeeded; |
| 3951 | } |
| 3952 | |
chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 3953 | if (inputWindowCommands.syncInputWindows) { |
| 3954 | flags |= eTraversalNeeded; |
| 3955 | } |
| 3956 | |
Vishnu Nair | ec0ab38 | 2019-02-13 15:32:56 -0800 | [diff] [blame] | 3957 | mPendingInputWindowCommands.merge(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 3958 | return flags; |
| 3959 | } |
| 3960 | |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 3961 | status_t SurfaceFlinger::createLayer(const String8& name, const sp<Client>& client, uint32_t w, |
| 3962 | uint32_t h, PixelFormat format, uint32_t flags, |
| 3963 | LayerMetadata metadata, sp<IBinder>* handle, |
| 3964 | sp<IGraphicBufferProducer>* gbp, sp<Layer>* parent) { |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 3965 | if (int32_t(w|h) < 0) { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 3966 | ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)", |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 3967 | int(w), int(h)); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 3968 | return BAD_VALUE; |
Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 3969 | } |
Andreas Huber | 8b42e8a | 2010-08-16 08:49:37 -0700 | [diff] [blame] | 3970 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 3971 | status_t result = NO_ERROR; |
| 3972 | |
| 3973 | sp<Layer> layer; |
| 3974 | |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 3975 | String8 uniqueName = getUniqueLayerName(name); |
| 3976 | |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 3977 | switch (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 3978 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 3979 | result = createBufferQueueLayer(client, uniqueName, w, h, flags, format, handle, gbp, |
| 3980 | &layer); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 3981 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | break; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 3983 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 3984 | result = createBufferStateLayer(client, uniqueName, w, h, flags, handle, &layer); |
| 3985 | break; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 3986 | case ISurfaceComposerClient::eFXSurfaceColor: |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3987 | // check if buffer size is set for color layer. |
| 3988 | if (w > 0 || h > 0) { |
| 3989 | ALOGE("createLayer() failed, w or h cannot be set for color layer (w=%d, h=%d)", |
| 3990 | int(w), int(h)); |
| 3991 | return BAD_VALUE; |
| 3992 | } |
| 3993 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 3994 | result = createColorLayer(client, |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 3995 | uniqueName, w, h, flags, |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 3996 | handle, &layer); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 3997 | break; |
Robert Carr | 6b3f6c5 | 2018-08-13 13:05:17 -0700 | [diff] [blame] | 3998 | case ISurfaceComposerClient::eFXSurfaceContainer: |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3999 | // check if buffer size is set for container layer. |
| 4000 | if (w > 0 || h > 0) { |
| 4001 | ALOGE("createLayer() failed, w or h cannot be set for container layer (w=%d, h=%d)", |
| 4002 | int(w), int(h)); |
| 4003 | return BAD_VALUE; |
| 4004 | } |
Robert Carr | 6b3f6c5 | 2018-08-13 13:05:17 -0700 | [diff] [blame] | 4005 | result = createContainerLayer(client, |
| 4006 | uniqueName, w, h, flags, |
| 4007 | handle, &layer); |
| 4008 | break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4009 | default: |
| 4010 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | break; |
| 4012 | } |
| 4013 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4014 | if (result != NO_ERROR) { |
| 4015 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4017 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 4018 | // window type is WINDOW_TYPE_DONT_SCREENSHOT from SurfaceControl.java |
| 4019 | // TODO b/64227542 |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4020 | if (metadata.has(METADATA_WINDOW_TYPE)) { |
| 4021 | int32_t windowType = metadata.getInt32(METADATA_WINDOW_TYPE, 0); |
| 4022 | if (windowType == 441731) { |
| 4023 | metadata.setInt32(METADATA_WINDOW_TYPE, 2024); // TYPE_NAVIGATION_BAR_PANEL |
| 4024 | layer->setPrimaryDisplayOnly(); |
| 4025 | } |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Evan Rosky | ef876c9 | 2019-01-25 17:46:06 -0800 | [diff] [blame] | 4028 | layer->setMetadata(metadata); |
Albert Chaulk | 479c60c | 2017-01-27 14:21:34 -0500 | [diff] [blame] | 4029 | |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 4030 | bool addToCurrentState = callingThreadHasUnscopedSurfaceFlingerAccess(); |
| 4031 | result = addClientLayer(client, *handle, *gbp, layer, *parent, |
| 4032 | addToCurrentState); |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4033 | if (result != NO_ERROR) { |
| 4034 | return result; |
| 4035 | } |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 4036 | mInterceptor->saveSurfaceCreation(layer); |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4037 | |
| 4038 | setTransactionFlags(eTransactionNeeded); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4039 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 4042 | String8 SurfaceFlinger::getUniqueLayerName(const String8& name) |
| 4043 | { |
| 4044 | bool matchFound = true; |
| 4045 | uint32_t dupeCounter = 0; |
| 4046 | |
| 4047 | // Tack on our counter whether there is a hit or not, so everyone gets a tag |
| 4048 | String8 uniqueName = name + "#" + String8(std::to_string(dupeCounter).c_str()); |
| 4049 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 4050 | // Grab the state lock since we're accessing mCurrentState |
| 4051 | Mutex::Autolock lock(mStateLock); |
| 4052 | |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 4053 | // Loop over layers until we're sure there is no matching name |
| 4054 | while (matchFound) { |
| 4055 | matchFound = false; |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 4056 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 4057 | if (layer->getName() == uniqueName) { |
| 4058 | matchFound = true; |
| 4059 | uniqueName = name + "#" + String8(std::to_string(++dupeCounter).c_str()); |
| 4060 | } |
| 4061 | }); |
| 4062 | } |
| 4063 | |
Marissa Wall | f1de4bd | 2018-05-22 13:05:01 -0700 | [diff] [blame] | 4064 | ALOGV_IF(dupeCounter > 0, "duplicate layer name: changing %s to %s", name.c_str(), |
| 4065 | uniqueName.c_str()); |
Cody Northrop | bc75528 | 2017-03-31 12:00:08 -0600 | [diff] [blame] | 4066 | |
| 4067 | return uniqueName; |
| 4068 | } |
| 4069 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 4070 | status_t SurfaceFlinger::createBufferQueueLayer(const sp<Client>& client, const String8& name, |
| 4071 | uint32_t w, uint32_t h, uint32_t flags, |
| 4072 | PixelFormat& format, sp<IBinder>* handle, |
| 4073 | sp<IGraphicBufferProducer>* gbp, |
| 4074 | sp<Layer>* outLayer) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | // initialize the surfaces |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4076 | switch (format) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | case PIXEL_FORMAT_TRANSPARENT: |
| 4078 | case PIXEL_FORMAT_TRANSLUCENT: |
| 4079 | format = PIXEL_FORMAT_RGBA_8888; |
| 4080 | break; |
| 4081 | case PIXEL_FORMAT_OPAQUE: |
Mathias Agopian | 8f10540 | 2010-04-05 18:01:24 -0700 | [diff] [blame] | 4082 | format = PIXEL_FORMAT_RGBX_8888; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | break; |
| 4084 | } |
| 4085 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 4086 | sp<BufferQueueLayer> layer = |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 4087 | getFactory().createBufferQueueLayer(LayerCreationArgs(this, client, name, w, h, flags)); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 4088 | status_t err = layer->setDefaultBufferProperties(w, h, format); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4089 | if (err == NO_ERROR) { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 4090 | *handle = layer->getHandle(); |
| 4091 | *gbp = layer->getProducer(); |
| 4092 | *outLayer = layer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4094 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 4095 | ALOGE_IF(err, "createBufferQueueLayer() failed (%s)", strerror(-err)); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4096 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | } |
| 4098 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4099 | status_t SurfaceFlinger::createBufferStateLayer(const sp<Client>& client, const String8& name, |
| 4100 | uint32_t w, uint32_t h, uint32_t flags, |
| 4101 | sp<IBinder>* handle, sp<Layer>* outLayer) { |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 4102 | sp<BufferStateLayer> layer = |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 4103 | getFactory().createBufferStateLayer(LayerCreationArgs(this, client, name, w, h, flags)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4104 | *handle = layer->getHandle(); |
| 4105 | *outLayer = layer; |
| 4106 | |
| 4107 | return NO_ERROR; |
| 4108 | } |
| 4109 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 4110 | status_t SurfaceFlinger::createColorLayer(const sp<Client>& client, |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4111 | const String8& name, uint32_t w, uint32_t h, uint32_t flags, |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 4112 | sp<IBinder>* handle, sp<Layer>* outLayer) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 4114 | *outLayer = getFactory().createColorLayer(LayerCreationArgs(this, client, name, w, h, flags)); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4115 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4116 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Robert Carr | 6b3f6c5 | 2018-08-13 13:05:17 -0700 | [diff] [blame] | 4119 | status_t SurfaceFlinger::createContainerLayer(const sp<Client>& client, |
| 4120 | const String8& name, uint32_t w, uint32_t h, uint32_t flags, |
| 4121 | sp<IBinder>* handle, sp<Layer>* outLayer) |
| 4122 | { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 4123 | *outLayer = |
| 4124 | getFactory().createContainerLayer(LayerCreationArgs(this, client, name, w, h, flags)); |
Robert Carr | 6b3f6c5 | 2018-08-13 13:05:17 -0700 | [diff] [blame] | 4125 | *handle = (*outLayer)->getHandle(); |
| 4126 | return NO_ERROR; |
| 4127 | } |
| 4128 | |
| 4129 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4130 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4131 | mLayersPendingRemoval.add(layer); |
| 4132 | mLayersRemoved = true; |
| 4133 | setTransactionFlags(eTransactionNeeded); |
| 4134 | } |
| 4135 | |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 4136 | void SurfaceFlinger::onHandleDestroyed(sp<Layer>& layer) |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 4137 | { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4138 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4139 | // If a layer has a parent, we allow it to out-live it's handle |
| 4140 | // with the idea that the parent holds a reference and will eventually |
| 4141 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4142 | // here. |
| 4143 | if (layer->getParent() == nullptr) { |
| 4144 | mCurrentState.layersSortedByZ.remove(layer); |
| 4145 | } |
| 4146 | markLayerPendingRemovalLocked(layer); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 4147 | layer.clear(); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 4150 | // --------------------------------------------------------------------------- |
| 4151 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4152 | void SurfaceFlinger::onInitializeDisplays() { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4153 | const auto display = getDefaultDisplayDeviceLocked(); |
| 4154 | if (!display) return; |
| 4155 | |
| 4156 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 4157 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4158 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 4159 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4160 | Vector<ComposerState> state; |
| 4161 | Vector<DisplayState> displays; |
| 4162 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 4163 | d.what = DisplayState::eDisplayProjectionChanged | |
| 4164 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4165 | d.token = token; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 4166 | d.layerStack = 0; |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4167 | d.orientation = DisplayState::eOrientationDefault; |
Jeff Brown | 4c05dd1 | 2012-09-09 00:07:17 -0700 | [diff] [blame] | 4168 | d.frame.makeInvalid(); |
| 4169 | d.viewport.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4170 | d.width = 0; |
| 4171 | d.height = 0; |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4172 | displays.add(d); |
Vishnu Nair | ec0ab38 | 2019-02-13 15:32:56 -0800 | [diff] [blame] | 4173 | setTransactionState(state, displays, 0, nullptr, mPendingInputWindowCommands, -1); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4174 | |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 4175 | setPowerModeInternal(display, HWC_POWER_MODE_NORMAL); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4176 | |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4177 | const nsecs_t vsyncPeriod = getVsyncPeriod(); |
| 4178 | mAnimFrameTracker.setDisplayRefreshPeriod(vsyncPeriod); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 4179 | |
Brian Anderson | d001058 | 2017-03-07 13:20:31 -0800 | [diff] [blame] | 4180 | // Use phase of 0 since phase is not known. |
| 4181 | // Use latency of 0, which will snap to the ideal latency. |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4182 | DisplayStatInfo stats{0 /* vsyncTime */, vsyncPeriod}; |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 4183 | setCompositorTimingSnapped(stats, 0); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 4187 | // Async since we may be called from the main thread. |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4188 | postMessageAsync( |
| 4189 | new LambdaMessage([this]() NO_THREAD_SAFETY_ANALYSIS { onInitializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 4192 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4193 | if (display->isVirtual()) { |
| 4194 | ALOGE("%s: Invalid operation on virtual display", __FUNCTION__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4195 | return; |
| 4196 | } |
| 4197 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4198 | const auto displayId = display->getId(); |
| 4199 | LOG_ALWAYS_FATAL_IF(!displayId); |
| 4200 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 4201 | ALOGD("Setting power mode %d on display %s", mode, to_string(*displayId).c_str()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4202 | |
| 4203 | int currentMode = display->getPowerMode(); |
| 4204 | if (mode == currentMode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4205 | return; |
| 4206 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4207 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4208 | display->setPowerMode(mode); |
| 4209 | |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 4210 | if (mInterceptor->isEnabled()) { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 4211 | mInterceptor->savePowerModeUpdate(display->getSequenceId(), mode); |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4214 | if (currentMode == HWC_POWER_MODE_OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 4215 | // Turn on the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4216 | getHwComposer().setPowerMode(*displayId, mode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4217 | if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4218 | mScheduler->onScreenAcquired(mAppConnectionHandle); |
| 4219 | mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4220 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4222 | mVisibleRegionsDirty = true; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4223 | mHasPoweredOff = true; |
Dan Stoza | c7a25ad | 2018-04-12 11:45:09 -0700 | [diff] [blame] | 4224 | repaintEverything(); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 4225 | |
| 4226 | struct sched_param param = {0}; |
| 4227 | param.sched_priority = 1; |
| 4228 | if (sched_setscheduler(0, SCHED_FIFO, ¶m) != 0) { |
| 4229 | ALOGW("Couldn't set SCHED_FIFO on display on"); |
| 4230 | } |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4231 | } else if (mode == HWC_POWER_MODE_OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 4232 | // Turn off the display |
| 4233 | struct sched_param param = {0}; |
| 4234 | if (sched_setscheduler(0, SCHED_OTHER, ¶m) != 0) { |
| 4235 | ALOGW("Couldn't set SCHED_OTHER on display off"); |
| 4236 | } |
| 4237 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4238 | if (display->isPrimary() && currentMode != HWC_POWER_MODE_DOZE_SUSPEND) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4239 | mScheduler->disableHardwareVsync(true); |
| 4240 | mScheduler->onScreenReleased(mAppConnectionHandle); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 4241 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4242 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4243 | getHwComposer().setPowerMode(*displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4244 | mVisibleRegionsDirty = true; |
| 4245 | // from this point on, SF will stop drawing on this display |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 4246 | } else if (mode == HWC_POWER_MODE_DOZE || |
| 4247 | mode == HWC_POWER_MODE_NORMAL) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4248 | // Update display while dozing |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4249 | getHwComposer().setPowerMode(*displayId, mode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4250 | if (display->isPrimary() && currentMode == HWC_POWER_MODE_DOZE_SUSPEND) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4251 | mScheduler->onScreenAcquired(mAppConnectionHandle); |
| 4252 | mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4253 | } |
| 4254 | } else if (mode == HWC_POWER_MODE_DOZE_SUSPEND) { |
| 4255 | // Leave display going to doze |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4256 | if (display->isPrimary()) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4257 | mScheduler->disableHardwareVsync(true); |
| 4258 | mScheduler->onScreenReleased(mAppConnectionHandle); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4259 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4260 | getHwComposer().setPowerMode(*displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4261 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 4262 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4263 | getHwComposer().setPowerMode(*displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4264 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4265 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 4266 | if (display->isPrimary()) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 4267 | mTimeStats->setPowerMode(mode); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4268 | if (mRefreshRateStats) { |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 4269 | // Update refresh rate stats. |
| 4270 | mRefreshRateStats->setPowerMode(mode); |
| 4271 | } |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 4274 | ALOGD("Finished setting power mode %d on display %s", mode, to_string(*displayId).c_str()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4275 | } |
| 4276 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4277 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4278 | postMessageSync(new LambdaMessage([&]() NO_THREAD_SAFETY_ANALYSIS { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4279 | const auto display = getDisplayDevice(displayToken); |
| 4280 | if (!display) { |
| 4281 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 4282 | displayToken.get()); |
| 4283 | } else if (display->isVirtual()) { |
| 4284 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 4285 | } else { |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 4286 | setPowerModeInternal(display, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4287 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4288 | })); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | // --------------------------------------------------------------------------- |
| 4292 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4293 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, |
| 4294 | bool asProto) NO_THREAD_SAFETY_ANALYSIS { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4295 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 4296 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 4297 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4298 | const int pid = ipc->getCallingPid(); |
| 4299 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 4300 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 4301 | if ((uid != AID_SHELL) && |
| 4302 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4303 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 4304 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | } else { |
Jesse Hall | fcd15b4 | 2014-12-23 13:57:23 -0800 | [diff] [blame] | 4306 | // Try to get the main lock, but give up after one second |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 4307 | // (this would indicate SF is stuck, but we want to be able to |
| 4308 | // print something in dumpsys). |
Jesse Hall | fcd15b4 | 2014-12-23 13:57:23 -0800 | [diff] [blame] | 4309 | status_t err = mStateLock.timedLock(s2ns(1)); |
| 4310 | bool locked = (err == NO_ERROR); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 4311 | if (!locked) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4312 | StringAppendF(&result, |
| 4313 | "SurfaceFlinger appears to be unresponsive (%s [%d]), dumping anyways " |
| 4314 | "(no locks held)\n", |
| 4315 | strerror(-err), err); |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 4316 | } |
| 4317 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4318 | using namespace std::string_literals; |
chaviw | a3d7bd3 | 2017-11-03 09:41:53 -0700 | [diff] [blame] | 4319 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4320 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 4321 | {"--clear-layer-stats"s, dumper([this](std::string&) { mLayerStats.clear(); })}, |
| 4322 | {"--disable-layer-stats"s, dumper([this](std::string&) { mLayerStats.disable(); })}, |
| 4323 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 4324 | {"--dispsync"s, dumper([this](std::string& s) { |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 4325 | mScheduler->dumpPrimaryDispSync(s); |
Ady Abraham | 3aff917 | 2019-02-07 19:10:26 -0800 | [diff] [blame] | 4326 | })}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4327 | {"--dump-layer-stats"s, dumper([this](std::string& s) { mLayerStats.dump(s); })}, |
| 4328 | {"--enable-layer-stats"s, dumper([this](std::string&) { mLayerStats.enable(); })}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4329 | {"--frame-events"s, dumper(&SurfaceFlinger::dumpFrameEventsLocked)}, |
| 4330 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 4331 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 4332 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
| 4333 | {"--static-screen"s, dumper(&SurfaceFlinger::dumpStaticScreenStats)}, |
| 4334 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4335 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVSync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4336 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 4337 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4338 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4339 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4340 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4341 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 4342 | (it->second)(args, asProto, result); |
| 4343 | } else { |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 4344 | if (asProto) { |
| 4345 | LayersProto layersProto = dumpProtoInfo(LayerVector::StateSet::Current); |
| 4346 | result.append(layersProto.SerializeAsString().c_str(), layersProto.ByteSize()); |
| 4347 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4348 | dumpAllLocked(args, result); |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 4349 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 4350 | } |
| 4351 | |
Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 4352 | if (locked) { |
| 4353 | mStateLock.unlock(); |
| 4354 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4356 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | return NO_ERROR; |
| 4358 | } |
| 4359 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4360 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4361 | mCurrentState.traverseInZOrder( |
| 4362 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getName().string()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4363 | } |
| 4364 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4365 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4366 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriod()); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 4367 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4368 | if (args.size() > 1) { |
| 4369 | const auto name = String8(args[1]); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4370 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 4371 | if (name == layer->getName()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 4372 | layer->dumpFrameStats(result); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 4373 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4374 | }); |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4375 | } else { |
| 4376 | mAnimFrameTracker.dumpStats(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4380 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4381 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4382 | if (args.size() < 2 || String8(args[1]) == layer->getName()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 4383 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4384 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4385 | }); |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 4386 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 4387 | mAnimFrameTracker.clearStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4388 | } |
| 4389 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4390 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 4391 | mTimeStats->parseArgs(asProto, args, result); |
| 4392 | } |
| 4393 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4394 | // This should only be called from the main thread. Otherwise it would need |
| 4395 | // the lock and should use mCurrentState rather than mDrawingState. |
| 4396 | void SurfaceFlinger::logFrameStats() { |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4397 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4398 | layer->logFrameStats(); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4399 | }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4400 | |
| 4401 | mAnimFrameTracker.logAndResetStats(String8("<win-anim>")); |
| 4402 | } |
| 4403 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4404 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 4405 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 4406 | |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 4407 | if (isLayerTripleBufferingDisabled()) |
| 4408 | result.append(" DISABLE_TRIPLE_BUFFERING"); |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 4409 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4410 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 4411 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
| 4412 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%" PRIu64, maxVirtualDisplaySize); |
| 4413 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
| 4414 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
| 4415 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 4416 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4419 | void SurfaceFlinger::dumpVSync(std::string& result) const { |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 4420 | mPhaseOffsets->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4421 | StringAppendF(&result, |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4422 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 " ns\n\n", |
Ana Krulec | 757f63a | 2019-01-25 10:46:18 -0800 | [diff] [blame] | 4423 | dispSyncPresentTimeOffset, getVsyncPeriod()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4424 | |
Ana Krulec | ba13ab3 | 2019-02-20 14:14:12 -0800 | [diff] [blame] | 4425 | StringAppendF(&result, "Scheduler enabled. 90Hz feature: %s\n", mUse90Hz ? "on" : "off"); |
| 4426 | StringAppendF(&result, "+ Smart 90 for video detection: %s\n\n", |
| 4427 | mUseSmart90ForVideo ? "on" : "off"); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4428 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4429 | } |
| 4430 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4431 | void SurfaceFlinger::dumpStaticScreenStats(std::string& result) const { |
| 4432 | result.append("Static screen stats:\n"); |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 4433 | for (size_t b = 0; b < SurfaceFlingerBE::NUM_BUCKETS - 1; ++b) { |
| 4434 | float bucketTimeSec = getBE().mFrameBuckets[b] / 1e9; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4435 | float percent = 100.0f * |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 4436 | static_cast<float>(getBE().mFrameBuckets[b]) / getBE().mTotalTime; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4437 | StringAppendF(&result, " < %zd frames: %.3f s (%.1f%%)\n", b + 1, bucketTimeSec, percent); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4438 | } |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 4439 | float bucketTimeSec = getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] / 1e9; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4440 | float percent = 100.0f * |
David Sodman | 4a36e93 | 2017-11-07 14:29:47 -0800 | [diff] [blame] | 4441 | static_cast<float>(getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1]) / getBE().mTotalTime; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4442 | StringAppendF(&result, " %zd+ frames: %.3f s (%.1f%%)\n", SurfaceFlingerBE::NUM_BUCKETS - 1, |
| 4443 | bucketTimeSec, percent); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4446 | void SurfaceFlinger::recordBufferingStats(const char* layerName, |
| 4447 | std::vector<OccupancyTracker::Segment>&& history) { |
David Sodman | cbaf083 | 2017-11-07 14:21:36 -0800 | [diff] [blame] | 4448 | Mutex::Autolock lock(getBE().mBufferingStatsMutex); |
| 4449 | auto& stats = getBE().mBufferingStats[layerName]; |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4450 | for (const auto& segment : history) { |
| 4451 | if (!segment.usedThirdBuffer) { |
| 4452 | stats.twoBufferTime += segment.totalTime; |
| 4453 | } |
| 4454 | if (segment.occupancyAverage < 1.0f) { |
| 4455 | stats.doubleBufferedTime += segment.totalTime; |
| 4456 | } else if (segment.occupancyAverage < 2.0f) { |
| 4457 | stats.tripleBufferedTime += segment.totalTime; |
| 4458 | } |
| 4459 | ++stats.numSegments; |
| 4460 | stats.totalTime += segment.totalTime; |
| 4461 | } |
| 4462 | } |
| 4463 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4464 | void SurfaceFlinger::dumpFrameEventsLocked(std::string& result) { |
| 4465 | result.append("Layer frame timestamps:\n"); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 4466 | |
| 4467 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; |
| 4468 | const size_t count = currentLayers.size(); |
| 4469 | for (size_t i=0 ; i<count ; i++) { |
| 4470 | currentLayers[i]->dumpFrameEvents(result); |
| 4471 | } |
| 4472 | } |
| 4473 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4474 | void SurfaceFlinger::dumpBufferingStats(std::string& result) const { |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4475 | result.append("Buffering stats:\n"); |
| 4476 | result.append(" [Layer name] <Active time> <Two buffer> " |
| 4477 | "<Double buffered> <Triple buffered>\n"); |
David Sodman | cbaf083 | 2017-11-07 14:21:36 -0800 | [diff] [blame] | 4478 | Mutex::Autolock lock(getBE().mBufferingStatsMutex); |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4479 | typedef std::tuple<std::string, float, float, float> BufferTuple; |
| 4480 | std::map<float, BufferTuple, std::greater<float>> sorted; |
David Sodman | cbaf083 | 2017-11-07 14:21:36 -0800 | [diff] [blame] | 4481 | for (const auto& statsPair : getBE().mBufferingStats) { |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4482 | const char* name = statsPair.first.c_str(); |
David Sodman | cbaf083 | 2017-11-07 14:21:36 -0800 | [diff] [blame] | 4483 | const SurfaceFlingerBE::BufferingStats& stats = statsPair.second; |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4484 | if (stats.numSegments == 0) { |
| 4485 | continue; |
| 4486 | } |
| 4487 | float activeTime = ns2ms(stats.totalTime) / 1000.0f; |
| 4488 | float twoBufferRatio = static_cast<float>(stats.twoBufferTime) / |
| 4489 | stats.totalTime; |
| 4490 | float doubleBufferRatio = static_cast<float>( |
| 4491 | stats.doubleBufferedTime) / stats.totalTime; |
| 4492 | float tripleBufferRatio = static_cast<float>( |
| 4493 | stats.tripleBufferedTime) / stats.totalTime; |
| 4494 | sorted.insert({activeTime, {name, twoBufferRatio, |
| 4495 | doubleBufferRatio, tripleBufferRatio}}); |
| 4496 | } |
| 4497 | for (const auto& sortedPair : sorted) { |
| 4498 | float activeTime = sortedPair.first; |
| 4499 | const BufferTuple& values = sortedPair.second; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4500 | StringAppendF(&result, " [%s] %.2f %.3f %.3f %.3f\n", std::get<0>(values).c_str(), |
| 4501 | activeTime, std::get<1>(values), std::get<2>(values), std::get<3>(values)); |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4502 | } |
| 4503 | result.append("\n"); |
| 4504 | } |
| 4505 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4506 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4507 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4508 | const auto displayId = display->getId(); |
| 4509 | if (!displayId) { |
| 4510 | continue; |
| 4511 | } |
| 4512 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 4513 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4514 | continue; |
| 4515 | } |
| 4516 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4517 | StringAppendF(&result, |
| 4518 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 4519 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4520 | uint8_t port; |
| 4521 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 4522 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4523 | result.append("no identification data\n"); |
| 4524 | continue; |
| 4525 | } |
| 4526 | |
| 4527 | if (!isEdid(data)) { |
| 4528 | result.append("unknown identification data: "); |
| 4529 | for (uint8_t byte : data) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4530 | StringAppendF(&result, "%x ", byte); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4531 | } |
| 4532 | result.append("\n"); |
| 4533 | continue; |
| 4534 | } |
| 4535 | |
| 4536 | const auto edid = parseEdid(data); |
| 4537 | if (!edid) { |
| 4538 | result.append("invalid EDID: "); |
| 4539 | for (uint8_t byte : data) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4540 | StringAppendF(&result, "%x ", byte); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4541 | } |
| 4542 | result.append("\n"); |
| 4543 | continue; |
| 4544 | } |
| 4545 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4546 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4547 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 4548 | result.append("\"\n"); |
| 4549 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4552 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
| 4553 | StringAppendF(&result, "Device has wide color display: %d\n", hasWideColorDisplay); |
| 4554 | StringAppendF(&result, "Device uses color management: %d\n", useColorManagement); |
| 4555 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 4556 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4557 | |
| 4558 | // TODO: print out if wide-color mode is active or not |
| 4559 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4560 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4561 | const auto displayId = display->getId(); |
| 4562 | if (!displayId) { |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4563 | continue; |
| 4564 | } |
| 4565 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4566 | StringAppendF(&result, "Display %s color modes:\n", to_string(*displayId).c_str()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4567 | std::vector<ColorMode> modes = getHwComposer().getColorModes(*displayId); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4568 | for (auto&& mode : modes) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4569 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4570 | } |
| 4571 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4572 | ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4573 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 4574 | decodeColorMode(currentMode).c_str(), currentMode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4575 | } |
| 4576 | result.append("\n"); |
| 4577 | } |
| 4578 | |
Jorim Jaggi | 8e0af36 | 2017-11-14 16:28:28 +0100 | [diff] [blame] | 4579 | LayersProto SurfaceFlinger::dumpProtoInfo(LayerVector::StateSet stateSet) const { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 4580 | LayersProto layersProto; |
Jorim Jaggi | 8e0af36 | 2017-11-14 16:28:28 +0100 | [diff] [blame] | 4581 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 4582 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
| 4583 | state.traverseInZOrder([&](Layer* layer) { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 4584 | LayerProto* layerProto = layersProto.add_layers(); |
Jorim Jaggi | 8e0af36 | 2017-11-14 16:28:28 +0100 | [diff] [blame] | 4585 | layer->writeToProto(layerProto, stateSet); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 4586 | }); |
| 4587 | |
| 4588 | return layersProto; |
| 4589 | } |
| 4590 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4591 | LayersProto SurfaceFlinger::dumpVisibleLayersProtoInfo( |
| 4592 | const sp<DisplayDevice>& displayDevice) const { |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4593 | LayersProto layersProto; |
Yiwei Zhang | 60d1a19 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 4594 | |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4595 | SizeProto* resolution = layersProto.mutable_resolution(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4596 | resolution->set_w(displayDevice->getWidth()); |
| 4597 | resolution->set_h(displayDevice->getHeight()); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4598 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4599 | auto display = displayDevice->getCompositionDisplay(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4600 | const auto& displayState = display->getState(); |
Yiwei Zhang | 60d1a19 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 4601 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4602 | layersProto.set_color_mode(decodeColorMode(displayState.colorMode)); |
| 4603 | layersProto.set_color_transform(decodeColorTransform(displayState.colorTransform)); |
| 4604 | layersProto.set_global_transform(displayState.orientation); |
| 4605 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4606 | const auto displayId = displayDevice->getId(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4607 | LOG_ALWAYS_FATAL_IF(!displayId); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4608 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4609 | if (!layer->visibleRegion.isEmpty() && !display->getOutputLayersOrderedByZ().empty()) { |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4610 | LayerProto* layerProto = layersProto.add_layers(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4611 | layer->writeToProto(layerProto, displayDevice); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 4612 | } |
| 4613 | }); |
| 4614 | |
| 4615 | return layersProto; |
| 4616 | } |
| 4617 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4618 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, std::string& result) const { |
| 4619 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4620 | Colorizer colorizer(colorize); |
| 4621 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4622 | // figure out if we're stuck somewhere |
| 4623 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4624 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4625 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 4626 | |
| 4627 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4628 | * Dump library configuration. |
| 4629 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4630 | |
| 4631 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4632 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4633 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4634 | appendSfConfigString(result); |
| 4635 | appendUiConfigString(result); |
| 4636 | appendGuiConfigString(result); |
| 4637 | result.append("\n"); |
| 4638 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 4639 | result.append("\nDisplay identification data:\n"); |
| 4640 | dumpDisplayIdentificationData(result); |
| 4641 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 4642 | result.append("\nWide-Color information:\n"); |
| 4643 | dumpWideColorInfo(result); |
| 4644 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4645 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 4646 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4647 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 4648 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4649 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 4650 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 4651 | colorizer.bold(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4652 | result.append("VSYNC configuration:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 4653 | colorizer.reset(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4654 | dumpVSync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4655 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4656 | |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 4657 | dumpStaticScreenStats(result); |
| 4658 | result.append("\n"); |
| 4659 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4660 | StringAppendF(&result, "Missed frame count: %u\n\n", mFrameMissedCount.load()); |
Marissa Wall | cfcdaa5 | 2018-05-21 15:45:59 -0700 | [diff] [blame] | 4661 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 4662 | dumpBufferingStats(result); |
| 4663 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4664 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4665 | * Dump the visible layer list |
| 4666 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4667 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4668 | StringAppendF(&result, "Visible layers (count = %zu)\n", mNumLayers); |
| 4669 | StringAppendF(&result, "GraphicBufferProducers: %zu, max %zu\n", |
| 4670 | mGraphicBufferProducerList.size(), mMaxGraphicBufferProducerListSize); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4671 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 4672 | |
Chia-I Wu | 2f88413 | 2018-09-13 15:17:58 -0700 | [diff] [blame] | 4673 | { |
| 4674 | LayersProto layersProto = dumpProtoInfo(LayerVector::StateSet::Current); |
| 4675 | auto layerTree = LayerProtoParser::generateLayerTree(layersProto); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4676 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
Chia-I Wu | 2f88413 | 2018-09-13 15:17:58 -0700 | [diff] [blame] | 4677 | result.append("\n"); |
| 4678 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4679 | |
| 4680 | /* |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 4681 | * Dump Display state |
| 4682 | */ |
| 4683 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4684 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4685 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4686 | colorizer.reset(result); |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4687 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4688 | display->dump(result); |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 4689 | } |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 4690 | result.append("\n"); |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 4691 | |
| 4692 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4693 | * Dump SurfaceFlinger global state |
| 4694 | */ |
| 4695 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4696 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 4697 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4698 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4699 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 4700 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4701 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4702 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4703 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 4704 | "undefinedRegion"); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4705 | StringAppendF(&result, " orientation=%d, isPoweredOn=%d\n", display->getOrientation(), |
| 4706 | display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 4707 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4708 | StringAppendF(&result, |
| 4709 | " transaction-flags : %08x\n" |
| 4710 | " gpu_to_cpu_unsupported : %d\n", |
| 4711 | mTransactionFlags.load(), !mGpuToCpuSupported); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4712 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4713 | if (const auto displayId = getInternalDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4714 | displayId && getHwComposer().isConnected(*displayId)) { |
| 4715 | const auto activeConfig = getHwComposer().getActiveConfig(*displayId); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4716 | StringAppendF(&result, |
| 4717 | " refresh-rate : %f fps\n" |
| 4718 | " x-dpi : %f\n" |
| 4719 | " y-dpi : %f\n", |
| 4720 | 1e9 / activeConfig->getVsyncPeriod(), activeConfig->getDpiX(), |
| 4721 | activeConfig->getDpiY()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4722 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4723 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4724 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4725 | |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 4726 | /* |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 4727 | * Tracing state |
| 4728 | */ |
| 4729 | mTracing.dump(result); |
| 4730 | result.append("\n"); |
| 4731 | |
| 4732 | /* |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 4733 | * HWC layer minidump |
| 4734 | */ |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4735 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4736 | const auto displayId = display->getId(); |
| 4737 | if (!displayId) { |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 4738 | continue; |
| 4739 | } |
| 4740 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4741 | StringAppendF(&result, "Display %s HWC layers:\n", to_string(*displayId).c_str()); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 4742 | Layer::miniDumpHeader(result); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 4743 | const sp<DisplayDevice> displayDevice = display; |
| 4744 | mCurrentState.traverseInZOrder( |
| 4745 | [&](Layer* layer) { layer->miniDump(result, displayDevice); }); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 4746 | result.append("\n"); |
| 4747 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4748 | |
| 4749 | /* |
| 4750 | * Dump HWComposer state |
| 4751 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4752 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 4753 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 4754 | colorizer.reset(result); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 4755 | bool hwcDisabled = mDebugDisableHWC || mDebugRegion; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4756 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4757 | getHwComposer().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4758 | |
| 4759 | /* |
| 4760 | * Dump gralloc state |
| 4761 | */ |
| 4762 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 4763 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 4764 | |
| 4765 | /* |
| 4766 | * Dump VrFlinger state if in use. |
| 4767 | */ |
| 4768 | if (mVrFlingerRequestsDisplay && mVrFlinger) { |
| 4769 | result.append("VrFlinger state:\n"); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4770 | result.append(mVrFlinger->Dump()); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 4771 | result.append("\n"); |
| 4772 | } |
Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 4773 | |
| 4774 | /** |
| 4775 | * Scheduler dump state. |
| 4776 | */ |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4777 | result.append("\nScheduler state:\n"); |
| 4778 | result.append(mScheduler->doDump() + "\n"); |
| 4779 | result.append(mRefreshRateStats->doDump() + "\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4780 | } |
| 4781 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4782 | const Vector<sp<Layer>>& SurfaceFlinger::getLayerSortedByZForHwcDisplay(DisplayId displayId) { |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 4783 | // Note: mStateLock is held here |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4784 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 4785 | if (display->getId() == displayId) { |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4786 | return getDisplayDeviceLocked(token)->getVisibleLayersSortedByZ(); |
Jesse Hall | 48bc05b | 2013-03-21 14:06:52 -0700 | [diff] [blame] | 4787 | } |
| 4788 | } |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4789 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 4790 | ALOGE("%s: Invalid display %s", __FUNCTION__, to_string(displayId).c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4791 | static const Vector<sp<Layer>> empty; |
| 4792 | return empty; |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 4793 | } |
| 4794 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 4795 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 4796 | mat4 colorMatrix; |
| 4797 | if (mGlobalSaturationFactor != 1.0f) { |
| 4798 | // Rec.709 luma coefficients |
| 4799 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 4800 | luminance *= 1.0f - mGlobalSaturationFactor; |
| 4801 | mat4 saturationMatrix = mat4( |
| 4802 | vec4{luminance.r + mGlobalSaturationFactor, luminance.r, luminance.r, 0.0f}, |
| 4803 | vec4{luminance.g, luminance.g + mGlobalSaturationFactor, luminance.g, 0.0f}, |
| 4804 | vec4{luminance.b, luminance.b, luminance.b + mGlobalSaturationFactor, 0.0f}, |
| 4805 | vec4{0.0f, 0.0f, 0.0f, 1.0f} |
| 4806 | ); |
| 4807 | colorMatrix = mClientColorMatrix * saturationMatrix * mDaltonizer(); |
| 4808 | } else { |
| 4809 | colorMatrix = mClientColorMatrix * mDaltonizer(); |
| 4810 | } |
| 4811 | |
| 4812 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 4813 | mCurrentState.colorMatrix = colorMatrix; |
| 4814 | mCurrentState.colorMatrixChanged = true; |
| 4815 | setTransactionFlags(eTransactionNeeded); |
| 4816 | } |
| 4817 | } |
| 4818 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 4819 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4820 | #pragma clang diagnostic push |
| 4821 | #pragma clang diagnostic error "-Wswitch-enum" |
| 4822 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 4823 | // These methods should at minimum make sure that the client requested |
| 4824 | // access to SF. |
Dan Stoza | e334440 | 2018-08-20 19:53:42 +0000 | [diff] [blame] | 4825 | case BOOT_FINISHED: |
| 4826 | case CLEAR_ANIMATION_FRAME_STATS: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4827 | case CREATE_DISPLAY: |
| 4828 | case DESTROY_DISPLAY: |
Dan Stoza | e334440 | 2018-08-20 19:53:42 +0000 | [diff] [blame] | 4829 | case ENABLE_VSYNC_INJECTIONS: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4830 | case GET_ACTIVE_COLOR_MODE: |
| 4831 | case GET_ANIMATION_FRAME_STATS: |
| 4832 | case GET_HDR_CAPABILITIES: |
| 4833 | case SET_ACTIVE_CONFIG: |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 4834 | case SET_ALLOWED_DISPLAY_CONFIGS: |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 4835 | case GET_ALLOWED_DISPLAY_CONFIGS: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4836 | case SET_ACTIVE_COLOR_MODE: |
Chia-I Wu | 90f669f | 2017-10-05 14:24:41 -0700 | [diff] [blame] | 4837 | case INJECT_VSYNC: |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 4838 | case SET_POWER_MODE: |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 4839 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 4840 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
| 4841 | case GET_DISPLAYED_CONTENT_SAMPLE: { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4842 | if (!callingThreadHasUnscopedSurfaceFlingerAccess()) { |
| 4843 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4844 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 4845 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 4846 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 4848 | return OK; |
| 4849 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4850 | case GET_LAYER_DEBUG_INFO: { |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 4851 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4852 | const int pid = ipc->getCallingPid(); |
| 4853 | const int uid = ipc->getCallingUid(); |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4854 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 4855 | ALOGE("Layer debug info permission denied for pid=%d, uid=%d", pid, uid); |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 4856 | return PERMISSION_DENIED; |
| 4857 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4858 | return OK; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4860 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 4861 | case CREATE_DISPLAY_EVENT_CONNECTION: |
| 4862 | // The following calls are currently used by clients that do not |
| 4863 | // request necessary permissions. However, they do not expose any secret |
| 4864 | // information, so it is OK to pass them. |
| 4865 | case AUTHENTICATE_SURFACE: |
| 4866 | case GET_ACTIVE_CONFIG: |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4867 | case GET_PHYSICAL_DISPLAY_IDS: |
| 4868 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4869 | case GET_DISPLAY_COLOR_MODES: |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 4870 | case GET_DISPLAY_NATIVE_PRIMARIES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4871 | case GET_DISPLAY_CONFIGS: |
| 4872 | case GET_DISPLAY_STATS: |
| 4873 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
| 4874 | // Calling setTransactionState is safe, because you need to have been |
| 4875 | // granted a reference to Client* and Handle* to do anything with it. |
| 4876 | case SET_TRANSACTION_STATE: |
Robert Carr | b89ea9d | 2018-12-10 13:01:14 -0800 | [diff] [blame] | 4877 | case CREATE_CONNECTION: |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 4878 | case GET_COLOR_MANAGEMENT: |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 4879 | case GET_COMPOSITION_PREFERENCE: |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 4880 | case GET_PROTECTED_CONTENT_SUPPORT: |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 4881 | case IS_WIDE_COLOR_DISPLAY: { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4882 | return OK; |
| 4883 | } |
| 4884 | case CAPTURE_LAYERS: |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 4885 | case CAPTURE_SCREEN: |
| 4886 | case ADD_REGION_SAMPLING_LISTENER: |
| 4887 | case REMOVE_REGION_SAMPLING_LISTENER: { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4888 | // codes that require permission check |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4889 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4890 | const int pid = ipc->getCallingPid(); |
| 4891 | const int uid = ipc->getCallingUid(); |
| 4892 | if ((uid != AID_GRAPHICS) && |
| 4893 | !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 4894 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 4895 | return PERMISSION_DENIED; |
| 4896 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4897 | return OK; |
| 4898 | } |
| 4899 | // The following codes are deprecated and should never be allowed to access SF. |
| 4900 | case CONNECT_DISPLAY_UNUSED: |
| 4901 | case CREATE_GRAPHIC_BUFFER_ALLOC_UNUSED: { |
| 4902 | ALOGE("Attempting to access SurfaceFlinger with unused code: %u", code); |
| 4903 | return PERMISSION_DENIED; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4904 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4906 | |
| 4907 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 4908 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 4909 | // We let them pass by default. |
| 4910 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 4911 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 4912 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 4913 | return OK; |
| 4914 | } |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 4915 | // Numbers from 1000 to 1032 are currently use for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4916 | // in onTransact verifies that the user is root, and has access to use SF. |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 4917 | if (code >= 1000 && code <= 1032) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4918 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 4919 | return OK; |
| 4920 | } |
| 4921 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 4922 | return PERMISSION_DENIED; |
| 4923 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 4926 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 4927 | uint32_t flags) { |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 4928 | status_t credentialCheck = CheckTransactCodeCredentials(code); |
| 4929 | if (credentialCheck != OK) { |
| 4930 | return credentialCheck; |
| 4931 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 4932 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4933 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 4934 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 4935 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 4936 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4937 | const int uid = ipc->getCallingUid(); |
| 4938 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 4939 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 4940 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 4941 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 4942 | "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] | 4943 | return PERMISSION_DENIED; |
| 4944 | } |
| 4945 | int n; |
| 4946 | switch (code) { |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 4947 | case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE |
Mathias Agopian | 35b48d1 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 4948 | case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | return NO_ERROR; |
| 4950 | case 1002: // SHOW_UPDATES |
| 4951 | n = data.readInt32(); |
| 4952 | mDebugRegion = n ? n : (mDebugRegion ? 0 : 1); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 4953 | invalidateHwcGeometry(); |
| 4954 | repaintEverything(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4955 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4956 | case 1004:{ // repaint everything |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 4957 | repaintEverything(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 4958 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4959 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 4960 | case 1005:{ // force transaction |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 4961 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4962 | setTransactionFlags( |
| 4963 | eTransactionNeeded| |
| 4964 | eDisplayTransactionNeeded| |
| 4965 | eTraversalNeeded); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 4966 | return NO_ERROR; |
| 4967 | } |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 4968 | case 1006:{ // send empty update |
| 4969 | signalRefresh(); |
| 4970 | return NO_ERROR; |
| 4971 | } |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 4972 | case 1008: // toggle use of hw composer |
| 4973 | n = data.readInt32(); |
| 4974 | mDebugDisableHWC = n ? 1 : 0; |
| 4975 | invalidateHwcGeometry(); |
| 4976 | repaintEverything(); |
| 4977 | return NO_ERROR; |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 4978 | case 1009: // toggle use of transform hint |
| 4979 | n = data.readInt32(); |
| 4980 | mDebugDisableTransformHint = n ? 1 : 0; |
| 4981 | invalidateHwcGeometry(); |
| 4982 | repaintEverything(); |
| 4983 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4984 | case 1010: // interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 4985 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | reply->writeInt32(0); |
| 4987 | reply->writeInt32(mDebugRegion); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 4988 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 4989 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4990 | return NO_ERROR; |
| 4991 | case 1013: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4992 | const auto display = getDefaultDisplayDevice(); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4993 | if (!display) { |
| 4994 | return NAME_NOT_FOUND; |
| 4995 | } |
| 4996 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4997 | reply->writeInt32(display->getPageFlipCount()); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 4998 | return NO_ERROR; |
| 4999 | } |
| 5000 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5001 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5002 | // daltonize |
| 5003 | n = data.readInt32(); |
| 5004 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5005 | case 1: |
| 5006 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 5007 | break; |
| 5008 | case 2: |
| 5009 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 5010 | break; |
| 5011 | case 3: |
| 5012 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 5013 | break; |
| 5014 | default: |
| 5015 | mDaltonizer.setType(ColorBlindnessType::None); |
| 5016 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5017 | } |
| 5018 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5019 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5020 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5021 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5022 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5023 | |
| 5024 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5025 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5027 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5028 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5029 | // apply a color matrix |
| 5030 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5031 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5032 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 5033 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5034 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5035 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5036 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5037 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5038 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5039 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5040 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 5041 | |
| 5042 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 5043 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5044 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 5045 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 5046 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 5047 | } |
| 5048 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5049 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5050 | return NO_ERROR; |
| 5051 | } |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 5052 | // This is an experimental interface |
| 5053 | // Needs to be shifted to proper binder interface when we productize |
| 5054 | case 1016: { |
Andy McFadden | 645b1f7 | 2014-06-10 14:43:32 -0700 | [diff] [blame] | 5055 | n = data.readInt32(); |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 5056 | // TODO(b/113612090): Evaluate if this can be removed. |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5057 | mScheduler->setRefreshSkipCount(n); |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 5058 | return NO_ERROR; |
| 5059 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 5060 | case 1017: { |
| 5061 | n = data.readInt32(); |
| 5062 | mForceFullDamage = static_cast<bool>(n); |
| 5063 | return NO_ERROR; |
| 5064 | } |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5065 | case 1018: { // Modify Choreographer's phase offset |
| 5066 | n = data.readInt32(); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5067 | mScheduler->setPhaseOffset(mAppConnectionHandle, static_cast<nsecs_t>(n)); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5068 | return NO_ERROR; |
| 5069 | } |
| 5070 | case 1019: { // Modify SurfaceFlinger's phase offset |
| 5071 | n = data.readInt32(); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5072 | mScheduler->setPhaseOffset(mSfConnectionHandle, static_cast<nsecs_t>(n)); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5073 | return NO_ERROR; |
| 5074 | } |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5075 | case 1020: { // Layer updates interceptor |
| 5076 | n = data.readInt32(); |
| 5077 | if (n) { |
| 5078 | ALOGV("Interceptor enabled"); |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 5079 | mInterceptor->enable(mDrawingState.layersSortedByZ, mDrawingState.displays); |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5080 | } |
| 5081 | else{ |
| 5082 | ALOGV("Interceptor disabled"); |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 5083 | mInterceptor->disable(); |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5084 | } |
| 5085 | return NO_ERROR; |
| 5086 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 5087 | case 1021: { // Disable HWC virtual displays |
| 5088 | n = data.readInt32(); |
| 5089 | mUseHwcVirtualDisplays = !n; |
| 5090 | return NO_ERROR; |
| 5091 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5092 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5093 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5094 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5095 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5096 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5097 | return NO_ERROR; |
| 5098 | } |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5099 | case 1023: { // Set native mode |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5100 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5101 | invalidateHwcGeometry(); |
| 5102 | repaintEverything(); |
| 5103 | return NO_ERROR; |
| 5104 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 5105 | // Deprecate, use 1030 to check whether the device is color managed. |
| 5106 | case 1024: { |
| 5107 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5108 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 5109 | case 1025: { // Set layer tracing |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5110 | n = data.readInt32(); |
| 5111 | if (n) { |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5112 | ALOGD("LayerTracing enabled"); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5113 | mTracing.enable(); |
| 5114 | doTracing("tracing.enable"); |
| 5115 | reply->writeInt32(NO_ERROR); |
| 5116 | } else { |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5117 | ALOGD("LayerTracing disabled"); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5118 | status_t err = mTracing.disable(); |
| 5119 | reply->writeInt32(err); |
| 5120 | } |
| 5121 | return NO_ERROR; |
| 5122 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 5123 | case 1026: { // Get layer tracing status |
| 5124 | reply->writeBool(mTracing.isEnabled()); |
| 5125 | return NO_ERROR; |
| 5126 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5127 | // Is a DisplayColorSetting supported? |
| 5128 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5129 | const auto display = getDefaultDisplayDevice(); |
| 5130 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5131 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5132 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5133 | |
| 5134 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 5135 | switch (setting) { |
| 5136 | case DisplayColorSetting::MANAGED: |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 5137 | reply->writeBool(useColorManagement); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5138 | break; |
| 5139 | case DisplayColorSetting::UNMANAGED: |
| 5140 | reply->writeBool(true); |
| 5141 | break; |
| 5142 | case DisplayColorSetting::ENHANCED: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5143 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5144 | break; |
| 5145 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5146 | reply->writeBool( |
| 5147 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5148 | break; |
| 5149 | } |
| 5150 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5151 | } |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 5152 | // Is VrFlinger active? |
| 5153 | case 1028: { |
| 5154 | Mutex::Autolock _l(mStateLock); |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 5155 | reply->writeBool(getHwComposer().isUsingVrComposer()); |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 5156 | return NO_ERROR; |
| 5157 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 5158 | // Is device color managed? |
| 5159 | case 1030: { |
| 5160 | reply->writeBool(useColorManagement); |
| 5161 | return NO_ERROR; |
| 5162 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 5163 | // Override default composition data space |
| 5164 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 5165 | // && adb shell stop zygote && adb shell start zygote |
| 5166 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 5167 | // adb shell stop zygote && adb shell start zygote |
| 5168 | case 1031: { |
| 5169 | Mutex::Autolock _l(mStateLock); |
| 5170 | n = data.readInt32(); |
| 5171 | if (n) { |
| 5172 | n = data.readInt32(); |
| 5173 | if (n) { |
| 5174 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 5175 | if (!validateCompositionDataspace(dataspace)) { |
| 5176 | return BAD_VALUE; |
| 5177 | } |
| 5178 | mDefaultCompositionDataspace = dataspace; |
| 5179 | } |
| 5180 | n = data.readInt32(); |
| 5181 | if (n) { |
| 5182 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 5183 | if (!validateCompositionDataspace(dataspace)) { |
| 5184 | return BAD_VALUE; |
| 5185 | } |
| 5186 | mWideColorGamutCompositionDataspace = dataspace; |
| 5187 | } |
| 5188 | } else { |
| 5189 | // restore composition data space. |
| 5190 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 5191 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
| 5192 | } |
| 5193 | return NO_ERROR; |
| 5194 | } |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 5195 | case 1032: { |
| 5196 | n = data.readInt32(); |
| 5197 | mDebugEnableProtectedContent = n; |
| 5198 | return NO_ERROR; |
| 5199 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | } |
| 5201 | } |
| 5202 | return err; |
| 5203 | } |
| 5204 | |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 5205 | void SurfaceFlinger::repaintEverything() { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 5206 | mRepaintEverything = true; |
Dan Stoza | c7a25ad | 2018-04-12 11:45:09 -0700 | [diff] [blame] | 5207 | signalTransaction(); |
Steven Thomas | 6d8110b | 2017-08-31 18:24:21 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
Ana Krulec | 7d1d683 | 2018-12-27 11:10:09 -0800 | [diff] [blame] | 5210 | void SurfaceFlinger::repaintEverythingForHWC() { |
| 5211 | mRepaintEverything = true; |
| 5212 | mEventQueue->invalidateForHWC(); |
| 5213 | } |
| 5214 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5215 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 5216 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 5217 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5218 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 5219 | ~WindowDisconnector() { |
| 5220 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5223 | private: |
| 5224 | ANativeWindow* mWindow; |
| 5225 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 5226 | }; |
| 5227 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5228 | status_t SurfaceFlinger::captureScreen(const sp<IBinder>& displayToken, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5229 | sp<GraphicBuffer>* outBuffer, const Dataspace reqDataspace, |
| 5230 | const ui::PixelFormat reqPixelFormat, Rect sourceCrop, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5231 | uint32_t reqWidth, uint32_t reqHeight, |
| 5232 | bool useIdentityTransform, |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 5233 | ISurfaceComposer::Rotation rotation, |
| 5234 | bool captureSecureLayers) { |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5235 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 5236 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5237 | if (!displayToken) return BAD_VALUE; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5238 | |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 5239 | auto renderAreaRotation = fromSurfaceComposerRotation(rotation); |
| 5240 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 5241 | sp<DisplayDevice> display; |
| 5242 | { |
| 5243 | Mutex::Autolock _l(mStateLock); |
Garfield Tan | 3b1b8af | 2018-03-16 17:37:33 -0700 | [diff] [blame] | 5244 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 5245 | display = getDisplayDeviceLocked(displayToken); |
| 5246 | if (!display) return BAD_VALUE; |
| 5247 | |
Chia-I Wu | cb02315 | 2018-08-28 12:57:23 -0700 | [diff] [blame] | 5248 | // set the requested width/height to the logical display viewport size |
| 5249 | // by default |
| 5250 | if (reqWidth == 0 || reqHeight == 0) { |
| 5251 | reqWidth = uint32_t(display->getViewport().width()); |
| 5252 | reqHeight = uint32_t(display->getViewport().height()); |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 5253 | } |
Yiwei Zhang | 06a58e2 | 2018-08-20 16:42:23 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5256 | DisplayRenderArea renderArea(display, sourceCrop, reqWidth, reqHeight, reqDataspace, |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 5257 | renderAreaRotation, captureSecureLayers); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5258 | |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 5259 | auto traverseLayers = std::bind(&SurfaceFlinger::traverseLayersInDisplay, this, display, |
| 5260 | std::placeholders::_1); |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5261 | return captureScreenCommon(renderArea, traverseLayers, outBuffer, reqPixelFormat, |
| 5262 | useIdentityTransform); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | status_t SurfaceFlinger::captureLayers(const sp<IBinder>& layerHandleBinder, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5266 | sp<GraphicBuffer>* outBuffer, const Dataspace reqDataspace, |
| 5267 | const ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5268 | float frameScale, bool childrenOnly) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5269 | ATRACE_CALL(); |
| 5270 | |
| 5271 | class LayerRenderArea : public RenderArea { |
| 5272 | public: |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5273 | LayerRenderArea(SurfaceFlinger* flinger, const sp<Layer>& layer, const Rect crop, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5274 | int32_t reqWidth, int32_t reqHeight, Dataspace reqDataSpace, |
| 5275 | bool childrenOnly) |
| 5276 | : RenderArea(reqWidth, reqHeight, CaptureFill::CLEAR, reqDataSpace), |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5277 | mLayer(layer), |
| 5278 | mCrop(crop), |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 5279 | mNeedsFiltering(false), |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5280 | mFlinger(flinger), |
| 5281 | mChildrenOnly(childrenOnly) {} |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 5282 | const ui::Transform& getTransform() const override { return mTransform; } |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5283 | Rect getBounds() const override { |
| 5284 | const Layer::State& layerState(mLayer->getDrawingState()); |
| 5285 | return mLayer->getBufferSize(layerState); |
| 5286 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5287 | int getHeight() const override { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5288 | return mLayer->getBufferSize(mLayer->getDrawingState()).getHeight(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5289 | } |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5290 | int getWidth() const override { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5291 | return mLayer->getBufferSize(mLayer->getDrawingState()).getWidth(); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5292 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5293 | bool isSecure() const override { return false; } |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 5294 | bool needsFiltering() const override { return mNeedsFiltering; } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 5295 | const sp<const DisplayDevice> getDisplayDevice() const override { return nullptr; } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5296 | Rect getSourceCrop() const override { |
| 5297 | if (mCrop.isEmpty()) { |
| 5298 | return getBounds(); |
| 5299 | } else { |
| 5300 | return mCrop; |
| 5301 | } |
| 5302 | } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5303 | class ReparentForDrawing { |
| 5304 | public: |
| 5305 | const sp<Layer>& oldParent; |
| 5306 | const sp<Layer>& newParent; |
| 5307 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 5308 | ReparentForDrawing(const sp<Layer>& oldParent, const sp<Layer>& newParent, |
| 5309 | const Rect& drawingBounds) |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5310 | : oldParent(oldParent), newParent(newParent) { |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 5311 | // Compute and cache the bounds for the new parent layer. |
| 5312 | newParent->computeBounds(drawingBounds.toFloatRect(), ui::Transform()); |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 5313 | oldParent->setChildrenDrawingParent(newParent); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5314 | } |
Vishnu Nair | bce6ffd | 2019-02-14 10:58:59 -0800 | [diff] [blame] | 5315 | ~ReparentForDrawing() { oldParent->setChildrenDrawingParent(oldParent); } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5316 | }; |
| 5317 | |
| 5318 | void render(std::function<void()> drawLayers) override { |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 5319 | const Rect sourceCrop = getSourceCrop(); |
| 5320 | // no need to check rotation because there is none |
| 5321 | mNeedsFiltering = sourceCrop.width() != getReqWidth() || |
| 5322 | sourceCrop.height() != getReqHeight(); |
| 5323 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5324 | if (!mChildrenOnly) { |
| 5325 | mTransform = mLayer->getTransform().inverse(); |
| 5326 | drawLayers(); |
| 5327 | } else { |
| 5328 | Rect bounds = getBounds(); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 5329 | screenshotParentLayer = mFlinger->getFactory().createContainerLayer( |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 5330 | LayerCreationArgs(mFlinger, nullptr, String8("Screenshot Parent"), |
| 5331 | bounds.getWidth(), bounds.getHeight(), 0)); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5332 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 5333 | ReparentForDrawing reparent(mLayer, screenshotParentLayer, sourceCrop); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5334 | drawLayers(); |
| 5335 | } |
| 5336 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5337 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5338 | private: |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5339 | const sp<Layer> mLayer; |
| 5340 | const Rect mCrop; |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5341 | |
| 5342 | // In the "childrenOnly" case we reparent the children to a screenshot |
| 5343 | // layer which has no properties set and which does not draw. |
| 5344 | sp<ContainerLayer> screenshotParentLayer; |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 5345 | ui::Transform mTransform; |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 5346 | bool mNeedsFiltering; |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5347 | |
| 5348 | SurfaceFlinger* mFlinger; |
| 5349 | const bool mChildrenOnly; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5350 | }; |
| 5351 | |
| 5352 | auto layerHandle = reinterpret_cast<Layer::Handle*>(layerHandleBinder.get()); |
| 5353 | auto parent = layerHandle->owner.promote(); |
| 5354 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5355 | if (parent == nullptr || parent->isRemovedFromCurrentState()) { |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5356 | ALOGE("captureLayers called with a removed parent"); |
| 5357 | return NAME_NOT_FOUND; |
| 5358 | } |
| 5359 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5360 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 5361 | const bool forSystem = uid == AID_GRAPHICS || uid == AID_SYSTEM; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5362 | if (!forSystem && parent->getCurrentState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5363 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
| 5364 | return PERMISSION_DENIED; |
| 5365 | } |
| 5366 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5367 | Rect crop(sourceCrop); |
| 5368 | if (sourceCrop.width() <= 0) { |
| 5369 | crop.left = 0; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5370 | crop.right = parent->getBufferSize(parent->getCurrentState()).getWidth(); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | if (sourceCrop.height() <= 0) { |
| 5374 | crop.top = 0; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 5375 | crop.bottom = parent->getBufferSize(parent->getCurrentState()).getHeight(); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | int32_t reqWidth = crop.width() * frameScale; |
| 5379 | int32_t reqHeight = crop.height() * frameScale; |
| 5380 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 5381 | // really small crop or frameScale |
| 5382 | if (reqWidth <= 0) { |
| 5383 | reqWidth = 1; |
| 5384 | } |
| 5385 | if (reqHeight <= 0) { |
| 5386 | reqHeight = 1; |
| 5387 | } |
| 5388 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5389 | LayerRenderArea renderArea(this, parent, crop, reqWidth, reqHeight, reqDataspace, childrenOnly); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5390 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5391 | auto traverseLayers = [parent, childrenOnly](const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5392 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 5393 | if (!layer->isVisible()) { |
| 5394 | return; |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5395 | } else if (childrenOnly && layer == parent.get()) { |
| 5396 | return; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5397 | } |
| 5398 | visitor(layer); |
| 5399 | }); |
| 5400 | }; |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5401 | return captureScreenCommon(renderArea, traverseLayers, outBuffer, reqPixelFormat, false); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | status_t SurfaceFlinger::captureScreenCommon(RenderArea& renderArea, |
| 5405 | TraverseLayersFunction traverseLayers, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5406 | sp<GraphicBuffer>* outBuffer, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5407 | const ui::PixelFormat reqPixelFormat, |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5408 | bool useIdentityTransform) { |
| 5409 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 5410 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 5411 | // TODO(b/116112787) Make buffer usage a parameter. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5412 | const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 5413 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 5414 | *outBuffer = |
| 5415 | getFactory().createGraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(), |
| 5416 | static_cast<android_pixel_format>(reqPixelFormat), 1, |
| 5417 | usage, "screenshot"); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5418 | |
Kevin DuBois | 7cbcc37 | 2019-02-25 14:53:28 -0800 | [diff] [blame] | 5419 | return captureScreenCommon(renderArea, traverseLayers, *outBuffer, useIdentityTransform); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 5420 | } |
| 5421 | |
Kevin DuBois | 7cbcc37 | 2019-02-25 14:53:28 -0800 | [diff] [blame] | 5422 | status_t SurfaceFlinger::captureScreenCommon(RenderArea& renderArea, |
| 5423 | TraverseLayersFunction traverseLayers, |
| 5424 | const sp<GraphicBuffer>& buffer, |
| 5425 | bool useIdentityTransform) { |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5426 | // This mutex protects syncFd and captureResult for communication of the return values from the |
| 5427 | // main thread back to this Binder thread |
| 5428 | std::mutex captureMutex; |
| 5429 | std::condition_variable captureCondition; |
| 5430 | std::unique_lock<std::mutex> captureLock(captureMutex); |
| 5431 | int syncFd = -1; |
| 5432 | std::optional<status_t> captureResult; |
| 5433 | |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 5434 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 5435 | const bool forSystem = uid == AID_GRAPHICS || uid == AID_SYSTEM; |
| 5436 | |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 5437 | sp<LambdaMessage> message = new LambdaMessage([&] { |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5438 | // If there is a refresh pending, bug out early and tell the binder thread to try again |
| 5439 | // after the refresh. |
| 5440 | if (mRefreshPending) { |
| 5441 | ATRACE_NAME("Skipping screenshot for now"); |
| 5442 | std::unique_lock<std::mutex> captureLock(captureMutex); |
| 5443 | captureResult = std::make_optional<status_t>(EAGAIN); |
| 5444 | captureCondition.notify_one(); |
| 5445 | return; |
| 5446 | } |
| 5447 | |
| 5448 | status_t result = NO_ERROR; |
| 5449 | int fd = -1; |
| 5450 | { |
| 5451 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 5452 | renderArea.render([&] { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 5453 | result = captureScreenImplLocked(renderArea, traverseLayers, buffer.get(), |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5454 | useIdentityTransform, forSystem, &fd); |
| 5455 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | { |
| 5459 | std::unique_lock<std::mutex> captureLock(captureMutex); |
| 5460 | syncFd = fd; |
| 5461 | captureResult = std::make_optional<status_t>(result); |
| 5462 | captureCondition.notify_one(); |
| 5463 | } |
| 5464 | }); |
| 5465 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5466 | status_t result = postMessageAsync(message); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5467 | if (result == NO_ERROR) { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 5468 | captureCondition.wait(captureLock, [&] { return captureResult; }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5469 | while (*captureResult == EAGAIN) { |
| 5470 | captureResult.reset(); |
| 5471 | result = postMessageAsync(message); |
| 5472 | if (result != NO_ERROR) { |
| 5473 | return result; |
| 5474 | } |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 5475 | captureCondition.wait(captureLock, [&] { return captureResult; }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5476 | } |
| 5477 | result = *captureResult; |
| 5478 | } |
| 5479 | |
| 5480 | if (result == NO_ERROR) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5481 | sync_wait(syncFd, -1); |
| 5482 | close(syncFd); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5483 | } |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5484 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5485 | return result; |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 5486 | } |
| 5487 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5488 | void SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea, |
Chia-I Wu | 1be50b5 | 2018-08-29 10:44:48 -0700 | [diff] [blame] | 5489 | TraverseLayersFunction traverseLayers, |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5490 | ANativeWindowBuffer* buffer, bool useIdentityTransform, |
| 5491 | int* outSyncFd) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 5492 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5493 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5494 | const auto reqWidth = renderArea.getReqWidth(); |
| 5495 | const auto reqHeight = renderArea.getReqHeight(); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 5496 | const auto sourceCrop = renderArea.getSourceCrop(); |
| 5497 | const auto rotation = renderArea.getRotationFlags(); |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 5498 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5499 | renderengine::DisplaySettings clientCompositionDisplay; |
| 5500 | std::vector<renderengine::LayerSettings> clientCompositionLayers; |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 5501 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5502 | // assume that bounds are never offset, and that they are the same as the |
| 5503 | // buffer bounds. |
| 5504 | clientCompositionDisplay.physicalDisplay = Rect(reqWidth, reqHeight); |
| 5505 | ui::Transform transform = renderArea.getTransform(); |
| 5506 | mat4 m; |
| 5507 | m[0][0] = transform[0][0]; |
| 5508 | m[0][1] = transform[0][1]; |
| 5509 | m[0][3] = transform[0][2]; |
| 5510 | m[1][0] = transform[1][0]; |
| 5511 | m[1][1] = transform[1][1]; |
| 5512 | m[1][3] = transform[1][2]; |
| 5513 | m[3][0] = transform[2][0]; |
| 5514 | m[3][1] = transform[2][1]; |
| 5515 | m[3][3] = transform[2][2]; |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 5516 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5517 | clientCompositionDisplay.globalTransform = m; |
| 5518 | mat4 rotMatrix; |
| 5519 | // Displacement for repositioning the clipping rectangle after rotating it |
| 5520 | // with the rotation hint. |
| 5521 | int displacementX = 0; |
| 5522 | int displacementY = 0; |
| 5523 | float rot90InRadians = 2.0f * static_cast<float>(M_PI) / 4.0f; |
| 5524 | switch (rotation) { |
| 5525 | case ui::Transform::ROT_90: |
| 5526 | rotMatrix = mat4::rotate(rot90InRadians, vec3(0, 0, 1)); |
| 5527 | displacementX = reqWidth; |
| 5528 | break; |
| 5529 | case ui::Transform::ROT_180: |
| 5530 | rotMatrix = mat4::rotate(rot90InRadians * 2.0f, vec3(0, 0, 1)); |
| 5531 | displacementX = reqWidth; |
| 5532 | displacementY = reqHeight; |
| 5533 | break; |
| 5534 | case ui::Transform::ROT_270: |
| 5535 | rotMatrix = mat4::rotate(rot90InRadians * 3.0f, vec3(0, 0, 1)); |
| 5536 | displacementY = reqHeight; |
| 5537 | break; |
| 5538 | default: |
| 5539 | break; |
| 5540 | } |
| 5541 | // We need to transform the clipping window into the right spot. |
| 5542 | // First, rotate the clipping rectangle by the rotation hint to get the |
| 5543 | // right orientation |
| 5544 | const vec4 clipTL = vec4(sourceCrop.left, sourceCrop.top, 0, 1); |
| 5545 | const vec4 clipBR = vec4(sourceCrop.right, sourceCrop.bottom, 0, 1); |
| 5546 | const vec4 rotClipTL = rotMatrix * clipTL; |
| 5547 | const vec4 rotClipBR = rotMatrix * clipBR; |
| 5548 | const int newClipLeft = std::min(rotClipTL[0], rotClipBR[0]); |
| 5549 | const int newClipTop = std::min(rotClipTL[1], rotClipBR[1]); |
| 5550 | const int newClipRight = std::max(rotClipTL[0], rotClipBR[0]); |
| 5551 | const int newClipBottom = std::max(rotClipTL[1], rotClipBR[1]); |
| 5552 | |
| 5553 | // Now reposition the clipping rectangle with the displacement vector |
| 5554 | // computed above. |
| 5555 | const mat4 displacementMat = mat4::translate(vec4(displacementX, displacementY, 0, 1)); |
| 5556 | |
| 5557 | clientCompositionDisplay.clip = |
| 5558 | Rect(newClipLeft + displacementX, newClipTop + displacementY, |
| 5559 | newClipRight + displacementX, newClipBottom + displacementY); |
| 5560 | |
| 5561 | // We need to perform the same transformation in layer space, so propagate |
| 5562 | // it to the global transform. |
| 5563 | mat4 clipTransform = displacementMat * rotMatrix; |
| 5564 | clientCompositionDisplay.globalTransform *= clipTransform; |
| 5565 | clientCompositionDisplay.outputDataspace = renderArea.getReqDataSpace(); |
| 5566 | clientCompositionDisplay.maxLuminance = DisplayDevice::sDefaultMaxLumiance; |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 5567 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 5568 | const float alpha = RenderArea::getCaptureFillValue(renderArea.getCaptureFill()); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 5569 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5570 | renderengine::LayerSettings fillLayer; |
| 5571 | fillLayer.source.buffer.buffer = nullptr; |
| 5572 | fillLayer.source.solidColor = half3(0.0, 0.0, 0.0); |
| 5573 | fillLayer.geometry.boundaries = FloatRect(0.0, 0.0, 1.0, 1.0); |
| 5574 | fillLayer.alpha = half(alpha); |
| 5575 | clientCompositionLayers.push_back(fillLayer); |
| 5576 | |
| 5577 | Region clearRegion = Region::INVALID_REGION; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5578 | traverseLayers([&](Layer* layer) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5579 | renderengine::LayerSettings layerSettings; |
| 5580 | bool prepared = layer->prepareClientLayer(renderArea, useIdentityTransform, clearRegion, |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 5581 | false, layerSettings); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5582 | if (prepared) { |
| 5583 | clientCompositionLayers.push_back(layerSettings); |
| 5584 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5585 | }); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5586 | |
| 5587 | clientCompositionDisplay.clearRegion = clearRegion; |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 5588 | // Use an empty fence for the buffer fence, since we just created the buffer so |
| 5589 | // there is no need for synchronization with the GPU. |
| 5590 | base::unique_fd bufferFence; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5591 | base::unique_fd drawFence; |
Peiyong Lin | 8f28a1d | 2019-02-07 17:25:12 -0800 | [diff] [blame] | 5592 | getRenderEngine().useProtectedContext(false); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5593 | getRenderEngine().drawLayers(clientCompositionDisplay, clientCompositionLayers, buffer, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 5594 | std::move(bufferFence), &drawFence); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5595 | |
| 5596 | *outSyncFd = drawFence.release(); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5599 | status_t SurfaceFlinger::captureScreenImplLocked(const RenderArea& renderArea, |
| 5600 | TraverseLayersFunction traverseLayers, |
| 5601 | ANativeWindowBuffer* buffer, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5602 | bool useIdentityTransform, |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 5603 | bool forSystem, |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5604 | int* outSyncFd) { |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 5605 | ATRACE_CALL(); |
| 5606 | |
Pablo Ceballos | b5b3563 | 2016-02-23 11:18:51 -0800 | [diff] [blame] | 5607 | bool secureLayerIsVisible = false; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5608 | |
| 5609 | traverseLayers([&](Layer* layer) { |
| 5610 | secureLayerIsVisible = secureLayerIsVisible || (layer->isVisible() && layer->isSecure()); |
| 5611 | }); |
Pablo Ceballos | b5b3563 | 2016-02-23 11:18:51 -0800 | [diff] [blame] | 5612 | |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 5613 | // We allow the system server to take screenshots of secure layers for |
| 5614 | // use in situations like the Screen-rotation animation and place |
| 5615 | // the impetus on WindowManager to not persist them. |
| 5616 | if (secureLayerIsVisible && !forSystem) { |
Pablo Ceballos | b5b3563 | 2016-02-23 11:18:51 -0800 | [diff] [blame] | 5617 | ALOGW("FB is protected: PERMISSION_DENIED"); |
| 5618 | return PERMISSION_DENIED; |
| 5619 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 5620 | renderScreenImplLocked(renderArea, traverseLayers, buffer, useIdentityTransform, outSyncFd); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 5621 | return NO_ERROR; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 5622 | } |
| 5623 | |
chaviw | 95ef3c4 | 2019-02-14 10:55:09 -0800 | [diff] [blame] | 5624 | void SurfaceFlinger::setInputWindowsFinished() { |
| 5625 | Mutex::Autolock _l(mStateLock); |
| 5626 | |
| 5627 | mPendingSyncInputWindows = false; |
| 5628 | mTransactionCV.broadcast(); |
| 5629 | } |
chaviw | 5f21a5e | 2019-02-14 10:00:34 -0800 | [diff] [blame] | 5630 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 5631 | // --------------------------------------------------------------------------- |
| 5632 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 5633 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 5634 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 5635 | } |
| 5636 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 5637 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 5638 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 5639 | } |
| 5640 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5641 | void SurfaceFlinger::traverseLayersInDisplay(const sp<const DisplayDevice>& display, |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5642 | const LayerVector::Visitor& visitor) { |
| 5643 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5644 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5645 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5646 | if (!layer->belongsToDisplay(display->getLayerStack(), false)) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5647 | continue; |
| 5648 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 5649 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5650 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5651 | if (!layer->belongsToDisplay(display->getLayerStack(), false)) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 5652 | return; |
| 5653 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5654 | if (!layer->isVisible()) { |
| 5655 | return; |
| 5656 | } |
| 5657 | visitor(layer); |
| 5658 | }); |
| 5659 | } |
| 5660 | } |
| 5661 | |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 5662 | void SurfaceFlinger::setAllowedDisplayConfigsInternal( |
| 5663 | const android::sp<android::IBinder>& displayToken, |
| 5664 | std::unique_ptr<const AllowedDisplayConfigs>&& allowedConfigs) { |
| 5665 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 5666 | if (!displayId) { |
| 5667 | ALOGE("setAllowedDisplayConfigsInternal: getPhysicalDisplayId failed"); |
| 5668 | return; |
| 5669 | } |
| 5670 | |
| 5671 | ALOGV("Updating allowed configs"); |
| 5672 | { |
| 5673 | std::lock_guard lock(mAllowedConfigsLock); |
| 5674 | mAllowedConfigs[*displayId] = std::move(allowedConfigs); |
| 5675 | } |
| 5676 | |
| 5677 | // make sure that the current config is still allowed |
| 5678 | int currentConfigIndex = getHwComposer().getActiveConfigIndex(*displayId); |
| 5679 | if (!isConfigAllowed(*displayId, currentConfigIndex)) { |
| 5680 | // TODO(b/122906558): stop querying HWC for the available configs and instead use the cached |
| 5681 | // configs queried on boot |
| 5682 | auto configs = getHwComposer().getConfigs(*displayId); |
| 5683 | |
| 5684 | for (int i = 0; i < configs.size(); i++) { |
| 5685 | if (isConfigAllowed(*displayId, i)) { |
| 5686 | // TODO: we switch to the first allowed config. In the future |
| 5687 | // we may want to enhance this logic to pick a similar config |
| 5688 | // to the current one |
| 5689 | ALOGV("Old config is not allowed - switching to config %d", i); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 5690 | setDesiredActiveConfig(displayToken, i, ConfigEvent::Changed); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 5691 | break; |
| 5692 | } |
| 5693 | } |
| 5694 | } |
| 5695 | } |
| 5696 | |
| 5697 | status_t SurfaceFlinger::setAllowedDisplayConfigs(const android::sp<android::IBinder>& displayToken, |
| 5698 | const std::vector<int32_t>& allowedConfigs) { |
| 5699 | ATRACE_CALL(); |
| 5700 | |
| 5701 | if (!displayToken) { |
| 5702 | ALOGE("setAllowedDisplayConfigs: displayToken is null"); |
| 5703 | return BAD_VALUE; |
| 5704 | } |
| 5705 | |
| 5706 | if (!allowedConfigs.size()) { |
| 5707 | ALOGE("setAllowedDisplayConfigs: empty config set provided"); |
| 5708 | return BAD_VALUE; |
| 5709 | } |
| 5710 | |
| 5711 | { |
| 5712 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 5713 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 5714 | if (!displayId) { |
| 5715 | ALOGE("setAllowedDisplayConfigs: display not found"); |
| 5716 | return NAME_NOT_FOUND; |
| 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | auto allowedDisplayConfigsBuilder = AllowedDisplayConfigs::Builder(); |
| 5721 | for (int config : allowedConfigs) { |
| 5722 | ALOGV("setAllowedDisplayConfigs: Adding config to the allowed configs = %d", config); |
| 5723 | allowedDisplayConfigsBuilder.addConfig(config); |
| 5724 | } |
| 5725 | auto allowedDisplayConfigs = allowedDisplayConfigsBuilder.build(); |
| 5726 | postMessageSync(new LambdaMessage([&]() NO_THREAD_SAFETY_ANALYSIS { |
| 5727 | setAllowedDisplayConfigsInternal(displayToken, std::move(allowedDisplayConfigs)); |
| 5728 | })); |
| 5729 | return NO_ERROR; |
| 5730 | } |
| 5731 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 5732 | status_t SurfaceFlinger::getAllowedDisplayConfigs(const android::sp<android::IBinder>& displayToken, |
| 5733 | std::vector<int32_t>* outAllowedConfigs) { |
| 5734 | ATRACE_CALL(); |
| 5735 | |
| 5736 | if (!displayToken) { |
| 5737 | ALOGE("getAllowedDisplayConfigs: displayToken is null"); |
| 5738 | return BAD_VALUE; |
| 5739 | } |
| 5740 | |
| 5741 | if (!outAllowedConfigs) { |
| 5742 | ALOGE("getAllowedDisplayConfigs: outAllowedConfigs is null"); |
| 5743 | return BAD_VALUE; |
| 5744 | } |
| 5745 | |
| 5746 | ConditionalLock stateLock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 5747 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 5748 | if (!displayId) { |
| 5749 | ALOGE("getAllowedDisplayConfigs: display not found"); |
| 5750 | return NAME_NOT_FOUND; |
| 5751 | } |
| 5752 | |
| 5753 | std::lock_guard allowedConfigLock(mAllowedConfigsLock); |
| 5754 | auto allowedConfigIterator = mAllowedConfigs.find(displayId.value()); |
| 5755 | if (allowedConfigIterator != mAllowedConfigs.end()) { |
| 5756 | allowedConfigIterator->second->getAllowedConfigs(outAllowedConfigs); |
| 5757 | } |
| 5758 | |
| 5759 | return NO_ERROR; |
| 5760 | } |
| 5761 | |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 5762 | // ---------------------------------------------------------------------------- |
| 5763 | |
| 5764 | void SetInputWindowsListener::onSetInputWindowsFinished() { |
| 5765 | mFlinger->setInputWindowsFinished(); |
| 5766 | } |
| 5767 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5768 | }; // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 5769 | |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 5770 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 5771 | #if defined(__gl_h_) |
| 5772 | #error "don't include gl/gl.h in this file" |
| 5773 | #endif |
| 5774 | |
| 5775 | #if defined(__gl2_h_) |
| 5776 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 5777 | #endif |