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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 20 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 21 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 22 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 23 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 24 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 25 | #include "SurfaceFlinger.h" |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 26 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 27 | #include <android-base/parseint.h> |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 28 | #include <android-base/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 29 | #include <android-base/stringprintf.h> |
| 30 | #include <android-base/strings.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 31 | #include <android/configuration.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 32 | #include <android/gui/IDisplayEventConnection.h> |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 33 | #include <android/gui/StaticDisplayInfo.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 34 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 35 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 36 | #include <android/hardware/configstore/1.1/types.h> |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 37 | #include <android/hardware/power/Boost.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 38 | #include <android/native_window.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <android/os/IInputFlinger.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 40 | #include <binder/IPCThreadState.h> |
| 41 | #include <binder/IServiceManager.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 42 | #include <binder/PermissionCache.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 43 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 44 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 46 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 47 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 48 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 49 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 50 | #include <compositionengine/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 51 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 52 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 53 | #include <configstore/Utils.h> |
| 54 | #include <cutils/compiler.h> |
| 55 | #include <cutils/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 56 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 57 | #include <ftl/future.h> |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 58 | #include <ftl/small_map.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 59 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 60 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 61 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 62 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 63 | #include <gui/LayerDebugInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 64 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 65 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 66 | #include <gui/Surface.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 67 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 68 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 69 | #include <layerproto/LayerProtoParser.h> |
| 70 | #include <log/log.h> |
| 71 | #include <private/android_filesystem_config.h> |
| 72 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 73 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 74 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 75 | #include <renderengine/impl/ExternalTexture.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 76 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 77 | #include <ui/ColorSpace.h> |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 78 | #include <ui/DataspaceUtils.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 79 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 80 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 81 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 82 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 83 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 84 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 85 | #include <ui/GraphicBufferAllocator.h> |
| 86 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 87 | #include <ui/StaticDisplayInfo.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 89 | #include <utils/String16.h> |
| 90 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 91 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 92 | #include <utils/misc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 94 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 95 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 96 | #include <cinttypes> |
| 97 | #include <cmath> |
| 98 | #include <cstdint> |
| 99 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 100 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <mutex> |
| 102 | #include <optional> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 103 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 104 | #include <unordered_map> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 106 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 107 | #include "BackgroundExecutor.h" |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 108 | #include "BufferStateLayer.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 109 | #include "Client.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 110 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 111 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 112 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 113 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 114 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 115 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 116 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 117 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 118 | #include "DisplayRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 119 | #include "EffectLayer.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 120 | #include "Effects/Daltonizer.h" |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 121 | #include "FlagManager.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 122 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 123 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 124 | #include "FrameTracer/FrameTracer.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 125 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 126 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 127 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 128 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 129 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 130 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 131 | #include "NativeWindowSurface.h" |
| 132 | #include "RefreshRateOverlay.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 133 | #include "RegionSamplingThread.h" |
Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 134 | #include "Scheduler/DispSyncSource.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 135 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 136 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 137 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 138 | #include "Scheduler/VsyncConfiguration.h" |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 139 | #include "Scheduler/VsyncController.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 140 | #include "StartPropertySetThread.h" |
| 141 | #include "SurfaceFlingerProperties.h" |
| 142 | #include "SurfaceInterceptor.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 143 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 144 | #include "TunnelModeEnabledReporter.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 145 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 146 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 147 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 148 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 149 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 150 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 151 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 152 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 153 | _Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"") |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 154 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 155 | // To enable layer borders in the system, change the below flag to true. |
| 156 | #undef DOES_CONTAIN_BORDER |
| 157 | #define DOES_CONTAIN_BORDER false |
| 158 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | namespace android { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 160 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 161 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 162 | using namespace std::string_literals; |
| 163 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 164 | using namespace hardware::configstore; |
| 165 | using namespace hardware::configstore::V1_0; |
| 166 | using namespace sysprop; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 167 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 168 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 169 | using aidl::android::hardware::graphics::composer3::Capability; |
| 170 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 171 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 172 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 173 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 174 | using base::StringAppendF; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 175 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 176 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 177 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 178 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 179 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 180 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 181 | using gui::aidl_utils::binderStatusFromStatusT; |
Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 182 | using ui::ColorMode; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 183 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 184 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 185 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 186 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 187 | using KernelIdleTimerController = scheduler::RefreshRateConfigs::KernelIdleTimerController; |
| 188 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 189 | namespace hal = android::hardware::graphics::composer::hal; |
| 190 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 191 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 192 | |
| 193 | #pragma clang diagnostic push |
| 194 | #pragma clang diagnostic error "-Wswitch-enum" |
| 195 | |
| 196 | bool isWideColorMode(const ColorMode colorMode) { |
| 197 | switch (colorMode) { |
| 198 | case ColorMode::DISPLAY_P3: |
| 199 | case ColorMode::ADOBE_RGB: |
| 200 | case ColorMode::DCI_P3: |
| 201 | case ColorMode::BT2020: |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 202 | case ColorMode::DISPLAY_BT2020: |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 203 | case ColorMode::BT2100_PQ: |
| 204 | case ColorMode::BT2100_HLG: |
| 205 | return true; |
| 206 | case ColorMode::NATIVE: |
| 207 | case ColorMode::STANDARD_BT601_625: |
| 208 | case ColorMode::STANDARD_BT601_625_UNADJUSTED: |
| 209 | case ColorMode::STANDARD_BT601_525: |
| 210 | case ColorMode::STANDARD_BT601_525_UNADJUSTED: |
| 211 | case ColorMode::STANDARD_BT709: |
| 212 | case ColorMode::SRGB: |
| 213 | return false; |
| 214 | } |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | #pragma clang diagnostic pop |
| 219 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 220 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 221 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 222 | |
| 223 | float getDensityFromProperty(const char* property, bool required) { |
| 224 | char value[PROPERTY_VALUE_MAX]; |
| 225 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 226 | if (!density && required) { |
| 227 | ALOGE("%s must be defined as a build property", property); |
| 228 | return FALLBACK_DENSITY; |
| 229 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 230 | return density; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 233 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 234 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 235 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 236 | } |
| 237 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 238 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 239 | const auto displayIdleTimerMsKey = [displayId] { |
| 240 | std::stringstream ss; |
| 241 | ss << "debug.sf.set_idle_timer_ms_" << displayId.value; |
| 242 | return ss.str(); |
| 243 | }(); |
| 244 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 245 | const int32_t displayIdleTimerMs = base::GetIntProperty(displayIdleTimerMsKey, 0); |
| 246 | if (displayIdleTimerMs > 0) { |
| 247 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 248 | } |
| 249 | |
| 250 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms", 0); |
| 251 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 252 | return std::chrono::milliseconds(millis); |
| 253 | } |
| 254 | |
| 255 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 256 | const auto displaySupportKernelIdleTimerKey = [displayId] { |
| 257 | std::stringstream ss; |
| 258 | ss << "debug.sf.support_kernel_idle_timer_" << displayId.value; |
| 259 | return ss.str(); |
| 260 | }(); |
| 261 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 262 | const auto displaySupportKernelIdleTimer = |
| 263 | base::GetBoolProperty(displaySupportKernelIdleTimerKey, false); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 264 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 267 | } // namespace anonymous |
| 268 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | // --------------------------------------------------------------------------- |
| 270 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 271 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 272 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 273 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 274 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 275 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 276 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 277 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 278 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 279 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 280 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 281 | |
Vishnu Nair | 4fb00ed | 2022-06-03 10:25:09 -0700 | [diff] [blame] | 282 | static const int MAX_TRACING_MEMORY = 1024 * 1024 * 1024; // 1GB |
| 283 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 284 | // --------------------------------------------------------------------------- |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 285 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 286 | bool SurfaceFlinger::useHwcForRgbToYuv; |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 287 | bool SurfaceFlinger::hasSyncFramework; |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 288 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 289 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 290 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 291 | bool SurfaceFlinger::hasWideColorDisplay; |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 292 | bool SurfaceFlinger::useContextPriority; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 293 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 294 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 295 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 296 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 297 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 298 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 299 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 300 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 301 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 302 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 303 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 304 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 305 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 306 | return std::string("Enhanced"); |
| 307 | default: |
| 308 | return std::string("Unknown ") + |
| 309 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 310 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 313 | bool callingThreadHasRotateSurfaceFlingerAccess() { |
| 314 | IPCThreadState* ipc = IPCThreadState::self(); |
| 315 | const int pid = ipc->getCallingPid(); |
| 316 | const int uid = ipc->getCallingUid(); |
| 317 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 318 | PermissionCache::checkPermission(sRotateSurfaceFlinger, pid, uid); |
| 319 | } |
| 320 | |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 321 | bool callingThreadHasInternalSystemWindowAccess() { |
| 322 | IPCThreadState* ipc = IPCThreadState::self(); |
| 323 | const int pid = ipc->getCallingPid(); |
| 324 | const int uid = ipc->getCallingUid(); |
Leon Scroggins III | cf7a7b2 | 2021-12-23 20:04:48 -0500 | [diff] [blame] | 325 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 326 | PermissionCache::checkPermission(sInternalSystemWindow, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 329 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 330 | : mFactory(factory), |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 331 | mPid(getpid()), |
Pablo Gamito | c351d6f | 2020-09-17 15:34:26 +0000 | [diff] [blame] | 332 | mInterceptor(mFactory.createSurfaceInterceptor()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 333 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 334 | mFrameTracer(mFactory.createFrameTracer()), |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 335 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
Dominik Laskowski | eddeda1 | 2019-07-19 11:54:13 -0700 | [diff] [blame] | 336 | mCompositionEngine(mFactory.createCompositionEngine()), |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 337 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 338 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 339 | mInternalDisplayDensity(getDensityFromProperty("ro.sf.lcd_density", true)), |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 340 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 341 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 342 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 343 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 344 | } |
Lloyd Pique | ac648ee | 2018-01-17 13:42:24 -0800 | [diff] [blame] | 345 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 346 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 347 | ALOGI("SurfaceFlinger is starting"); |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 348 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 349 | hasSyncFramework = running_without_sync_framework(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 351 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 352 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 353 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 354 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 355 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 356 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 357 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 358 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 359 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 360 | hasWideColorDisplay = has_wide_color_display(false); |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 361 | mDefaultCompositionDataspace = |
| 362 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
Peiyong Lin | 8cabfc3 | 2019-06-14 14:25:43 -0700 | [diff] [blame] | 363 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 364 | hasWideColorDisplay ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 365 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 366 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 367 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 368 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 369 | wideColorGamutCompositionPixelFormat = |
| 370 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 371 | |
Yichi Chen | da901bf | 2019-06-28 14:58:27 +0800 | [diff] [blame] | 372 | mColorSpaceAgnosticDataspace = |
| 373 | static_cast<ui::Dataspace>(color_space_agnostic_dataspace(Dataspace::UNKNOWN)); |
| 374 | |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 375 | mLayerCachingEnabled = [] { |
| 376 | const bool enable = |
| 377 | android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false); |
| 378 | return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable); |
| 379 | }(); |
| 380 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 381 | useContextPriority = use_context_priority(true); |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 382 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 383 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 384 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | // debugging stuff... |
| 386 | char value[PROPERTY_VALUE_MAX]; |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 387 | |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 388 | property_get("ro.bq.gpu_to_cpu_unsupported", value, "0"); |
Mathias Agopian | 50210b9 | 2013-03-21 21:13:21 -0700 | [diff] [blame] | 389 | mGpuToCpuSupported = !atoi(value); |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 390 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 391 | property_get("ro.build.type", value, "user"); |
| 392 | mIsUserBuild = strcmp(value, "user") == 0; |
| 393 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 394 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
Orion Hodson | 34397da | 2019-02-04 09:36:10 +0000 | [diff] [blame] | 395 | |
| 396 | // DDMS debugging deprecated (b/120782499) |
| 397 | property_get("debug.sf.ddms", value, "0"); |
| 398 | int debugDdms = atoi(value); |
| 399 | ALOGI_IF(debugDdms, "DDMS debugging not supported"); |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 400 | |
Ady Abraham | adb9a99 | 2019-09-19 21:21:55 +0000 | [diff] [blame] | 401 | property_get("debug.sf.enable_gl_backpressure", value, "0"); |
| 402 | mPropagateBackpressureClientComposition = atoi(value); |
| 403 | ALOGI_IF(mPropagateBackpressureClientComposition, |
| 404 | "Enabling backpressure propagation for Client Composition"); |
| 405 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 406 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 407 | bool supportsBlurs = atoi(value); |
Lucas Dupin | 00f1642 | 2020-03-11 11:33:04 -0700 | [diff] [blame] | 408 | mSupportsBlur = supportsBlurs; |
| 409 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
Lucas Dupin | 2dd6f39 | 2020-02-18 17:43:36 -0800 | [diff] [blame] | 410 | property_get("ro.sf.blurs_are_expensive", value, "0"); |
| 411 | mBlursAreExpensive = atoi(value); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 412 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 413 | const size_t defaultListSize = MAX_LAYERS; |
Dan Stoza | 0a0158c | 2018-03-16 13:38:54 -0700 | [diff] [blame] | 414 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 415 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
Alec Mouri | 601393f | 2020-02-21 13:26:52 -0800 | [diff] [blame] | 416 | mGraphicBufferProducerListSizeLogThreshold = |
| 417 | std::max(static_cast<int>(0.95 * |
| 418 | static_cast<double>(mMaxGraphicBufferProducerListSize)), |
| 419 | 1); |
Dan Stoza | 0a0158c | 2018-03-16 13:38:54 -0700 | [diff] [blame] | 420 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 421 | property_get("debug.sf.luma_sampling", value, "1"); |
| 422 | mLumaSampling = atoi(value); |
| 423 | |
Vishnu Nair | b2a999b | 2020-01-23 13:43:02 -0800 | [diff] [blame] | 424 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 425 | mDisableClientCompositionCache = atoi(value); |
| 426 | |
Vishnu Nair | 3539d81 | 2022-02-26 09:20:17 -0800 | [diff] [blame] | 427 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 428 | mPredictCompositionStrategy = atoi(value); |
| 429 | |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 430 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 431 | mTreat170mAsSrgb = atoi(value); |
| 432 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 433 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 434 | // but since /data may be encrypted, we need to wait until after vold |
| 435 | // comes online to attempt to read the property. The property is |
| 436 | // instead read after the boot animation |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 437 | |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 438 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 439 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 440 | // services that are not listed in the manifests. Considered |
| 441 | // deriving the setting from the set service name, but it |
| 442 | // would be brittle if the name that's not 'default' is used |
| 443 | // for production purposes later on. |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 444 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 445 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 446 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 447 | |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 448 | mRefreshRateOverlaySpinner = property_get_bool("sf.debug.show_refresh_rate_overlay_spinner", 0); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 449 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 450 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
| 451 | mTransactionTracing.emplace(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 452 | } |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 453 | |
| 454 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 455 | |
| 456 | // Power hint session mode, representing which hint(s) to send: early, late, or both) |
| 457 | mPowerHintSessionMode = |
| 458 | {.late = base::GetBoolProperty("debug.sf.send_late_power_session_hint"s, true), |
Matt Buckley | 58a3645 | 2022-07-20 20:53:32 +0000 | [diff] [blame] | 459 | .early = base::GetBoolProperty("debug.sf.send_early_power_session_hint"s, false)}; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 463 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 464 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 465 | } |
| 466 | |
Ady Abraham | fb67be1 | 2022-08-10 10:46:22 -0700 | [diff] [blame] | 467 | if (base::GetBoolProperty("debug.sf.latch_unsignaled"s, false)) { |
| 468 | return LatchUnsignaledConfig::Always; |
| 469 | } |
| 470 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 471 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 474 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 475 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 476 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 477 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 478 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 479 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 480 | // Sever the link to inputflinger since it's gone as well. |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 481 | static_cast<void>(mScheduler->schedule( |
Ady Abraham | 8101553 | 2022-08-02 16:27:53 +0000 | [diff] [blame] | 482 | [this] { mInputFlinger.clear(); })); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 483 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 484 | // restore initial conditions (default device unblank, etc) |
| 485 | initializeDisplays(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 486 | |
| 487 | // restart the boot-animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 488 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 491 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 492 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 495 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 496 | // onTransact already checks for some permissions, but adding an additional check here. |
| 497 | // This is to ensure that only system and graphics can request to create a secure |
| 498 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 499 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 500 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 501 | ALOGE("Only privileged processes can create a secure display"); |
| 502 | return nullptr; |
| 503 | } |
| 504 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 505 | class DisplayToken : public BBinder { |
| 506 | sp<SurfaceFlinger> flinger; |
| 507 | virtual ~DisplayToken() { |
| 508 | // no more references, this display must be terminated |
| 509 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 510 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 511 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 512 | } |
| 513 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 514 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 515 | : flinger(flinger) { |
| 516 | } |
| 517 | }; |
| 518 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 519 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 520 | |
| 521 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 522 | // Display ID is assigned when virtual display is allocated by HWC. |
| 523 | DisplayDeviceState state; |
| 524 | state.isSecure = secure; |
| 525 | state.displayName = displayName; |
| 526 | mCurrentState.displays.add(token, state); |
| 527 | mInterceptor->saveDisplayCreation(state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 528 | return token; |
| 529 | } |
| 530 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 531 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 532 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 533 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 534 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 535 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 536 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 537 | return; |
| 538 | } |
| 539 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 540 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 541 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 542 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 543 | return; |
| 544 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 545 | mInterceptor->saveDisplayDeletion(state.sequenceId); |
| 546 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 547 | setTransactionFlags(eDisplayTransactionNeeded); |
| 548 | } |
| 549 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 550 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 551 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 552 | if (!generator && enable) { |
| 553 | ALOGI("Enabling HAL virtual displays"); |
| 554 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 555 | } else if (generator && !enable) { |
| 556 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 557 | generator.reset(); |
| 558 | } |
| 559 | } |
| 560 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 561 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 562 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 563 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 564 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 565 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 566 | return *id; |
| 567 | } |
| 568 | |
| 569 | generator->releaseId(*id); |
| 570 | } else { |
| 571 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 572 | } |
| 573 | |
| 574 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 575 | } |
| 576 | |
| 577 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 578 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 579 | return *id; |
| 580 | } |
| 581 | |
| 582 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 583 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 584 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 585 | generator->releaseId(*id); |
| 586 | } |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 591 | LOG_ALWAYS_FATAL_IF(!id); |
| 592 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 593 | } |
| 594 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 595 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 596 | std::vector<PhysicalDisplayId> displayIds; |
| 597 | displayIds.reserve(mPhysicalDisplayTokens.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 598 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 599 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 600 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 601 | |
| 602 | for (const auto& [id, token] : mPhysicalDisplayTokens) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 603 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 604 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 605 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 606 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 607 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 608 | return displayIds; |
| 609 | } |
| 610 | |
| 611 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 612 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 613 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 616 | status_t SurfaceFlinger::getColorManagement(bool* outGetColorManagement) const { |
| 617 | if (!outGetColorManagement) { |
| 618 | return BAD_VALUE; |
| 619 | } |
| 620 | *outGetColorManagement = useColorManagement; |
| 621 | return NO_ERROR; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 624 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 625 | return mCompositionEngine->getHwComposer(); |
| 626 | } |
| 627 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 628 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
| 629 | return mCompositionEngine->getRenderEngine(); |
| 630 | } |
| 631 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 632 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 633 | return *mCompositionEngine.get(); |
| 634 | } |
| 635 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 636 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 637 | if (mBootFinished == true) { |
| 638 | ALOGE("Extra call to bootFinished"); |
| 639 | return; |
| 640 | } |
| 641 | mBootFinished = true; |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 642 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 643 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 644 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 645 | |
| 646 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 647 | mRenderEnginePrimeCacheFuture.get(); |
| 648 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | const nsecs_t now = systemTime(); |
| 650 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 651 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 652 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 653 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 654 | mFrameTimeline->onBootFinished(); |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 655 | getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 656 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 657 | // wait patiently for the window manager death |
| 658 | const String16 name("window"); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 659 | mWindowManager = defaultServiceManager()->getService(name); |
| 660 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 661 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 665 | // formerly we would just kill the process, but we now ask it to exit so it |
| 666 | // can choose where to stop the animation. |
| 667 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 668 | |
| 669 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 670 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 671 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 672 | |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 673 | sp<IBinder> input(defaultServiceManager()->getService(String16("inputflinger"))); |
| 674 | |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 675 | static_cast<void>(mScheduler->schedule([=] { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 676 | if (input == nullptr) { |
| 677 | ALOGE("Failed to link to input service"); |
| 678 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 679 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 680 | } |
| 681 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 682 | readPersistentProperties(); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 683 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 684 | const bool powerHintEnabled = mFlagManager.use_adpf_cpu_hint(); |
| 685 | mPowerAdvisor->enablePowerHint(powerHintEnabled); |
| 686 | const bool powerHintUsed = mPowerAdvisor->usePowerHintSession(); |
| 687 | ALOGD("Power hint is %s", |
| 688 | powerHintUsed ? "supported" : (powerHintEnabled ? "unsupported" : "disabled")); |
| 689 | if (powerHintUsed) { |
| 690 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 691 | std::vector<int32_t> tidList; |
| 692 | tidList.emplace_back(gettid()); |
| 693 | if (renderEngineTid.has_value()) { |
| 694 | tidList.emplace_back(*renderEngineTid); |
| 695 | } |
| 696 | if (!mPowerAdvisor->startPowerHintSession(tidList)) { |
| 697 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 698 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 701 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 702 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 703 | if (property_get_bool("sf.debug.show_refresh_rate_overlay", false)) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 704 | FTL_FAKE_GUARD(mStateLock, enableRefreshRateOverlay(true)); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 705 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 706 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | } |
| 708 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 709 | uint32_t SurfaceFlinger::getNewTexture() { |
| 710 | { |
| 711 | std::lock_guard lock(mTexturePoolMutex); |
| 712 | if (!mTexturePool.empty()) { |
| 713 | uint32_t name = mTexturePool.back(); |
| 714 | mTexturePool.pop_back(); |
| 715 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
| 716 | return name; |
| 717 | } |
| 718 | |
| 719 | // The pool was too small, so increase it for the future |
| 720 | ++mTexturePoolSize; |
| 721 | } |
| 722 | |
| 723 | // The pool was empty, so we need to get a new texture name directly using a |
| 724 | // blocking call to the main thread |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 725 | auto genTextures = [this] { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 726 | uint32_t name = 0; |
| 727 | getRenderEngine().genTextures(1, &name); |
| 728 | return name; |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 729 | }; |
| 730 | if (std::this_thread::get_id() == mMainThreadId) { |
| 731 | return genTextures(); |
| 732 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 733 | return mScheduler->schedule(genTextures).get(); |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 734 | } |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 737 | void SurfaceFlinger::deleteTextureAsync(uint32_t texture) { |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 738 | std::lock_guard lock(mTexturePoolMutex); |
| 739 | // We don't change the pool size, so the fix-up logic in postComposition will decide whether |
| 740 | // to actually delete this or not based on mTexturePoolSize |
| 741 | mTexturePool.push_back(texture); |
| 742 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 745 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 746 | chooseRenderEngineTypeViaSysProp() { |
| 747 | char prop[PROPERTY_VALUE_MAX]; |
| 748 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
| 749 | |
| 750 | if (strcmp(prop, "gles") == 0) { |
| 751 | return renderengine::RenderEngine::RenderEngineType::GLES; |
| 752 | } else if (strcmp(prop, "threaded") == 0) { |
| 753 | return renderengine::RenderEngine::RenderEngineType::THREADED; |
| 754 | } else if (strcmp(prop, "skiagl") == 0) { |
| 755 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 756 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 757 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
| 758 | } else { |
| 759 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 760 | return {}; |
| 761 | } |
| 762 | } |
| 763 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 764 | // Do not call property_set on main thread which will be blocked by init |
| 765 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 766 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 767 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 768 | "Initializing graphics H/W..."); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 769 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 770 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 771 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 772 | // 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] | 773 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 774 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 775 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 776 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
| 777 | .setUseColorManagerment(useColorManagement) |
| 778 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 779 | .setPrecacheToneMapperShaderOnly(false) |
| 780 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 781 | .setContextPriority( |
| 782 | useContextPriority |
| 783 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 784 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
| 785 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 786 | builder.setRenderEngineType(type.value()); |
| 787 | } |
| 788 | mCompositionEngine->setRenderEngine(renderengine::RenderEngine::create(builder.build())); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 789 | mMaxRenderTargetSize = |
| 790 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 791 | |
| 792 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 793 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 794 | ALOGW("Failed to set main task profile"); |
| 795 | } |
| 796 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 797 | mCompositionEngine->setTimeStats(mTimeStats); |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 798 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 799 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 800 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 801 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 802 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 803 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 804 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 805 | enableHalVirtualDisplays(true); |
| 806 | } |
| 807 | |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 808 | // Process any initial hotplug and resulting display changes. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 809 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 810 | "Initial display configuration failed: HWC did not hotplug"); |
| 811 | processDisplayChangesLocked(); |
| 812 | |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 813 | const auto display = getDefaultDisplayDeviceLocked(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 814 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 815 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 816 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 817 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 818 | // initialize our drawing state |
| 819 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 820 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 821 | // set initial conditions (e.g. unblank default device) |
| 822 | initializeDisplays(); |
| 823 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 824 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 825 | |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 826 | char primeShaderCache[PROPERTY_VALUE_MAX]; |
| 827 | property_get("service.sf.prime_shader_cache", primeShaderCache, "1"); |
| 828 | if (atoi(primeShaderCache)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 829 | if (setSchedFifo(false) != NO_ERROR) { |
| 830 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 831 | } |
| 832 | |
| 833 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(); |
| 834 | |
| 835 | if (setSchedFifo(true) != NO_ERROR) { |
| 836 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 837 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 838 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 839 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 840 | onActiveDisplaySizeChanged(display); |
Derek Sollenberger | c4a05e1 | 2021-03-24 16:45:20 -0400 | [diff] [blame] | 841 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 842 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 843 | |
| 844 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 845 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 846 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 847 | |
| 848 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 849 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 850 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 852 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 855 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 856 | Mutex::Autolock _l(mStateLock); |
| 857 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 858 | char value[PROPERTY_VALUE_MAX]; |
| 859 | |
| 860 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 861 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 862 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 863 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 864 | |
| 865 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 866 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 867 | |
| 868 | property_get("persist.sys.sf.color_mode", value, "0"); |
| 869 | mForceColorMode = static_cast<ColorMode>(atoi(value)); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 872 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 873 | // Start boot animation service by setting a property mailbox |
| 874 | // 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] | 875 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 876 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 877 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 878 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 879 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 880 | } |
| 881 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 883 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 884 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 885 | std::vector<FrameEvent>* outSupported) const { |
| 886 | *outSupported = { |
| 887 | FrameEvent::REQUESTED_PRESENT, |
| 888 | FrameEvent::ACQUIRE, |
| 889 | FrameEvent::LATCH, |
| 890 | FrameEvent::FIRST_REFRESH_START, |
| 891 | FrameEvent::LAST_REFRESH_START, |
| 892 | FrameEvent::GPU_COMPOSITION_DONE, |
| 893 | FrameEvent::DEQUEUE_READY, |
| 894 | FrameEvent::RELEASE, |
| 895 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 896 | |
| 897 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 898 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 899 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 900 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 901 | } |
| 902 | return NO_ERROR; |
| 903 | } |
| 904 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 905 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 906 | if (!displayToken || !state) { |
| 907 | return BAD_VALUE; |
| 908 | } |
| 909 | |
| 910 | Mutex::Autolock lock(mStateLock); |
| 911 | |
| 912 | const auto display = getDisplayDeviceLocked(displayToken); |
| 913 | if (!display) { |
| 914 | return NAME_NOT_FOUND; |
| 915 | } |
| 916 | |
| 917 | state->layerStack = display->getLayerStack(); |
| 918 | state->orientation = display->getOrientation(); |
| 919 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 920 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 921 | state->layerStackSpaceRect = |
| 922 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 923 | |
| 924 | return NO_ERROR; |
| 925 | } |
| 926 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 927 | status_t SurfaceFlinger::getStaticDisplayInfo(const sp<IBinder>& displayToken, |
| 928 | ui::StaticDisplayInfo* info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 929 | if (!displayToken || !info) { |
| 930 | return BAD_VALUE; |
| 931 | } |
| 932 | |
| 933 | Mutex::Autolock lock(mStateLock); |
| 934 | |
| 935 | const auto display = getDisplayDeviceLocked(displayToken); |
| 936 | if (!display) { |
| 937 | return NAME_NOT_FOUND; |
| 938 | } |
| 939 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 940 | if (const auto connectionType = display->getConnectionType()) |
| 941 | info->connectionType = *connectionType; |
| 942 | else { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 943 | return INVALID_OPERATION; |
| 944 | } |
| 945 | |
| 946 | if (mEmulatedDisplayDensity) { |
| 947 | info->density = mEmulatedDisplayDensity; |
| 948 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 949 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 950 | ? mInternalDisplayDensity |
| 951 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 952 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 953 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 954 | |
| 955 | info->secure = display->isSecure(); |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 956 | info->deviceProductInfo = display->getDeviceProductInfo(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 957 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 958 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 959 | return NO_ERROR; |
| 960 | } |
| 961 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 962 | status_t SurfaceFlinger::getDynamicDisplayInfo(const sp<IBinder>& displayToken, |
| 963 | ui::DynamicDisplayInfo* info) { |
| 964 | if (!displayToken || !info) { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 965 | return BAD_VALUE; |
| 966 | } |
| 967 | |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 968 | Mutex::Autolock lock(mStateLock); |
| 969 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 970 | const auto display = getDisplayDeviceLocked(displayToken); |
| 971 | if (!display) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 972 | return NAME_NOT_FOUND; |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 973 | } |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 974 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 975 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
| 976 | if (!displayId) { |
| 977 | return INVALID_OPERATION; |
| 978 | } |
| 979 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 980 | info->activeDisplayModeId = display->getActiveMode()->getId().value(); |
Mathias Agopian | 1604f77 | 2012-09-18 21:54:42 -0700 | [diff] [blame] | 981 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 982 | const auto& supportedModes = display->getSupportedModes(); |
| 983 | info->supportedDisplayModes.clear(); |
| 984 | info->supportedDisplayModes.reserve(supportedModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 985 | |
| 986 | for (const auto& [id, mode] : supportedModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 987 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 988 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 989 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 990 | auto [width, height] = mode->getResolution(); |
| 991 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 992 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 993 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 994 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 995 | std::swap(width, height); |
| 996 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 999 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1000 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1001 | outMode.xDpi = xDpi; |
| 1002 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1003 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1004 | const nsecs_t period = mode->getVsyncPeriod(); |
| 1005 | outMode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1006 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 1007 | const auto vsyncConfigSet = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1008 | mVsyncConfiguration->getConfigsForRefreshRate(Fps::fromValue(outMode.refreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1009 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1010 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1011 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1012 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1013 | // This is how far in advance a buffer must be queued for |
| 1014 | // presentation at a given time. If you want a buffer to appear |
| 1015 | // on the screen at time N, you must submit the buffer before |
| 1016 | // (N - presentationDeadline). |
| 1017 | // |
| 1018 | // Normally it's one full refresh period (to give SF a chance to |
| 1019 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1020 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1021 | // composer or panel must be accounted for here. |
| 1022 | // |
| 1023 | // We add an additional 1ms to allow for processing time and |
| 1024 | // differences between the ideal and actual refresh rate. |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1025 | outMode.presentationDeadline = period - outMode.sfVsyncOffset + 1000000; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1026 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1027 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1030 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1031 | info->supportedColorModes = getDisplayColorModes(*display); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1032 | info->hdrCapabilities = display->getHdrCapabilities(); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1033 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1034 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1035 | getHwComposer().hasDisplayCapability(*displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1036 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1037 | info->gameContentTypeSupported = |
| 1038 | getHwComposer().supportsContentType(*displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1039 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1040 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1041 | |
| 1042 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1043 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(*displayId)) { |
| 1044 | if (const auto modeId = display->translateModeId(*hwcId)) { |
| 1045 | info->preferredBootDisplayMode = modeId->value(); |
| 1046 | } |
| 1047 | } |
| 1048 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1049 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1050 | return NO_ERROR; |
| 1051 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1052 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1053 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>&, DisplayStatInfo* outStats) { |
| 1054 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1055 | return BAD_VALUE; |
| 1056 | } |
| 1057 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1058 | const auto& schedule = mScheduler->getVsyncSchedule(); |
| 1059 | outStats->vsyncTime = schedule.vsyncDeadlineAfter(scheduler::SchedulerClock::now()).ns(); |
| 1060 | outStats->vsyncPeriod = schedule.period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1061 | return NO_ERROR; |
| 1062 | } |
| 1063 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 1064 | void SurfaceFlinger::setDesiredActiveMode(const ActiveModeInfo& info) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1065 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1066 | |
| 1067 | if (!info.mode) { |
| 1068 | ALOGW("requested display mode is null"); |
| 1069 | return; |
| 1070 | } |
| 1071 | auto display = getDisplayDeviceLocked(info.mode->getPhysicalDisplayId()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1072 | if (!display) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1073 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1074 | return; |
| 1075 | } |
| 1076 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1077 | if (display->setDesiredActiveMode(info)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1078 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1079 | |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 1080 | // Start receiving vsync samples now, so that we can detect a period |
| 1081 | // switch. |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1082 | mScheduler->resyncToHardwareVsync(true, info.mode->getFps()); |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1083 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1084 | // VsyncController model is locked. |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 1085 | modulateVsync(&VsyncModulator::onRefreshRateChangeInitiated); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1086 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1087 | updatePhaseConfiguration(info.mode->getFps()); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 1088 | mScheduler->setModeChangePending(true); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1089 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1092 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<IBinder>& displayToken, int modeId) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1093 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1094 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1095 | if (!displayToken) { |
| 1096 | return BAD_VALUE; |
| 1097 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1098 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1099 | auto future = mScheduler->schedule([=]() -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1100 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1101 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 1102 | ALOGE("Attempt to set allowed display modes for invalid display token %p", |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1103 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1104 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 1108 | ALOGW("Attempt to set allowed display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1109 | return INVALID_OPERATION; |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1110 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1111 | |
| 1112 | const auto mode = display->getMode(DisplayModeId{modeId}); |
| 1113 | if (!mode) { |
| 1114 | ALOGW("Attempt to switch to an unsupported mode %d.", modeId); |
| 1115 | return BAD_VALUE; |
| 1116 | } |
| 1117 | |
| 1118 | const auto fps = mode->getFps(); |
| 1119 | // Keep the old switching type. |
| 1120 | const auto allowGroupSwitching = |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1121 | display->refreshRateConfigs().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1122 | const scheduler::RefreshRateConfigs::Policy policy{mode->getId(), |
| 1123 | allowGroupSwitching, |
| 1124 | {fps, fps}}; |
| 1125 | constexpr bool kOverridePolicy = false; |
| 1126 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 1127 | return setDesiredDisplayModeSpecsInternal(display, policy, kOverridePolicy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1128 | }); |
| 1129 | |
| 1130 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1131 | } |
| 1132 | |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1133 | void SurfaceFlinger::updateInternalStateWithChangedMode() { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1134 | ATRACE_CALL(); |
| 1135 | |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1136 | const auto display = getDefaultDisplayDeviceLocked(); |
| 1137 | if (!display) { |
| 1138 | return; |
| 1139 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1140 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1141 | const auto upcomingModeInfo = |
| 1142 | FTL_FAKE_GUARD(kMainThreadContext, display->getUpcomingActiveMode()); |
| 1143 | |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1144 | if (!upcomingModeInfo.mode) { |
| 1145 | // There is no pending mode change. This can happen if the active |
| 1146 | // display changed and the mode change happened on a different display. |
| 1147 | return; |
| 1148 | } |
| 1149 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1150 | if (display->getActiveMode()->getResolution() != upcomingModeInfo.mode->getResolution()) { |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1151 | auto& state = mCurrentState.displays.editValueFor(display->getDisplayToken()); |
| 1152 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1153 | // way the framebuffer). |
| 1154 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1155 | state.physical->activeMode = upcomingModeInfo.mode; |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1156 | processDisplayChangesLocked(); |
| 1157 | |
| 1158 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1159 | return; |
| 1160 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1161 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1162 | // We just created this display so we can call even if we are not on the main thread. |
| 1163 | ftl::FakeGuard guard(kMainThreadContext); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1164 | display->setActiveMode(upcomingModeInfo.mode->getId()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1165 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1166 | const Fps refreshRate = upcomingModeInfo.mode->getFps(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1167 | mRefreshRateStats->setRefreshRate(refreshRate); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 1168 | updatePhaseConfiguration(refreshRate); |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1169 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 1170 | if (upcomingModeInfo.event != DisplayModeEvent::None) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1171 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, upcomingModeInfo.mode); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1172 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1175 | void SurfaceFlinger::clearDesiredActiveModeState(const sp<DisplayDevice>& display) { |
| 1176 | display->clearDesiredActiveModeState(); |
| 1177 | if (isDisplayActiveLocked(display)) { |
| 1178 | mScheduler->setModeChangePending(false); |
| 1179 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1182 | void SurfaceFlinger::desiredActiveModeChangeDone(const sp<DisplayDevice>& display) { |
| 1183 | const auto refreshRate = display->getDesiredActiveMode()->mode->getFps(); |
| 1184 | clearDesiredActiveModeState(display); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1185 | mScheduler->resyncToHardwareVsync(true, refreshRate); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1186 | updatePhaseConfiguration(refreshRate); |
| 1187 | } |
| 1188 | |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1189 | void SurfaceFlinger::setActiveModeInHwcIfNeeded() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1190 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1191 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1192 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1193 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1194 | for (const auto& iter : mDisplays) { |
| 1195 | const auto& display = iter.second; |
| 1196 | if (!display || !display->isInternal()) { |
| 1197 | continue; |
| 1198 | } |
| 1199 | |
| 1200 | // Store the local variable to release the lock. |
| 1201 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1202 | if (!desiredActiveMode) { |
| 1203 | // No desired active mode pending to be applied |
| 1204 | continue; |
| 1205 | } |
| 1206 | |
| 1207 | if (!isDisplayActiveLocked(display)) { |
| 1208 | // display is no longer the active display, so abort the mode change |
| 1209 | clearDesiredActiveModeState(display); |
| 1210 | continue; |
| 1211 | } |
| 1212 | |
| 1213 | const auto desiredMode = display->getMode(desiredActiveMode->mode->getId()); |
| 1214 | if (!desiredMode) { |
| 1215 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
| 1216 | desiredActiveMode->mode->getId().value()); |
| 1217 | clearDesiredActiveModeState(display); |
| 1218 | continue; |
| 1219 | } |
| 1220 | |
| 1221 | const auto refreshRate = desiredMode->getFps(); |
| 1222 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1223 | desiredMode->getId().value(), to_string(refreshRate).c_str(), |
| 1224 | to_string(display->getId()).c_str()); |
| 1225 | |
| 1226 | if (display->getActiveMode()->getId() == desiredActiveMode->mode->getId()) { |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1227 | // we are already in the requested mode, there is nothing left to do |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1228 | desiredActiveModeChangeDone(display); |
| 1229 | continue; |
| 1230 | } |
| 1231 | |
| 1232 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1233 | // allowed modes might have changed by the time we process the refresh. |
| 1234 | // Make sure the desired mode is still allowed |
| 1235 | const auto displayModeAllowed = |
| 1236 | display->refreshRateConfigs().isModeAllowed(desiredActiveMode->mode->getId()); |
| 1237 | if (!displayModeAllowed) { |
Marin Shalamanov | dd00c00 | 2021-11-04 16:54:38 +0100 | [diff] [blame] | 1238 | clearDesiredActiveModeState(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1239 | continue; |
| 1240 | } |
| 1241 | |
| 1242 | // TODO(b/142753666) use constrains |
| 1243 | hal::VsyncPeriodChangeConstraints constraints; |
| 1244 | constraints.desiredTimeNanos = systemTime(); |
| 1245 | constraints.seamlessRequired = false; |
| 1246 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1247 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1248 | const auto status = FTL_FAKE_GUARD(kMainThreadContext, |
| 1249 | display->initiateModeChange(*desiredActiveMode, |
| 1250 | constraints, &outTimeline)); |
| 1251 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1252 | if (status != NO_ERROR) { |
| 1253 | // initiateModeChange may fail if a hotplug event is just about |
| 1254 | // to be sent. We just log the error in this case. |
| 1255 | ALOGW("initiateModeChange failed: %d", status); |
| 1256 | continue; |
| 1257 | } |
| 1258 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1259 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1260 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1261 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1262 | mSetActiveModePending = true; |
| 1263 | } else { |
| 1264 | // Updating the internal state should be done outside the loop, |
| 1265 | // because it can recreate a DisplayDevice and modify mDisplays |
| 1266 | // which will invalidate the iterator. |
| 1267 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if (displayToUpdateImmediately) { |
| 1272 | updateInternalStateWithChangedMode(); |
| 1273 | |
| 1274 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
| 1275 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1276 | if (desiredActiveMode && |
| 1277 | display->getActiveMode()->getId() == desiredActiveMode->mode->getId()) { |
| 1278 | desiredActiveModeChangeDone(display); |
| 1279 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1280 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1281 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1282 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1283 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1284 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1285 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1286 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1287 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1288 | for (const auto& [_, display] : mDisplays) { |
| 1289 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1290 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1291 | } |
| 1292 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1293 | }); |
| 1294 | |
| 1295 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1298 | std::vector<ColorMode> SurfaceFlinger::getDisplayColorModes(const DisplayDevice& display) { |
| 1299 | auto modes = getHwComposer().getColorModes(display.getPhysicalId()); |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1300 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1301 | // If the display is internal and the configuration claims it's not wide color capable, |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1302 | // filter out all wide color modes. The typical reason why this happens is that the |
| 1303 | // hardware is not good enough to support GPU composition of wide color, and thus the |
| 1304 | // OEMs choose to disable this capability. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1305 | if (display.getConnectionType() == ui::DisplayConnectionType::Internal && |
| 1306 | !hasWideColorDisplay) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1307 | const auto newEnd = std::remove_if(modes.begin(), modes.end(), isWideColorMode); |
| 1308 | modes.erase(newEnd, modes.end()); |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1309 | } |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1310 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1311 | return modes; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1314 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1315 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1316 | if (!displayToken) { |
| 1317 | return BAD_VALUE; |
| 1318 | } |
| 1319 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1320 | Mutex::Autolock lock(mStateLock); |
| 1321 | |
| 1322 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1323 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1324 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1327 | const auto connectionType = display->getConnectionType(); |
| 1328 | if (connectionType != ui::DisplayConnectionType::Internal) { |
| 1329 | return INVALID_OPERATION; |
| 1330 | } |
| 1331 | |
| 1332 | // TODO(b/229846990): For now, assume that all internal displays have the same primaries. |
| 1333 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1334 | return NO_ERROR; |
| 1335 | } |
| 1336 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1337 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1338 | if (!displayToken) { |
| 1339 | return BAD_VALUE; |
| 1340 | } |
| 1341 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1342 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1343 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1344 | if (!display) { |
| 1345 | ALOGE("Attempt to set active color mode %s (%d) for invalid display token %p", |
| 1346 | decodeColorMode(mode).c_str(), mode, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1347 | return NAME_NOT_FOUND; |
| 1348 | } |
| 1349 | |
| 1350 | if (display->isVirtual()) { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1351 | ALOGW("Attempt to set active color mode %s (%d) for virtual display", |
| 1352 | decodeColorMode(mode).c_str(), mode); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1353 | return INVALID_OPERATION; |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1354 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1355 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1356 | const auto modes = getDisplayColorModes(*display); |
| 1357 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1358 | |
| 1359 | if (mode < ColorMode::NATIVE || !exists) { |
| 1360 | ALOGE("Attempt to set invalid active color mode %s (%d) for display token %p", |
| 1361 | decodeColorMode(mode).c_str(), mode, displayToken.get()); |
| 1362 | return BAD_VALUE; |
| 1363 | } |
| 1364 | |
| 1365 | display->getCompositionDisplay()->setColorProfile( |
| 1366 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC, Dataspace::UNKNOWN}); |
| 1367 | |
| 1368 | return NO_ERROR; |
| 1369 | }); |
| 1370 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1371 | // TODO(b/195698395): Propagate error. |
| 1372 | future.wait(); |
| 1373 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1374 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1375 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1376 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1377 | auto future = mScheduler->schedule( |
| 1378 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1379 | |
| 1380 | *outSupport = future.get(); |
| 1381 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1384 | status_t SurfaceFlinger::setBootDisplayMode(const sp<IBinder>& displayToken, |
| 1385 | ui::DisplayModeId modeId) { |
| 1386 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1387 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1388 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1389 | if (!display) { |
| 1390 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1391 | return NAME_NOT_FOUND; |
| 1392 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1393 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1394 | if (display->isVirtual()) { |
| 1395 | ALOGE("%s: Invalid operation on virtual display", whence); |
| 1396 | return INVALID_OPERATION; |
| 1397 | } |
| 1398 | |
| 1399 | const auto displayId = display->getPhysicalId(); |
| 1400 | const auto mode = display->getMode(DisplayModeId{modeId}); |
| 1401 | if (!mode) { |
| 1402 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId, |
| 1403 | to_string(displayId).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1404 | return BAD_VALUE; |
| 1405 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1406 | |
| 1407 | return getHwComposer().setBootDisplayMode(displayId, mode->getHwcId()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1408 | }); |
| 1409 | return future.get(); |
| 1410 | } |
| 1411 | |
| 1412 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1413 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1414 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1415 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1416 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1417 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1418 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1419 | return BAD_VALUE; |
| 1420 | } |
| 1421 | }); |
| 1422 | return future.get(); |
| 1423 | } |
| 1424 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1425 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1426 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1427 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1428 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1429 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1430 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1431 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1432 | } |
| 1433 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1436 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1437 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1438 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1439 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1440 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1441 | getHwComposer().setContentType(*displayId, type); |
| 1442 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1443 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1444 | } |
| 1445 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1448 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1449 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1450 | Mutex::Autolock lock(mStateLock); |
| 1451 | |
| 1452 | auto display = getDisplayDeviceLocked(displayToken); |
| 1453 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1454 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1455 | return NAME_NOT_FOUND; |
| 1456 | } |
| 1457 | |
| 1458 | display->overrideHdrTypes(hdrTypes); |
| 1459 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true /* connected */); |
| 1460 | return NO_ERROR; |
| 1461 | } |
| 1462 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1463 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::string* pulledData, bool* success) { |
| 1464 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1465 | return NO_ERROR; |
| 1466 | } |
| 1467 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1468 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1469 | ui::PixelFormat* outFormat, |
| 1470 | ui::Dataspace* outDataspace, |
| 1471 | uint8_t* outComponentMask) const { |
| 1472 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1473 | return BAD_VALUE; |
| 1474 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1475 | |
| 1476 | Mutex::Autolock lock(mStateLock); |
| 1477 | |
| 1478 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1479 | if (!displayId) { |
| 1480 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1481 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1482 | |
| 1483 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1484 | outDataspace, outComponentMask); |
| 1485 | } |
| 1486 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1487 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1488 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1489 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1490 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1491 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1492 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1493 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1494 | componentMask, maxFrames); |
| 1495 | } else { |
| 1496 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1497 | return NAME_NOT_FOUND; |
| 1498 | } |
| 1499 | }); |
| 1500 | |
| 1501 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1504 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1505 | uint64_t maxFrames, uint64_t timestamp, |
| 1506 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1507 | Mutex::Autolock lock(mStateLock); |
| 1508 | |
| 1509 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1510 | if (!displayId) { |
| 1511 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1514 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1517 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1518 | if (!outSupported) { |
| 1519 | return BAD_VALUE; |
| 1520 | } |
| 1521 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1522 | return NO_ERROR; |
| 1523 | } |
| 1524 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1525 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1526 | bool* outIsWideColorDisplay) const { |
| 1527 | if (!displayToken || !outIsWideColorDisplay) { |
| 1528 | return BAD_VALUE; |
| 1529 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1530 | |
| 1531 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1532 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1533 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1534 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1535 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1536 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1537 | *outIsWideColorDisplay = |
| 1538 | display->isPrimary() ? hasWideColorDisplay : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1539 | return NO_ERROR; |
| 1540 | } |
| 1541 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1542 | status_t SurfaceFlinger::enableVSyncInjections(bool enable) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1543 | auto future = mScheduler->schedule([=] { |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 1544 | Mutex::Autolock lock(mStateLock); |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1545 | |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 1546 | if (const auto handle = mScheduler->enableVSyncInjection(enable)) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1547 | mScheduler->setInjector(enable ? mScheduler->getEventConnection(handle) : nullptr); |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1548 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1549 | }); |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 1550 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1551 | future.wait(); |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1552 | return NO_ERROR; |
| 1553 | } |
| 1554 | |
| 1555 | status_t SurfaceFlinger::injectVSync(nsecs_t when) { |
Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 1556 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1557 | const nsecs_t expectedPresentTime = calculateExpectedPresentTime(TimePoint::fromNs(when)).ns(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1558 | const nsecs_t deadlineTimestamp = expectedPresentTime; |
| 1559 | return mScheduler->injectVSync(when, expectedPresentTime, deadlineTimestamp) ? NO_ERROR |
| 1560 | : BAD_VALUE; |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1563 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1564 | outLayers->clear(); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1565 | auto future = mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1566 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1567 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1568 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1569 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1570 | }); |
| 1571 | |
| 1572 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1573 | return NO_ERROR; |
| 1574 | } |
| 1575 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1576 | status_t SurfaceFlinger::getCompositionPreference( |
| 1577 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1578 | Dataspace* outWideColorGamutDataspace, |
| 1579 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1580 | *outDataspace = mDefaultCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1581 | *outPixelFormat = defaultCompositionPixelFormat; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1582 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1583 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1584 | return NO_ERROR; |
| 1585 | } |
| 1586 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1587 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1588 | const sp<IBinder>& stopLayerHandle, |
| 1589 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1590 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1591 | return BAD_VALUE; |
| 1592 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1593 | |
| 1594 | const wp<Layer> stopLayer = fromHandle(stopLayerHandle); |
| 1595 | mRegionSamplingThread->addListener(samplingArea, stopLayer, listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1596 | return NO_ERROR; |
| 1597 | } |
| 1598 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1599 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1600 | if (!listener) { |
| 1601 | return BAD_VALUE; |
| 1602 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1603 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1604 | return NO_ERROR; |
| 1605 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1606 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1607 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1608 | if (!listener) { |
| 1609 | return BAD_VALUE; |
| 1610 | } |
| 1611 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1612 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1613 | return NO_ERROR; |
| 1614 | } |
| 1615 | |
| 1616 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1617 | if (!listener) { |
| 1618 | return BAD_VALUE; |
| 1619 | } |
| 1620 | mFpsReporter->removeListener(listener); |
| 1621 | return NO_ERROR; |
| 1622 | } |
| 1623 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1624 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1625 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1626 | if (!listener) { |
| 1627 | return BAD_VALUE; |
| 1628 | } |
| 1629 | |
| 1630 | mTunnelModeEnabledReporter->addListener(listener); |
| 1631 | return NO_ERROR; |
| 1632 | } |
| 1633 | |
| 1634 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1635 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1636 | if (!listener) { |
| 1637 | return BAD_VALUE; |
| 1638 | } |
| 1639 | |
| 1640 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1641 | return NO_ERROR; |
| 1642 | } |
| 1643 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1644 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1645 | bool* outSupport) const { |
| 1646 | if (!displayToken || !outSupport) { |
| 1647 | return BAD_VALUE; |
| 1648 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1649 | |
| 1650 | Mutex::Autolock lock(mStateLock); |
| 1651 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1652 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1653 | if (!displayId) { |
| 1654 | return NAME_NOT_FOUND; |
| 1655 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1656 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1657 | return NO_ERROR; |
| 1658 | } |
| 1659 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1660 | bool SurfaceFlinger::hasVisibleHdrLayer(const sp<DisplayDevice>& display) { |
| 1661 | bool hasHdrLayers = false; |
| 1662 | mDrawingState.traverse([&, |
| 1663 | compositionDisplay = display->getCompositionDisplay()](Layer* layer) { |
| 1664 | hasHdrLayers |= (layer->isVisible() && |
| 1665 | compositionDisplay->includesLayer(layer->getCompositionEngineLayerFE()) && |
| 1666 | isHdrDataspace(layer->getDataSpace())); |
| 1667 | }); |
| 1668 | return hasHdrLayers; |
| 1669 | } |
| 1670 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1671 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1672 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1673 | if (!displayToken) { |
| 1674 | return BAD_VALUE; |
| 1675 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1676 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1677 | const char* const whence = __func__; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1678 | return ftl::Future(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1679 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1680 | const bool supportsDisplayBrightnessCommand = |
| 1681 | getHwComposer().getComposer()->isSupported( |
| 1682 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1683 | // If we support applying display brightness as a command, then we also support |
| 1684 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1685 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1686 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1687 | float currentDimmingRatio = |
| 1688 | compositionDisplay->editState().sdrWhitePointNits / |
| 1689 | compositionDisplay->editState().displayBrightnessNits; |
| 1690 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1691 | brightness.displayBrightnessNits); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1692 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1693 | display->stageBrightness(brightness.displayBrightness)); |
| 1694 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1695 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1696 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1697 | scheduleComposite(FrameHint::kNone); |
| 1698 | } else { |
| 1699 | scheduleCommit(FrameHint::kNone); |
| 1700 | } |
| 1701 | return ftl::yield<status_t>(OK); |
| 1702 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1703 | return getHwComposer() |
| 1704 | .setDisplayBrightness(display->getPhysicalId(), |
| 1705 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1706 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1707 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1708 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1709 | } |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1710 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1711 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1712 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 1713 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1714 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 1715 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1716 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1717 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1720 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 1721 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1722 | if (!displayToken) { |
| 1723 | return BAD_VALUE; |
| 1724 | } |
| 1725 | |
| 1726 | Mutex::Autolock lock(mStateLock); |
| 1727 | |
| 1728 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1729 | if (!display) { |
| 1730 | return NAME_NOT_FOUND; |
| 1731 | } |
| 1732 | const auto displayId = display->getId(); |
| 1733 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1734 | if (!hdrInfoReporter) { |
| 1735 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 1736 | } |
| 1737 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 1738 | |
| 1739 | |
| 1740 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1741 | return OK; |
| 1742 | } |
| 1743 | |
| 1744 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 1745 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1746 | if (!displayToken) { |
| 1747 | return BAD_VALUE; |
| 1748 | } |
| 1749 | |
| 1750 | Mutex::Autolock lock(mStateLock); |
| 1751 | |
| 1752 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1753 | if (!display) { |
| 1754 | return NAME_NOT_FOUND; |
| 1755 | } |
| 1756 | const auto displayId = display->getId(); |
| 1757 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1758 | if (hdrInfoReporter) { |
| 1759 | hdrInfoReporter->removeListener(listener); |
| 1760 | } |
| 1761 | return OK; |
| 1762 | } |
| 1763 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1764 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1765 | using hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1766 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1767 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1768 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1769 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | return NO_ERROR; |
| 1773 | } |
| 1774 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 1775 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 1776 | const sp<IBinder>& displayToken, |
| 1777 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 1778 | if (!displayToken || !outSupport) { |
| 1779 | return BAD_VALUE; |
| 1780 | } |
| 1781 | |
| 1782 | Mutex::Autolock lock(mStateLock); |
| 1783 | |
| 1784 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1785 | if (!displayId) { |
| 1786 | return NAME_NOT_FOUND; |
| 1787 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 1788 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 1789 | return NO_ERROR; |
| 1790 | } |
| 1791 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 1792 | // ---------------------------------------------------------------------------- |
| 1793 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 1794 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 1795 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1796 | const auto& handle = |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 1797 | vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 1798 | ? mSfConnectionHandle |
| 1799 | : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 1800 | |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 1801 | return mScheduler->createDisplayEventConnection(handle, eventRegistration); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1804 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1805 | if (hint == FrameHint::kActive) { |
| 1806 | mScheduler->resetIdleTimer(); |
| 1807 | } |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1808 | mPowerAdvisor->notifyDisplayUpdateImminent(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 1809 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1812 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 1813 | mMustComposite = true; |
| 1814 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void SurfaceFlinger::scheduleRepaint() { |
| 1818 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1819 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1822 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1823 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1824 | } |
| 1825 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 1826 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 1827 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 1828 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 1831 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 1832 | } |
| 1833 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1834 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 1835 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Ady Abraham | 248bce8 | 2021-09-16 14:29:59 -0700 | [diff] [blame] | 1836 | const std::string tracePeriod = [vsyncPeriod]() { |
| 1837 | if (ATRACE_ENABLED() && vsyncPeriod) { |
| 1838 | std::stringstream ss; |
| 1839 | ss << "(" << *vsyncPeriod << ")"; |
| 1840 | return ss.str(); |
| 1841 | } |
| 1842 | return std::string(); |
| 1843 | }(); |
| 1844 | ATRACE_FORMAT("onComposerHalVsync%s", tracePeriod.c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1845 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1846 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | e116647 | 2021-07-15 10:56:06 -0700 | [diff] [blame] | 1847 | const auto displayId = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 1848 | if (displayId) { |
| 1849 | const auto token = getPhysicalDisplayTokenLocked(*displayId); |
| 1850 | const auto display = getDisplayDeviceLocked(token); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 1851 | display->onVsync(timestamp); |
| 1852 | } |
| 1853 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1854 | if (!getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1855 | return; |
| 1856 | } |
| 1857 | |
Ady Abraham | e116647 | 2021-07-15 10:56:06 -0700 | [diff] [blame] | 1858 | const bool isActiveDisplay = |
| 1859 | displayId && getPhysicalDisplayTokenLocked(*displayId) == mActiveDisplayToken; |
| 1860 | if (!isActiveDisplay) { |
| 1861 | // For now, we don't do anything with non active display vsyncs. |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 1862 | return; |
| 1863 | } |
| 1864 | |
Alec Mouri | f8e689c | 2019-05-20 18:32:22 -0700 | [diff] [blame] | 1865 | bool periodFlushed = false; |
Ady Abraham | 5dee2f1 | 2020-02-05 17:49:47 -0800 | [diff] [blame] | 1866 | mScheduler->addResyncSample(timestamp, vsyncPeriod, &periodFlushed); |
Alec Mouri | f8e689c | 2019-05-20 18:32:22 -0700 | [diff] [blame] | 1867 | if (periodFlushed) { |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 1868 | modulateVsync(&VsyncModulator::onRefreshRateChangeCompleted); |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 1869 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1872 | void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, |
| 1873 | hal::Connection connection) { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 1874 | { |
| 1875 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 1876 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 1877 | } |
| 1878 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 1879 | if (mScheduler) { |
| 1880 | mScheduler->scheduleConfigure(); |
| 1881 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1884 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 1885 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 1886 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1887 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1888 | |
| 1889 | if (timeline.refreshRequired) { |
| 1890 | scheduleComposite(FrameHint::kNone); |
| 1891 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1894 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 1895 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 1896 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 1897 | } |
| 1898 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 1899 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1900 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1901 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 1902 | } |
| 1903 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 1904 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 1905 | ATRACE_CALL(); |
| 1906 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 1907 | } |
| 1908 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 1909 | void SurfaceFlinger::setVsyncEnabled(bool enabled) { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 1910 | ATRACE_CALL(); |
Ady Abraham | 9ba2512 | 2019-06-03 17:10:55 -0700 | [diff] [blame] | 1911 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 1912 | // On main thread to avoid race conditions with display power state. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1913 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 1914 | mHWCVsyncPendingState = enabled ? hal::Vsync::ENABLE : hal::Vsync::DISABLE; |
Ady Abraham | 9ba2512 | 2019-06-03 17:10:55 -0700 | [diff] [blame] | 1915 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 1916 | if (const auto display = getDefaultDisplayDeviceLocked(); |
| 1917 | display && display->isPoweredOn()) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 1918 | setHWCVsyncEnabled(display->getPhysicalId(), mHWCVsyncPendingState); |
Ady Abraham | 9ba2512 | 2019-06-03 17:10:55 -0700 | [diff] [blame] | 1919 | } |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 1920 | })); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1923 | auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1924 | -> const FenceTimePtr& { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1925 | const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1926 | const size_t i = static_cast<size_t>(isTwoVsyncsAhead); |
| 1927 | return mPreviousPresentFences[i].fenceTime; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1930 | bool SurfaceFlinger::isFencePending(const FenceTimePtr& fence, int graceTimeMs) { |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 1931 | ATRACE_CALL(); |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 1932 | if (fence == FenceTime::NO_FENCE) { |
Ady Abraham | 1157930 | 2019-09-19 12:35:58 -0700 | [diff] [blame] | 1933 | return false; |
| 1934 | } |
| 1935 | |
Dan Stoza | 5908305 | 2020-04-28 10:13:20 -0700 | [diff] [blame] | 1936 | const status_t status = fence->wait(graceTimeMs); |
| 1937 | // This is the same as Fence::Status::Unsignaled, but it saves a getStatus() call, |
| 1938 | // which calls wait(0) again internally |
| 1939 | return status == -ETIME; |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1942 | TimePoint SurfaceFlinger::calculateExpectedPresentTime(TimePoint frameTime) const { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1943 | const auto& schedule = mScheduler->getVsyncSchedule(); |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 1944 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1945 | const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(frameTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1946 | if (mVsyncModulator->getVsyncConfig().sfOffset > 0) { |
| 1947 | return vsyncDeadline; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1950 | // Inflate the expected present time if we're targeting the next vsync. |
| 1951 | return vsyncDeadline + schedule.period(); |
Alec Mouri | aa61419 | 2019-06-06 13:28:34 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 1954 | void SurfaceFlinger::configure() FTL_FAKE_GUARD(kMainThreadContext) { |
| 1955 | Mutex::Autolock lock(mStateLock); |
| 1956 | if (configureLocked()) { |
| 1957 | setTransactionFlags(eDisplayTransactionNeeded); |
| 1958 | } |
| 1959 | } |
| 1960 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1961 | bool SurfaceFlinger::commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1962 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1963 | // The expectedVsyncTime, which was predicted when this frame was scheduled, is normally in the |
| 1964 | // future relative to frameTime, but may not be for delayed frames. Adjust mExpectedPresentTime |
| 1965 | // accordingly, but not mScheduledPresentTime. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1966 | const TimePoint lastScheduledPresentTime = mScheduledPresentTime; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1967 | mScheduledPresentTime = expectedVsyncTime; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 1968 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1969 | // Calculate the expected present time once and use the cached value throughout this frame to |
| 1970 | // make sure all layers are seeing this same value. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1971 | mExpectedPresentTime = expectedVsyncTime >= frameTime ? expectedVsyncTime |
| 1972 | : calculateExpectedPresentTime(frameTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1973 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 1974 | ATRACE_FORMAT("%s %" PRId64 " vsyncIn %.2fms%s", __func__, vsyncId.value, |
| 1975 | ticks<std::milli, float>(mExpectedPresentTime - scheduler::SchedulerClock::now()), |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 1976 | mExpectedPresentTime == expectedVsyncTime ? "" : " (adjusted)"); |
Ady Abraham | 893c99d | 2021-04-30 16:00:23 -0700 | [diff] [blame] | 1977 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1978 | const Period vsyncPeriod = mScheduler->getVsyncSchedule().period(); |
| 1979 | const FenceTimePtr& previousPresentFence = getPreviousPresentFence(frameTime, vsyncPeriod); |
| 1980 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 1981 | // When Backpressure propagation is enabled we want to give a small grace period |
| 1982 | // for the present fence to fire instead of just giving up on this frame to handle cases |
| 1983 | // where present fence is just about to get signaled. |
| 1984 | const int graceTimeForPresentFenceMs = |
John Reck | 2ec5391 | 2020-07-07 16:53:55 -0700 | [diff] [blame] | 1985 | (mPropagateBackpressureClientComposition || !mHadClientComposition) ? 1 : 0; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 1986 | |
| 1987 | // Pending frames may trigger backpressure propagation. |
| 1988 | const TracedOrdinal<bool> framePending = {"PrevFramePending", |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1989 | isFencePending(previousPresentFence, |
| 1990 | graceTimeForPresentFenceMs)}; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 1991 | |
| 1992 | // Frame missed counts for metrics tracking. |
| 1993 | // A frame is missed if the prior frame is still pending. If no longer pending, |
| 1994 | // then we still count the frame as missed if the predicted present time |
| 1995 | // was further in the past than when the fence actually fired. |
| 1996 | |
| 1997 | // Add some slop to correct for drift. This should generally be |
| 1998 | // smaller than a typical frame duration, but should not be so small |
| 1999 | // that it reports reasonable drift as a missed frame. |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2000 | const nsecs_t frameMissedSlop = vsyncPeriod.ns() / 2; |
| 2001 | const nsecs_t previousPresentTime = previousPresentFence->getSignalTime(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2002 | const TracedOrdinal<bool> frameMissed = {"PrevFrameMissed", |
| 2003 | framePending || |
| 2004 | (previousPresentTime >= 0 && |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2005 | (lastScheduledPresentTime.ns() < |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2006 | previousPresentTime - frameMissedSlop))}; |
| 2007 | const TracedOrdinal<bool> hwcFrameMissed = {"PrevHwcFrameMissed", |
| 2008 | mHadDeviceComposition && frameMissed}; |
| 2009 | const TracedOrdinal<bool> gpuFrameMissed = {"PrevGpuFrameMissed", |
| 2010 | mHadClientComposition && frameMissed}; |
| 2011 | |
| 2012 | if (frameMissed) { |
| 2013 | mFrameMissedCount++; |
| 2014 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | if (hwcFrameMissed) { |
| 2018 | mHwcFrameMissedCount++; |
| 2019 | } |
| 2020 | |
| 2021 | if (gpuFrameMissed) { |
| 2022 | mGpuFrameMissedCount++; |
| 2023 | } |
| 2024 | |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 2025 | if (mTracingEnabledChanged) { |
| 2026 | mLayerTracingEnabled = mLayerTracing.isEnabled(); |
| 2027 | mTracingEnabledChanged = false; |
| 2028 | } |
| 2029 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2030 | // If we are in the middle of a mode change and the fence hasn't |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2031 | // fired yet just wait for the next commit. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2032 | if (mSetActiveModePending) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2033 | if (framePending) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2034 | mScheduler->scheduleFrame(); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2035 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | // We received the present fence from the HWC, so we assume it successfully updated |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2039 | // the mode, hence we update SF. |
| 2040 | mSetActiveModePending = false; |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2041 | { |
| 2042 | Mutex::Autolock lock(mStateLock); |
| 2043 | updateInternalStateWithChangedMode(); |
| 2044 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
John Reck | 2ec5391 | 2020-07-07 16:53:55 -0700 | [diff] [blame] | 2047 | if (framePending) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2048 | if ((hwcFrameMissed && !gpuFrameMissed) || mPropagateBackpressureClientComposition) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2049 | scheduleCommit(FrameHint::kNone); |
| 2050 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2054 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2055 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
| 2056 | const auto activeDisplay = |
| 2057 | FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayToken)); |
| 2058 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2059 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2060 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 1151f46 | 2022-07-29 00:13:27 +0000 | [diff] [blame] | 2061 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
Matt Buckley | 1151f46 | 2022-07-29 00:13:27 +0000 | [diff] [blame] | 2062 | const nsecs_t vsyncPeriod = display->getActiveMode()->getVsyncPeriod(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2063 | mPowerAdvisor->setCommitStart(frameTime.ns()); |
| 2064 | mPowerAdvisor->setExpectedPresentTime(mExpectedPresentTime.ns()); |
| 2065 | |
| 2066 | // Frame delay is how long we should have minus how long we actually have. |
| 2067 | const Duration idealSfWorkDuration = mVsyncModulator->getVsyncConfig().sfWorkDuration; |
| 2068 | const Duration frameDelay = idealSfWorkDuration - (mExpectedPresentTime - frameTime); |
| 2069 | |
| 2070 | mPowerAdvisor->setFrameDelay(frameDelay.ns()); |
| 2071 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration.ns()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2072 | mPowerAdvisor->setTargetWorkDuration(vsyncPeriod); |
| 2073 | |
| 2074 | // Send early hint here to make sure there's not another frame pending |
| 2075 | if (mPowerHintSessionMode.early) { |
| 2076 | // Send a rough prediction for this frame based on last frame's timing info |
| 2077 | mPowerAdvisor->sendPredictedWorkDuration(); |
| 2078 | } |
| 2079 | } |
| 2080 | |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2081 | if (mRefreshRateOverlaySpinner) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2082 | Mutex::Autolock lock(mStateLock); |
| 2083 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2084 | display->animateRefreshRateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2088 | // Composite if transactions were committed, or if requested by HWC. |
| 2089 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2090 | { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2091 | mFrameTimeline->setSfWakeUp(vsyncId.value, frameTime.ns(), |
| 2092 | Fps::fromPeriodNsecs(vsyncPeriod.ns())); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2093 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2094 | bool needsTraversal = false; |
| 2095 | if (clearTransactionFlags(eTransactionFlushNeeded)) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 2096 | needsTraversal |= commitMirrorDisplays(vsyncId); |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 2097 | needsTraversal |= commitCreatedLayers(vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 2098 | needsTraversal |= flushTransactionQueues(vsyncId); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | const bool shouldCommit = |
| 2102 | (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2103 | if (shouldCommit) { |
| 2104 | commitTransactions(); |
| 2105 | } |
| 2106 | |
| 2107 | if (transactionFlushNeeded()) { |
| 2108 | setTransactionFlags(eTransactionFlushNeeded); |
| 2109 | } |
| 2110 | |
| 2111 | mustComposite |= shouldCommit; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2112 | mustComposite |= latchBuffers(); |
| 2113 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2114 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2115 | // been latched in the commit callback |
| 2116 | if (!needsTraversal) { |
| 2117 | // Invoke empty transaction callbacks early. |
| 2118 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2119 | } else { |
| 2120 | // Invoke OnCommit callbacks. |
| 2121 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2122 | } |
| 2123 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2124 | updateLayerGeometry(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | // Layers need to get updated (in the previous line) before we can use them for |
| 2128 | // choosing the refresh rate. |
| 2129 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2130 | // and may eventually call to ~Layer() if it holds the last reference |
| 2131 | { |
| 2132 | Mutex::Autolock _l(mStateLock); |
| 2133 | mScheduler->chooseRefreshRateForContent(); |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2134 | setActiveModeInHwcIfNeeded(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2137 | updateCursorAsync(); |
| 2138 | updateInputFlinger(); |
| 2139 | |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2140 | if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
| 2141 | // This will block and tracing should only be enabled for debugging. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2142 | mLayerTracing.notify(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2143 | } |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2144 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2145 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2146 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2147 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2148 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2151 | void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2152 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2153 | ATRACE_FORMAT("%s %" PRId64, __func__, vsyncId.value); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2154 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2155 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2156 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2157 | refreshArgs.outputs.reserve(displays.size()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2158 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2159 | for (const auto& [_, display] : displays) { |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2160 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2161 | displayIds.push_back(display->getId()); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2162 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2163 | mPowerAdvisor->setDisplays(displayIds); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2164 | mDrawingState.traverseInZOrder([&refreshArgs](Layer* layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2165 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2166 | refreshArgs.layers.push_back(layerFE); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2167 | }); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2168 | |
| 2169 | if (DOES_CONTAIN_BORDER) { |
| 2170 | refreshArgs.borderInfoList.clear(); |
| 2171 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2172 | if (layer->isBorderEnabled()) { |
| 2173 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2174 | info.width = layer->getBorderWidth(); |
| 2175 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2176 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2177 | info.layerIds.push_back(ilayer->getSequence()); |
| 2178 | }); |
| 2179 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2180 | } |
| 2181 | }); |
| 2182 | } |
| 2183 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2184 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2185 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2186 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2187 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2188 | } |
| 2189 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2190 | refreshArgs.outputColorSetting = useColorManagement |
| 2191 | ? mDisplayColorSetting |
| 2192 | : compositionengine::OutputColorSetting::kUnmanaged; |
| 2193 | refreshArgs.colorSpaceAgnosticDataspace = mColorSpaceAgnosticDataspace; |
| 2194 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2195 | |
| 2196 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2197 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Lucas Dupin | 2dd6f39 | 2020-02-18 17:43:36 -0800 | [diff] [blame] | 2198 | refreshArgs.blursAreExpensive = mBlursAreExpensive; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 2199 | refreshArgs.internalDisplayRotationFlags = DisplayDevice::getPrimaryDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2200 | |
| 2201 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2202 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2203 | mDrawingState.colorMatrixChanged = false; |
| 2204 | } |
| 2205 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2206 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2207 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2208 | if (mDebugFlashDelay != 0) { |
| 2209 | refreshArgs.devOptForceClientComposition = true; |
| 2210 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2211 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2212 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2213 | const auto prevVsyncTime = mExpectedPresentTime - mScheduler->getVsyncSchedule().period(); |
Ady Abraham | caba298 | 2021-06-16 16:45:04 -0700 | [diff] [blame] | 2214 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2215 | |
Ady Abraham | caba298 | 2021-06-16 16:45:04 -0700 | [diff] [blame] | 2216 | refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration; |
Ady Abraham | ec7aa8a | 2021-06-28 12:37:09 -0700 | [diff] [blame] | 2217 | refreshArgs.previousPresentFence = mPreviousPresentFences[0].fenceTime; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2218 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2219 | refreshArgs.expectedPresentTime = mExpectedPresentTime.ns(); |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 2220 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2221 | // Store the present time just before calling to the composition engine so we could notify |
| 2222 | // the scheduler. |
| 2223 | const auto presentTime = systemTime(); |
| 2224 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2225 | mCompositionEngine->present(refreshArgs); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2226 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2227 | mTimeStats->recordFrameDuration(frameTime.ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2228 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2229 | // Send a power hint hint after presentation is finished |
| 2230 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 1809d90 | 2022-08-05 06:51:43 +0000 | [diff] [blame] | 2231 | mPowerAdvisor->setSfPresentTiming(mPreviousPresentFences[0].fenceTime->getSignalTime(), |
| 2232 | systemTime()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2233 | if (mPowerHintSessionMode.late) { |
| 2234 | mPowerAdvisor->sendActualWorkDuration(); |
| 2235 | } |
| 2236 | } |
| 2237 | |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2238 | if (mScheduler->onPostComposition(presentTime)) { |
| 2239 | scheduleComposite(FrameHint::kNone); |
| 2240 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2241 | |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2242 | postComposition(); |
| 2243 | |
Midas Chien | 50f52e2 | 2020-09-26 17:57:42 +0800 | [diff] [blame] | 2244 | const bool prevFrameHadClientComposition = mHadClientComposition; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2245 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2246 | mHadClientComposition = mHadDeviceComposition = mReusedClientComposition = false; |
| 2247 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
| 2248 | for (const auto& [_, display] : displays) { |
| 2249 | const auto& state = display->getCompositionDisplay()->getState(); |
| 2250 | mHadClientComposition |= state.usesClientComposition && !state.reusedClientComposition; |
| 2251 | mHadDeviceComposition |= state.usesDeviceComposition; |
| 2252 | mReusedClientComposition |= state.reusedClientComposition; |
| 2253 | clientCompositionRecord.predicted |= |
| 2254 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2255 | clientCompositionRecord.predictionSucceeded |= |
| 2256 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2259 | clientCompositionRecord.hadClientComposition = mHadClientComposition; |
| 2260 | clientCompositionRecord.reused = mReusedClientComposition; |
| 2261 | clientCompositionRecord.changed = prevFrameHadClientComposition != mHadClientComposition; |
| 2262 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2263 | |
Yichi Chen | 28dee2c | 2020-07-06 21:24:14 +0800 | [diff] [blame] | 2264 | // TODO: b/160583065 Enable skip validation when SF caches all client composition layers |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 2265 | const bool usedGpuComposition = mHadClientComposition || mReusedClientComposition; |
| 2266 | modulateVsync(&VsyncModulator::onDisplayRefresh, usedGpuComposition); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2267 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2268 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2269 | if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2270 | // This will block and should only be used for debugging. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2271 | mLayerTracing.notify(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | df52905 | 2019-06-07 14:53:14 -0700 | [diff] [blame] | 2272 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2273 | |
| 2274 | mVisibleRegionsWereDirtyThisFrame = mVisibleRegionsDirty; // Cache value for use in post-comp |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2275 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2276 | |
| 2277 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2278 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2279 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2280 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2281 | if (mPowerHintSessionEnabled) { |
| 2282 | mPowerAdvisor->setCompositeEnd(systemTime()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2283 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2284 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2285 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2286 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2287 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2288 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2289 | if (mVisibleRegionsDirty) { |
| 2290 | computeLayerBounds(); |
| 2291 | } |
| 2292 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2293 | for (auto& layer : mLayersPendingRefresh) { |
| 2294 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2295 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2296 | invalidateLayerStack(layer, visibleReg); |
| 2297 | } |
| 2298 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2301 | bool SurfaceFlinger::isHdrLayer(Layer* layer) const { |
Alec Mouri | 2c0ea35 | 2022-04-12 16:30:24 +0000 | [diff] [blame] | 2302 | // Treat all layers as non-HDR if: |
| 2303 | // 1. They do not have a valid HDR dataspace. Currently we treat those as PQ or HLG. and |
| 2304 | // 2. The layer is allowed to be dimmed. WindowManager may disable dimming in order to |
| 2305 | // keep animations invoking SDR screenshots of HDR layers seamless. Treat such tagged |
| 2306 | // layers as HDR so that DisplayManagerService does not try to change the screen brightness |
| 2307 | if (!isHdrDataspace(layer->getDataSpace()) && layer->isDimmingEnabled()) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2308 | return false; |
| 2309 | } |
| 2310 | if (mIgnoreHdrCameraLayers) { |
| 2311 | auto buffer = layer->getBuffer(); |
| 2312 | if (buffer && (buffer->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
| 2313 | return false; |
| 2314 | } |
| 2315 | } |
| 2316 | return true; |
| 2317 | } |
| 2318 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2319 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2320 | bool isPrimary) const { |
| 2321 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2322 | if (!id) { |
| 2323 | return ui::ROTATION_0; |
| 2324 | } |
| 2325 | if (getHwComposer().getComposer()->isSupported( |
| 2326 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2327 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2328 | case Hwc2::AidlTransform::ROT_90: |
| 2329 | return ui::ROTATION_90; |
| 2330 | case Hwc2::AidlTransform::ROT_180: |
| 2331 | return ui::ROTATION_180; |
| 2332 | case Hwc2::AidlTransform::ROT_270: |
| 2333 | return ui::ROTATION_270; |
| 2334 | default: |
| 2335 | return ui::ROTATION_0; |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | if (isPrimary) { |
| 2340 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2341 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2342 | case Values::ORIENTATION_90: |
| 2343 | return ui::ROTATION_90; |
| 2344 | case Values::ORIENTATION_180: |
| 2345 | return ui::ROTATION_180; |
| 2346 | case Values::ORIENTATION_270: |
| 2347 | return ui::ROTATION_270; |
| 2348 | default: |
| 2349 | break; |
| 2350 | } |
| 2351 | } |
| 2352 | return ui::ROTATION_0; |
| 2353 | } |
| 2354 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 2355 | void SurfaceFlinger::postComposition() { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2356 | ATRACE_CALL(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2357 | ALOGV(__func__); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2358 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2359 | const auto* display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2360 | |
| 2361 | std::shared_ptr<FenceTime> glCompositionDoneFenceTime; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2362 | if (display && display->getCompositionDisplay()->getState().usesClientComposition) { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2363 | glCompositionDoneFenceTime = |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2364 | std::make_shared<FenceTime>(display->getCompositionDisplay() |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2365 | ->getRenderSurface() |
| 2366 | ->getClientTargetAcquireFence()); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2367 | } else { |
| 2368 | glCompositionDoneFenceTime = FenceTime::NO_FENCE; |
| 2369 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2370 | |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 2371 | mPreviousPresentFences[1] = mPreviousPresentFences[0]; |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 2372 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2373 | auto presentFence = |
| 2374 | display ? getHwComposer().getPresentFence(display->getPhysicalId()) : Fence::NO_FENCE; |
| 2375 | |
| 2376 | auto presentFenceTime = std::make_shared<FenceTime>(presentFence); |
| 2377 | mPreviousPresentFences[0] = {presentFence, presentFenceTime}; |
| 2378 | |
| 2379 | const TimePoint presentTime = scheduler::SchedulerClock::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 2380 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2381 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 2382 | // information from previous' frame classification is already available when sending jank info |
| 2383 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2384 | mFrameTimeline->setSfPresent(presentTime.ns(), presentFenceTime, glCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2385 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2386 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 2387 | // be sampled a little later than when we started doing work for this frame, |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2388 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2389 | const TimePoint compositeTime = |
| 2390 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 2391 | const Duration presentLatency = |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2392 | mPresentLatencyTracker.trackPendingFrame(compositeTime, presentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2393 | |
| 2394 | const auto& schedule = mScheduler->getVsyncSchedule(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2395 | const TimePoint vsyncDeadline = schedule.vsyncDeadlineAfter(presentTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2396 | const Period vsyncPeriod = schedule.period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2397 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2398 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2399 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2400 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2401 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2402 | for (const auto& layer: mLayersWithQueuedFrames) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2403 | layer->onPostComposition(display, glCompositionDoneFenceTime, presentFenceTime, |
| 2404 | compositorTiming); |
| 2405 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2406 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2407 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2408 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 2409 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2410 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2411 | { |
| 2412 | Mutex::Autolock lock(mStateLock); |
| 2413 | if (mFpsReporter) { |
| 2414 | mFpsReporter->dispatchLayerFps(); |
| 2415 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 2416 | |
| 2417 | if (mTunnelModeEnabledReporter) { |
| 2418 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 2419 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2420 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 2421 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 2422 | if (reporter && reporter->hasListeners()) { |
| 2423 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 2424 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2428 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 2429 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2430 | } |
| 2431 | |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2432 | if (haveNewListeners || mSomeDataspaceChanged || mVisibleRegionsWereDirtyThisFrame) { |
| 2433 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 2434 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 2435 | int32_t maxArea = 0; |
| 2436 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 2437 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2438 | if (layer->isVisible() && compositionDisplay->includesLayer(layerFe)) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2439 | if (isHdrLayer(layer)) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2440 | const auto* outputLayer = |
| 2441 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 2442 | if (outputLayer) { |
| 2443 | info.numberOfHdrLayers++; |
| 2444 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 2445 | const int32_t area = displayFrame.width() * displayFrame.height(); |
| 2446 | if (area > maxArea) { |
| 2447 | maxArea = area; |
| 2448 | info.maxW = displayFrame.width(); |
| 2449 | info.maxH = displayFrame.height(); |
| 2450 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 2451 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2452 | } |
| 2453 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2454 | }); |
| 2455 | listener->dispatchHdrLayerInfo(info); |
| 2456 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2459 | mSomeDataspaceChanged = false; |
| 2460 | mVisibleRegionsWereDirtyThisFrame = false; |
| 2461 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2462 | mTransactionCallbackInvoker.addPresentFence(std::move(presentFence)); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 2463 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 2464 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
Valerie Hau | 4b67844 | 2020-04-14 10:50:42 -0700 | [diff] [blame] | 2465 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2466 | mTimeStats->incrementTotalFrames(); |
| 2467 | mTimeStats->setPresentFenceGlobal(presentFenceTime); |
| 2468 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 2469 | if (display && display->isInternal() && display->getPowerMode() == hal::PowerMode::ON && |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2470 | presentFenceTime->isValid()) { |
| 2471 | mScheduler->addPresentFence(std::move(presentFenceTime)); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2474 | const bool isDisplayConnected = |
| 2475 | display && getHwComposer().isConnected(display->getPhysicalId()); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2476 | |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 2477 | if (!hasSyncFramework) { |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2478 | if (isDisplayConnected && display->isPoweredOn()) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2479 | mScheduler->enableHardwareVsync(); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 2483 | const size_t sfConnections = mScheduler->getEventThreadConnectionCount(mSfConnectionHandle); |
| 2484 | const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle); |
| 2485 | mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections); |
| 2486 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2487 | if (isDisplayConnected && !display->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 2488 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2489 | return; |
| 2490 | } |
| 2491 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2492 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 2493 | getRenderEngine().cleanupPostRender(); |
| 2494 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2495 | { |
| 2496 | std::lock_guard lock(mTexturePoolMutex); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 2497 | if (mTexturePool.size() < mTexturePoolSize) { |
| 2498 | const size_t refillCount = mTexturePoolSize - mTexturePool.size(); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2499 | const size_t offset = mTexturePool.size(); |
| 2500 | mTexturePool.resize(mTexturePoolSize); |
| 2501 | getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset); |
| 2502 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 2503 | } else if (mTexturePool.size() > mTexturePoolSize) { |
| 2504 | const size_t deleteCount = mTexturePool.size() - mTexturePoolSize; |
| 2505 | const size_t offset = mTexturePoolSize; |
| 2506 | getRenderEngine().deleteTextures(deleteCount, mTexturePool.data() + offset); |
| 2507 | mTexturePool.resize(mTexturePoolSize); |
| 2508 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2509 | } |
| 2510 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 2511 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 2512 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 2513 | // side-effect of getTotalSize(), so we check that again here |
| 2514 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 2515 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 2516 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 2517 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2518 | |
| 2519 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 2522 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2523 | const ui::Size maxSize = [this] { |
| 2524 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 2525 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2526 | // The LayerTraceGenerator tool runs without displays. |
| 2527 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 2528 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2529 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 2530 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 2531 | const auto& display = pair.second; |
| 2532 | return {std::max(size.getWidth(), display->getWidth()), |
| 2533 | std::max(size.getHeight(), display->getHeight())}; |
| 2534 | }); |
| 2535 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 2536 | |
| 2537 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 2538 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2539 | const float xMax = maxSize.getWidth() * 10.f; |
| 2540 | const float yMax = maxSize.getHeight() * 10.f; |
| 2541 | |
| 2542 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2546 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 2547 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 2548 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2549 | } |
| 2550 | } |
| 2551 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 2552 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 2553 | ATRACE_CALL(); |
| 2554 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 2555 | // Keep a copy of the drawing state (that is going to be overwritten |
| 2556 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 2557 | // effects of the State assignment don't happen with mStateLock held, |
| 2558 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 2559 | State drawingState(mDrawingState); |
| 2560 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 2561 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 2562 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 2564 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 2565 | // so we can call commitTransactionsLocked unconditionally. |
| 2566 | // We clear the flags with mStateLock held to guarantee that |
| 2567 | // mCurrentState won't change until the transaction is committed. |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 2568 | modulateVsync(&VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 2569 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 2570 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 2571 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2574 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 2575 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 2576 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 2577 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2578 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 2579 | int attempt = 0; |
| 2580 | constexpr int kMaxAttempts = 3; |
| 2581 | do { |
| 2582 | hwcModes = getHwComposer().getModes(displayId); |
| 2583 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 2584 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2585 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 2586 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2587 | }; |
| 2588 | |
| 2589 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 2590 | break; |
| 2591 | } |
| 2592 | } while (++attempt < kMaxAttempts); |
| 2593 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 2594 | if (attempt == kMaxAttempts) { |
| 2595 | const std::string activeMode = |
| 2596 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 2597 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 2598 | "hwcModes={%s}", |
| 2599 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 2600 | return {}; |
| 2601 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2602 | |
| 2603 | DisplayModes oldModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2604 | if (const auto token = getPhysicalDisplayTokenLocked(displayId)) { |
| 2605 | oldModes = getDisplayDeviceLocked(token)->getSupportedModes(); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2606 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2607 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2608 | ui::DisplayModeId nextModeId = 1 + |
| 2609 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 2610 | [](ui::DisplayModeId max, const auto& pair) { |
| 2611 | return std::max(max, pair.first.value()); |
| 2612 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2613 | |
| 2614 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2615 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2616 | const DisplayModeId id{nextModeId++}; |
| 2617 | newModes.try_emplace(id, |
| 2618 | DisplayMode::Builder(hwcMode.hwcId) |
| 2619 | .setId(id) |
| 2620 | .setPhysicalDisplayId(displayId) |
| 2621 | .setResolution({hwcMode.width, hwcMode.height}) |
| 2622 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
| 2623 | .setDpiX(hwcMode.dpiX) |
| 2624 | .setDpiY(hwcMode.dpiY) |
| 2625 | .setGroup(hwcMode.configGroup) |
| 2626 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2627 | } |
| 2628 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2629 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2630 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2631 | [](const auto& lhs, const auto& rhs) { |
| 2632 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2633 | }); |
| 2634 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2635 | // Keep IDs if modes have not changed. |
| 2636 | const auto& modes = sameModes ? oldModes : newModes; |
| 2637 | const DisplayModePtr activeMode = |
| 2638 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 2639 | return pair.second->getHwcId() == activeModeHwcId; |
| 2640 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 2641 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2642 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2643 | } |
| 2644 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2645 | bool SurfaceFlinger::configureLocked() { |
| 2646 | std::vector<HotplugEvent> events; |
| 2647 | { |
| 2648 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2649 | events = std::move(mPendingHotplugEvents); |
| 2650 | } |
| 2651 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 2652 | for (const auto [hwcDisplayId, connection] : events) { |
| 2653 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 2654 | const auto displayId = info->id; |
| 2655 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2656 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 2657 | if (const char* const log = |
| 2658 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 2659 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 2660 | hwcDisplayId); |
| 2661 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2662 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2663 | } |
| 2664 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2665 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 2666 | } |
| 2667 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 2668 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 2669 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 2670 | DisplayIdentificationInfo&& info) { |
| 2671 | const auto tokenOpt = mPhysicalDisplayTokens.get(displayId); |
| 2672 | if (!connected) { |
| 2673 | LOG_ALWAYS_FATAL_IF(!tokenOpt); |
| 2674 | |
| 2675 | if (const ssize_t index = mCurrentState.displays.indexOfKey(tokenOpt->get()); index >= 0) { |
| 2676 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
| 2677 | mInterceptor->saveDisplayDeletion(state.sequenceId); |
| 2678 | mCurrentState.displays.removeItemsAt(index); |
| 2679 | } |
| 2680 | |
| 2681 | mPhysicalDisplayTokens.erase(displayId); |
| 2682 | return "Disconnecting"; |
| 2683 | } |
| 2684 | |
| 2685 | auto [supportedModes, activeMode] = loadDisplayModes(displayId); |
| 2686 | if (!activeMode) { |
| 2687 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 2688 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 2689 | getHwComposer().disconnectDisplay(displayId); |
| 2690 | return nullptr; |
| 2691 | } |
| 2692 | |
| 2693 | if (tokenOpt) { |
| 2694 | auto& state = mCurrentState.displays.editValueFor(tokenOpt->get()); |
| 2695 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 2696 | state.physical->supportedModes = std::move(supportedModes); |
| 2697 | state.physical->activeMode = std::move(activeMode); |
| 2698 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
| 2699 | state.physical->deviceProductInfo = std::move(info.deviceProductInfo); |
| 2700 | } |
| 2701 | return "Reconnecting"; |
| 2702 | } |
| 2703 | |
| 2704 | DisplayDeviceState state; |
| 2705 | state.physical = {.id = displayId, |
| 2706 | .type = getHwComposer().getDisplayConnectionType(displayId), |
| 2707 | .hwcDisplayId = hwcDisplayId, |
| 2708 | .deviceProductInfo = std::move(info.deviceProductInfo), |
| 2709 | .supportedModes = std::move(supportedModes), |
| 2710 | .activeMode = std::move(activeMode)}; |
| 2711 | state.isSecure = true; // All physical displays are currently considered secure. |
| 2712 | state.displayName = std::move(info.name); |
| 2713 | |
| 2714 | sp<IBinder> token = sp<BBinder>::make(); |
| 2715 | mCurrentState.displays.add(token, state); |
| 2716 | mPhysicalDisplayTokens.try_emplace(displayId, std::move(token)); |
| 2717 | mInterceptor->saveDisplayCreation(state); |
| 2718 | return "Connecting"; |
| 2719 | } |
| 2720 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 2721 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 2722 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 2723 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 2724 | } |
| 2725 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2726 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 2727 | const wp<IBinder>& displayToken, |
| 2728 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2729 | const DisplayDeviceState& state, |
| 2730 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2731 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2732 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 2733 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 2734 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2735 | creationArgs.isSecure = state.isSecure; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2736 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2737 | creationArgs.hasWideColorGamut = false; |
| 2738 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 2739 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 2740 | if (const auto& physical = state.physical) { |
| 2741 | creationArgs.connectionType = physical->type; |
Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 2742 | creationArgs.supportedModes = physical->supportedModes; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2743 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 2744 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 2745 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 2746 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2747 | scheduler::RefreshRateConfigs::Config config = |
| 2748 | {.enableFrameRateOverride = android::sysprop::enable_frame_rate_override(false), |
| 2749 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 2750 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 2751 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 2752 | .kernelIdleTimerController = kernelIdleTimerController}; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2753 | creationArgs.refreshRateConfigs = |
| 2754 | std::make_shared<scheduler::RefreshRateConfigs>(creationArgs.supportedModes, |
| 2755 | creationArgs.activeModeId, config); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 2756 | } |
| 2757 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2758 | if (const auto id = PhysicalDisplayId::tryCast(compositionDisplay->getId())) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 2759 | creationArgs.isPrimary = id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2760 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2761 | if (useColorManagement) { |
| 2762 | std::vector<ColorMode> modes = getHwComposer().getColorModes(*id); |
| 2763 | for (ColorMode colorMode : modes) { |
| 2764 | if (isWideColorMode(colorMode)) { |
| 2765 | creationArgs.hasWideColorGamut = true; |
| 2766 | } |
| 2767 | |
| 2768 | std::vector<RenderIntent> renderIntents = |
| 2769 | getHwComposer().getRenderIntents(*id, colorMode); |
| 2770 | creationArgs.hwcColorModes.emplace(colorMode, renderIntents); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2771 | } |
| 2772 | } |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 2773 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2774 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2775 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 2776 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 2777 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 2778 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2779 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 2780 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2781 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2782 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2783 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2784 | // Make sure that composition can never be stalled by a virtual display |
| 2785 | // 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] | 2786 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 2787 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2788 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 2789 | } |
| 2790 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 2791 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2792 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 2793 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 2794 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2795 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 2796 | creationArgs.initialPowerMode = |
| 2797 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2798 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 2799 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2800 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 2801 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2802 | |
| 2803 | ColorMode defaultColorMode = ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 2804 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 2805 | if (display->hasWideColorGamut()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2806 | defaultColorMode = ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 2807 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2808 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2809 | display->getCompositionDisplay()->setColorProfile( |
| 2810 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
| 2811 | RenderIntent::COLORIMETRIC, |
| 2812 | Dataspace::UNKNOWN}); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2813 | if (!state.isVirtual()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2814 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2815 | display->setActiveMode(state.physical->activeMode->getId())); |
Marin Shalamanov | 7ce8764 | 2020-05-06 13:45:58 +0200 | [diff] [blame] | 2816 | display->setDeviceProductInfo(state.physical->deviceProductInfo); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 2817 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2818 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2819 | display->setLayerStack(state.layerStack); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2820 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 2821 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2822 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 2823 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2824 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2825 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 2826 | } |
| 2827 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2828 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 2829 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2830 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2831 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 2832 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2833 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2834 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 2835 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2836 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2837 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2838 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2839 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2840 | int format; |
| 2841 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2842 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2843 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2844 | } else { |
| 2845 | // Virtual displays without a surface are dormant: |
| 2846 | // they have external state (layer stack, projection, |
| 2847 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 2848 | return; |
| 2849 | } |
| 2850 | |
| 2851 | compositionengine::DisplayCreationArgsBuilder builder; |
| 2852 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2853 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2854 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 2855 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2856 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2857 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2858 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2859 | builder.setIsSecure(state.isSecure); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 2860 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2861 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2862 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 2863 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2864 | |
| 2865 | sp<compositionengine::DisplaySurface> displaySurface; |
| 2866 | sp<IGraphicBufferProducer> producer; |
| 2867 | sp<IGraphicBufferProducer> bqProducer; |
| 2868 | sp<IGraphicBufferConsumer> bqConsumer; |
| 2869 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 2870 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2871 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2872 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 2873 | LOG_FATAL_IF(!displayId); |
| 2874 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
| 2875 | bqProducer, bqConsumer, state.displayName); |
| 2876 | displaySurface = surface; |
| 2877 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2878 | } else { |
| 2879 | ALOGE_IF(state.surface != nullptr, |
| 2880 | "adding a supported display, but rendering " |
| 2881 | "surface is provided (%p), ignoring it", |
| 2882 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2883 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 2884 | LOG_FATAL_IF(!displayId); |
| 2885 | displaySurface = |
| 2886 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 2887 | state.physical->activeMode->getResolution(), |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2888 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2889 | producer = bqProducer; |
| 2890 | } |
| 2891 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2892 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 2893 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 2894 | displaySurface, producer); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2895 | if (display->isPrimary()) { |
| 2896 | initScheduler(display); |
| 2897 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2898 | if (!state.isVirtual()) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2899 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2900 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 2901 | |
| 2902 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 2906 | auto display = getDisplayDeviceLocked(displayToken); |
| 2907 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2908 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2909 | |
| 2910 | if (display->isVirtual()) { |
| 2911 | releaseVirtualDisplay(display->getVirtualId()); |
| 2912 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2913 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 2918 | |
| 2919 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2920 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 2921 | // Destroy the display without holding the mStateLock. |
| 2922 | // This is a temporary solution until we can manage transaction queues without |
| 2923 | // holding the mStateLock. |
| 2924 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 2925 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 2926 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 2927 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 2928 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 2929 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 2930 | // The display will be disconnected and removed from the mDisplays list so it will |
| 2931 | // not be accessible. |
| 2932 | })); |
| 2933 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 2937 | const DisplayDeviceState& currentState, |
| 2938 | const DisplayDeviceState& drawingState) { |
| 2939 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 2940 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2941 | |
| 2942 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2943 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | 23c31af | 2020-09-09 15:01:47 +0200 | [diff] [blame] | 2944 | getRenderEngine().cleanFramebufferCache(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2945 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2946 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 2947 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2948 | if (display->isVirtual()) { |
| 2949 | releaseVirtualDisplay(display->getVirtualId()); |
| 2950 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2951 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2952 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2953 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2954 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2955 | if (const auto& physical = currentState.physical) { |
| 2956 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 2957 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2958 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2959 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 2960 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2961 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 2962 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2963 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 2964 | |
| 2965 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2966 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2967 | updateInternalDisplayVsyncLocked(display); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 2968 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2969 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2970 | return; |
| 2971 | } |
| 2972 | |
| 2973 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 2974 | if (currentState.layerStack != drawingState.layerStack) { |
| 2975 | display->setLayerStack(currentState.layerStack); |
| 2976 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 2977 | if (currentState.flags != drawingState.flags) { |
| 2978 | display->setFlags(currentState.flags); |
| 2979 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2980 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2981 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 2982 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 2983 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 2984 | currentState.orientedDisplaySpaceRect); |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 2985 | if (isDisplayActiveLocked(display)) { |
| 2986 | mActiveDisplayTransformHint = display->getTransformHint(); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 2987 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2988 | } |
| 2989 | if (currentState.width != drawingState.width || |
| 2990 | currentState.height != drawingState.height) { |
| 2991 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 2992 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 2993 | if (isDisplayActiveLocked(display)) { |
| 2994 | onActiveDisplaySizeChanged(display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | } |
| 2998 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 2999 | void SurfaceFlinger::updateInternalDisplayVsyncLocked(const sp<DisplayDevice>& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3000 | mVsyncConfiguration->reset(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3001 | const Fps refreshRate = activeDisplay->refreshRateConfigs().getActiveMode()->getFps(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3002 | updatePhaseConfiguration(refreshRate); |
| 3003 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3004 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3005 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3006 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3007 | // here we take advantage of Vector's copy-on-write semantics to |
| 3008 | // improve performance by skipping the transaction entirely when |
| 3009 | // know that the lists are identical |
| 3010 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3011 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3012 | if (!curr.isIdenticalTo(draw)) { |
| 3013 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3014 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3015 | |
| 3016 | // find the displays that were removed |
| 3017 | // (ie: in drawing state but not in current state) |
| 3018 | // also handle displays that changed |
| 3019 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3020 | for (size_t i = 0; i < draw.size(); i++) { |
| 3021 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3022 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3023 | if (j < 0) { |
| 3024 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3025 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3026 | } else { |
| 3027 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3028 | const DisplayDeviceState& currentState = curr[j]; |
| 3029 | const DisplayDeviceState& drawingState = draw[i]; |
| 3030 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3031 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | // find displays that were added |
| 3035 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3036 | for (size_t i = 0; i < curr.size(); i++) { |
| 3037 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3038 | if (draw.indexOfKey(displayToken) < 0) { |
| 3039 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3043 | |
| 3044 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3045 | } |
| 3046 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3047 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3048 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3049 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
| 3050 | if (displayTransactionNeeded) { |
| 3051 | processDisplayChangesLocked(); |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3052 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3053 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3055 | if (mSomeChildrenChanged) { |
| 3056 | mVisibleRegionsDirty = true; |
| 3057 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3058 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3061 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3062 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3063 | // Layers and/or displays have changed, so update the transform hint for each layer. |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3064 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3065 | // NOTE: we do this here, rather than when presenting the display so that |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3066 | // the hint is set before we acquire a buffer from the surface texture. |
| 3067 | // |
| 3068 | // NOTE: layer transactions have taken place already, so we use their |
| 3069 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3070 | // happened yet, so we must use the current state layer list |
| 3071 | // (soon to become the drawing state list). |
| 3072 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3073 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3074 | ui::LayerStack layerStack; |
| 3075 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3076 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3077 | // NOTE: we rely on the fact that layers are sorted by |
| 3078 | // layerStack first (so we don't have to traverse the list |
| 3079 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3080 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3081 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3082 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3083 | |
| 3084 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3085 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3086 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3087 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3088 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3089 | |
| 3090 | // Pick the primary display if another display mirrors the layer. |
| 3091 | if (hintDisplay) { |
| 3092 | hintDisplay = nullptr; |
| 3093 | break; |
| 3094 | } |
| 3095 | |
| 3096 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3097 | } |
| 3098 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3099 | |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3100 | if (!hintDisplay && mDisplays.size() > 0) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3101 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3102 | // redraw after transform hint changes. See bug 8508397. |
Robert Carr | 56a0b9a | 2017-12-04 16:06:13 -0800 | [diff] [blame] | 3103 | |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3104 | // could be null when this layer is using a layerStack |
| 3105 | // that is not visible on any display. Also can occur at |
| 3106 | // screen off/on times. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3107 | hintDisplay = getDefaultDisplayDeviceLocked(); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3108 | } |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3109 | |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3110 | if (hintDisplay) { |
| 3111 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 3112 | } else { |
| 3113 | ALOGW("Ignoring transform hint update for %s", layer->getDebugName()); |
| 3114 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3115 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3116 | } |
| 3117 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3118 | if (mLayersAdded) { |
| 3119 | mLayersAdded = false; |
| 3120 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3121 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3122 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | // some layers might have been removed, so |
| 3126 | // we need to update the regions they're exposing. |
| 3127 | if (mLayersRemoved) { |
| 3128 | mLayersRemoved = false; |
| 3129 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3130 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3131 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3132 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3133 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3134 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3135 | visibleReg.set(layer->getScreenBounds()); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3136 | invalidateLayerStack(sp<Layer>::fromExisting(layer), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3137 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3138 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | } |
| 3140 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3141 | doCommitTransactions(); |
| 3142 | signalSynchronousTransactions(CountDownLatch::eSyncTransaction); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3145 | void SurfaceFlinger::updateInputFlinger() { |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3146 | ATRACE_CALL(); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3147 | if (!mInputFlinger) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3148 | return; |
| 3149 | } |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3150 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3151 | std::vector<WindowInfo> windowInfos; |
| 3152 | std::vector<DisplayInfo> displayInfos; |
| 3153 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3154 | if (mUpdateInputInfo) { |
| 3155 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3156 | updateWindowInfo = true; |
| 3157 | buildWindowInfos(windowInfos, displayInfos); |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3158 | } else if (mInputWindowCommands.empty()) { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3159 | return; |
| 3160 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3161 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3162 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3163 | windowInfos = std::move(windowInfos), |
| 3164 | displayInfos = std::move(displayInfos), |
| 3165 | inputWindowCommands = |
| 3166 | std::move(mInputWindowCommands), |
| 3167 | inputFlinger = mInputFlinger, this]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3168 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3169 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3170 | mWindowInfosListenerInvoker |
| 3171 | ->windowInfosChanged(windowInfos, displayInfos, |
| 3172 | inputWindowCommands.windowInfosReportedListeners); |
| 3173 | } else { |
| 3174 | // If there are listeners but no changes to input windows, call the listeners |
| 3175 | // immediately. |
| 3176 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3177 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3178 | listener->onWindowInfosReported(); |
| 3179 | } |
| 3180 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3181 | } |
| 3182 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3183 | inputFlinger->setFocusedWindow(focusRequest); |
| 3184 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3185 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3186 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3187 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3188 | } |
| 3189 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3190 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3191 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3192 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3193 | if (!supportsDisplayBrightnessCommand) { |
| 3194 | return; |
| 3195 | } |
| 3196 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3197 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3198 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3199 | if (!needsComposite) { |
| 3200 | const status_t error = |
| 3201 | getHwComposer() |
| 3202 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3203 | display->getCompositionDisplay() |
| 3204 | ->getState() |
| 3205 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3206 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3207 | .applyImmediately = true}) |
| 3208 | .get(); |
| 3209 | |
| 3210 | ALOGE_IF(error != NO_ERROR, |
| 3211 | "Error setting display brightness for display %s: %d (%s)", |
| 3212 | display->getDebugName().c_str(), error, strerror(error)); |
| 3213 | } |
| 3214 | display->persistBrightness(needsComposite); |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3219 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 3220 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3221 | ftl::SmallMap<ui::LayerStack, DisplayDevice::InputInfo, 4> displayInputInfos; |
| 3222 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3223 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3224 | const auto layerStack = display->getLayerStack(); |
| 3225 | const auto info = display->getInputInfo(); |
| 3226 | |
| 3227 | const auto [it, emplaced] = displayInputInfos.try_emplace(layerStack, info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3228 | if (emplaced) { |
Prabir Pradhan | 8b89c2f | 2021-07-29 16:30:14 +0000 | [diff] [blame] | 3229 | continue; |
| 3230 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3231 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3232 | // If the layer stack is mirrored on multiple displays, the first display that is configured |
| 3233 | // to receive input takes precedence. |
| 3234 | auto& otherInfo = it->second; |
| 3235 | if (otherInfo.receivesInput) { |
Prabir Pradhan | 977e7c3 | 2022-02-15 04:55:52 -0800 | [diff] [blame] | 3236 | ALOGW_IF(display->receivesInput(), |
| 3237 | "Multiple displays claim to accept input for the same layer stack: %u", |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3238 | layerStack.id); |
| 3239 | } else { |
| 3240 | otherInfo = info; |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3241 | } |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 3242 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3243 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3244 | static size_t sNumWindowInfos = 0; |
| 3245 | outWindowInfos.reserve(sNumWindowInfos); |
| 3246 | sNumWindowInfos = 0; |
| 3247 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3248 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 3249 | if (!layer->needsInputInfo()) return; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3250 | |
Dominik Laskowski | 54494bd | 2022-08-02 13:37:14 -0700 | [diff] [blame] | 3251 | const auto opt = displayInputInfos.get(layer->getLayerStack()) |
| 3252 | .transform([](const DisplayDevice::InputInfo& info) { |
| 3253 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 3254 | }); |
| 3255 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 3256 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3257 | }); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3258 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3259 | sNumWindowInfos = outWindowInfos.size(); |
| 3260 | |
| 3261 | outDisplayInfos.reserve(displayInputInfos.size()); |
| 3262 | for (const auto& [_, info] : displayInputInfos) { |
| 3263 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3264 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3267 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3268 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3269 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3270 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3271 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3272 | } |
| 3273 | } |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3274 | |
| 3275 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3278 | void SurfaceFlinger::requestDisplayMode(DisplayModePtr mode, DisplayModeEvent event) { |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3279 | // If this is called from the main thread mStateLock must be locked before |
| 3280 | // Currently the only way to call this function from the main thread is from |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3281 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3282 | |
| 3283 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3284 | |
| 3285 | const auto display = getDefaultDisplayDeviceLocked(); |
| 3286 | if (!display || mBootStage != BootStage::FINISHED) { |
| 3287 | return; |
| 3288 | } |
| 3289 | ATRACE_CALL(); |
| 3290 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3291 | if (!display->refreshRateConfigs().isModeAllowed(mode->getId())) { |
| 3292 | ALOGV("Skipping disallowed mode %d", mode->getId().value()); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3293 | return; |
| 3294 | } |
| 3295 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3296 | setDesiredActiveMode({std::move(mode), event}); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 3297 | } |
| 3298 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3299 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 3300 | PhysicalDisplayId displayId = [&]() { |
| 3301 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 3302 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 3303 | }(); |
| 3304 | |
| 3305 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 3306 | } |
| 3307 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3308 | void SurfaceFlinger::initScheduler(const sp<DisplayDevice>& display) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3309 | if (mScheduler) { |
Ady Abraham | ac2bf48 | 2021-07-20 10:59:51 -0700 | [diff] [blame] | 3310 | // If the scheduler is already initialized, this means that we received |
| 3311 | // a hotplug(connected) on the primary display. In that case we should |
| 3312 | // update the scheduler with the most recent display information. |
| 3313 | ALOGW("Scheduler already initialized, updating instead"); |
| 3314 | mScheduler->setRefreshRateConfigs(display->holdRefreshRateConfigs()); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3315 | return; |
| 3316 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3317 | const auto currRefreshRate = display->getActiveMode()->getFps(); |
Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 3318 | mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(*mTimeStats, currRefreshRate, |
| 3319 | hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3320 | |
Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 3321 | mVsyncConfiguration = getFactory().createVsyncConfiguration(currRefreshRate); |
Ady Abraham | 23ea9da | 2021-07-14 16:32:56 -0700 | [diff] [blame] | 3322 | mVsyncModulator = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 3323 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3324 | using Feature = scheduler::Feature; |
| 3325 | scheduler::FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3326 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3327 | if (sysprop::use_content_detection_for_refresh_rate(false)) { |
| 3328 | features |= Feature::kContentDetection; |
| 3329 | } |
| 3330 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 3331 | features |= Feature::kTracePredictedVsync; |
| 3332 | } |
| 3333 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 3334 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3335 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3336 | } |
| 3337 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3338 | mScheduler = std::make_unique<scheduler::Scheduler>(static_cast<ICompositor&>(*this), |
| 3339 | static_cast<ISchedulerCallback&>(*this), |
| 3340 | features); |
| 3341 | { |
| 3342 | auto configs = display->holdRefreshRateConfigs(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3343 | if (configs->kernelIdleTimerController().has_value()) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3344 | features |= Feature::kKernelIdleTimer; |
| 3345 | } |
| 3346 | |
| 3347 | mScheduler->createVsyncSchedule(features); |
| 3348 | mScheduler->setRefreshRateConfigs(std::move(configs)); |
| 3349 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3350 | setVsyncEnabled(false); |
| 3351 | mScheduler->startTimers(); |
| 3352 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 3353 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 3354 | const nsecs_t vsyncPeriod = currRefreshRate.getPeriodNsecs(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3355 | mAppConnectionHandle = |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 3356 | mScheduler->createConnection("app", mFrameTimeline->getTokenManager(), |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 3357 | /*workDuration=*/configs.late.appWorkDuration, |
| 3358 | /*readyDuration=*/configs.late.sfWorkDuration, |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3359 | impl::EventThread::InterceptVSyncsCallback()); |
| 3360 | mSfConnectionHandle = |
Ady Abraham | 55fa727 | 2020-09-30 19:19:27 -0700 | [diff] [blame] | 3361 | mScheduler->createConnection("appSf", mFrameTimeline->getTokenManager(), |
| 3362 | /*workDuration=*/std::chrono::nanoseconds(vsyncPeriod), |
| 3363 | /*readyDuration=*/configs.late.sfWorkDuration, |
| 3364 | [this](nsecs_t timestamp) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3365 | mInterceptor->saveVSyncEvent(timestamp); |
| 3366 | }); |
| 3367 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3368 | mScheduler->initVsync(mScheduler->getVsyncSchedule().getDispatch(), |
| 3369 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3370 | |
| 3371 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3372 | sp<RegionSamplingThread>::make(*this, |
| 3373 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 3374 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 3375 | // Dispatch a mode change request for the primary display on scheduler |
Alec Mouri | 60aee1c | 2019-10-28 16:18:59 -0700 | [diff] [blame] | 3376 | // initialization, so that the EventThreads always contain a reference to a |
| 3377 | // prior configuration. |
| 3378 | // |
| 3379 | // This is a bit hacky, but this avoids a back-pointer into the main SF |
| 3380 | // classes from EventThread, and there should be no run-time binder cost |
| 3381 | // anyway since there are no connected apps at this point. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 3382 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, display->getActiveMode()); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 3385 | void SurfaceFlinger::updatePhaseConfiguration(const Fps& refreshRate) { |
| 3386 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Ady Abraham | 55fa727 | 2020-09-30 19:19:27 -0700 | [diff] [blame] | 3387 | setVsyncConfig(mVsyncModulator->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs()), |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 3388 | refreshRate.getPeriodNsecs()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Ady Abraham | 55fa727 | 2020-09-30 19:19:27 -0700 | [diff] [blame] | 3391 | void SurfaceFlinger::setVsyncConfig(const VsyncModulator::VsyncConfig& config, |
| 3392 | nsecs_t vsyncPeriod) { |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 3393 | mScheduler->setDuration(mAppConnectionHandle, |
| 3394 | /*workDuration=*/config.appWorkDuration, |
| 3395 | /*readyDuration=*/config.sfWorkDuration); |
| 3396 | mScheduler->setDuration(mSfConnectionHandle, |
Ady Abraham | 55fa727 | 2020-09-30 19:19:27 -0700 | [diff] [blame] | 3397 | /*workDuration=*/std::chrono::nanoseconds(vsyncPeriod), |
| 3398 | /*readyDuration=*/config.sfWorkDuration); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3399 | mScheduler->setDuration(config.sfWorkDuration); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3402 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 3403 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3405 | if (!mLayersPendingRemoval.isEmpty()) { |
| 3406 | // Notify removed layers now that they can't be drawn from |
| 3407 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3408 | // Ensure any buffers set to display on any children are released. |
| 3409 | if (l->isRemovedFromCurrentState()) { |
| 3410 | l->latchAndReleaseBuffer(); |
| 3411 | } |
| 3412 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 3413 | // If a layer has a parent, we allow it to out-live it's handle |
| 3414 | // with the idea that the parent holds a reference and will eventually |
| 3415 | // be cleaned up. However no one cleans up the top-level so we do so |
| 3416 | // here. |
| 3417 | if (l->isAtRoot()) { |
| 3418 | l->setIsAtRoot(false); |
| 3419 | mCurrentState.layersSortedByZ.remove(l); |
| 3420 | } |
| 3421 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3422 | // If the layer has been removed and has no parent, then it will not be reachable |
| 3423 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 3424 | // ensure we can copy its current to drawing state. |
| 3425 | if (!l->getParent()) { |
| 3426 | mOffscreenLayers.emplace(l.get()); |
| 3427 | } |
| 3428 | } |
| 3429 | mLayersPendingRemoval.clear(); |
| 3430 | } |
| 3431 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3432 | mDrawingState = mCurrentState; |
| 3433 | // clear the "changed" flags in current state |
| 3434 | mCurrentState.colorMatrixChanged = false; |
| 3435 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 3436 | if (mVisibleRegionsDirty) { |
| 3437 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 3438 | rootLayer->commitChildList(); |
| 3439 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 3440 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 3441 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3442 | commitOffscreenLayers(); |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 3443 | if (mNumClones > 0) { |
| 3444 | mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); }); |
| 3445 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 3448 | void SurfaceFlinger::commitOffscreenLayers() { |
| 3449 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 3450 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3451 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
| 3452 | layer->doTransaction(0); |
| 3453 | layer->commitChildList(); |
| 3454 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 3455 | }); |
| 3456 | } |
| 3457 | } |
| 3458 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 3459 | void SurfaceFlinger::invalidateLayerStack(const sp<const Layer>& layer, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3460 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3461 | auto display = displayDevice->getCompositionDisplay(); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3462 | if (display->includesLayer(layer->getOutputFilter())) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3463 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 3464 | } |
| 3465 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3468 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 3469 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3470 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3471 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3473 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3474 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3475 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 3476 | |
| 3477 | // Store the set of layers that need updates. This set must not change as |
| 3478 | // buffers are being latched, as this could result in a deadlock. |
| 3479 | // Example: Two producers share the same command stream and: |
| 3480 | // 1.) Layer 0 is latched |
| 3481 | // 2.) Layer 0 gets a new frame |
| 3482 | // 2.) Layer 1 gets a new frame |
| 3483 | // 3.) Layer 1 is latched. |
| 3484 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 3485 | // second frame. But layer 0's second frame could be waiting on display. |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 3486 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3487 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
| 3488 | const uint32_t flags = layer->doTransaction(0); |
| 3489 | if (flags & Layer::eVisibleRegion) { |
| 3490 | mVisibleRegionsDirty = true; |
| 3491 | } |
| 3492 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3493 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3494 | if (layer->hasReadyFrame()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3495 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3496 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3497 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 3498 | layer->useEmptyDamage(); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3499 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3500 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3501 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3502 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 3503 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 3504 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 3505 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 3506 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 3507 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 3508 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 3509 | } |
| 3510 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 3511 | if (!mLayersWithQueuedFrames.empty()) { |
| 3512 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 3513 | // writes to Layer current state. See also b/119481871 |
| 3514 | Mutex::Autolock lock(mStateLock); |
| 3515 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 3516 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 3517 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3518 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 3519 | newDataLatched = true; |
| 3520 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 3521 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3522 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3523 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 3524 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 3525 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3526 | |
| 3527 | // If we will need to wake up at some time in the future to deal with a |
| 3528 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 3529 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 3530 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3531 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3532 | } |
| 3533 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 3534 | // enter boot animation on first buffer latch |
| 3535 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 3536 | ALOGI("Enter boot animation"); |
| 3537 | mBootStage = BootStage::BOOTANIMATION; |
| 3538 | } |
| 3539 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 3540 | if (mNumClones > 0) { |
| 3541 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 3542 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 3543 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3544 | // 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] | 3545 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | } |
| 3547 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 3548 | status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 3549 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 3550 | bool addToRoot, uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 3551 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 3552 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 3553 | MAX_LAYERS); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 3554 | static_cast<void>(mScheduler->schedule([=] { |
| 3555 | ALOGE("Dumping random sampling of on-screen layers: "); |
| 3556 | mDrawingState.traverse([&](Layer *layer) { |
| 3557 | // Aim to dump about 200 layers to avoid totally trashing |
| 3558 | // logcat. On the other hand, if there really are 4096 layers |
| 3559 | // something has gone totally wrong its probably the most |
| 3560 | // useful information in logcat. |
| 3561 | if (rand() % 20 == 13) { |
| 3562 | ALOGE("Layer: %s", layer->getName().c_str()); |
| 3563 | } |
| 3564 | }); |
| 3565 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 3566 | if (rand() % 20 == 13) { |
| 3567 | ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str()); |
| 3568 | } |
| 3569 | } |
| 3570 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 3571 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 3574 | { |
| 3575 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 3576 | mCreatedLayers.emplace_back(layer, parent, addToRoot); |
| 3577 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 3578 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 3579 | layer->updateTransformHint(mActiveDisplayTransformHint); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 3580 | if (outTransformHint) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3581 | *outTransformHint = mActiveDisplayTransformHint; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 3582 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 3583 | // attach this layer to the client |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 3584 | if (client != nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 3585 | client->attachLayer(handle, layer); |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 3586 | } |
Mathias Agopian | 4f11374 | 2011-05-03 16:21:41 -0700 | [diff] [blame] | 3587 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 3588 | setTransactionFlags(eTransactionNeeded); |
| 3589 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3592 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 3593 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3596 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
| 3597 | return mTransactionFlags.fetch_and(~mask) & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 3600 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 3601 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3602 | modulateVsync(&VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 3603 | |
| 3604 | if (const bool scheduled = mTransactionFlags.fetch_or(mask) & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 3605 | scheduleCommit(frameHint); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 3606 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | } |
| 3608 | |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3609 | int SurfaceFlinger::flushPendingTransactionQueues( |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3610 | std::vector<TransactionState>& transactions, |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3611 | std::unordered_map<sp<IBinder>, uint64_t, SpHash<IBinder>>& bufferLayersReadyToPresent, |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3612 | bool tryApplyUnsignaled) { |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3613 | std::unordered_set<sp<IBinder>, SpHash<IBinder>> applyTokensWithUnsignaledTransactions; |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3614 | int transactionsPendingBarrier = 0; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3615 | auto it = mPendingTransactionQueues.begin(); |
| 3616 | while (it != mPendingTransactionQueues.end()) { |
| 3617 | auto& [applyToken, transactionQueue] = *it; |
| 3618 | while (!transactionQueue.empty()) { |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3619 | // if we are in LatchUnsignaledConfig::AutoSingleLayer |
| 3620 | // then we should have only one applyToken for processing. |
| 3621 | // so we can stop further transactions on this applyToken. |
| 3622 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer && |
| 3623 | !applyTokensWithUnsignaledTransactions.empty()) { |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3624 | ATRACE_NAME("stopTransactionProcessing"); |
| 3625 | break; |
| 3626 | } |
| 3627 | |
| 3628 | auto& transaction = transactionQueue.front(); |
| 3629 | const auto ready = |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3630 | transactionIsReadyToBeApplied(transaction, transaction.frameTimelineInfo, |
| 3631 | transaction.isAutoTimestamp, |
| 3632 | TimePoint::fromNs(transaction.desiredPresentTime), |
| 3633 | transaction.originUid, transaction.states, |
| 3634 | bufferLayersReadyToPresent, transactions.size(), |
| 3635 | tryApplyUnsignaled); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3636 | ATRACE_INT("TransactionReadiness", static_cast<int>(ready)); |
| 3637 | if (ready == TransactionReadiness::NotReady) { |
| 3638 | setTransactionFlags(eTransactionFlushNeeded); |
| 3639 | break; |
| 3640 | } |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3641 | if (ready == TransactionReadiness::NotReadyBarrier) { |
| 3642 | transactionsPendingBarrier++; |
| 3643 | setTransactionFlags(eTransactionFlushNeeded); |
| 3644 | break; |
| 3645 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3646 | transaction.traverseStatesWithBuffers([&](const layer_state_t& state) { |
Xiang Wang | 76236e1 | 2022-03-22 17:25:30 +0000 | [diff] [blame] | 3647 | const bool frameNumberChanged = state.bufferData->flags.test( |
| 3648 | BufferData::BufferDataChange::frameNumberChanged); |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3649 | if (frameNumberChanged) { |
| 3650 | bufferLayersReadyToPresent[state.surface] = state.bufferData->frameNumber; |
| 3651 | } else { |
| 3652 | // Barrier function only used for BBQ which always includes a frame number |
| 3653 | bufferLayersReadyToPresent[state.surface] = |
| 3654 | std::numeric_limits<uint64_t>::max(); |
| 3655 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3656 | }); |
| 3657 | const bool appliedUnsignaled = (ready == TransactionReadiness::ReadyUnsignaled); |
| 3658 | if (appliedUnsignaled) { |
| 3659 | applyTokensWithUnsignaledTransactions.insert(transaction.applyToken); |
| 3660 | } |
| 3661 | |
| 3662 | transactions.emplace_back(std::move(transaction)); |
| 3663 | transactionQueue.pop(); |
Vishnu Nair | 60d902e | 2022-07-20 02:55:37 +0000 | [diff] [blame] | 3664 | mPendingTransactionCount--; |
| 3665 | ATRACE_INT("TransactionQueue", mPendingTransactionCount.load()); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | if (transactionQueue.empty()) { |
| 3669 | it = mPendingTransactionQueues.erase(it); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3670 | } else { |
| 3671 | it = std::next(it, 1); |
| 3672 | } |
| 3673 | } |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3674 | return transactionsPendingBarrier; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3675 | } |
| 3676 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3677 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Valerie Hau | fce31b8 | 2019-04-30 16:41:14 -0700 | [diff] [blame] | 3678 | // to prevent onHandleDestroyed from being called while the lock is held, |
| 3679 | // we must keep a copy of the transactions (specifically the composer |
| 3680 | // states) around outside the scope of the lock |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 3681 | std::vector<TransactionState> transactions; |
Vishnu Nair | 12f62a0 | 2021-02-03 16:23:16 -0800 | [diff] [blame] | 3682 | // Layer handles that have transactions with buffers that are ready to be applied. |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3683 | std::unordered_map<sp<IBinder>, uint64_t, SpHash<IBinder>> bufferLayersReadyToPresent; |
Valerie Hau | fce31b8 | 2019-04-30 16:41:14 -0700 | [diff] [blame] | 3684 | { |
Vishnu Nair | 12f62a0 | 2021-02-03 16:23:16 -0800 | [diff] [blame] | 3685 | Mutex::Autolock _l(mStateLock); |
| 3686 | { |
Vishnu Nair | 60d902e | 2022-07-20 02:55:37 +0000 | [diff] [blame] | 3687 | while (!mLocklessTransactionQueue.isEmpty()) { |
| 3688 | auto maybeTransaction = mLocklessTransactionQueue.pop(); |
| 3689 | if (!maybeTransaction.has_value()) { |
| 3690 | break; |
| 3691 | } |
| 3692 | auto transaction = maybeTransaction.value(); |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3693 | mPendingTransactionQueues[transaction.applyToken].push(std::move(transaction)); |
Valerie Hau | fce31b8 | 2019-04-30 16:41:14 -0700 | [diff] [blame] | 3694 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 3695 | |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3696 | // Transactions with a buffer pending on a barrier may be on a different applyToken |
| 3697 | // than the transaction which satisfies our barrier. In fact this is the exact use case |
| 3698 | // that the primitive is designed for. This means we may first process |
| 3699 | // the barrier dependent transaction, determine it ineligible to complete |
| 3700 | // and then satisfy in a later inner iteration of flushPendingTransactionQueues. |
| 3701 | // The barrier dependent transaction was eligible to be presented in this frame |
| 3702 | // but we would have prevented it without case. To fix this we continually |
| 3703 | // loop through flushPendingTransactionQueues until we perform an iteration |
| 3704 | // where the number of transactionsPendingBarrier doesn't change. This way |
| 3705 | // we can continue to resolve dependency chains of barriers as far as possible. |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3706 | int lastTransactionsPendingBarrier = 0; |
| 3707 | int transactionsPendingBarrier = 0; |
| 3708 | do { |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3709 | lastTransactionsPendingBarrier = transactionsPendingBarrier; |
| 3710 | transactionsPendingBarrier = |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3711 | flushPendingTransactionQueues(transactions, bufferLayersReadyToPresent, |
| 3712 | /*tryApplyUnsignaled*/ false); |
| 3713 | } while (lastTransactionsPendingBarrier != transactionsPendingBarrier); |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3714 | |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3715 | // We collected all transactions that could apply without latching unsignaled buffers. |
| 3716 | // If we are allowing latch unsignaled of some form, now it's the time to go over the |
| 3717 | // transactions that were not applied and try to apply them unsignaled. |
| 3718 | if (enableLatchUnsignaledConfig != LatchUnsignaledConfig::Disabled) { |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3719 | flushPendingTransactionQueues(transactions, bufferLayersReadyToPresent, |
| 3720 | /*tryApplyUnsignaled*/ true); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3721 | } |
| 3722 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 3723 | return applyTransactions(transactions, vsyncId); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 3724 | } |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 3728 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3729 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 3730 | bool needsTraversal = false; |
| 3731 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 3732 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 3733 | needsTraversal |= |
| 3734 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 3735 | transaction.displays, transaction.flags, |
| 3736 | transaction.inputWindowCommands, |
| 3737 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
| 3738 | transaction.buffer, transaction.postTime, |
| 3739 | transaction.permissions, transaction.hasListenerCallbacks, |
| 3740 | transaction.listenerCallbacks, transaction.originPid, |
| 3741 | transaction.originUid, transaction.id); |
| 3742 | if (transaction.transactionCommittedSignal) { |
| 3743 | mTransactionCommittedSignals.emplace_back( |
| 3744 | std::move(transaction.transactionCommittedSignal)); |
| 3745 | } |
| 3746 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 3747 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 3748 | if (mTransactionTracing) { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3749 | mTransactionTracing->addCommittedTransactions(transactions, vsyncId.value); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 3750 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 3751 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 60d902e | 2022-07-20 02:55:37 +0000 | [diff] [blame] | 3755 | return !mPendingTransactionQueues.empty() || !mLocklessTransactionQueue.isEmpty(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3758 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 3759 | const auto prediction = |
| 3760 | mFrameTimeline->getTokenManager()->getPredictionsForToken(vsyncId.value); |
| 3761 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3762 | return false; |
| 3763 | } |
| 3764 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3765 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 3766 | |
| 3767 | // The duration for which SF can delay a frame if it is considered early based on the |
| 3768 | // VsyncModulator::VsyncConfig::appWorkDuration. |
| 3769 | if (constexpr std::chrono::nanoseconds kEarlyLatchMaxThreshold = 100ms; |
| 3770 | std::chrono::abs(predictedPresentTime - expectedPresentTime) >= kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3771 | return false; |
| 3772 | } |
| 3773 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3774 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule().period() / 2; |
| 3775 | |
| 3776 | return predictedPresentTime >= expectedPresentTime && |
| 3777 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3778 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3779 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3780 | bool SurfaceFlinger::shouldLatchUnsignaled(const sp<Layer>& layer, const layer_state_t& state, |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 3781 | size_t numStates, size_t totalTXapplied) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3782 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
| 3783 | ALOGV("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
| 3784 | return false; |
| 3785 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3786 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3787 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Always) { |
| 3788 | ALOGV("%s: true (LatchUnsignaledConfig::Always)", __func__); |
| 3789 | return true; |
| 3790 | } |
| 3791 | |
| 3792 | // We only want to latch unsignaled when a single layer is updated in this |
| 3793 | // transaction (i.e. not a blast sync transaction). |
| 3794 | if (numStates != 1) { |
| 3795 | ALOGV("%s: false (numStates=%zu)", __func__, numStates); |
| 3796 | return false; |
| 3797 | } |
| 3798 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 3799 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
| 3800 | if (totalTXapplied > 0) { |
| 3801 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; totalTXapplied=%zu)", |
| 3802 | __func__, totalTXapplied); |
| 3803 | return false; |
| 3804 | } |
| 3805 | |
| 3806 | // We don't want to latch unsignaled if are in early / client composition |
| 3807 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 3808 | // or window animations being slow. |
| 3809 | const auto isDefaultVsyncConfig = mVsyncModulator->isVsyncConfigDefault(); |
| 3810 | if (!isDefaultVsyncConfig) { |
| 3811 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; !isDefaultVsyncConfig)", |
| 3812 | __func__); |
| 3813 | return false; |
| 3814 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | if (!layer->simpleBufferUpdate(state)) { |
| 3818 | ALOGV("%s: false (!simpleBufferUpdate)", __func__); |
| 3819 | return false; |
| 3820 | } |
| 3821 | |
| 3822 | ALOGV("%s: true", __func__); |
| 3823 | return true; |
| 3824 | } |
| 3825 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3826 | auto SurfaceFlinger::transactionIsReadyToBeApplied( |
| 3827 | TransactionState& transaction, const FrameTimelineInfo& info, bool isAutoTimestamp, |
| 3828 | TimePoint desiredPresentTime, uid_t originUid, const Vector<ComposerState>& states, |
| 3829 | const std::unordered_map<sp<IBinder>, uint64_t, SpHash<IBinder>>& |
| 3830 | bufferLayersReadyToPresent, |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3831 | size_t totalTXapplied, bool tryApplyUnsignaled) const -> TransactionReadiness { |
Ady Abraham | 3bea425 | 2021-11-30 23:18:13 +0000 | [diff] [blame] | 3832 | ATRACE_FORMAT("transactionIsReadyToBeApplied vsyncId: %" PRId64, info.vsyncId); |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3833 | // Do not present if the desiredPresentTime has not passed unless it is more than one second |
| 3834 | // in the future. We ignore timestamps more than 1 second in the future for stability reasons. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3835 | if (!isAutoTimestamp && desiredPresentTime >= mExpectedPresentTime && |
| 3836 | desiredPresentTime < mExpectedPresentTime + 1s) { |
Ady Abraham | 2f43b20 | 2021-03-12 12:34:52 -0800 | [diff] [blame] | 3837 | ATRACE_NAME("not current"); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3838 | return TransactionReadiness::NotReady; |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3839 | } |
| 3840 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3841 | if (!mScheduler->isVsyncValid(mExpectedPresentTime, originUid)) { |
Ady Abraham | 5690bda | 2021-03-12 15:01:18 -0800 | [diff] [blame] | 3842 | ATRACE_NAME("!isVsyncValid"); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3843 | return TransactionReadiness::NotReady; |
Ady Abraham | 5690bda | 2021-03-12 15:01:18 -0800 | [diff] [blame] | 3844 | } |
| 3845 | |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3846 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the expected |
| 3847 | // present time of this transaction. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 3848 | if (isAutoTimestamp && frameIsEarly(mExpectedPresentTime, VsyncId{info.vsyncId})) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3849 | ATRACE_NAME("frameIsEarly"); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3850 | return TransactionReadiness::NotReady; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3853 | bool fenceUnsignaled = false; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 3854 | auto queueProcessTime = systemTime(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3855 | for (const ComposerState& state : states) { |
| 3856 | const layer_state_t& s = state.state; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 3857 | |
Ady Abraham | f20c192 | 2020-12-21 18:39:01 -0800 | [diff] [blame] | 3858 | sp<Layer> layer = nullptr; |
| 3859 | if (s.surface) { |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 3860 | layer = fromHandle(s.surface).promote(); |
Vishnu Nair | ddf9b5c | 2021-03-29 18:53:41 -0700 | [diff] [blame] | 3861 | } else if (s.hasBufferChanges()) { |
Ady Abraham | f20c192 | 2020-12-21 18:39:01 -0800 | [diff] [blame] | 3862 | ALOGW("Transaction with buffer, but no Layer?"); |
| 3863 | continue; |
| 3864 | } |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 3865 | if (!layer) { |
| 3866 | continue; |
| 3867 | } |
Ady Abraham | 43752eb | 2021-03-04 16:24:25 -0800 | [diff] [blame] | 3868 | |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3869 | if (s.hasBufferChanges() && s.bufferData->hasBarrier && |
| 3870 | ((layer->getDrawingState().frameNumber) < s.bufferData->barrierFrameNumber)) { |
| 3871 | const bool willApplyBarrierFrame = |
| 3872 | (bufferLayersReadyToPresent.find(s.surface) != bufferLayersReadyToPresent.end()) && |
| 3873 | (bufferLayersReadyToPresent.at(s.surface) >= s.bufferData->barrierFrameNumber); |
| 3874 | if (!willApplyBarrierFrame) { |
| 3875 | ATRACE_NAME("NotReadyBarrier"); |
| 3876 | return TransactionReadiness::NotReadyBarrier; |
| 3877 | } |
| 3878 | } |
| 3879 | |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 3880 | const bool allowLatchUnsignaled = tryApplyUnsignaled && |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3881 | shouldLatchUnsignaled(layer, s, states.size(), totalTXapplied); |
Ady Abraham | 16f48f1 | 2022-02-14 21:54:59 -0800 | [diff] [blame] | 3882 | ATRACE_FORMAT("%s allowLatchUnsignaled=%s", layer->getName().c_str(), |
| 3883 | allowLatchUnsignaled ? "true" : "false"); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3884 | |
| 3885 | const bool acquireFenceChanged = s.bufferData && |
| 3886 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 3887 | s.bufferData->acquireFence; |
| 3888 | fenceUnsignaled = fenceUnsignaled || |
| 3889 | (acquireFenceChanged && |
| 3890 | s.bufferData->acquireFence->getStatus() == Fence::Status::Unsignaled); |
| 3891 | |
| 3892 | if (fenceUnsignaled && !allowLatchUnsignaled) { |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 3893 | if (!transaction.sentFenceTimeoutWarning && |
Vishnu Nair | 55e8f51 | 2022-07-20 04:10:32 +0000 | [diff] [blame] | 3894 | queueProcessTime - transaction.postTime > std::chrono::nanoseconds(4s).count()) { |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 3895 | transaction.sentFenceTimeoutWarning = true; |
| 3896 | auto listener = s.bufferData->releaseBufferListener; |
| 3897 | if (listener) { |
| 3898 | listener->onTransactionQueueStalled(); |
| 3899 | } |
| 3900 | } |
| 3901 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3902 | ATRACE_NAME("fence unsignaled"); |
| 3903 | return TransactionReadiness::NotReady; |
| 3904 | } |
| 3905 | |
Vishnu Nair | ddf9b5c | 2021-03-29 18:53:41 -0700 | [diff] [blame] | 3906 | if (s.hasBufferChanges()) { |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 3907 | // If backpressure is enabled and we already have a buffer to commit, keep the |
| 3908 | // transaction in the queue. |
Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 3909 | const bool hasPendingBuffer = bufferLayersReadyToPresent.find(s.surface) != |
| 3910 | bufferLayersReadyToPresent.end(); |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 3911 | if (layer->backpressureEnabled() && hasPendingBuffer && isAutoTimestamp) { |
Ady Abraham | 2f43b20 | 2021-03-12 12:34:52 -0800 | [diff] [blame] | 3912 | ATRACE_NAME("hasPendingBuffer"); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3913 | return TransactionReadiness::NotReady; |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 3914 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3915 | } |
| 3916 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 3917 | return fenceUnsignaled ? TransactionReadiness::ReadyUnsignaled : TransactionReadiness::Ready; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3920 | void SurfaceFlinger::queueTransaction(TransactionState& state) { |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3921 | // Generate a CountDownLatch pending state if this is a synchronous transaction. |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3922 | if (state.flags & eSynchronous) { |
| 3923 | state.transactionCommittedSignal = |
| 3924 | std::make_shared<CountDownLatch>(CountDownLatch::eSyncTransaction); |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3925 | } |
| 3926 | |
Vishnu Nair | 60d902e | 2022-07-20 02:55:37 +0000 | [diff] [blame] | 3927 | mLocklessTransactionQueue.push(state); |
| 3928 | mPendingTransactionCount++; |
| 3929 | ATRACE_INT("TransactionQueue", mPendingTransactionCount.load()); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3930 | |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3931 | const auto schedule = [](uint32_t flags) { |
Ady Abraham | 8cbd307 | 2021-03-15 16:39:06 -0700 | [diff] [blame] | 3932 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 3933 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3934 | return TransactionSchedule::Late; |
| 3935 | }(state.flags); |
| 3936 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 3937 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
| 3938 | |
| 3939 | setTransactionFlags(eTransactionFlushNeeded, schedule, state.applyToken, frameHint); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3940 | } |
| 3941 | |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3942 | void SurfaceFlinger::waitForSynchronousTransaction( |
| 3943 | const CountDownLatch& transactionCommittedSignal) { |
| 3944 | // applyTransactionState is called on the main SF thread. While a given process may wish |
| 3945 | // to wait on synchronous transactions, the main SF thread should apply the transaction and |
| 3946 | // set the value to notify this after committed. |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame] | 3947 | if (!transactionCommittedSignal.wait_until( |
| 3948 | std::chrono::nanoseconds(mAnimationTransactionTimeout))) { |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3949 | ALOGE("setTransactionState timed out!"); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3950 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3951 | } |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3952 | |
Arthur Hung | 2274a31 | 2021-04-28 15:13:06 +0000 | [diff] [blame] | 3953 | void SurfaceFlinger::signalSynchronousTransactions(const uint32_t flag) { |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3954 | for (auto it = mTransactionCommittedSignals.begin(); |
| 3955 | it != mTransactionCommittedSignals.end();) { |
Arthur Hung | 2274a31 | 2021-04-28 15:13:06 +0000 | [diff] [blame] | 3956 | if ((*it)->countDown(flag)) { |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3957 | it = mTransactionCommittedSignals.erase(it); |
| 3958 | } else { |
| 3959 | it++; |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | } |
| 3963 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 3964 | status_t SurfaceFlinger::setTransactionState( |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 3965 | const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 3966 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
| 3967 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 3968 | bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, |
Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 3969 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 3970 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 3971 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 3972 | uint32_t permissions = |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 3973 | callingThreadHasUnscopedSurfaceFlingerAccess() ? |
| 3974 | layer_state_t::Permission::ACCESS_SURFACE_FLINGER : 0; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 3975 | // Avoid checking for rotation permissions if the caller already has ACCESS_SURFACE_FLINGER |
| 3976 | // permissions. |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 3977 | if ((permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 3978 | callingThreadHasRotateSurfaceFlingerAccess()) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 3979 | permissions |= layer_state_t::Permission::ROTATE_SURFACE_FLINGER; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 3980 | } |
| 3981 | |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 3982 | if (callingThreadHasInternalSystemWindowAccess()) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 3983 | permissions |= layer_state_t::Permission::INTERNAL_SYSTEM_WINDOW; |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 3986 | if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) && |
Ady Abraham | 8cbd307 | 2021-03-15 16:39:06 -0700 | [diff] [blame] | 3987 | (flags & (eEarlyWakeupStart | eEarlyWakeupEnd))) { |
| 3988 | ALOGE("Only WindowManager is allowed to use eEarlyWakeup[Start|End] flags"); |
| 3989 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3990 | } |
| 3991 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 3992 | const int64_t postTime = systemTime(); |
| 3993 | |
| 3994 | IPCThreadState* ipc = IPCThreadState::self(); |
| 3995 | const int originPid = ipc->getCallingPid(); |
| 3996 | const int originUid = ipc->getCallingUid(); |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 3997 | TransactionState state{frameTimelineInfo, states, |
| 3998 | displays, flags, |
| 3999 | applyToken, inputWindowCommands, |
| 4000 | desiredPresentTime, isAutoTimestamp, |
| 4001 | uncacheBuffer, postTime, |
| 4002 | permissions, hasListenerCallbacks, |
| 4003 | listenerCallbacks, originPid, |
| 4004 | originUid, transactionId}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4005 | |
| 4006 | // Check for incoming buffer updates and increment the pending buffer count. |
| 4007 | state.traverseStatesWithBuffers([&](const layer_state_t& state) { |
| 4008 | mBufferCountTracker.increment(state.surface->localBinder()); |
| 4009 | }); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4010 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4011 | if (mTransactionTracing) { |
| 4012 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4013 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4014 | queueTransaction(state); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4015 | |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4016 | // Check the pending state to make sure the transaction is synchronous. |
| 4017 | if (state.transactionCommittedSignal) { |
| 4018 | waitForSynchronousTransaction(*state.transactionCommittedSignal); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4021 | return NO_ERROR; |
| 4022 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4023 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4024 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4025 | Vector<ComposerState>& states, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4026 | const Vector<DisplayState>& displays, uint32_t flags, |
| 4027 | const InputWindowCommands& inputWindowCommands, |
| 4028 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4029 | const client_cache_t& uncacheBuffer, |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4030 | const int64_t postTime, uint32_t permissions, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4031 | bool hasListenerCallbacks, |
| 4032 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4033 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4034 | uint32_t transactionFlags = 0; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 4035 | for (const DisplayState& display : displays) { |
| 4036 | transactionFlags |= setDisplayStateLocked(display); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4039 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4040 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4041 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4042 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4043 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4046 | uint32_t clientStateFlags = 0; |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4047 | for (int i = 0; i < states.size(); i++) { |
| 4048 | ComposerState& state = states.editItemAt(i); |
| 4049 | clientStateFlags |= setClientStateLocked(frameTimelineInfo, state, desiredPresentTime, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4050 | isAutoTimestamp, postTime, permissions); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4051 | if ((flags & eAnimation) && state.state.surface) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4052 | if (const auto layer = fromHandle(state.state.surface).promote()) { |
| 4053 | using LayerUpdateType = scheduler::LayerHistory::LayerUpdateType; |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 4054 | mScheduler->recordLayerHistory(layer.get(), |
| 4055 | isAutoTimestamp ? 0 : desiredPresentTime, |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4056 | LayerUpdateType::AnimationTX); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4057 | } |
| 4058 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4061 | transactionFlags |= clientStateFlags; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 4062 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4063 | if (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 4064 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
| 4065 | } else if (!inputWindowCommands.empty()) { |
| 4066 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4067 | } |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4068 | |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 4069 | if (uncacheBuffer.isValid()) { |
| 4070 | ClientCache::getInstance().erase(uncacheBuffer); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4073 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4074 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4075 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4076 | // transaction for empty animation transactions. |
| 4077 | if (transactionFlags == 0 && |
| 4078 | ((flags & eSynchronous) || (flags & eAnimation))) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4079 | transactionFlags = eTransactionNeeded; |
| 4080 | } |
| 4081 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4082 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4083 | if (transactionFlags) { |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4084 | if (mInterceptor->isEnabled()) { |
| 4085 | mInterceptor->saveTransaction(states, mCurrentState.displays, displays, flags, |
Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 4086 | originPid, originUid, transactionId); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4087 | } |
| 4088 | |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4089 | // We are on the main thread, we are about to preform a traversal. Clear the traversal bit |
| 4090 | // so we don't have to wake up again next frame to preform an unnecessary traversal. |
| 4091 | if (transactionFlags & eTraversalNeeded) { |
| 4092 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4093 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4094 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4095 | if (transactionFlags) { |
| 4096 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4097 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4099 | |
| 4100 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | } |
| 4102 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4103 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4104 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4105 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4106 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4107 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4108 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4109 | |
| 4110 | const uint32_t what = s.what; |
| 4111 | if (what & DisplayState::eSurfaceChanged) { |
| 4112 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4113 | state.surface = s.surface; |
| 4114 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4115 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4116 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4117 | if (what & DisplayState::eLayerStackChanged) { |
| 4118 | if (state.layerStack != s.layerStack) { |
| 4119 | state.layerStack = s.layerStack; |
| 4120 | flags |= eDisplayTransactionNeeded; |
| 4121 | } |
| 4122 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4123 | if (what & DisplayState::eFlagsChanged) { |
| 4124 | if (state.flags != s.flags) { |
| 4125 | state.flags = s.flags; |
| 4126 | flags |= eDisplayTransactionNeeded; |
| 4127 | } |
| 4128 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4129 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4130 | if (state.orientation != s.orientation) { |
| 4131 | state.orientation = s.orientation; |
| 4132 | flags |= eDisplayTransactionNeeded; |
| 4133 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4134 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4135 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4136 | flags |= eDisplayTransactionNeeded; |
| 4137 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4138 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 4139 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4140 | flags |= eDisplayTransactionNeeded; |
| 4141 | } |
| 4142 | } |
| 4143 | if (what & DisplayState::eDisplaySizeChanged) { |
| 4144 | if (state.width != s.width) { |
| 4145 | state.width = s.width; |
| 4146 | flags |= eDisplayTransactionNeeded; |
| 4147 | } |
| 4148 | if (state.height != s.height) { |
| 4149 | state.height = s.height; |
| 4150 | flags |= eDisplayTransactionNeeded; |
| 4151 | } |
| 4152 | } |
| 4153 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4154 | return flags; |
| 4155 | } |
| 4156 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4157 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4158 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4159 | const int pid = ipc->getCallingPid(); |
| 4160 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4161 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4162 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 4163 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4164 | return false; |
| 4165 | } |
| 4166 | return true; |
| 4167 | } |
| 4168 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4169 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4170 | ComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4171 | int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4172 | int64_t postTime, uint32_t permissions) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4173 | layer_state_t& s = composerState.state; |
| 4174 | s.sanitize(permissions); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4175 | |
| 4176 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4177 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4178 | // Starts a registration but separates the callback ids according to callback type. This |
| 4179 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4180 | // note that startRegistration will not re-register if the listener has |
| 4181 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4182 | |
| 4183 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 4184 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4185 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 4189 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4190 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4191 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4194 | const uint64_t what = s.what; |
| 4195 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4196 | sp<Layer> layer = nullptr; |
| 4197 | if (s.surface) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4198 | layer = fromHandle(s.surface).promote(); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4199 | } else { |
| 4200 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 4201 | ALOGW("Attempt to set client state with a null layer handle"); |
| 4202 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4203 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4204 | for (auto& [listener, callbackIds] : s.listeners) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4205 | mTransactionCallbackInvoker.registerUnpresentedCallbackHandle( |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4206 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 4207 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4208 | return 0; |
| 4209 | } |
| 4210 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 4211 | // Only set by BLAST adapter layers |
| 4212 | if (what & layer_state_t::eProducerDisconnect) { |
| 4213 | layer->onDisconnect(); |
| 4214 | } |
| 4215 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4216 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 4217 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4218 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4219 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4220 | } |
| 4221 | if (what & layer_state_t::eLayerChanged) { |
| 4222 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4223 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4224 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 4225 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4226 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4227 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4228 | mCurrentState.layersSortedByZ.add(layer); |
| 4229 | // we need traversal (state changed) |
| 4230 | // AND transaction (list changed) |
| 4231 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4232 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4233 | } else { |
| 4234 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4235 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4236 | } |
| 4237 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4238 | } |
| 4239 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4240 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4241 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4242 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 4243 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4244 | if (p == nullptr) { |
| 4245 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4246 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 4247 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4248 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4249 | mCurrentState.layersSortedByZ.add(layer); |
| 4250 | // we need traversal (state changed) |
| 4251 | // AND transaction (list changed) |
| 4252 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4253 | } |
| 4254 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4255 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4256 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4257 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4258 | } |
| 4259 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4260 | if (what & layer_state_t::eAlphaChanged) { |
| 4261 | if (layer->setAlpha(s.alpha)) |
| 4262 | flags |= eTraversalNeeded; |
| 4263 | } |
| 4264 | if (what & layer_state_t::eColorChanged) { |
| 4265 | if (layer->setColor(s.color)) |
| 4266 | flags |= eTraversalNeeded; |
| 4267 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 4268 | if (what & layer_state_t::eColorTransformChanged) { |
| 4269 | if (layer->setColorTransform(s.colorTransform)) { |
| 4270 | flags |= eTraversalNeeded; |
| 4271 | } |
| 4272 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 4273 | if (what & layer_state_t::eBackgroundColorChanged) { |
| 4274 | if (layer->setBackgroundColor(s.color, s.bgColorAlpha, s.bgColorDataspace)) { |
| 4275 | flags |= eTraversalNeeded; |
| 4276 | } |
| 4277 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4278 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4279 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4280 | } |
| 4281 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 4282 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 4283 | flags |= eTraversalNeeded; |
| 4284 | } |
| 4285 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4286 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4287 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 4288 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 4289 | if (layer->setCornerRadius(s.cornerRadius)) |
| 4290 | flags |= eTraversalNeeded; |
| 4291 | } |
Galia Peycheva | 33713f7 | 2021-05-27 10:24:20 +0200 | [diff] [blame] | 4292 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4293 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 4294 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 4295 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4296 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 4297 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4298 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 4299 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4300 | flags |= eTraversalNeeded; |
| 4301 | } |
| 4302 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4303 | if (what & layer_state_t::eLayerStackChanged) { |
| 4304 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 4305 | // We only allow setting layer stacks for top level layers, |
| 4306 | // everything else inherits layer stack from its parent. |
| 4307 | if (layer->hasParent()) { |
| 4308 | ALOGE("Attempt to set layer stack on layer with parent (%s) is invalid", |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4309 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4310 | } else if (idx < 0) { |
| 4311 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4312 | "that also does not appear in the top level layer list. Something" |
| 4313 | " has gone wrong.", |
| 4314 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4315 | } else if (layer->setLayerStack(s.layerStack)) { |
| 4316 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4317 | mCurrentState.layersSortedByZ.add(layer); |
| 4318 | // we need traversal (state changed) |
| 4319 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4320 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4321 | } |
| 4322 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4323 | if (what & layer_state_t::eTransformChanged) { |
| 4324 | if (layer->setTransform(s.transform)) flags |= eTraversalNeeded; |
| 4325 | } |
| 4326 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 4327 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 4328 | flags |= eTraversalNeeded; |
| 4329 | } |
| 4330 | if (what & layer_state_t::eCropChanged) { |
| 4331 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 4332 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4333 | if (what & layer_state_t::eDataspaceChanged) { |
| 4334 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 4335 | } |
| 4336 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 4337 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 4338 | } |
| 4339 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 4340 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 4341 | } |
| 4342 | if (what & layer_state_t::eApiChanged) { |
| 4343 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 4344 | } |
| 4345 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 4346 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 4347 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4348 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4349 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 4350 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4351 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 4352 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4353 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4354 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4355 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4356 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 4357 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4358 | // The transaction will be received on the Task layer and needs to be applied to all |
| 4359 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 4360 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4361 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4362 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4363 | |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4364 | if (layer->setMetadata(s.metadata)) flags |= eTraversalNeeded; |
| 4365 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 4366 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 4367 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 4368 | flags |= eTraversalNeeded; |
| 4369 | } |
| 4370 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 4371 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 4372 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 4373 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 4374 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 4375 | const auto compatibility = |
| 4376 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 4377 | |
| 4378 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 4379 | flags |= eTraversalNeeded; |
| 4380 | } |
| 4381 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4382 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4383 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4384 | flags |= eTraversalNeeded; |
| 4385 | } |
| 4386 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4387 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4388 | const auto compatibility = |
| 4389 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 4390 | const auto strategy = |
| 4391 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 4392 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4393 | if (layer->setFrameRate( |
| 4394 | Layer::FrameRate(Fps::fromValue(s.frameRate), compatibility, strategy))) { |
| 4395 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 4396 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4397 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4398 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 4399 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 4400 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 4401 | } |
| 4402 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 4403 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 4404 | layer->setAutoRefresh(s.autoRefresh); |
| 4405 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 4406 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 4407 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 4408 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 4409 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4410 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 4411 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 4412 | } |
| 4413 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 4414 | if (what & layer_state_t::eStretchChanged) { |
| 4415 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 4416 | flags |= eTraversalNeeded; |
| 4417 | } |
| 4418 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 4419 | if (what & layer_state_t::eBufferCropChanged) { |
| 4420 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 4421 | flags |= eTraversalNeeded; |
| 4422 | } |
| 4423 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4424 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 4425 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 4426 | flags |= eTraversalNeeded; |
| 4427 | } |
| 4428 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 4429 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4430 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 4431 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4432 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 4433 | } |
| 4434 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4435 | // This has to happen after we reparent children because when we reparent to null we remove |
| 4436 | // child layers from current state and remove its relative z. If the children are reparented in |
| 4437 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 4438 | // lose its relative z order. |
| 4439 | if (what & layer_state_t::eReparent) { |
| 4440 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 4441 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 4442 | ? s.parentSurfaceControlForChild->getHandle() |
| 4443 | : nullptr; |
| 4444 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4445 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 4446 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4447 | mCurrentState.layersSortedByZ.remove(layer); |
| 4448 | } |
| 4449 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 4450 | } |
| 4451 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4452 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 4453 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 4454 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4455 | callbackHandles.emplace_back( |
| 4456 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4457 | } |
| 4458 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 4459 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 4460 | if (what & layer_state_t::eBufferChanged) { |
| 4461 | std::shared_ptr<renderengine::ExternalTexture> buffer = |
| 4462 | getExternalTextureFromBufferData(*s.bufferData, layer->getDebugName()); |
| 4463 | if (layer->setBuffer(buffer, *s.bufferData, postTime, desiredPresentTime, isAutoTimestamp, |
| 4464 | dequeueBufferTimestamp, frameTimelineInfo)) { |
| 4465 | flags |= eTraversalNeeded; |
| 4466 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4467 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4468 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 4469 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4470 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4471 | if (layer->setTransactionCompletedListeners(callbackHandles)) flags |= eTraversalNeeded; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4472 | // Do not put anything that updates layer state or modifies flags after |
| 4473 | // setTransactionCompletedListener |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4474 | return flags; |
| 4475 | } |
| 4476 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4477 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4478 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 4479 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4480 | } |
| 4481 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 4482 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
| 4483 | const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle, |
| 4484 | int32_t* outLayerId) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4485 | if (!mirrorFromHandle) { |
| 4486 | return NAME_NOT_FOUND; |
| 4487 | } |
| 4488 | |
| 4489 | sp<Layer> mirrorLayer; |
| 4490 | sp<Layer> mirrorFrom; |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4491 | { |
| 4492 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 4493 | mirrorFrom = fromHandle(mirrorFromHandle).promote(); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4494 | if (!mirrorFrom) { |
| 4495 | return NAME_NOT_FOUND; |
| 4496 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 4497 | LayerCreationArgs mirrorArgs = args; |
| 4498 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
| 4499 | status_t result = createEffectLayer(mirrorArgs, outHandle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4500 | if (result != NO_ERROR) { |
| 4501 | return result; |
| 4502 | } |
| 4503 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4504 | mirrorLayer->setClonedChild(mirrorFrom->createClone()); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
Ady Abraham | 9f0a400 | 2020-10-05 15:47:26 -0700 | [diff] [blame] | 4507 | *outLayerId = mirrorLayer->sequence; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4508 | if (mTransactionTracing) { |
| 4509 | mTransactionTracing->onMirrorLayerAdded((*outHandle)->localBinder(), mirrorLayer->sequence, |
| 4510 | args.name, mirrorFrom->sequence); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 4511 | } |
| 4512 | return addClientLayer(args.client, *outHandle, mirrorLayer /* layer */, nullptr /* parent */, |
Vishnu Nair | 858a3b4 | 2022-01-12 20:42:28 -0800 | [diff] [blame] | 4513 | false /* addToRoot */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 4516 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
| 4517 | sp<IBinder>* outHandle, int32_t* outLayerId) { |
| 4518 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4519 | const int uid = ipc->getCallingUid(); |
| 4520 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 4521 | ALOGE("Permission denied when trying to mirror display"); |
| 4522 | return PERMISSION_DENIED; |
| 4523 | } |
| 4524 | |
| 4525 | ui::LayerStack layerStack; |
| 4526 | sp<Layer> rootMirrorLayer; |
| 4527 | status_t result = 0; |
| 4528 | |
| 4529 | { |
| 4530 | Mutex::Autolock lock(mStateLock); |
| 4531 | |
| 4532 | const auto display = getDisplayDeviceLocked(displayId); |
| 4533 | if (!display) { |
| 4534 | return NAME_NOT_FOUND; |
| 4535 | } |
| 4536 | |
| 4537 | layerStack = display->getLayerStack(); |
| 4538 | LayerCreationArgs mirrorArgs = args; |
| 4539 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
| 4540 | result = createEffectLayer(mirrorArgs, outHandle, &rootMirrorLayer); |
| 4541 | *outLayerId = rootMirrorLayer->sequence; |
| 4542 | result |= addClientLayer(args.client, *outHandle, rootMirrorLayer /* layer */, |
| 4543 | nullptr /* parent */, true /* addToRoot */, |
| 4544 | nullptr /* outTransformHint */); |
| 4545 | } |
| 4546 | |
| 4547 | if (result != NO_ERROR) { |
| 4548 | return result; |
| 4549 | } |
| 4550 | |
| 4551 | if (mTransactionTracing) { |
| 4552 | mTransactionTracing->onLayerAdded((*outHandle)->localBinder(), *outLayerId, args.name, |
| 4553 | args.flags, -1 /* parentId */); |
| 4554 | } |
| 4555 | |
| 4556 | { |
| 4557 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 4558 | mMirrorDisplays.emplace_back(layerStack, *outHandle, args.client); |
| 4559 | } |
| 4560 | |
| 4561 | setTransactionFlags(eTransactionFlushNeeded); |
| 4562 | return NO_ERROR; |
| 4563 | } |
| 4564 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4565 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, sp<IBinder>* outHandle, |
Ady Abraham | 9f0a400 | 2020-10-05 15:47:26 -0700 | [diff] [blame] | 4566 | const sp<IBinder>& parentHandle, int32_t* outLayerId, |
| 4567 | const sp<Layer>& parentLayer, uint32_t* outTransformHint) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 4568 | ALOG_ASSERT(parentLayer == nullptr || parentHandle == nullptr, |
| 4569 | "Expected only one of parentLayer or parentHandle to be non-null. " |
| 4570 | "Programmer error?"); |
| 4571 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4572 | status_t result = NO_ERROR; |
| 4573 | |
| 4574 | sp<Layer> layer; |
| 4575 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4576 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4577 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame^] | 4578 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 4579 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 4580 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 4581 | FMT_FALLTHROUGH; |
| 4582 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4583 | result = createBufferStateLayer(args, outHandle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 4584 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 4585 | if (pendingBufferCounter) { |
| 4586 | std::string counterName = layer->getPendingBufferCounterName(); |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4587 | mBufferCountTracker.add((*outHandle)->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 4588 | pendingBufferCounter); |
| 4589 | } |
| 4590 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4591 | default: |
| 4592 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | break; |
| 4594 | } |
| 4595 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4596 | if (result != NO_ERROR) { |
| 4597 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4599 | |
Vishnu Nair | 858a3b4 | 2022-01-12 20:42:28 -0800 | [diff] [blame] | 4600 | bool addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 4601 | wp<Layer> parent(parentHandle != nullptr ? fromHandle(parentHandle) : parentLayer); |
| 4602 | if (parentHandle != nullptr && parent == nullptr) { |
| 4603 | ALOGE("Invalid parent handle %p.", parentHandle.get()); |
| 4604 | addToRoot = false; |
| 4605 | } |
| 4606 | if (parentLayer != nullptr) { |
| 4607 | addToRoot = false; |
| 4608 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4609 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 4610 | int parentId = -1; |
| 4611 | // We can safely promote the layer in binder thread because we have a strong reference |
| 4612 | // to the layer's handle inside this scope or we were passed in a sp reference to the layer. |
| 4613 | sp<Layer> parentSp = parent.promote(); |
| 4614 | if (parentSp != nullptr) { |
| 4615 | parentId = parentSp->getSequence(); |
| 4616 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4617 | if (mTransactionTracing) { |
| 4618 | mTransactionTracing->onLayerAdded((*outHandle)->localBinder(), layer->sequence, args.name, |
| 4619 | args.flags, parentId); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 4620 | } |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 4621 | |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 4622 | result = addClientLayer(args.client, *outHandle, layer, parent, addToRoot, outTransformHint); |
| 4623 | if (result != NO_ERROR) { |
| 4624 | return result; |
| 4625 | } |
| 4626 | |
Ady Abraham | 9f0a400 | 2020-10-05 15:47:26 -0700 | [diff] [blame] | 4627 | *outLayerId = layer->sequence; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4628 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4629 | } |
| 4630 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4631 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4632 | sp<Layer>* outLayer) { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 4633 | args.textureName = getNewTexture(); |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4634 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4635 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 4636 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 4639 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 4640 | sp<Layer>* outLayer) { |
| 4641 | *outLayer = getFactory().createEffectLayer(args); |
| 4642 | *handle = (*outLayer)->getHandle(); |
| 4643 | return NO_ERROR; |
| 4644 | } |
| 4645 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4646 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4647 | mLayersPendingRemoval.add(layer); |
| 4648 | mLayersRemoved = true; |
| 4649 | setTransactionFlags(eTransactionNeeded); |
| 4650 | } |
| 4651 | |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 4652 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4653 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4654 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 4655 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 4656 | layer.clear(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4657 | if (mTransactionTracing) { |
| 4658 | mTransactionTracing->onHandleRemoved(handle); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 4659 | } |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 4662 | // --------------------------------------------------------------------------- |
| 4663 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4664 | void SurfaceFlinger::onInitializeDisplays() { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4665 | const auto display = getDefaultDisplayDeviceLocked(); |
| 4666 | if (!display) return; |
| 4667 | |
| 4668 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 4669 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 4670 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 4671 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4672 | Vector<ComposerState> state; |
| 4673 | Vector<DisplayState> displays; |
| 4674 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 4675 | d.what = DisplayState::eDisplayProjectionChanged | |
| 4676 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 4677 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4678 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 4679 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4680 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 4681 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4682 | d.width = 0; |
| 4683 | d.height = 0; |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4684 | displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4685 | |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 4686 | nsecs_t now = systemTime(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4687 | |
| 4688 | int64_t transactionId = (((int64_t)mPid) << 32) | mUniqueTransactionId++; |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4689 | // It should be on the main thread, apply it directly. |
| 4690 | applyTransactionState(FrameTimelineInfo{}, state, displays, 0, mInputWindowCommands, |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 4691 | /* desiredPresentTime */ now, true, {}, /* postTime */ now, true, false, |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4692 | {}, mPid, getuid(), transactionId); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4693 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4694 | setPowerModeInternal(display, hal::PowerMode::ON); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 4695 | |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 4696 | mActiveDisplayTransformHint = display->getTransformHint(); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 4700 | // Async since we may be called from the main thread. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4701 | static_cast<void>( |
| 4702 | mScheduler->schedule([this]() FTL_FAKE_GUARD(mStateLock) { onInitializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 4703 | } |
| 4704 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4705 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 4706 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 4707 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4708 | return; |
| 4709 | } |
| 4710 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4711 | const auto displayId = display->getPhysicalId(); |
| 4712 | 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] | 4713 | |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 4714 | std::optional<hal::PowerMode> currentMode = display->getPowerMode(); |
| 4715 | if (currentMode.has_value() && mode == *currentMode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4716 | return; |
| 4717 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4718 | |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 4719 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayToken); |
| 4720 | if (activeDisplay != display && display->isInternal() && activeDisplay && |
| 4721 | activeDisplay->isPoweredOn()) { |
| 4722 | ALOGW("Trying to change power mode on non active display while the active display is ON"); |
| 4723 | } |
| 4724 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4725 | display->setPowerMode(mode); |
| 4726 | |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 4727 | if (mInterceptor->isEnabled()) { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4728 | mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 4729 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 4730 | const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 4731 | if (*currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 4732 | // Turn on the display |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 4733 | if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 4734 | onActiveDisplayChangedLocked(display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 4735 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 4736 | // Keep uclamp in a separate syscall and set it before changing to RT due to b/190237315. |
| 4737 | // We can merge the syscall later. |
| 4738 | if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) { |
| 4739 | ALOGW("Couldn't set uclamp.min on display on: %s\n", strerror(errno)); |
| 4740 | } |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 4741 | if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) { |
| 4742 | ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno)); |
| 4743 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4744 | getHwComposer().setPowerMode(displayId, mode); |
Ady Abraham | adc914c | 2021-10-13 17:04:27 -0700 | [diff] [blame] | 4745 | if (isDisplayActiveLocked(display) && mode != hal::PowerMode::DOZE_SUSPEND) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 4746 | setHWCVsyncEnabled(displayId, mHWCVsyncPendingState); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4747 | mScheduler->onScreenAcquired(mAppConnectionHandle); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 4748 | mScheduler->resyncToHardwareVsync(true, refreshRate); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4749 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4751 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4752 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4753 | } else if (mode == hal::PowerMode::OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 4754 | // Turn off the display |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 4755 | if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) { |
| 4756 | ALOGW("Couldn't set SCHED_OTHER on display off: %s\n", strerror(errno)); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 4757 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 4758 | if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { |
| 4759 | ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); |
| 4760 | } |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 4761 | if (isDisplayActiveLocked(display) && *currentMode != hal::PowerMode::DOZE_SUSPEND) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4762 | mScheduler->disableHardwareVsync(true); |
| 4763 | mScheduler->onScreenReleased(mAppConnectionHandle); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 4764 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4765 | |
Ady Abraham | 27c7021 | 2019-06-11 10:52:26 -0700 | [diff] [blame] | 4766 | // Make sure HWVsync is disabled before turning off the display |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 4767 | setHWCVsyncEnabled(displayId, hal::Vsync::DISABLE); |
Ady Abraham | 27c7021 | 2019-06-11 10:52:26 -0700 | [diff] [blame] | 4768 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4769 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4770 | mVisibleRegionsDirty = true; |
| 4771 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4772 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4773 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4774 | getHwComposer().setPowerMode(displayId, mode); |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 4775 | if (isDisplayActiveLocked(display) && *currentMode == hal::PowerMode::DOZE_SUSPEND) { |
Yifei Zhang | f0bd62e | 2021-06-16 15:27:05 -0700 | [diff] [blame] | 4776 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 4777 | mVisibleRegionsDirty = true; |
| 4778 | scheduleRepaint(); |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4779 | mScheduler->onScreenAcquired(mAppConnectionHandle); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 4780 | mScheduler->resyncToHardwareVsync(true, refreshRate); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4781 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4782 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4783 | // Leave display going to doze |
Ady Abraham | adc914c | 2021-10-13 17:04:27 -0700 | [diff] [blame] | 4784 | if (isDisplayActiveLocked(display)) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4785 | mScheduler->disableHardwareVsync(true); |
| 4786 | mScheduler->onScreenReleased(mAppConnectionHandle); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 4787 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4788 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 4789 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 4790 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4791 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4792 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4793 | |
Ady Abraham | adc914c | 2021-10-13 17:04:27 -0700 | [diff] [blame] | 4794 | if (isDisplayActiveLocked(display)) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 4795 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4796 | mRefreshRateStats->setPowerMode(mode); |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame] | 4797 | mScheduler->setDisplayPowerMode(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4800 | 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] | 4801 | } |
| 4802 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4803 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4804 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 4805 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 4806 | if (!display) { |
| 4807 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 4808 | displayToken.get()); |
| 4809 | } else if (display->isVirtual()) { |
| 4810 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 4811 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 4812 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 4813 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 4814 | }); |
| 4815 | |
| 4816 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4819 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4820 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 4821 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 4822 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4823 | const int pid = ipc->getCallingPid(); |
| 4824 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 4825 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 4826 | if ((uid != AID_SHELL) && |
| 4827 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4828 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 4829 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4831 | static const std::unordered_map<std::string, Dumper> dumpers = { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 4832 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4833 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 4834 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 4835 | {"--dispsync"s, dumper([this](std::string& s) { mScheduler->dumpVsync(s); })}, |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 4836 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4837 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 4838 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 4839 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 4840 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4841 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4842 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVSync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4843 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 4844 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 4845 | {"--hwclayers"s, dumper(&SurfaceFlinger::dumpHwcLayersMinidumpLocked)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4846 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4847 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4848 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4849 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4850 | bool dumpLayers = true; |
| 4851 | { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4852 | TimedLock lock(mStateLock, s2ns(1), __func__); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4853 | if (!lock.locked()) { |
| 4854 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 4855 | strerror(-lock.status), lock.status); |
| 4856 | } |
| 4857 | |
| 4858 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 4859 | (it->second)(args, asProto, result); |
| 4860 | dumpLayers = false; |
| 4861 | } else if (!asProto) { |
| 4862 | dumpAllLocked(args, result); |
| 4863 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4866 | if (dumpLayers) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 4867 | LayersTraceFileProto traceFileProto = mLayerTracing.createTraceFileProto(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 4868 | LayersTraceProto* layersTrace = traceFileProto.add_entry(); |
| 4869 | LayersProto layersProto = dumpProtoFromMainThread(); |
| 4870 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 4871 | dumpDisplayProto(*layersTrace); |
| 4872 | |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 4873 | if (asProto) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 4874 | result.append(traceFileProto.SerializeAsString()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 4875 | } else { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 4876 | // Dump info that we need to access from the main thread |
chaviw | a2b9fab | 2021-09-08 14:46:30 -0500 | [diff] [blame] | 4877 | const auto layerTree = LayerProtoParser::generateLayerTree(layersTrace->layers()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 4878 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
| 4879 | result.append("\n"); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 4880 | dumpOffscreenLayers(result); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 4881 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 4882 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4884 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4885 | return NO_ERROR; |
| 4886 | } |
| 4887 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 4888 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4889 | if (asProto) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 4890 | mLayerTracing.writeToFile(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4891 | if (mTransactionTracing) { |
| 4892 | mTransactionTracing->writeToFile(); |
| 4893 | } |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | return doDump(fd, DumpArgs(), asProto); |
| 4897 | } |
| 4898 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4899 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4900 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4901 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4902 | } |
| 4903 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4904 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 4905 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 4906 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 4907 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 4908 | const auto name = String8(args[1]); |
| 4909 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
| 4910 | if (layer->getName() == name.string()) { |
| 4911 | layer->dumpFrameStats(result); |
| 4912 | } |
| 4913 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 4914 | } |
| 4915 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4916 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4917 | const bool clearAll = args.size() < 2; |
| 4918 | const auto name = clearAll ? String8() : String8(args[1]); |
| 4919 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4920 | mCurrentState.traverse([&](Layer* layer) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4921 | if (clearAll || layer->getName() == name.string()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 4922 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4923 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4924 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 4925 | } |
| 4926 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 4927 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 4928 | mTimeStats->parseArgs(asProto, args, result); |
| 4929 | } |
| 4930 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 4931 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 4932 | mFrameTimeline->parseArgs(args, result); |
| 4933 | } |
| 4934 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 4935 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 4936 | static TimePoint sTimestamp = now; |
| 4937 | if (now - sTimestamp < 30min) return; |
| 4938 | sTimestamp = now; |
| 4939 | |
| 4940 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 4941 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4944 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 4945 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 4946 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4947 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 4948 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 4949 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 4950 | getHwComposer().getMaxVirtualDisplayDimension()); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4951 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
| 4952 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
| 4953 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 4954 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4957 | void SurfaceFlinger::dumpVSync(std::string& result) const { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 4958 | mScheduler->dump(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 4959 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4960 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 4961 | result.append("\n"); |
| 4962 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 4963 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4964 | StringAppendF(&result, |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 4965 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 " ns\n\n", |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 4966 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4967 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 4968 | StringAppendF(&result, "(mode override by backdoor: %s)\n\n", |
| 4969 | mDebugDisplayModeSetByBackdoor ? "yes" : "no"); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 4970 | |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 4971 | mScheduler->dump(mAppConnectionHandle, result); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 4972 | mScheduler->dumpVsync(result); |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 4973 | StringAppendF(&result, "mHWCVsyncPendingState=%s mLastHWCVsyncState=%s\n", |
| 4974 | to_string(mHWCVsyncPendingState).c_str(), to_string(mLastHWCVsyncState).c_str()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 4977 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 4978 | for (const auto& [token, display] : mDisplays) { |
| 4979 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 4980 | compositionDisplay->dumpPlannerInfo(args, result); |
| 4981 | } |
| 4982 | } |
| 4983 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 4984 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 4985 | for (const auto& [token, display] : mDisplays) { |
| 4986 | display->getCompositionDisplay()->dump(result); |
| 4987 | result += '\n'; |
| 4988 | } |
| 4989 | } |
| 4990 | |
| 4991 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
| 4992 | for (const auto& [token, display] : mDisplays) { |
| 4993 | display->dump(result); |
| 4994 | result += '\n'; |
| 4995 | } |
| 4996 | } |
| 4997 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 4998 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4999 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5000 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5001 | if (!displayId) { |
| 5002 | continue; |
| 5003 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5004 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5005 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5006 | continue; |
| 5007 | } |
| 5008 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5009 | StringAppendF(&result, |
| 5010 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 5011 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5012 | uint8_t port; |
| 5013 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5014 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5015 | result.append("no identification data\n"); |
| 5016 | continue; |
| 5017 | } |
| 5018 | |
| 5019 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5020 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5021 | continue; |
| 5022 | } |
| 5023 | |
| 5024 | const auto edid = parseEdid(data); |
| 5025 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5026 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5027 | continue; |
| 5028 | } |
| 5029 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5030 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5031 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 5032 | result.append("\"\n"); |
| 5033 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5034 | } |
| 5035 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5036 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 5037 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 5038 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5039 | uint8_t port; |
| 5040 | DisplayIdentificationData data; |
| 5041 | |
| 5042 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 5043 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 5044 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 5045 | } |
| 5046 | } |
| 5047 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5048 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 5049 | StringAppendF(&result, "Device has wide color built-in display: %d\n", hasWideColorDisplay); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5050 | StringAppendF(&result, "Device uses color management: %d\n", useColorManagement); |
| 5051 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 5052 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5053 | |
| 5054 | // TODO: print out if wide-color mode is active or not |
| 5055 | |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 5056 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5057 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5058 | if (!displayId) { |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5059 | continue; |
| 5060 | } |
| 5061 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5062 | StringAppendF(&result, "Display %s color modes:\n", to_string(*displayId).c_str()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5063 | std::vector<ColorMode> modes = getHwComposer().getColorModes(*displayId); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5064 | for (auto&& mode : modes) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5065 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5066 | } |
| 5067 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 5068 | ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5069 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 5070 | decodeColorMode(currentMode).c_str(), currentMode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5071 | } |
| 5072 | result.append("\n"); |
| 5073 | } |
| 5074 | |
Dominik Laskowski | 542c9dc | 2020-04-10 12:42:02 -0700 | [diff] [blame] | 5075 | LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5076 | LayersProto layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 5077 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5078 | layer->writeToProto(layersProto, traceFlags); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 5079 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5080 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5081 | return layersProto; |
| 5082 | } |
| 5083 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5084 | void SurfaceFlinger::dumpDisplayProto(LayersTraceProto& layersTraceProto) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5085 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5086 | DisplayProto* displayProto = layersTraceProto.add_displays(); |
| 5087 | displayProto->set_id(display->getId().value); |
| 5088 | displayProto->set_name(display->getDisplayName()); |
| 5089 | displayProto->set_layer_stack(display->getLayerStack().id); |
| 5090 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 5091 | [&]() { return displayProto->mutable_size(); }); |
| 5092 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 5093 | return displayProto->mutable_layer_stack_space_rect(); |
| 5094 | }); |
| 5095 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 5096 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 5097 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5098 | } |
| 5099 | } |
| 5100 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5101 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 5102 | getHwComposer().dump(result); |
| 5103 | } |
| 5104 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5105 | void SurfaceFlinger::dumpOffscreenLayersProto(LayersProto& layersProto, uint32_t traceFlags) const { |
| 5106 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 5107 | // it. |
| 5108 | LayerProto* rootProto = layersProto.add_layers(); |
| 5109 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 5110 | rootProto->set_id(offscreenRootLayerId); |
| 5111 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 5112 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5113 | |
| 5114 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5115 | // Add layer as child of the fake root |
| 5116 | rootProto->add_children(offscreenLayer->sequence); |
| 5117 | |
| 5118 | // Add layer |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5119 | LayerProto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5120 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5124 | LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5125 | return mScheduler->schedule([=] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5128 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5129 | auto future = mScheduler->schedule([this] { |
| 5130 | std::string result; |
| 5131 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5132 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 5133 | [&](Layer* layer) { layer->dumpCallingUidPid(result); }); |
| 5134 | } |
| 5135 | return result; |
| 5136 | }); |
| 5137 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5138 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5139 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5142 | void SurfaceFlinger::dumpHwcLayersMinidumpLocked(std::string& result) const { |
| 5143 | for (const auto& [token, display] : mDisplays) { |
| 5144 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 5145 | if (!displayId) { |
| 5146 | continue; |
| 5147 | } |
| 5148 | |
| 5149 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 5150 | (isDisplayActiveLocked(display) ? "active" : "inactive")); |
| 5151 | Layer::miniDumpHeader(result); |
| 5152 | |
| 5153 | const DisplayDevice& ref = *display; |
| 5154 | mCurrentState.traverseInZOrder([&](Layer* layer) { layer->miniDump(result, ref); }); |
| 5155 | result.append("\n"); |
| 5156 | } |
| 5157 | } |
| 5158 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5159 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, std::string& result) const { |
| 5160 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5161 | Colorizer colorizer(colorize); |
| 5162 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5163 | // figure out if we're stuck somewhere |
| 5164 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5165 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5166 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 5167 | |
| 5168 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5169 | * Dump library configuration. |
| 5170 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5171 | |
| 5172 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5173 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5174 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5175 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5176 | result.append("\n"); |
| 5177 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5178 | result.append("\nDisplay identification data:\n"); |
| 5179 | dumpDisplayIdentificationData(result); |
| 5180 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5181 | result.append("\nWide-Color information:\n"); |
| 5182 | dumpWideColorInfo(result); |
| 5183 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5184 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5185 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5186 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5187 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5188 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5189 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5190 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5191 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5192 | colorizer.reset(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5193 | dumpVSync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 5194 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5195 | |
Alec Mouri | 40189b0 | 2019-03-05 15:07:54 -0800 | [diff] [blame] | 5196 | StringAppendF(&result, "Total missed frame count: %u\n", mFrameMissedCount.load()); |
| 5197 | StringAppendF(&result, "HWC missed frame count: %u\n", mHwcFrameMissedCount.load()); |
| 5198 | StringAppendF(&result, "GPU missed frame count: %u\n\n", mGpuFrameMissedCount.load()); |
Marissa Wall | cfcdaa5 | 2018-05-21 15:45:59 -0700 | [diff] [blame] | 5199 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5200 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5201 | * Dump the visible layer list |
| 5202 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5203 | colorizer.bold(result); |
chaviw | eadf0d4 | 2019-08-12 13:28:29 -0700 | [diff] [blame] | 5204 | StringAppendF(&result, "Visible layers (count = %zu)\n", mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5205 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5206 | |
Chia-I Wu | 2f88413 | 2018-09-13 15:17:58 -0700 | [diff] [blame] | 5207 | { |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 5208 | StringAppendF(&result, "Composition layers\n"); |
| 5209 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 5210 | auto* compositionState = layer->getCompositionState(); |
Vishnu Nair | 4952917 | 2020-02-25 10:19:44 -0800 | [diff] [blame] | 5211 | if (!compositionState || !compositionState->isVisible) return; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 5212 | |
| 5213 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 5214 | layer->getDebugName() ? layer->getDebugName() |
| 5215 | : "<unknown>"); |
| 5216 | compositionState->dump(result); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 5217 | }); |
| 5218 | } |
| 5219 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5220 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5221 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5222 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5223 | dumpDisplays(result); |
| 5224 | dumpCompositionDisplays(result); |
| 5225 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 5226 | |
| 5227 | mCompositionEngine->dump(result); |
| 5228 | |
| 5229 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5230 | * Dump SurfaceFlinger global state |
| 5231 | */ |
| 5232 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5233 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 5234 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5235 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5236 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 5237 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5238 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 5239 | result.append("ClientCache state:\n"); |
| 5240 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 5241 | DebugEGLImageTracker::getInstance()->dump(result); |
| 5242 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5243 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 5244 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 5245 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5246 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 5247 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 5248 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5249 | StringAppendF(&result, |
| 5250 | " transaction-flags : %08x\n" |
| 5251 | " gpu_to_cpu_unsupported : %d\n", |
| 5252 | mTransactionFlags.load(), !mGpuToCpuSupported); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5253 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 5254 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5255 | std::string fps, xDpi, yDpi; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 5256 | if (const auto activeMode = display->getActiveMode()) { |
| 5257 | fps = to_string(activeMode->getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 5258 | |
| 5259 | const auto dpi = activeMode->getDpi(); |
| 5260 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 5261 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5262 | } else { |
| 5263 | fps = "unknown"; |
| 5264 | xDpi = "unknown"; |
| 5265 | yDpi = "unknown"; |
| 5266 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5267 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5268 | " refresh-rate : %s\n" |
| 5269 | " x-dpi : %s\n" |
| 5270 | " y-dpi : %s\n", |
| 5271 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5272 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5273 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5274 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5275 | |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 5276 | /* |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5277 | * Tracing state |
| 5278 | */ |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5279 | mLayerTracing.dump(result); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5280 | |
| 5281 | result.append("\nTransaction tracing: "); |
| 5282 | if (mTransactionTracing) { |
| 5283 | result.append("enabled\n"); |
| 5284 | mTransactionTracing->dump(result); |
| 5285 | } else { |
| 5286 | result.append("disabled\n"); |
| 5287 | } |
| 5288 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5289 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5290 | dumpHwcLayersMinidumpLocked(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5291 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 5292 | { |
| 5293 | DumpArgs plannerArgs; |
| 5294 | plannerArgs.add(); // first argument is ignored |
| 5295 | plannerArgs.add(String16("--layers")); |
| 5296 | dumpPlannerInfo(plannerArgs, result); |
| 5297 | } |
| 5298 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5299 | /* |
| 5300 | * Dump HWComposer state |
| 5301 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5302 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 5303 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5304 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5305 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5306 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 5307 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5308 | |
| 5309 | /* |
| 5310 | * Dump gralloc state |
| 5311 | */ |
| 5312 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 5313 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 5314 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 5315 | /* |
| 5316 | * Dump flag/property manager state |
| 5317 | */ |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 5318 | mFlagManager.dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 5319 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 5320 | result.append(mTimeStats->miniDump()); |
| 5321 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5322 | } |
| 5323 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 5324 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 5325 | if (saturation == 1) { |
| 5326 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5327 | } |
| 5328 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 5329 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 5330 | luminance *= 1.0f - saturation; |
| 5331 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 5332 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 5333 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 5334 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 5335 | return saturationMatrix; |
| 5336 | } |
| 5337 | |
| 5338 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 5339 | mat4 colorMatrix = |
| 5340 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 5341 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5342 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 5343 | mCurrentState.colorMatrix = colorMatrix; |
| 5344 | mCurrentState.colorMatrixChanged = true; |
| 5345 | setTransactionFlags(eTransactionNeeded); |
| 5346 | } |
| 5347 | } |
| 5348 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 5349 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5350 | #pragma clang diagnostic push |
| 5351 | #pragma clang diagnostic error "-Wswitch-enum" |
| 5352 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 5353 | // These methods should at minimum make sure that the client requested |
| 5354 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5355 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 5356 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 5357 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5358 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5359 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 5360 | // permission dynamically. Don't use the permission cache for this check. |
| 5361 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5362 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5363 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5364 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 5365 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 5366 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5367 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 5368 | return OK; |
| 5369 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5370 | // The following calls are currently used by clients that do not |
| 5371 | // request necessary permissions. However, they do not expose any secret |
| 5372 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 5373 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 5374 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5375 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 5376 | case GET_DISPLAY_MODES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5377 | // Calling setTransactionState is safe, because you need to have been |
| 5378 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5379 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 5380 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5381 | return OK; |
| 5382 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 5383 | case BOOT_FINISHED: |
| 5384 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 5385 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5386 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 5387 | case CREATE_DISPLAY: |
| 5388 | case DESTROY_DISPLAY: |
| 5389 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 5390 | case GET_PHYSICAL_DISPLAY_IDS: |
| 5391 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 5392 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 5393 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 5394 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 5395 | case GET_DISPLAY_STATE: |
| 5396 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 5397 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 5398 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 5399 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 5400 | case SET_ACTIVE_COLOR_MODE: |
| 5401 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 5402 | case CLEAR_BOOT_DISPLAY_MODE: |
| 5403 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 5404 | case SET_AUTO_LOW_LATENCY_MODE: |
| 5405 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 5406 | case CAPTURE_LAYERS: |
| 5407 | case CAPTURE_DISPLAY: |
| 5408 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 5409 | case CLEAR_ANIMATION_FRAME_STATS: |
| 5410 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 5411 | case OVERRIDE_HDR_TYPES: |
| 5412 | case ON_PULL_ATOM: |
| 5413 | case ENABLE_VSYNC_INJECTIONS: |
| 5414 | case INJECT_VSYNC: |
| 5415 | case GET_LAYER_DEBUG_INFO: |
| 5416 | case GET_COLOR_MANAGEMENT: |
| 5417 | case GET_COMPOSITION_PREFERENCE: |
| 5418 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 5419 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 5420 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 5421 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 5422 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 5423 | case ADD_REGION_SAMPLING_LISTENER: |
| 5424 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 5425 | case ADD_FPS_LISTENER: |
| 5426 | case REMOVE_FPS_LISTENER: |
| 5427 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 5428 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 5429 | case ADD_WINDOW_INFOS_LISTENER: |
| 5430 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 5431 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 5432 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 5433 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 5434 | case SET_DISPLAY_BRIGHTNESS: |
| 5435 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 5436 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 5437 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 5438 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 5439 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 5440 | case SET_FRAME_RATE: |
| 5441 | case SET_OVERRIDE_FRAME_RATE: |
| 5442 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 5443 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 5444 | case GET_GPU_CONTEXT_PRIORITY: |
| 5445 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 5446 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 5447 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5449 | |
| 5450 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 5451 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 5452 | // We let them pass by default. |
| 5453 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 5454 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 5455 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 5456 | return OK; |
| 5457 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 5458 | // Numbers from 1000 to 1042 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5459 | // in onTransact verifies that the user is root, and has access to use SF. |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 5460 | if (code >= 1000 && code <= 1042) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5461 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 5462 | return OK; |
| 5463 | } |
| 5464 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 5465 | return PERMISSION_DENIED; |
| 5466 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 5469 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 5470 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5471 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 5472 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 5473 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 5474 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 5476 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 5477 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 5478 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5479 | const int uid = ipc->getCallingUid(); |
| 5480 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 5481 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 5482 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 5483 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 5484 | "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] | 5485 | return PERMISSION_DENIED; |
| 5486 | } |
| 5487 | int n; |
| 5488 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5489 | case 1000: // Unused. |
| 5490 | case 1001: |
| 5491 | return NAME_NOT_FOUND; |
| 5492 | case 1002: // Toggle flashing on surface damage. |
| 5493 | if (const int delay = data.readInt32(); delay > 0) { |
| 5494 | mDebugFlashDelay = delay; |
| 5495 | } else { |
| 5496 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 5497 | } |
| 5498 | scheduleRepaint(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5500 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 5501 | case 1006: |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5502 | scheduleComposite(FrameHint::kActive); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5504 | case 1005: { // Force commit ahead of next VSYNC. |
| 5505 | Mutex::Autolock lock(mStateLock); |
| 5506 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | |
| 5507 | eTraversalNeeded); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 5508 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5510 | case 1007: // Unused. |
| 5511 | return NAME_NOT_FOUND; |
| 5512 | case 1008: // Toggle forced GPU composition. |
| 5513 | mDebugDisableHWC = data.readInt32() != 0; |
| 5514 | scheduleRepaint(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 5515 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5516 | case 1009: // Toggle use of transform hint. |
| 5517 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 5518 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 5519 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5520 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 5521 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5523 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 5524 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 5525 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5527 | case 1013: // Unused. |
| 5528 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5529 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5530 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5531 | // daltonize |
| 5532 | n = data.readInt32(); |
| 5533 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5534 | case 1: |
| 5535 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 5536 | break; |
| 5537 | case 2: |
| 5538 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 5539 | break; |
| 5540 | case 3: |
| 5541 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 5542 | break; |
| 5543 | default: |
| 5544 | mDaltonizer.setType(ColorBlindnessType::None); |
| 5545 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5546 | } |
| 5547 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5548 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5549 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5550 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 5551 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5552 | |
| 5553 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5554 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5556 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5557 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5558 | // apply a color matrix |
| 5559 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5560 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5561 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 5562 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5563 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5564 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 5565 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5566 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5567 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5568 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5569 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 5570 | |
| 5571 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 5572 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5573 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 5574 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 5575 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 5576 | } |
| 5577 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5578 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 5579 | return NO_ERROR; |
| 5580 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 5581 | case 1016: { // Unused. |
| 5582 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 5583 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 5584 | case 1017: { |
| 5585 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 5586 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 5587 | return NO_ERROR; |
| 5588 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 5589 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5590 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 5591 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5592 | return NO_ERROR; |
| 5593 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 5594 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5595 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 5596 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 5597 | return NO_ERROR; |
| 5598 | } |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5599 | case 1020: { // Layer updates interceptor |
| 5600 | n = data.readInt32(); |
| 5601 | if (n) { |
| 5602 | ALOGV("Interceptor enabled"); |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 5603 | mInterceptor->enable(mDrawingState.layersSortedByZ, mDrawingState.displays); |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5604 | } |
| 5605 | else{ |
| 5606 | ALOGV("Interceptor disabled"); |
Lloyd Pique | 4dccc41 | 2018-01-22 17:21:36 -0800 | [diff] [blame] | 5607 | mInterceptor->disable(); |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 5608 | } |
| 5609 | return NO_ERROR; |
| 5610 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 5611 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5612 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5613 | static_cast<void>( |
| 5614 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 5615 | return NO_ERROR; |
| 5616 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5617 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5618 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5619 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5620 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 5621 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 5622 | return NO_ERROR; |
| 5623 | } |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5624 | case 1023: { // Set native mode |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 5625 | int32_t colorMode; |
| 5626 | |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5627 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 5628 | if (data.readInt32(&colorMode) == NO_ERROR) { |
| 5629 | mForceColorMode = static_cast<ColorMode>(colorMode); |
| 5630 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5631 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5632 | return NO_ERROR; |
| 5633 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 5634 | // Deprecate, use 1030 to check whether the device is color managed. |
| 5635 | case 1024: { |
| 5636 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 5637 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 5638 | case 1025: { // Set layer tracing |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5639 | n = data.readInt32(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 5640 | bool tracingEnabledChanged; |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5641 | if (n == 1) { |
| 5642 | int64_t fixedStartingTime = data.readInt64(); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5643 | ALOGD("LayerTracing enabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5644 | tracingEnabledChanged = mLayerTracing.enable(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 5645 | if (tracingEnabledChanged) { |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 5646 | int64_t startingTime = |
| 5647 | (fixedStartingTime) ? fixedStartingTime : systemTime(); |
| 5648 | mScheduler |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5649 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) { |
Pablo Gamito | b877579 | 2022-06-10 15:02:42 +0000 | [diff] [blame] | 5650 | mLayerTracing.notify(true /* visibleRegionDirty */, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5651 | startingTime, mLastCommittedVsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 5652 | }) |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5653 | .wait(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 5654 | } |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5655 | } else if (n == 2) { |
| 5656 | std::string filename = std::string(data.readCString()); |
| 5657 | ALOGD("LayerTracing disabled. Trace wrote to %s", filename.c_str()); |
| 5658 | tracingEnabledChanged = mLayerTracing.disable(filename.c_str()); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5659 | } else { |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5660 | ALOGD("LayerTracing disabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5661 | tracingEnabledChanged = mLayerTracing.disable(); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5662 | } |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 5663 | mTracingEnabledChanged = tracingEnabledChanged; |
| 5664 | reply->writeInt32(NO_ERROR); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 5665 | return NO_ERROR; |
| 5666 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 5667 | case 1026: { // Get layer tracing status |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5668 | reply->writeBool(mLayerTracing.isEnabled()); |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 5669 | return NO_ERROR; |
| 5670 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5671 | // Is a DisplayColorSetting supported? |
| 5672 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5673 | const auto display = getDefaultDisplayDevice(); |
| 5674 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5675 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5676 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5677 | |
| 5678 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 5679 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 5680 | case DisplayColorSetting::kManaged: |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 5681 | reply->writeBool(useColorManagement); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5682 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 5683 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5684 | reply->writeBool(true); |
| 5685 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 5686 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5687 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5688 | break; |
| 5689 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5690 | reply->writeBool( |
| 5691 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 5692 | break; |
| 5693 | } |
| 5694 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 5695 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 5696 | case 1028: { // Unused. |
| 5697 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 5698 | } |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 5699 | // Set buffer size for SF tracing (value in KB) |
| 5700 | case 1029: { |
| 5701 | n = data.readInt32(); |
| 5702 | if (n <= 0 || n > MAX_TRACING_MEMORY) { |
| 5703 | ALOGW("Invalid buffer size: %d KB", n); |
| 5704 | reply->writeInt32(BAD_VALUE); |
| 5705 | return BAD_VALUE; |
| 5706 | } |
| 5707 | |
| 5708 | ALOGD("Updating trace buffer to %d KB", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5709 | mLayerTracing.setBufferSize(n * 1024); |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 5710 | reply->writeInt32(NO_ERROR); |
| 5711 | return NO_ERROR; |
| 5712 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 5713 | // Is device color managed? |
| 5714 | case 1030: { |
| 5715 | reply->writeBool(useColorManagement); |
| 5716 | return NO_ERROR; |
| 5717 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 5718 | // Override default composition data space |
| 5719 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 5720 | // && adb shell stop zygote && adb shell start zygote |
| 5721 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 5722 | // adb shell stop zygote && adb shell start zygote |
| 5723 | case 1031: { |
| 5724 | Mutex::Autolock _l(mStateLock); |
| 5725 | n = data.readInt32(); |
| 5726 | if (n) { |
| 5727 | n = data.readInt32(); |
| 5728 | if (n) { |
| 5729 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 5730 | if (!validateCompositionDataspace(dataspace)) { |
| 5731 | return BAD_VALUE; |
| 5732 | } |
| 5733 | mDefaultCompositionDataspace = dataspace; |
| 5734 | } |
| 5735 | n = data.readInt32(); |
| 5736 | if (n) { |
| 5737 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 5738 | if (!validateCompositionDataspace(dataspace)) { |
| 5739 | return BAD_VALUE; |
| 5740 | } |
| 5741 | mWideColorGamutCompositionDataspace = dataspace; |
| 5742 | } |
| 5743 | } else { |
| 5744 | // restore composition data space. |
| 5745 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 5746 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
| 5747 | } |
| 5748 | return NO_ERROR; |
| 5749 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 5750 | // Set trace flags |
| 5751 | case 1033: { |
| 5752 | n = data.readUint32(); |
| 5753 | ALOGD("Updating trace flags to 0x%x", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5754 | mLayerTracing.setTraceFlags(n); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 5755 | reply->writeInt32(NO_ERROR); |
| 5756 | return NO_ERROR; |
| 5757 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 5758 | case 1034: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5759 | auto future = mScheduler->schedule([&] { |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 5760 | switch (n = data.readInt32()) { |
| 5761 | case 0: |
| 5762 | case 1: |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5763 | FTL_FAKE_GUARD(mStateLock, |
| 5764 | enableRefreshRateOverlay(static_cast<bool>(n))); |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 5765 | break; |
| 5766 | default: { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5767 | reply->writeBool( |
| 5768 | FTL_FAKE_GUARD(mStateLock, isRefreshRateOverlayEnabled())); |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 5769 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 5770 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5771 | }); |
| 5772 | |
| 5773 | future.wait(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 5774 | return NO_ERROR; |
| 5775 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 5776 | case 1035: { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 5777 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 5778 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 5779 | const auto display = [&]() -> sp<IBinder> { |
| 5780 | uint64_t value; |
| 5781 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5782 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 5783 | } |
| 5784 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 5785 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 5786 | return getPhysicalDisplayToken(*id); |
| 5787 | } |
| 5788 | |
| 5789 | ALOGE("Invalid physical display ID"); |
| 5790 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 5791 | }(); |
| 5792 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 5793 | mDebugDisplayModeSetByBackdoor = false; |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 5794 | const status_t result = setActiveModeFromBackdoor(display, modeId); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 5795 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 5796 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 5797 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5798 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 5799 | // manager frame rate policy a new policy which allows switching between all refresh |
| 5800 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 5801 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5802 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5803 | return mScheduler |
| 5804 | ->schedule([this] { |
| 5805 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5806 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5807 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5808 | // This is a little racy, but not in a way that hurts anything. As |
| 5809 | // we grab the defaultMode from the display manager policy, we could |
| 5810 | // be setting a new display manager policy, leaving us using a stale |
| 5811 | // defaultMode. The defaultMode doesn't matter for the override |
| 5812 | // policy though, since we set allowGroupSwitching to true, so it's |
| 5813 | // not a problem. |
| 5814 | scheduler::RefreshRateConfigs::Policy overridePolicy; |
| 5815 | overridePolicy.defaultMode = display->refreshRateConfigs() |
| 5816 | .getDisplayManagerPolicy() |
| 5817 | .defaultMode; |
| 5818 | overridePolicy.allowGroupSwitching = true; |
| 5819 | constexpr bool kOverridePolicy = true; |
| 5820 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy, |
| 5821 | kOverridePolicy); |
| 5822 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5823 | .get(); |
| 5824 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5825 | return mScheduler |
| 5826 | ->schedule([this] { |
| 5827 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5828 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5829 | constexpr bool kOverridePolicy = true; |
| 5830 | return setDesiredDisplayModeSpecsInternal(display, {}, |
| 5831 | kOverridePolicy); |
| 5832 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 5833 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 5834 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 5835 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 5836 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 5837 | // reallocate the display state including framebuffers. |
| 5838 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 5839 | const hal::HWDisplayId hwcId = |
| 5840 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 5841 | |
| 5842 | onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 5843 | return NO_ERROR; |
| 5844 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 5845 | // Modify the max number of display frames stored within FrameTimeline |
| 5846 | case 1038: { |
| 5847 | n = data.readInt32(); |
| 5848 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 5849 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 5850 | return BAD_VALUE; |
| 5851 | } |
| 5852 | if (n == 0) { |
| 5853 | // restore to default |
| 5854 | mFrameTimeline->reset(); |
| 5855 | return NO_ERROR; |
| 5856 | } |
| 5857 | mFrameTimeline->setMaxDisplayFrames(n); |
| 5858 | return NO_ERROR; |
| 5859 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 5860 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 5861 | PhysicalDisplayId displayId = [&]() { |
| 5862 | Mutex::Autolock lock(mStateLock); |
| 5863 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 5864 | }(); |
| 5865 | |
| 5866 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 5867 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 5868 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 5869 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 5870 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 5871 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 5872 | // Toggle caching feature |
| 5873 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 5874 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 5875 | // caching to a particular physical display |
| 5876 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5877 | auto future = mScheduler->schedule([&] { |
| 5878 | n = data.readInt32(); |
| 5879 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 5880 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 5881 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 5882 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 5883 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 5884 | return NAME_NOT_FOUND; |
| 5885 | } |
| 5886 | } |
| 5887 | { |
| 5888 | Mutex::Autolock lock(mStateLock); |
| 5889 | mLayerCachingEnabled = n != 0; |
| 5890 | for (const auto& [_, display] : mDisplays) { |
| 5891 | if (!inputId || *inputId == display->getPhysicalId()) { |
| 5892 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 5893 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5894 | } |
| 5895 | } |
| 5896 | return OK; |
| 5897 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 5898 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5899 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 5900 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 5901 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 5902 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 5903 | return NO_ERROR; |
| 5904 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5905 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5906 | if (mTransactionTracing) { |
| 5907 | if (data.readInt32()) { |
| 5908 | // Transaction tracing is always running but allow the user to temporarily |
| 5909 | // increase the buffer when actively debugging. |
| 5910 | mTransactionTracing->setBufferSize( |
| 5911 | TransactionTracing::ACTIVE_TRACING_BUFFER_SIZE); |
| 5912 | } else { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5913 | mTransactionTracing->writeToFile(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5914 | mTransactionTracing->setBufferSize( |
| 5915 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5916 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5917 | } |
| 5918 | reply->writeInt32(NO_ERROR); |
| 5919 | return NO_ERROR; |
| 5920 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 5921 | case 1042: { // Write layers trace or transaction trace to file |
| 5922 | if (mTransactionTracing) { |
| 5923 | mTransactionTracing->writeToFile(); |
| 5924 | } |
| 5925 | if (mLayerTracingEnabled) { |
| 5926 | mLayerTracing.writeToFile(); |
| 5927 | } |
| 5928 | reply->writeInt32(NO_ERROR); |
| 5929 | return NO_ERROR; |
| 5930 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | return err; |
| 5934 | } |
| 5935 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 5936 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 5937 | static bool updateOverlay = |
| 5938 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 5939 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 5940 | |
| 5941 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 5942 | // mRefreshRateConfigs->getActiveMode() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5943 | static_cast<void>(mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5944 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 5945 | if (!display) { |
| 5946 | ALOGW("%s: default display is null", __func__); |
| 5947 | return; |
| 5948 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 5949 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 5950 | |
| 5951 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 5952 | const std::optional<DisplayModeId> desiredModeId = desiredActiveMode |
| 5953 | ? std::make_optional(desiredActiveMode->mode->getId()) |
| 5954 | : std::nullopt; |
| 5955 | |
| 5956 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 5957 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 5958 | if (display->onKernelTimerChanged(desiredModeId, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 5959 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 5960 | } |
| 5961 | })); |
| 5962 | } |
| 5963 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 5964 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 5965 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 5966 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 5967 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 5968 | const auto timeout = getIdleTimerTimeout(displayId); |
| 5969 | if (isKernelIdleTimerHwcSupported) { |
| 5970 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 5971 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 5972 | // In order to decide if we can use the HWC api for idle timer |
| 5973 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 5974 | // without relying on hasDisplayCapability. |
| 5975 | // hasDisplayCapability relies on DisplayCapabilities |
| 5976 | // which are updated after we set the PowerMode::ON. |
| 5977 | // DISPLAY_IDLE_TIMER is a display driver property |
| 5978 | // and is available before the PowerMode::ON |
| 5979 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 5980 | } |
| 5981 | return {std::nullopt, timeout}; |
| 5982 | } |
| 5983 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 5984 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 5985 | } |
| 5986 | |
| 5987 | return {std::nullopt, timeout}; |
| 5988 | } |
| 5989 | |
| 5990 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 5991 | KernelIdleTimerController controller, |
| 5992 | PhysicalDisplayId displayId) { |
| 5993 | switch (controller) { |
| 5994 | case KernelIdleTimerController::HwcApi: { |
| 5995 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 5996 | break; |
| 5997 | } |
| 5998 | case KernelIdleTimerController::Sysprop: { |
| 5999 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 6000 | break; |
| 6001 | } |
| 6002 | } |
| 6003 | } |
| 6004 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6005 | void SurfaceFlinger::toggleKernelIdleTimer() { |
| 6006 | using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction; |
| 6007 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6008 | const auto display = getDefaultDisplayDeviceLocked(); |
| 6009 | if (!display) { |
| 6010 | ALOGW("%s: default display is null", __func__); |
| 6011 | return; |
| 6012 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6013 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6014 | // If the support for kernel idle timer is disabled for the active display, |
| 6015 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6016 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
| 6017 | display->refreshRateConfigs().kernelIdleTimerController(); |
| 6018 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6019 | return; |
| 6020 | } |
| 6021 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6022 | const KernelIdleTimerAction action = display->refreshRateConfigs().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6023 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6024 | switch (action) { |
| 6025 | case KernelIdleTimerAction::TurnOff: |
| 6026 | if (mKernelIdleTimerEnabled) { |
| 6027 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6028 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 6029 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 6030 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6031 | mKernelIdleTimerEnabled = false; |
| 6032 | } |
| 6033 | break; |
| 6034 | case KernelIdleTimerAction::TurnOn: |
| 6035 | if (!mKernelIdleTimerEnabled) { |
| 6036 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6037 | const std::chrono::milliseconds timeout = |
| 6038 | display->refreshRateConfigs().getIdleTimerTimeout(); |
| 6039 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 6040 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6041 | mKernelIdleTimerEnabled = true; |
| 6042 | } |
| 6043 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6044 | } |
| 6045 | } |
| 6046 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6047 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 6048 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6049 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6050 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 6051 | ~WindowDisconnector() { |
| 6052 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6055 | private: |
| 6056 | ANativeWindow* mWindow; |
| 6057 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6058 | }; |
| 6059 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6060 | static Dataspace pickDataspaceFromColorMode(const ColorMode colorMode) { |
| 6061 | switch (colorMode) { |
| 6062 | case ColorMode::DISPLAY_P3: |
| 6063 | case ColorMode::BT2100_PQ: |
| 6064 | case ColorMode::BT2100_HLG: |
| 6065 | case ColorMode::DISPLAY_BT2020: |
| 6066 | return Dataspace::DISPLAY_P3; |
| 6067 | default: |
| 6068 | return Dataspace::V0_SRGB; |
| 6069 | } |
| 6070 | } |
| 6071 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6072 | static bool hasCaptureBlackoutContentPermission() { |
| 6073 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6074 | const int pid = ipc->getCallingPid(); |
| 6075 | const int uid = ipc->getCallingUid(); |
| 6076 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 6077 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 6078 | } |
| 6079 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6080 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 6081 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6082 | const int pid = ipc->getCallingPid(); |
| 6083 | const int uid = ipc->getCallingUid(); |
| 6084 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 6085 | return OK; |
| 6086 | } |
| 6087 | |
| 6088 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 6089 | // itself, we allow it to continue. |
| 6090 | if (captureArgs.uid == uid) { |
| 6091 | return OK; |
| 6092 | } |
| 6093 | |
| 6094 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 6095 | return PERMISSION_DENIED; |
| 6096 | } |
| 6097 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6098 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 6099 | static constexpr int kFifoPriority = 2; |
| 6100 | static constexpr int kOtherPriority = 0; |
| 6101 | |
| 6102 | struct sched_param param = {0}; |
| 6103 | int sched_policy; |
| 6104 | if (enabled) { |
| 6105 | sched_policy = SCHED_FIFO; |
| 6106 | param.sched_priority = kFifoPriority; |
| 6107 | } else { |
| 6108 | sched_policy = SCHED_OTHER; |
| 6109 | param.sched_priority = kOtherPriority; |
| 6110 | } |
| 6111 | |
| 6112 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 6113 | return -errno; |
| 6114 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6115 | |
| 6116 | return NO_ERROR; |
| 6117 | } |
| 6118 | |
| 6119 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 6120 | static const unsigned int kUclampMin = |
| 6121 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 6122 | |
| 6123 | if (!kUclampMin) { |
| 6124 | // uclamp.min set to 0 (default), skip setting |
| 6125 | return NO_ERROR; |
| 6126 | } |
| 6127 | |
| 6128 | // Currently, there is no wrapper in bionic: b/183240349. |
| 6129 | struct sched_attr { |
| 6130 | uint32_t size; |
| 6131 | uint32_t sched_policy; |
| 6132 | uint64_t sched_flags; |
| 6133 | int32_t sched_nice; |
| 6134 | uint32_t sched_priority; |
| 6135 | uint64_t sched_runtime; |
| 6136 | uint64_t sched_deadline; |
| 6137 | uint64_t sched_period; |
| 6138 | uint32_t sched_util_min; |
| 6139 | uint32_t sched_util_max; |
| 6140 | }; |
| 6141 | |
| 6142 | sched_attr attr = {}; |
| 6143 | attr.size = sizeof(attr); |
| 6144 | |
| 6145 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 6146 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 6147 | attr.sched_util_max = 1024; |
| 6148 | |
| 6149 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 6150 | return -errno; |
| 6151 | } |
| 6152 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6153 | return NO_ERROR; |
| 6154 | } |
| 6155 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6156 | status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6157 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6158 | ATRACE_CALL(); |
| 6159 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6160 | status_t validate = validateScreenshotPermissions(args); |
| 6161 | if (validate != OK) { |
| 6162 | return validate; |
| 6163 | } |
| 6164 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6165 | if (!args.displayToken) return BAD_VALUE; |
| 6166 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6167 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6168 | ui::LayerStack layerStack; |
| 6169 | ui::Size reqSize(args.width, args.height); |
| 6170 | ui::Dataspace dataspace; |
| 6171 | { |
| 6172 | Mutex::Autolock lock(mStateLock); |
| 6173 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
| 6174 | if (!display) return NAME_NOT_FOUND; |
| 6175 | displayWeak = display; |
| 6176 | layerStack = display->getLayerStack(); |
| 6177 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6178 | // set the requested width/height to the logical display layer stack rect size by default |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6179 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6180 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 6183 | // The dataspace is depended on the color mode of display, that could use non-native mode |
| 6184 | // (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes, |
| 6185 | // and failed if display is not in native mode. This provide a way to force using native |
| 6186 | // colors when capture. |
Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 6187 | dataspace = args.dataspace; |
| 6188 | if (dataspace == ui::Dataspace::UNKNOWN) { |
arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 6189 | const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode; |
| 6190 | dataspace = pickDataspaceFromColorMode(colorMode); |
| 6191 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6194 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6195 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 6196 | args.useIdentityTransform, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6197 | }); |
| 6198 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6199 | auto traverseLayers = [this, args, layerStack](const LayerVector::Visitor& visitor) { |
| 6200 | traverseLayersInLayerStack(layerStack, args.uid, visitor); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6201 | }; |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6202 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6203 | auto future = captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize, |
| 6204 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 6205 | captureListener); |
| 6206 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6207 | } |
| 6208 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6209 | status_t SurfaceFlinger::captureDisplay(DisplayId displayId, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6210 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6211 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6212 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6213 | ui::Size size; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6214 | ui::Dataspace dataspace; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6215 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6216 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6217 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6218 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6219 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6220 | return NAME_NOT_FOUND; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6221 | } |
| 6222 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6223 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6224 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6225 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6226 | |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6227 | dataspace = |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6228 | pickDataspaceFromColorMode(display->getCompositionDisplay()->getState().colorMode); |
| 6229 | } |
| 6230 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6231 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6232 | return DisplayRenderArea::create(displayWeak, Rect(), size, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 6233 | false /* useIdentityTransform */, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6234 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6235 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6236 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6237 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6238 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, visitor); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6239 | }; |
| 6240 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6241 | if (captureListener == nullptr) { |
| 6242 | ALOGE("capture screen must provide a capture listener callback"); |
| 6243 | return BAD_VALUE; |
| 6244 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6245 | |
| 6246 | constexpr bool kAllowProtected = false; |
| 6247 | constexpr bool kGrayscale = false; |
| 6248 | |
| 6249 | auto future = captureScreenCommon(std::move(renderAreaFuture), traverseLayers, size, |
| 6250 | ui::PixelFormat::RGBA_8888, kAllowProtected, kGrayscale, |
| 6251 | captureListener); |
| 6252 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6253 | } |
| 6254 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6255 | status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6256 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6257 | ATRACE_CALL(); |
| 6258 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6259 | status_t validate = validateScreenshotPermissions(args); |
| 6260 | if (validate != OK) { |
| 6261 | return validate; |
| 6262 | } |
| 6263 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6264 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6265 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6266 | Rect crop(args.sourceCrop); |
Huihong Luo | a339d0a | 2022-02-05 09:42:42 -0800 | [diff] [blame] | 6267 | std::unordered_set<sp<Layer>, SpHash<Layer>> excludeLayers; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6268 | ui::Dataspace dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6269 | |
| 6270 | // Call this before holding mStateLock to avoid any deadlocking. |
| 6271 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
| 6272 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6273 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6274 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 6275 | |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 6276 | parent = fromHandle(args.layerHandle).promote(); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 6277 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6278 | ALOGE("captureLayers called with an invalid or removed parent"); |
| 6279 | return NAME_NOT_FOUND; |
| 6280 | } |
| 6281 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6282 | if (!canCaptureBlackoutContent && |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 6283 | parent->getDrawingState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6284 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
| 6285 | return PERMISSION_DENIED; |
| 6286 | } |
| 6287 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 6288 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6289 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6290 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6291 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6292 | } |
| 6293 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6294 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6295 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6296 | crop.bottom = parentSourceBounds.getHeight(); |
| 6297 | } |
| 6298 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6299 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6300 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 6301 | // crop was not specified, or an invalid frame scale was provided. |
| 6302 | return BAD_VALUE; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6303 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6304 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6305 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6306 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 6307 | sp<Layer> excludeLayer = fromHandle(handle).promote(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6308 | if (excludeLayer != nullptr) { |
| 6309 | excludeLayers.emplace(excludeLayer); |
| 6310 | } else { |
| 6311 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
| 6312 | return NAME_NOT_FOUND; |
| 6313 | } |
| 6314 | } |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 6315 | |
arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 6316 | // The dataspace is depended on the color mode of display, that could use non-native mode |
| 6317 | // (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes, |
| 6318 | // and failed if display is not in native mode. This provide a way to force using native |
| 6319 | // colors when capture. |
Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 6320 | dataspace = args.dataspace; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6321 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 6322 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 6323 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 6324 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 6325 | ALOGW("Failed to captureLayes: crop or scale too small"); |
| 6326 | return BAD_VALUE; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 6329 | Rect layerStackSpaceRect(0, 0, reqSize.width, reqSize.height); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6330 | bool childrenOnly = args.childrenOnly; |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6331 | RenderAreaFuture renderAreaFuture = ftl::defer([=]() -> std::unique_ptr<RenderArea> { |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6332 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6333 | childrenOnly, layerStackSpaceRect, |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 6334 | args.captureSecureLayers); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6335 | }); |
| 6336 | |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6337 | auto traverseLayers = [parent, args, excludeLayers](const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6338 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 6339 | if (!layer->isVisible()) { |
| 6340 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6341 | } else if (args.childrenOnly && layer == parent.get()) { |
| 6342 | return; |
| 6343 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 6344 | return; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6345 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 6346 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 6347 | auto p = sp<Layer>::fromExisting(layer); |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 6348 | while (p != nullptr) { |
| 6349 | if (excludeLayers.count(p) != 0) { |
| 6350 | return; |
| 6351 | } |
| 6352 | p = p->getParent(); |
| 6353 | } |
| 6354 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6355 | visitor(layer); |
| 6356 | }); |
| 6357 | }; |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 6358 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6359 | if (captureListener == nullptr) { |
| 6360 | ALOGE("capture screen must provide a capture listener callback"); |
| 6361 | return BAD_VALUE; |
| 6362 | } |
| 6363 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6364 | auto future = captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize, |
| 6365 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 6366 | captureListener); |
| 6367 | return fenceStatus(future.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6370 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6371 | RenderAreaFuture renderAreaFuture, TraverseLayersFunction traverseLayers, |
| 6372 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, bool allowProtected, bool grayscale, |
| 6373 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6374 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 6375 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 6376 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 6377 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 6378 | ") that exceeds render target size limit.", |
| 6379 | bufferSize.getWidth(), bufferSize.getHeight()); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6380 | return ftl::yield<FenceResult>(base::unexpected(BAD_VALUE)).share(); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 6381 | } |
| 6382 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6383 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 6384 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 6385 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 6386 | // application to avoid being screenshot or drawn via unsecure display. |
| 6387 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 6388 | bool hasProtectedLayer = false; |
| 6389 | if (allowProtected && supportsProtected) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6390 | auto future = mScheduler->schedule([=]() { |
| 6391 | bool protectedLayerFound = false; |
| 6392 | traverseLayers([&](Layer* layer) { |
| 6393 | protectedLayerFound = |
| 6394 | protectedLayerFound || (layer->isVisible() && layer->isProtected()); |
| 6395 | }); |
| 6396 | return protectedLayerFound; |
| 6397 | }); |
| 6398 | hasProtectedLayer = future.get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6399 | } |
| 6400 | |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 6401 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 6402 | GRALLOC_USAGE_HW_TEXTURE | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6403 | (hasProtectedLayer && allowProtected && supportsProtected |
| 6404 | ? GRALLOC_USAGE_PROTECTED |
| 6405 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6406 | sp<GraphicBuffer> buffer = |
| 6407 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 6408 | static_cast<android_pixel_format>(reqPixelFormat), |
| 6409 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 6410 | |
| 6411 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 6412 | if (bufferStatus != OK) { |
| 6413 | // Animations may end up being really janky, but don't crash here. |
| 6414 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 6415 | // too much. |
| 6416 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 6417 | return ftl::yield<FenceResult>(base::unexpected(bufferStatus)).share(); |
| 6418 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 6419 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 6420 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 6421 | renderengine::impl::ExternalTexture::Usage:: |
| 6422 | WRITEABLE); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 6423 | return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, texture, |
Derek Sollenberger | 3425788 | 2021-04-06 18:32:34 +0000 | [diff] [blame] | 6424 | false /* regionSampling */, grayscale, captureListener); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 6425 | } |
| 6426 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6427 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 6428 | RenderAreaFuture renderAreaFuture, TraverseLayersFunction traverseLayers, |
| 6429 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 6430 | bool grayscale, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6431 | ATRACE_CALL(); |
| 6432 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6433 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 6434 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6435 | auto future = mScheduler->schedule([=, renderAreaFuture = std::move(renderAreaFuture)]() mutable |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6436 | -> ftl::SharedFuture<FenceResult> { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6437 | ScreenCaptureResults captureResults; |
| 6438 | std::unique_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
| 6439 | if (!renderArea) { |
| 6440 | ALOGW("Skipping screen capture because of invalid render area."); |
Patrick Williams | fdb57bb | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 6441 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 6442 | captureListener->onScreenCaptureCompleted(captureResults); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6443 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6444 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6445 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6446 | ftl::SharedFuture<FenceResult> renderFuture; |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6447 | renderArea->render([&] { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6448 | renderFuture = |
| 6449 | renderScreenImpl(*renderArea, traverseLayers, buffer, canCaptureBlackoutContent, |
| 6450 | regionSampling, grayscale, captureResults); |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6451 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6452 | |
| 6453 | if (captureListener) { |
Dominik Laskowski | fb3beed | 2022-07-07 07:34:38 -0700 | [diff] [blame] | 6454 | // Defer blocking on renderFuture back to the Binder thread. |
| 6455 | return ftl::Future(std::move(renderFuture)) |
| 6456 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 6457 | FenceResult fenceResult) mutable -> FenceResult { |
Patrick Williams | fdb57bb | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 6458 | captureResults.fenceResult = std::move(fenceResult); |
Dominik Laskowski | fb3beed | 2022-07-07 07:34:38 -0700 | [diff] [blame] | 6459 | captureListener->onScreenCaptureCompleted(captureResults); |
| 6460 | return base::unexpected(NO_ERROR); |
| 6461 | }) |
| 6462 | .share(); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6463 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6464 | return renderFuture; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6465 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6466 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6467 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6468 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 6469 | return future; |
| 6470 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6471 | |
| 6472 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 6473 | } |
| 6474 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 6475 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 6476 | const RenderArea& renderArea, TraverseLayersFunction traverseLayers, |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6477 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 6478 | bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, |
| 6479 | ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 6480 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6481 | |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6482 | traverseLayers([&](Layer* layer) { |
| 6483 | captureResults.capturedSecureLayers = |
| 6484 | captureResults.capturedSecureLayers || (layer->isVisible() && layer->isSecure()); |
| 6485 | }); |
| 6486 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 6487 | const bool useProtected = buffer->getUsage() & GRALLOC_USAGE_PROTECTED; |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6488 | |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6489 | // We allow the system server to take screenshots of secure layers for |
| 6490 | // use in situations like the Screen-rotation animation and place |
| 6491 | // the impetus on WindowManager to not persist them. |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6492 | if (captureResults.capturedSecureLayers && !canCaptureBlackoutContent) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6493 | ALOGW("FB is protected: PERMISSION_DENIED"); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6494 | return ftl::yield<FenceResult>(base::unexpected(PERMISSION_DENIED)).share(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6495 | } |
| 6496 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 6497 | captureResults.buffer = buffer->getBuffer(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 6498 | auto dataspace = renderArea.getReqDataSpace(); |
| 6499 | auto parent = renderArea.getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 6500 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 6501 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 6502 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 6503 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 6504 | if ((dataspace == ui::Dataspace::UNKNOWN) && (parent != nullptr)) { |
| 6505 | Mutex::Autolock lock(mStateLock); |
| 6506 | auto display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 6507 | return display.getLayerStack() == layerStack; |
| 6508 | }); |
| 6509 | if (!display) { |
| 6510 | // If the layer is not on a display, use the dataspace for the default display. |
| 6511 | display = getDefaultDisplayDeviceLocked(); |
| 6512 | } |
| 6513 | |
| 6514 | const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode; |
| 6515 | dataspace = pickDataspaceFromColorMode(colorMode); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 6516 | renderIntent = display->getCompositionDisplay()->getState().renderIntent; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 6517 | sdrWhitePointNits = display->getCompositionDisplay()->getState().sdrWhitePointNits; |
| 6518 | displayBrightnessNits = display->getCompositionDisplay()->getState().displayBrightnessNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 6519 | } |
| 6520 | captureResults.capturedDataspace = dataspace; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6521 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6522 | const auto reqWidth = renderArea.getReqWidth(); |
| 6523 | const auto reqHeight = renderArea.getReqHeight(); |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 6524 | const auto sourceCrop = renderArea.getSourceCrop(); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 6525 | const auto transform = renderArea.getTransform(); |
| 6526 | const auto rotation = renderArea.getRotationFlags(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6527 | const auto& layerStackSpaceRect = renderArea.getLayerStackSpaceRect(); |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 6528 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6529 | renderengine::DisplaySettings clientCompositionDisplay; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 6530 | std::vector<compositionengine::LayerFE::LayerSettings> clientCompositionLayers; |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6531 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6532 | // assume that bounds are never offset, and that they are the same as the |
| 6533 | // buffer bounds. |
| 6534 | clientCompositionDisplay.physicalDisplay = Rect(reqWidth, reqHeight); |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 6535 | clientCompositionDisplay.clip = sourceCrop; |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 6536 | clientCompositionDisplay.orientation = rotation; |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 6537 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 6538 | clientCompositionDisplay.outputDataspace = dataspace; |
Sally Qi | e258f09 | 2022-05-19 15:24:12 -0700 | [diff] [blame] | 6539 | clientCompositionDisplay.currentLuminanceNits = displayBrightnessNits; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6540 | clientCompositionDisplay.maxLuminance = DisplayDevice::sDefaultMaxLumiance; |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 6541 | clientCompositionDisplay.renderIntent = |
| 6542 | static_cast<aidl::android::hardware::graphics::composer3::RenderIntent>(renderIntent); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 6543 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6544 | const float colorSaturation = grayscale ? 0 : 1; |
| 6545 | clientCompositionDisplay.colorTransform = calculateColorMatrix(colorSaturation); |
| 6546 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 6547 | const float alpha = RenderArea::getCaptureFillValue(renderArea.getCaptureFill()); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 6548 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 6549 | compositionengine::LayerFE::LayerSettings fillLayer; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6550 | fillLayer.source.buffer.buffer = nullptr; |
| 6551 | fillLayer.source.solidColor = half3(0.0, 0.0, 0.0); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 6552 | fillLayer.geometry.boundaries = |
| 6553 | FloatRect(sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6554 | fillLayer.alpha = half(alpha); |
| 6555 | clientCompositionLayers.push_back(fillLayer); |
| 6556 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 6557 | const auto display = renderArea.getDisplayDevice(); |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 6558 | std::vector<Layer*> renderedLayers; |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 6559 | bool disableBlurs = false; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6560 | traverseLayers([&](Layer* layer) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 6561 | disableBlurs |= layer->getDrawingState().sidebandStream != nullptr; |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 6562 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 6563 | Region clip(renderArea.getBounds()); |
| 6564 | compositionengine::LayerFE::ClientCompositionTargetSettings targetSettings{ |
| 6565 | clip, |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 6566 | layer->needsFilteringForScreenshots(display.get(), transform) || |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 6567 | renderArea.needsFiltering(), |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 6568 | renderArea.isSecure(), |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6569 | useProtected, |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6570 | layerStackSpaceRect, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 6571 | clientCompositionDisplay.outputDataspace, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 6572 | true, /* realContentIsVisible */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 6573 | false, /* clearContent */ |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 6574 | disableBlurs ? compositionengine::LayerFE::ClientCompositionTargetSettings:: |
| 6575 | BlurSetting::Disabled |
| 6576 | : compositionengine::LayerFE::ClientCompositionTargetSettings:: |
| 6577 | BlurSetting::Enabled, |
Sally Qi | db65301 | 2022-05-04 13:12:22 -0700 | [diff] [blame] | 6578 | isHdrLayer(layer) ? displayBrightnessNits : sdrWhitePointNits, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 6579 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 6580 | }; |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 6581 | std::optional<compositionengine::LayerFE::LayerSettings> settings = |
| 6582 | layer->prepareClientComposition(targetSettings); |
| 6583 | if (!settings) { |
| 6584 | return; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 6585 | } |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 6586 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 6587 | settings->geometry.positionTransform = |
| 6588 | transform.asMatrix4() * settings->geometry.positionTransform; |
| 6589 | // There's no need to process blurs when we're executing region sampling, |
| 6590 | // we're just trying to understand what we're drawing, and doing so without |
| 6591 | // blurs is already a pretty good approximation. |
| 6592 | if (regionSampling) { |
| 6593 | settings->backgroundBlurRadius = 0; |
Patrick Williams | 3fbc8ca | 2022-08-19 15:35:24 +0000 | [diff] [blame] | 6594 | settings->blurRegions.clear(); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 6595 | } |
| 6596 | captureResults.capturedHdrLayers |= isHdrLayer(layer); |
| 6597 | |
| 6598 | clientCompositionLayers.push_back(std::move(*settings)); |
| 6599 | renderedLayers.push_back(layer); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6600 | }); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6601 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6602 | std::vector<renderengine::LayerSettings> clientRenderEngineLayers; |
| 6603 | clientRenderEngineLayers.reserve(clientCompositionLayers.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 6604 | std::transform(clientCompositionLayers.begin(), clientCompositionLayers.end(), |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6605 | std::back_inserter(clientRenderEngineLayers), |
| 6606 | [](compositionengine::LayerFE::LayerSettings& settings) |
| 6607 | -> renderengine::LayerSettings { return settings; }); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 6608 | |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 6609 | // Use an empty fence for the buffer fence, since we just created the buffer so |
| 6610 | // there is no need for synchronization with the GPU. |
| 6611 | base::unique_fd bufferFence; |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6612 | getRenderEngine().useProtectedContext(useProtected); |
Alec Mouri | 0d99510 | 2021-02-24 16:53:38 -0800 | [diff] [blame] | 6613 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6614 | constexpr bool kUseFramebufferCache = false; |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 6615 | const auto future = getRenderEngine() |
| 6616 | .drawLayers(clientCompositionDisplay, clientRenderEngineLayers, |
| 6617 | buffer, kUseFramebufferCache, std::move(bufferFence)) |
| 6618 | .share(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 6619 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6620 | for (auto* layer : renderedLayers) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6621 | layer->onLayerDisplayed(future); |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 6622 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 6623 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6624 | // Always switch back to unprotected context. |
| 6625 | getRenderEngine().useProtectedContext(false); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 6626 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6627 | return future; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 6628 | } |
| 6629 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6630 | // --------------------------------------------------------------------------- |
| 6631 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 6632 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 6633 | layersSortedByZ.traverse(visitor); |
| 6634 | } |
| 6635 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 6636 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 6637 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 6638 | } |
| 6639 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 6640 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 6641 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 6642 | } |
| 6643 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6644 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6645 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6646 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 6647 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6648 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 6649 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6650 | continue; |
| 6651 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 6652 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6653 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 6654 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 6655 | return; |
| 6656 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6657 | if (!layer->isVisible()) { |
| 6658 | return; |
| 6659 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6660 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 6661 | return; |
| 6662 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6663 | visitor(layer); |
| 6664 | }); |
| 6665 | } |
| 6666 | } |
| 6667 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6668 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6669 | const sp<DisplayDevice>& display, |
| 6670 | const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) { |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 6671 | Mutex::Autolock lock(mStateLock); |
| 6672 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6673 | if (mDebugDisplayModeSetByBackdoor) { |
| 6674 | // ignore this request as mode is overridden by backdoor |
| 6675 | return NO_ERROR; |
| 6676 | } |
| 6677 | |
Ady Abraham | a92a568 | 2022-06-07 23:35:38 +0000 | [diff] [blame] | 6678 | const status_t setPolicyResult = display->setRefreshRatePolicy(policy, overridePolicy); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6679 | if (setPolicyResult < 0) { |
| 6680 | return BAD_VALUE; |
| 6681 | } |
| 6682 | if (setPolicyResult == scheduler::RefreshRateConfigs::CURRENT_POLICY_UNCHANGED) { |
| 6683 | return NO_ERROR; |
| 6684 | } |
| 6685 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6686 | scheduler::RefreshRateConfigs::Policy currentPolicy = |
| 6687 | display->refreshRateConfigs().getCurrentPolicy(); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 6688 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6689 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 6690 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6691 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 6692 | // be depending in this callback. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6693 | const auto activeMode = display->getActiveMode(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6694 | if (isDisplayActiveLocked(display)) { |
| 6695 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
| 6696 | toggleKernelIdleTimer(); |
| 6697 | } else { |
| 6698 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
| 6699 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 6700 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6701 | const DisplayModePtr preferredDisplayMode = [&] { |
| 6702 | const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
| 6703 | if (schedulerMode && schedulerMode->getPhysicalDisplayId() == display->getPhysicalId()) { |
| 6704 | return schedulerMode; |
| 6705 | } |
| 6706 | |
| 6707 | return display->getMode(currentPolicy.defaultMode); |
| 6708 | }(); |
| 6709 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 6710 | ALOGV("trying to switch to Scheduler preferred mode %d (%s)", |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6711 | preferredDisplayMode->getId().value(), to_string(preferredDisplayMode->getFps()).c_str()); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 6712 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6713 | if (display->refreshRateConfigs().isModeAllowed(preferredDisplayMode->getId())) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 6714 | ALOGV("switching to Scheduler preferred display mode %d", |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6715 | preferredDisplayMode->getId().value()); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 6716 | setDesiredActiveMode({preferredDisplayMode, DisplayModeEvent::Changed}); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 6717 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 6718 | LOG_ALWAYS_FATAL("Desired display mode not allowed: %d", |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6719 | preferredDisplayMode->getId().value()); |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 6720 | } |
| 6721 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 6722 | return NO_ERROR; |
| 6723 | } |
| 6724 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 6725 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs( |
| 6726 | const sp<IBinder>& displayToken, ui::DisplayModeId defaultMode, bool allowGroupSwitching, |
| 6727 | float primaryRefreshRateMin, float primaryRefreshRateMax, float appRequestRefreshRateMin, |
| 6728 | float appRequestRefreshRateMax) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 6729 | ATRACE_CALL(); |
| 6730 | |
| 6731 | if (!displayToken) { |
| 6732 | return BAD_VALUE; |
| 6733 | } |
| 6734 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6735 | auto future = mScheduler->schedule([=]() -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6736 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6737 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6738 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6739 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 6740 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6741 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6742 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 6743 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6744 | } else { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 6745 | using Policy = scheduler::RefreshRateConfigs::Policy; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6746 | const Policy policy{DisplayModeId(defaultMode), |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 6747 | allowGroupSwitching, |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 6748 | {Fps::fromValue(primaryRefreshRateMin), |
| 6749 | Fps::fromValue(primaryRefreshRateMax)}, |
| 6750 | {Fps::fromValue(appRequestRefreshRateMin), |
| 6751 | Fps::fromValue(appRequestRefreshRateMax)}}; |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 6752 | constexpr bool kOverridePolicy = false; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 6753 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6754 | return setDesiredDisplayModeSpecsInternal(display, policy, kOverridePolicy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 6755 | } |
| 6756 | }); |
| 6757 | |
| 6758 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6759 | } |
| 6760 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 6761 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 6762 | ui::DisplayModeId* outDefaultMode, |
| 6763 | bool* outAllowGroupSwitching, |
| 6764 | float* outPrimaryRefreshRateMin, |
| 6765 | float* outPrimaryRefreshRateMax, |
| 6766 | float* outAppRequestRefreshRateMin, |
| 6767 | float* outAppRequestRefreshRateMax) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6768 | ATRACE_CALL(); |
| 6769 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6770 | if (!displayToken || !outDefaultMode || !outPrimaryRefreshRateMin || |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 6771 | !outPrimaryRefreshRateMax || !outAppRequestRefreshRateMin || !outAppRequestRefreshRateMax) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6772 | return BAD_VALUE; |
| 6773 | } |
| 6774 | |
| 6775 | Mutex::Autolock lock(mStateLock); |
| 6776 | const auto display = getDisplayDeviceLocked(displayToken); |
| 6777 | if (!display) { |
| 6778 | return NAME_NOT_FOUND; |
| 6779 | } |
| 6780 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6781 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6782 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 6783 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6784 | |
| 6785 | scheduler::RefreshRateConfigs::Policy policy = |
| 6786 | display->refreshRateConfigs().getDisplayManagerPolicy(); |
| 6787 | *outDefaultMode = policy.defaultMode.value(); |
| 6788 | *outAllowGroupSwitching = policy.allowGroupSwitching; |
| 6789 | *outPrimaryRefreshRateMin = policy.primaryRange.min.getValue(); |
| 6790 | *outPrimaryRefreshRateMax = policy.primaryRange.max.getValue(); |
| 6791 | *outAppRequestRefreshRateMin = policy.appRequestRange.min.getValue(); |
| 6792 | *outAppRequestRefreshRateMax = policy.appRequestRange.max.getValue(); |
| 6793 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 6794 | } |
| 6795 | |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 6796 | wp<Layer> SurfaceFlinger::fromHandle(const sp<IBinder>& handle) const { |
| 6797 | return Layer::fromHandle(handle); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6798 | } |
| 6799 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 6800 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 6801 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 6802 | if (!layer->isRemovedFromCurrentState()) { |
| 6803 | mScheduler->registerLayer(layer); |
| 6804 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 6805 | } |
| 6806 | |
| 6807 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 6808 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 6809 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 6810 | if (!layer->isRemovedFromCurrentState()) { |
| 6811 | mScheduler->deregisterLayer(layer); |
| 6812 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6813 | if (mTransactionTracing) { |
| 6814 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 6815 | } |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 6816 | } |
| 6817 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6818 | void SurfaceFlinger::onLayerUpdate() { |
| 6819 | scheduleCommit(FrameHint::kActive); |
| 6820 | } |
| 6821 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 6822 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 6823 | // Here we add children in the current state to offscreen layers and remove the |
| 6824 | // layer itself from the offscreen layer list. Since |
| 6825 | // this is the dtor, it is safe to access the current state. This keeps us |
| 6826 | // from dangling children layers such that they are not reachable from the |
| 6827 | // Drawing state nor the offscreen layer list |
| 6828 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 6829 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 6830 | for (auto& child : layer->getCurrentChildren()) { |
| 6831 | mOffscreenLayers.emplace(child.get()); |
| 6832 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 6833 | mOffscreenLayers.erase(layer); |
| 6834 | } |
| 6835 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 6836 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 6837 | mOffscreenLayers.erase(layer); |
| 6838 | } |
| 6839 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 6840 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 6841 | float lightPosY, float lightPosZ, |
| 6842 | float lightRadius) { |
| 6843 | Mutex::Autolock _l(mStateLock); |
| 6844 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 6845 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 6846 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 6847 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 6848 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 6849 | |
| 6850 | // these values are overridden when calculating the shadow settings for a layer. |
| 6851 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 6852 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 6853 | return NO_ERROR; |
| 6854 | } |
| 6855 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 6856 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 6857 | const { |
| 6858 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 6859 | // on the work to remove the table in that bug rather than adding more to |
| 6860 | // it. |
| 6861 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6862 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 6863 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 6864 | }; |
| 6865 | return genericLayerMetadataKeyMap; |
| 6866 | } |
| 6867 | |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 6868 | status_t SurfaceFlinger::setOverrideFrameRate(uid_t uid, float frameRate) { |
| 6869 | PhysicalDisplayId displayId = [&]() { |
| 6870 | Mutex::Autolock lock(mStateLock); |
| 6871 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 6872 | }(); |
| 6873 | |
| 6874 | mScheduler->setGameModeRefreshRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 6875 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 6876 | return NO_ERROR; |
| 6877 | } |
| 6878 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6879 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 6880 | for (const auto& [ignored, display] : mDisplays) { |
| 6881 | if (display->isInternal()) { |
| 6882 | display->enableRefreshRateOverlay(enable, mRefreshRateOverlaySpinner); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6883 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 6884 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6885 | } |
| 6886 | |
Pablo Gamito | 6ee484d | 2020-07-30 14:26:28 +0000 | [diff] [blame] | 6887 | status_t SurfaceFlinger::addTransactionTraceListener( |
| 6888 | const sp<gui::ITransactionTraceListener>& listener) { |
| 6889 | if (!listener) { |
| 6890 | return BAD_VALUE; |
| 6891 | } |
| 6892 | |
| 6893 | mInterceptor->addTransactionTraceListener(listener); |
| 6894 | |
| 6895 | return NO_ERROR; |
| 6896 | } |
| 6897 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6898 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 6899 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 6900 | } |
| 6901 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 6902 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
| 6903 | std::chrono::nanoseconds presentLatency) { |
| 6904 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 6905 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6906 | pipelineDepth++; |
| 6907 | } |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 6908 | return std::max(1ll, pipelineDepth - 1); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6909 | } |
| 6910 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 6911 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 6912 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6913 | |
| 6914 | if (!getHwComposer().isHeadless()) { |
| 6915 | if (const auto display = getDefaultDisplayDevice()) { |
| 6916 | maxRefreshRate = display->refreshRateConfigs().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6917 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6921 | return NO_ERROR; |
| 6922 | } |
| 6923 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 6924 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 6925 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6926 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6927 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 6928 | refreshRate = *frameRateOverride; |
| 6929 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6930 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6931 | refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6932 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6933 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6934 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 6935 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 6936 | } |
| 6937 | |
| 6938 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 6939 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 6940 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 6941 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 6942 | } |
| 6943 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 6944 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 6945 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6946 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 6947 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 6948 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 6952 | bool addToRoot = state.addToRoot; |
| 6953 | if (state.initialParent != nullptr) { |
| 6954 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6955 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 6956 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 6957 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6958 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6959 | } |
| 6960 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 6961 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 6962 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6963 | mCurrentState.layersSortedByZ.add(layer); |
| 6964 | } else if (parent == nullptr) { |
| 6965 | layer->onRemovedFromCurrentState(); |
| 6966 | } else if (parent->isRemovedFromCurrentState()) { |
| 6967 | parent->addChild(layer); |
| 6968 | layer->onRemovedFromCurrentState(); |
| 6969 | } else { |
| 6970 | parent->addChild(layer); |
| 6971 | } |
| 6972 | |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 6973 | layer->updateTransformHint(mActiveDisplayTransformHint); |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 6974 | if (mTransactionTracing) { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 6975 | mTransactionTracing->onLayerAddedToDrawingState(layer->getSequence(), vsyncId.value); |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 6976 | } |
Arthur Hung | 23e0750 | 2021-10-15 11:58:19 +0000 | [diff] [blame] | 6977 | mInterceptor->saveSurfaceCreation(layer); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 6978 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 6979 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6980 | void SurfaceFlinger::sample() { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 6981 | if (!mLumaSampling || !mRegionSamplingThread) { |
| 6982 | return; |
| 6983 | } |
| 6984 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6985 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 6986 | } |
| 6987 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6988 | void SurfaceFlinger::onActiveDisplaySizeChanged(const sp<DisplayDevice>& activeDisplay) { |
| 6989 | mScheduler->onActiveDisplayAreaChanged(activeDisplay->getWidth() * activeDisplay->getHeight()); |
| 6990 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay->getSize()); |
| 6991 | } |
| 6992 | |
| 6993 | void SurfaceFlinger::onActiveDisplayChangedLocked(const sp<DisplayDevice>& activeDisplay) { |
| 6994 | ATRACE_CALL(); |
| 6995 | |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 6996 | if (const auto display = getDisplayDeviceLocked(mActiveDisplayToken)) { |
| 6997 | display->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
| 6998 | } |
| 6999 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7000 | if (!activeDisplay) { |
| 7001 | ALOGE("%s: activeDisplay is null", __func__); |
| 7002 | return; |
| 7003 | } |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 7004 | mActiveDisplayToken = activeDisplay->getDisplayToken(); |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 7005 | activeDisplay->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7006 | updateInternalDisplayVsyncLocked(activeDisplay); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7007 | mScheduler->setModeChangePending(false); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7008 | mScheduler->setRefreshRateConfigs(activeDisplay->holdRefreshRateConfigs()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7009 | onActiveDisplaySizeChanged(activeDisplay); |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 7010 | mActiveDisplayTransformHint = activeDisplay->getTransformHint(); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 7011 | |
| 7012 | // Update the kernel timer for the current active display, since the policy |
| 7013 | // for this display might have changed when it was not the active display. |
| 7014 | toggleKernelIdleTimer(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7015 | } |
| 7016 | |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7017 | status_t SurfaceFlinger::addWindowInfosListener( |
| 7018 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 7019 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener); |
| 7020 | return NO_ERROR; |
| 7021 | } |
| 7022 | |
| 7023 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 7024 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 7025 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 7026 | return NO_ERROR; |
| 7027 | } |
| 7028 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7029 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
| 7030 | const BufferData& bufferData, const char* layerName) const { |
| 7031 | bool cacheIdChanged = bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 7032 | bool bufferSizeExceedsLimit = false; |
| 7033 | std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr; |
| 7034 | if (cacheIdChanged && bufferData.buffer != nullptr) { |
| 7035 | bufferSizeExceedsLimit = exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), |
| 7036 | bufferData.buffer->getHeight()); |
| 7037 | if (!bufferSizeExceedsLimit) { |
| 7038 | ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 7039 | buffer = ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 7040 | } |
| 7041 | } else if (cacheIdChanged) { |
| 7042 | buffer = ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 7043 | } else if (bufferData.buffer != nullptr) { |
| 7044 | bufferSizeExceedsLimit = exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), |
| 7045 | bufferData.buffer->getHeight()); |
| 7046 | if (!bufferSizeExceedsLimit) { |
| 7047 | buffer = std::make_shared< |
| 7048 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 7049 | renderengine::impl::ExternalTexture:: |
| 7050 | Usage::READABLE); |
| 7051 | } |
| 7052 | } |
| 7053 | ALOGE_IF(bufferSizeExceedsLimit, |
| 7054 | "Attempted to create an ExternalTexture for layer %s that exceeds render target size " |
| 7055 | "limit.", |
| 7056 | layerName); |
| 7057 | return buffer; |
| 7058 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7059 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7060 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7061 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 7062 | { |
| 7063 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 7064 | mirrorDisplays = std::move(mMirrorDisplays); |
| 7065 | mMirrorDisplays.clear(); |
| 7066 | if (mirrorDisplays.size() == 0) { |
| 7067 | return false; |
| 7068 | } |
| 7069 | } |
| 7070 | |
| 7071 | sp<IBinder> unused; |
| 7072 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 7073 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 7074 | // accidentally. |
| 7075 | sp<Layer> rootMirrorLayer = Layer::fromHandle(mirrorDisplay.rootHandle).promote(); |
| 7076 | rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 7077 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 7078 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 7079 | layer->isInternalDisplayOverlay()) { |
| 7080 | continue; |
| 7081 | } |
| 7082 | |
| 7083 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 7084 | ISurfaceComposerClient::eNoColorFill, |
| 7085 | gui::LayerMetadata()); |
| 7086 | sp<Layer> childMirror; |
| 7087 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
| 7088 | childMirror->setClonedChild(layer->createClone()); |
| 7089 | if (mTransactionTracing) { |
| 7090 | mTransactionTracing->onLayerAddedToDrawingState(childMirror->getSequence(), |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7091 | vsyncId.value); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7092 | } |
| 7093 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 7094 | } |
| 7095 | } |
| 7096 | return true; |
| 7097 | } |
| 7098 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7099 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7100 | std::vector<LayerCreatedState> createdLayers; |
| 7101 | { |
| 7102 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 7103 | createdLayers = std::move(mCreatedLayers); |
| 7104 | mCreatedLayers.clear(); |
| 7105 | if (createdLayers.size() == 0) { |
| 7106 | return false; |
| 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | Mutex::Autolock _l(mStateLock); |
| 7111 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 7112 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7113 | } |
| 7114 | createdLayers.clear(); |
| 7115 | mLayersAdded = true; |
| 7116 | return true; |
| 7117 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7118 | |
| 7119 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7120 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 7121 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 7122 | status_t status = checkAccessPermission(); |
| 7123 | if (status != OK) { |
| 7124 | return binderStatusFromStatusT(status); |
| 7125 | } |
| 7126 | mFlinger->bootFinished(); |
| 7127 | return binder::Status::ok(); |
| 7128 | } |
| 7129 | |
| 7130 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 7131 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
| 7132 | sp<IDisplayEventConnection>* outConnection) { |
| 7133 | sp<IDisplayEventConnection> conn = |
| 7134 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration); |
| 7135 | if (conn == nullptr) { |
| 7136 | *outConnection = nullptr; |
| 7137 | return binderStatusFromStatusT(BAD_VALUE); |
| 7138 | } else { |
| 7139 | *outConnection = conn; |
| 7140 | return binder::Status::ok(); |
| 7141 | } |
| 7142 | } |
| 7143 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7144 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 7145 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7146 | if (client->initCheck() == NO_ERROR) { |
| 7147 | *outClient = client; |
| 7148 | return binder::Status::ok(); |
| 7149 | } else { |
| 7150 | *outClient = nullptr; |
| 7151 | return binderStatusFromStatusT(BAD_VALUE); |
| 7152 | } |
| 7153 | } |
| 7154 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7155 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
| 7156 | sp<IBinder>* outDisplay) { |
| 7157 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7158 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7159 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7160 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7161 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
| 7162 | *outDisplay = mFlinger->createDisplay(displayName8, secure); |
| 7163 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 7167 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7168 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7169 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7170 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7171 | mFlinger->destroyDisplay(display); |
| 7172 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7173 | } |
| 7174 | |
| 7175 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 7176 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 7177 | std::vector<int64_t> displayIds; |
| 7178 | displayIds.reserve(physicalDisplayIds.size()); |
| 7179 | for (auto item : physicalDisplayIds) { |
| 7180 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 7181 | } |
| 7182 | *outDisplayIds = displayIds; |
| 7183 | return binder::Status::ok(); |
| 7184 | } |
| 7185 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7186 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 7187 | sp<IBinder>* outDisplay) { |
| 7188 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 7189 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 7190 | return binder::Status::ok(); |
| 7191 | } |
| 7192 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7193 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 7194 | status_t status = checkAccessPermission(); |
| 7195 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7196 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7197 | } |
| 7198 | mFlinger->setPowerMode(display, mode); |
| 7199 | return binder::Status::ok(); |
| 7200 | } |
| 7201 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 7202 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 7203 | std::vector<FrameEvent>* outSupported) { |
| 7204 | status_t status; |
| 7205 | if (!outSupported) { |
| 7206 | status = UNEXPECTED_NULL; |
| 7207 | } else { |
| 7208 | outSupported->clear(); |
| 7209 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 7210 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7211 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 7212 | } |
| 7213 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7214 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 7215 | gui::DisplayStatInfo* outStatInfo) { |
| 7216 | DisplayStatInfo statInfo; |
| 7217 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 7218 | if (status == NO_ERROR) { |
| 7219 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 7220 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 7221 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7222 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 7226 | gui::DisplayState* outState) { |
| 7227 | ui::DisplayState state; |
| 7228 | status_t status = mFlinger->getDisplayState(display, &state); |
| 7229 | if (status == NO_ERROR) { |
| 7230 | outState->layerStack = state.layerStack.id; |
| 7231 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 7232 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 7233 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 7234 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7235 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7236 | } |
| 7237 | |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 7238 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(const sp<IBinder>& display, |
| 7239 | gui::StaticDisplayInfo* outInfo) { |
| 7240 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 7241 | ui::StaticDisplayInfo info; |
| 7242 | status_t status = mFlinger->getStaticDisplayInfo(display, &info); |
| 7243 | if (status == NO_ERROR) { |
| 7244 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 7245 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 7246 | outInfo->density = info.density; |
| 7247 | outInfo->secure = info.secure; |
| 7248 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 7249 | |
| 7250 | gui::DeviceProductInfo dinfo; |
| 7251 | std::optional<DeviceProductInfo> dpi = info.deviceProductInfo; |
| 7252 | dinfo.name = std::move(dpi->name); |
| 7253 | dinfo.manufacturerPnpId = |
| 7254 | std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), dpi->manufacturerPnpId.end()); |
| 7255 | dinfo.productId = dpi->productId; |
Kriti Dang | 1de958d | 2022-05-30 15:26:58 +0200 | [diff] [blame] | 7256 | dinfo.relativeAddress = |
| 7257 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 7258 | if (const auto* model = |
| 7259 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 7260 | gui::DeviceProductInfo::ModelYear modelYear; |
| 7261 | modelYear.year = model->year; |
| 7262 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 7263 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 7264 | &dpi->manufactureOrModelDate)) { |
| 7265 | gui::DeviceProductInfo::ManufactureYear date; |
| 7266 | date.modelYear.year = manufacture->year; |
| 7267 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 7268 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 7269 | &dpi->manufactureOrModelDate)) { |
| 7270 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 7271 | date.manufactureYear.modelYear.year = manufacture->year; |
| 7272 | date.week = manufacture->week; |
| 7273 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 7274 | } |
| 7275 | |
| 7276 | outInfo->deviceProductInfo = dinfo; |
| 7277 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7278 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 7279 | } |
| 7280 | |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 7281 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfo(const sp<IBinder>& display, |
| 7282 | gui::DynamicDisplayInfo* outInfo) { |
| 7283 | ui::DynamicDisplayInfo info; |
| 7284 | status_t status = mFlinger->getDynamicDisplayInfo(display, &info); |
| 7285 | if (status == NO_ERROR) { |
| 7286 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 7287 | outInfo->supportedDisplayModes.clear(); |
| 7288 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 7289 | for (const auto& mode : info.supportedDisplayModes) { |
| 7290 | gui::DisplayMode outMode; |
| 7291 | outMode.id = mode.id; |
| 7292 | outMode.resolution.width = mode.resolution.width; |
| 7293 | outMode.resolution.height = mode.resolution.height; |
| 7294 | outMode.xDpi = mode.xDpi; |
| 7295 | outMode.yDpi = mode.yDpi; |
| 7296 | outMode.refreshRate = mode.refreshRate; |
| 7297 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 7298 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 7299 | outMode.presentationDeadline = mode.presentationDeadline; |
| 7300 | outMode.group = mode.group; |
| 7301 | outInfo->supportedDisplayModes.push_back(outMode); |
| 7302 | } |
| 7303 | |
| 7304 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 7305 | |
| 7306 | outInfo->supportedColorModes.clear(); |
| 7307 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 7308 | for (const auto& cmode : info.supportedColorModes) { |
| 7309 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 7310 | } |
| 7311 | |
| 7312 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 7313 | |
| 7314 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 7315 | hdrCapabilities.supportedHdrTypes.clear(); |
| 7316 | hdrCapabilities.supportedHdrTypes.reserve( |
| 7317 | info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 7318 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 7319 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 7320 | } |
| 7321 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 7322 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 7323 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 7324 | |
| 7325 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 7326 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 7327 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 7328 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7329 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 7330 | } |
| 7331 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7332 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 7333 | gui::DisplayPrimaries* outPrimaries) { |
| 7334 | ui::DisplayPrimaries primaries; |
| 7335 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 7336 | if (status == NO_ERROR) { |
| 7337 | outPrimaries->red.X = primaries.red.X; |
| 7338 | outPrimaries->red.Y = primaries.red.Y; |
| 7339 | outPrimaries->red.Z = primaries.red.Z; |
| 7340 | |
| 7341 | outPrimaries->green.X = primaries.green.X; |
| 7342 | outPrimaries->green.Y = primaries.green.Y; |
| 7343 | outPrimaries->green.Z = primaries.green.Z; |
| 7344 | |
| 7345 | outPrimaries->blue.X = primaries.blue.X; |
| 7346 | outPrimaries->blue.Y = primaries.blue.Y; |
| 7347 | outPrimaries->blue.Z = primaries.blue.Z; |
| 7348 | |
| 7349 | outPrimaries->white.X = primaries.white.X; |
| 7350 | outPrimaries->white.Y = primaries.white.Y; |
| 7351 | outPrimaries->white.Z = primaries.white.Z; |
| 7352 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7353 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7354 | } |
| 7355 | |
| 7356 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 7357 | status_t status = checkAccessPermission(); |
| 7358 | if (status == OK) { |
| 7359 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 7360 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7361 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 7365 | int displayModeId) { |
| 7366 | status_t status = checkAccessPermission(); |
| 7367 | if (status == OK) { |
| 7368 | status = mFlinger->setBootDisplayMode(display, |
| 7369 | static_cast<ui::DisplayModeId>(displayModeId)); |
| 7370 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7371 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7372 | } |
| 7373 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7374 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 7375 | status_t status = checkAccessPermission(); |
| 7376 | if (status == OK) { |
| 7377 | status = mFlinger->clearBootDisplayMode(display); |
| 7378 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7379 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 7383 | status_t status = checkAccessPermission(); |
| 7384 | if (status == OK) { |
| 7385 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 7386 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7387 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 7391 | status_t status = checkAccessPermission(); |
| 7392 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7393 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7394 | } |
| 7395 | mFlinger->setAutoLowLatencyMode(display, on); |
| 7396 | return binder::Status::ok(); |
| 7397 | } |
| 7398 | |
| 7399 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 7400 | status_t status = checkAccessPermission(); |
| 7401 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7402 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7403 | } |
| 7404 | mFlinger->setGameContentType(display, on); |
| 7405 | return binder::Status::ok(); |
| 7406 | } |
| 7407 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7408 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 7409 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 7410 | status_t status = mFlinger->captureDisplay(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7411 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
| 7415 | int64_t displayId, const sp<IScreenCaptureListener>& captureListener) { |
| 7416 | status_t status; |
| 7417 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7418 | const int uid = ipc->getCallingUid(); |
| 7419 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 7420 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
| 7421 | status = mFlinger->captureDisplay(*id, captureListener); |
| 7422 | } else { |
| 7423 | status = PERMISSION_DENIED; |
| 7424 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7425 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 7429 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 7430 | status_t status = mFlinger->captureLayers(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7431 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7432 | } |
| 7433 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7434 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 7435 | const std::vector<int32_t>& hdrTypes) { |
| 7436 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 7437 | // permission dynamically. Don't use the permission cache for this check. |
| 7438 | status_t status = checkAccessPermission(false); |
| 7439 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7440 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7441 | } |
| 7442 | |
| 7443 | std::vector<ui::Hdr> hdrTypesVector; |
| 7444 | for (int32_t i : hdrTypes) { |
| 7445 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 7446 | } |
| 7447 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7448 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 7452 | status_t status; |
| 7453 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 7454 | if (uid != AID_SYSTEM) { |
| 7455 | status = PERMISSION_DENIED; |
| 7456 | } else { |
| 7457 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 7458 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7459 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7460 | } |
| 7461 | |
| 7462 | binder::Status SurfaceComposerAIDL::enableVSyncInjections(bool enable) { |
| 7463 | if (!mFlinger->hasMockHwc()) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7464 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | status_t status = checkAccessPermission(); |
| 7468 | if (status == OK) { |
| 7469 | status = mFlinger->enableVSyncInjections(enable); |
| 7470 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7471 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | binder::Status SurfaceComposerAIDL::injectVSync(int64_t when) { |
| 7475 | if (!mFlinger->hasMockHwc()) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7476 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7477 | } |
| 7478 | |
| 7479 | status_t status = checkAccessPermission(); |
| 7480 | if (status == OK) { |
| 7481 | status = mFlinger->injectVSync(when); |
| 7482 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7483 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 7487 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7488 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7492 | const int pid = ipc->getCallingPid(); |
| 7493 | const int uid = ipc->getCallingUid(); |
| 7494 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 7495 | ALOGE("Layer debug info permission denied for pid=%d, uid=%d", pid, uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7496 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7497 | } |
| 7498 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7499 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | binder::Status SurfaceComposerAIDL::getColorManagement(bool* outGetColorManagement) { |
| 7503 | status_t status = mFlinger->getColorManagement(outGetColorManagement); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7504 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7505 | } |
| 7506 | |
| 7507 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 7508 | ui::Dataspace dataspace; |
| 7509 | ui::PixelFormat pixelFormat; |
| 7510 | ui::Dataspace wideColorGamutDataspace; |
| 7511 | ui::PixelFormat wideColorGamutPixelFormat; |
| 7512 | status_t status = |
| 7513 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 7514 | &wideColorGamutPixelFormat); |
| 7515 | if (status == NO_ERROR) { |
| 7516 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 7517 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 7518 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 7519 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 7520 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7521 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 7525 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 7526 | status_t status = checkAccessPermission(); |
| 7527 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7528 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7529 | } |
| 7530 | |
| 7531 | ui::PixelFormat format; |
| 7532 | ui::Dataspace dataspace; |
| 7533 | uint8_t componentMask; |
| 7534 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 7535 | &componentMask); |
| 7536 | if (status == NO_ERROR) { |
| 7537 | outAttrs->format = static_cast<int32_t>(format); |
| 7538 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 7539 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 7540 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7541 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7542 | } |
| 7543 | |
| 7544 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 7545 | bool enable, |
| 7546 | int8_t componentMask, |
| 7547 | int64_t maxFrames) { |
| 7548 | status_t status = checkAccessPermission(); |
| 7549 | if (status == OK) { |
| 7550 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 7551 | static_cast<uint8_t>(componentMask), |
| 7552 | static_cast<uint64_t>(maxFrames)); |
| 7553 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7554 | return binderStatusFromStatusT(status); |
| 7555 | } |
| 7556 | |
| 7557 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 7558 | int64_t maxFrames, int64_t timestamp, |
| 7559 | gui::DisplayedFrameStats* outStats) { |
| 7560 | if (!outStats) { |
| 7561 | return binderStatusFromStatusT(BAD_VALUE); |
| 7562 | } |
| 7563 | |
| 7564 | status_t status = checkAccessPermission(); |
| 7565 | if (status != OK) { |
| 7566 | return binderStatusFromStatusT(status); |
| 7567 | } |
| 7568 | |
| 7569 | DisplayedFrameStats stats; |
| 7570 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 7571 | static_cast<uint64_t>(timestamp), &stats); |
| 7572 | if (status == NO_ERROR) { |
| 7573 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 7574 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 7575 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 7576 | for (const auto& s : stats.component_0_sample) { |
| 7577 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 7578 | } |
| 7579 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 7580 | for (const auto& s : stats.component_1_sample) { |
| 7581 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 7582 | } |
| 7583 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 7584 | for (const auto& s : stats.component_2_sample) { |
| 7585 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 7586 | } |
| 7587 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 7588 | for (const auto& s : stats.component_3_sample) { |
| 7589 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 7590 | } |
| 7591 | } |
| 7592 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 7596 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7597 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7598 | } |
| 7599 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7600 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 7601 | bool* outIsWideColorDisplay) { |
| 7602 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7603 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7604 | } |
| 7605 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7606 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 7607 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 7608 | const sp<gui::IRegionSamplingListener>& listener) { |
| 7609 | status_t status = checkReadFrameBufferPermission(); |
| 7610 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7611 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7612 | } |
| 7613 | android::Rect rect; |
| 7614 | rect.left = samplingArea.left; |
| 7615 | rect.top = samplingArea.top; |
| 7616 | rect.right = samplingArea.right; |
| 7617 | rect.bottom = samplingArea.bottom; |
| 7618 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7619 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 7623 | const sp<gui::IRegionSamplingListener>& listener) { |
| 7624 | status_t status = checkReadFrameBufferPermission(); |
| 7625 | if (status == OK) { |
| 7626 | status = mFlinger->removeRegionSamplingListener(listener); |
| 7627 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7628 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 7632 | const sp<gui::IFpsListener>& listener) { |
| 7633 | status_t status = checkReadFrameBufferPermission(); |
| 7634 | if (status == OK) { |
| 7635 | status = mFlinger->addFpsListener(taskId, listener); |
| 7636 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7637 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 7641 | status_t status = checkReadFrameBufferPermission(); |
| 7642 | if (status == OK) { |
| 7643 | status = mFlinger->removeFpsListener(listener); |
| 7644 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7645 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 7649 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 7650 | status_t status = checkAccessPermission(); |
| 7651 | if (status == OK) { |
| 7652 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 7653 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7654 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 7658 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 7659 | status_t status = checkAccessPermission(); |
| 7660 | if (status == OK) { |
| 7661 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 7662 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7663 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs( |
| 7667 | const sp<IBinder>& displayToken, int32_t defaultMode, bool allowGroupSwitching, |
| 7668 | float primaryRefreshRateMin, float primaryRefreshRateMax, float appRequestRefreshRateMin, |
| 7669 | float appRequestRefreshRateMax) { |
| 7670 | status_t status = checkAccessPermission(); |
| 7671 | if (status == OK) { |
| 7672 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, |
| 7673 | static_cast<ui::DisplayModeId>(defaultMode), |
| 7674 | allowGroupSwitching, primaryRefreshRateMin, |
| 7675 | primaryRefreshRateMax, |
| 7676 | appRequestRefreshRateMin, |
| 7677 | appRequestRefreshRateMax); |
| 7678 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7679 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 7683 | gui::DisplayModeSpecs* outSpecs) { |
| 7684 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7685 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | status_t status = checkAccessPermission(); |
| 7689 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7690 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7691 | } |
| 7692 | |
| 7693 | ui::DisplayModeId displayModeId; |
| 7694 | bool allowGroupSwitching; |
| 7695 | float primaryRefreshRateMin; |
| 7696 | float primaryRefreshRateMax; |
| 7697 | float appRequestRefreshRateMin; |
| 7698 | float appRequestRefreshRateMax; |
| 7699 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, &displayModeId, |
| 7700 | &allowGroupSwitching, &primaryRefreshRateMin, |
| 7701 | &primaryRefreshRateMax, &appRequestRefreshRateMin, |
| 7702 | &appRequestRefreshRateMax); |
| 7703 | if (status == NO_ERROR) { |
| 7704 | outSpecs->defaultMode = displayModeId; |
| 7705 | outSpecs->allowGroupSwitching = allowGroupSwitching; |
| 7706 | outSpecs->primaryRefreshRateMin = primaryRefreshRateMin; |
| 7707 | outSpecs->primaryRefreshRateMax = primaryRefreshRateMax; |
| 7708 | outSpecs->appRequestRefreshRateMin = appRequestRefreshRateMin; |
| 7709 | outSpecs->appRequestRefreshRateMax = appRequestRefreshRateMax; |
| 7710 | } |
| 7711 | |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7712 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7713 | } |
| 7714 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7715 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 7716 | bool* outSupport) { |
| 7717 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7718 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7719 | } |
| 7720 | |
| 7721 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 7722 | const gui::DisplayBrightness& brightness) { |
| 7723 | status_t status = checkControlDisplayBrightnessPermission(); |
| 7724 | if (status == OK) { |
| 7725 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 7726 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7727 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7728 | } |
| 7729 | |
| 7730 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 7731 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 7732 | status_t status = checkControlDisplayBrightnessPermission(); |
| 7733 | if (status == OK) { |
| 7734 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 7735 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7736 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 7740 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 7741 | status_t status = checkControlDisplayBrightnessPermission(); |
| 7742 | if (status == OK) { |
| 7743 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 7744 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7745 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7746 | } |
| 7747 | |
| 7748 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 7749 | status_t status = checkAccessPermission(); |
| 7750 | if (status == OK) { |
| 7751 | status = mFlinger->notifyPowerBoost(boostId); |
| 7752 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7753 | return binderStatusFromStatusT(status); |
| 7754 | } |
| 7755 | |
| 7756 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 7757 | const gui::Color& spotColor, |
| 7758 | float lightPosY, float lightPosZ, |
| 7759 | float lightRadius) { |
| 7760 | status_t status = checkAccessPermission(); |
| 7761 | if (status != OK) { |
| 7762 | return binderStatusFromStatusT(status); |
| 7763 | } |
| 7764 | |
| 7765 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 7766 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 7767 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 7768 | lightPosZ, lightRadius); |
| 7769 | return binderStatusFromStatusT(status); |
| 7770 | } |
| 7771 | |
| 7772 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 7773 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 7774 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 7775 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 7776 | if (status != NO_ERROR) { |
| 7777 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 7778 | return binderStatusFromStatusT(status); |
| 7779 | } |
| 7780 | |
| 7781 | if (!support || !support.has_value()) { |
| 7782 | outSupport->reset(); |
| 7783 | } else { |
| 7784 | outSupport->emplace(); |
| 7785 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 7786 | outSupport->value().alphaInterpretation = |
| 7787 | static_cast<int32_t>(support->alphaInterpretation); |
| 7788 | } |
| 7789 | |
| 7790 | return binder::Status::ok(); |
| 7791 | } |
| 7792 | |
| 7793 | binder::Status SurfaceComposerAIDL::setOverrideFrameRate(int32_t uid, float frameRate) { |
| 7794 | status_t status; |
| 7795 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 7796 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 7797 | status = mFlinger->setOverrideFrameRate(uid, frameRate); |
| 7798 | } else { |
| 7799 | ALOGE("setOverrideFrameRate() permission denied for uid: %d", c_uid); |
| 7800 | status = PERMISSION_DENIED; |
| 7801 | } |
| 7802 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7803 | } |
| 7804 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7805 | binder::Status SurfaceComposerAIDL::addTransactionTraceListener( |
| 7806 | const sp<gui::ITransactionTraceListener>& listener) { |
| 7807 | status_t status; |
| 7808 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7809 | const int uid = ipc->getCallingUid(); |
| 7810 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 7811 | status = mFlinger->addTransactionTraceListener(listener); |
| 7812 | } else { |
| 7813 | status = PERMISSION_DENIED; |
| 7814 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7815 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7816 | } |
| 7817 | |
| 7818 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 7819 | *outPriority = mFlinger->getGpuContextPriority(); |
| 7820 | return binder::Status::ok(); |
| 7821 | } |
| 7822 | |
| 7823 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 7824 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7825 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
| 7829 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 7830 | status_t status; |
| 7831 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 7832 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS) { |
| 7833 | status = mFlinger->addWindowInfosListener(windowInfosListener); |
| 7834 | } else { |
| 7835 | status = PERMISSION_DENIED; |
| 7836 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7837 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 7841 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 7842 | status_t status; |
| 7843 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 7844 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS) { |
| 7845 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 7846 | } else { |
| 7847 | status = PERMISSION_DENIED; |
| 7848 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7849 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7850 | } |
| 7851 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7852 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 7853 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 7854 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7855 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 7856 | ipc->getCallingUid()); |
| 7857 | return PERMISSION_DENIED; |
| 7858 | } |
| 7859 | return OK; |
| 7860 | } |
| 7861 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7862 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 7863 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7864 | const int pid = ipc->getCallingPid(); |
| 7865 | const int uid = ipc->getCallingUid(); |
| 7866 | if ((uid != AID_GRAPHICS) && |
| 7867 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 7868 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 7869 | return PERMISSION_DENIED; |
| 7870 | } |
| 7871 | return OK; |
| 7872 | } |
| 7873 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7874 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 7875 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7876 | const int pid = ipc->getCallingPid(); |
| 7877 | const int uid = ipc->getCallingUid(); |
| 7878 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7879 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 7880 | return PERMISSION_DENIED; |
| 7881 | } |
| 7882 | return OK; |
| 7883 | } |
| 7884 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7885 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 7886 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 7887 | #if defined(__gl_h_) |
| 7888 | #error "don't include gl/gl.h in this file" |
| 7889 | #endif |
| 7890 | |
| 7891 | #if defined(__gl2_h_) |
| 7892 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 7893 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 7894 | |
| 7895 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 7896 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |