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> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 47 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 48 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 49 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 50 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 51 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 52 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 54 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 55 | #include <configstore/Utils.h> |
| 56 | #include <cutils/compiler.h> |
| 57 | #include <cutils/properties.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 58 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 59 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 60 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 61 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 62 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 63 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 64 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 65 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 66 | #include <gui/IProducerListener.h> |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 67 | #include <gui/LayerDebugInfo.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 68 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 69 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 70 | #include <gui/Surface.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 71 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 72 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 73 | #include <layerproto/LayerProtoParser.h> |
| 74 | #include <log/log.h> |
| 75 | #include <private/android_filesystem_config.h> |
| 76 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 77 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 78 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 79 | #include <renderengine/impl/ExternalTexture.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 80 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 81 | #include <ui/ColorSpace.h> |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 82 | #include <ui/DataspaceUtils.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 83 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 84 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 85 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 86 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 87 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 88 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 89 | #include <ui/GraphicBufferAllocator.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 90 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 91 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 92 | #include <ui/StaticDisplayInfo.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 94 | #include <utils/String16.h> |
| 95 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 96 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 97 | #include <utils/misc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 99 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 100 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <cinttypes> |
| 102 | #include <cmath> |
| 103 | #include <cstdint> |
| 104 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 105 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 106 | #include <mutex> |
| 107 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 108 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 109 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 110 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 111 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 113 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 114 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 115 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 116 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 117 | #include "Colorizer.h" |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 118 | #include "Display/DisplayMap.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 119 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 120 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 121 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 122 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 123 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 124 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 125 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 126 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 127 | #include "Effects/Daltonizer.h" |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 128 | #include "FlagManager.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 129 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 130 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 131 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 132 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 133 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 134 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 135 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 136 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 137 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 138 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 139 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 140 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 141 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 142 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 143 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 144 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 145 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 146 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 147 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 148 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 149 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 150 | #include "StartPropertySetThread.h" |
| 151 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 152 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 153 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 154 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 155 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 156 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 157 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 158 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 159 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 160 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 161 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 162 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 163 | _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] | 164 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 165 | // To enable layer borders in the system, change the below flag to true. |
| 166 | #undef DOES_CONTAIN_BORDER |
| 167 | #define DOES_CONTAIN_BORDER false |
| 168 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | namespace android { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 170 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 171 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 172 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 173 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 174 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 175 | using namespace hardware::configstore; |
| 176 | using namespace hardware::configstore::V1_0; |
| 177 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 178 | using ftl::Flags; |
| 179 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 180 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 181 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 182 | using aidl::android::hardware::graphics::composer3::Capability; |
| 183 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 184 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 185 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 186 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 187 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 188 | using display::PhysicalDisplay; |
| 189 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 190 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 191 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 192 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 193 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 194 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 195 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 196 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 197 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 198 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 199 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 200 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 201 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 202 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 203 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 204 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 205 | namespace hal = android::hardware::graphics::composer::hal; |
| 206 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 207 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 208 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 209 | static constexpr int FOUR_K_WIDTH = 3840; |
| 210 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 211 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 212 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 213 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 214 | |
| 215 | float getDensityFromProperty(const char* property, bool required) { |
| 216 | char value[PROPERTY_VALUE_MAX]; |
| 217 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 218 | if (!density && required) { |
| 219 | ALOGE("%s must be defined as a build property", property); |
| 220 | return FALLBACK_DENSITY; |
| 221 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 222 | return density; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 225 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 226 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 227 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 228 | } |
| 229 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 230 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 231 | const auto displayIdleTimerMsKey = [displayId] { |
| 232 | std::stringstream ss; |
| 233 | ss << "debug.sf.set_idle_timer_ms_" << displayId.value; |
| 234 | return ss.str(); |
| 235 | }(); |
| 236 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 237 | const int32_t displayIdleTimerMs = base::GetIntProperty(displayIdleTimerMsKey, 0); |
| 238 | if (displayIdleTimerMs > 0) { |
| 239 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 240 | } |
| 241 | |
| 242 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms", 0); |
| 243 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 244 | return std::chrono::milliseconds(millis); |
| 245 | } |
| 246 | |
| 247 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 248 | const auto displaySupportKernelIdleTimerKey = [displayId] { |
| 249 | std::stringstream ss; |
| 250 | ss << "debug.sf.support_kernel_idle_timer_" << displayId.value; |
| 251 | return ss.str(); |
| 252 | }(); |
| 253 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 254 | const auto displaySupportKernelIdleTimer = |
| 255 | base::GetBoolProperty(displaySupportKernelIdleTimerKey, false); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 256 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 259 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 260 | using fps_approx_ops::operator>; |
| 261 | Fps refreshRate = Fps::fromValue(outMode.refreshRate); |
| 262 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 263 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 264 | } |
| 265 | |
| 266 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 267 | ui::DisplayMode& outMode) { |
| 268 | if (isAbove4k30(outMode) && |
| 269 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 270 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 271 | for (ui::Hdr type : displayHdrTypes) { |
| 272 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 273 | outMode.supportedHdrTypes.push_back(type); |
| 274 | } |
| 275 | } |
| 276 | } else { |
| 277 | for (ui::Hdr type : displayHdrTypes) { |
| 278 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 279 | outMode.supportedHdrTypes.push_back(type); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 286 | std::vector<ui::Hdr> hdrTypes; |
| 287 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 288 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 289 | hdrTypes.push_back(type); |
| 290 | } |
| 291 | } |
| 292 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 293 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 294 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 295 | } |
| 296 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 297 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 298 | if (!surfaceControl) { |
| 299 | return UNASSIGNED_LAYER_ID; |
| 300 | } |
| 301 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 302 | } |
| 303 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 304 | } // namespace anonymous |
| 305 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | // --------------------------------------------------------------------------- |
| 307 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 308 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 309 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 310 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 311 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 312 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 313 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 314 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 315 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 316 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 317 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 318 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 319 | |
Vishnu Nair | 4fb00ed | 2022-06-03 10:25:09 -0700 | [diff] [blame] | 320 | static const int MAX_TRACING_MEMORY = 1024 * 1024 * 1024; // 1GB |
| 321 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 322 | // --------------------------------------------------------------------------- |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 323 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 324 | bool SurfaceFlinger::useHwcForRgbToYuv; |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 325 | bool SurfaceFlinger::hasSyncFramework; |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 326 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 327 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 328 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 329 | bool SurfaceFlinger::useContextPriority; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 330 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 331 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 332 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 333 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 334 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 335 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 336 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 337 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 338 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 339 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 340 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 341 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 342 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 343 | return std::string("Enhanced"); |
| 344 | default: |
| 345 | return std::string("Unknown ") + |
| 346 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 347 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 350 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 351 | IPCThreadState* ipc = IPCThreadState::self(); |
| 352 | const int pid = ipc->getCallingPid(); |
| 353 | const int uid = ipc->getCallingUid(); |
| 354 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 355 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 358 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 359 | : mFactory(factory), |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 360 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 361 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Adithya Srinivasan | 2db3c1b | 2020-11-18 12:43:17 -0800 | [diff] [blame] | 362 | mFrameTracer(mFactory.createFrameTracer()), |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 363 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
Dominik Laskowski | eddeda1 | 2019-07-19 11:54:13 -0700 | [diff] [blame] | 364 | mCompositionEngine(mFactory.createCompositionEngine()), |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 365 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 366 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 367 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
Roman Kiryanov | 3388bf9 | 2022-11-11 15:35:16 -0800 | [diff] [blame] | 368 | mInternalDisplayDensity( |
| 369 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 370 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 371 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 372 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 373 | } |
Lloyd Pique | ac648ee | 2018-01-17 13:42:24 -0800 | [diff] [blame] | 374 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 375 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 376 | ALOGI("SurfaceFlinger is starting"); |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 377 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 378 | hasSyncFramework = running_without_sync_framework(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 380 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
Fabien Sanglard | c45a7d9 | 2017-03-14 13:24:22 -0700 | [diff] [blame] | 381 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 382 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 383 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 384 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
Fabien Sanglard | 1971b63 | 2017-03-10 14:50:03 -0800 | [diff] [blame] | 385 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 386 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 387 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 388 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 389 | mSupportsWideColor = has_wide_color_display(false); |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 390 | mDefaultCompositionDataspace = |
| 391 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
Peiyong Lin | 8cabfc3 | 2019-06-14 14:25:43 -0700 | [diff] [blame] | 392 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 393 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 394 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 395 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 396 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 397 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 398 | wideColorGamutCompositionPixelFormat = |
| 399 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
Peiyong Lin | b3839ad | 2018-09-05 15:37:19 -0700 | [diff] [blame] | 400 | |
Yichi Chen | da901bf | 2019-06-28 14:58:27 +0800 | [diff] [blame] | 401 | mColorSpaceAgnosticDataspace = |
| 402 | static_cast<ui::Dataspace>(color_space_agnostic_dataspace(Dataspace::UNKNOWN)); |
| 403 | |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 404 | mLayerCachingEnabled = [] { |
| 405 | const bool enable = |
| 406 | android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false); |
| 407 | return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable); |
| 408 | }(); |
| 409 | |
Sundong Ahn | d5e08f6 | 2018-12-12 20:27:28 +0900 | [diff] [blame] | 410 | useContextPriority = use_context_priority(true); |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 411 | |
Sundong Ahn | 85131bd | 2019-02-18 15:51:53 +0900 | [diff] [blame] | 412 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 413 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // debugging stuff... |
| 415 | char value[PROPERTY_VALUE_MAX]; |
Mathias Agopian | 8afb7e3 | 2011-08-15 20:44:40 -0700 | [diff] [blame] | 416 | |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 417 | property_get("ro.build.type", value, "user"); |
| 418 | mIsUserBuild = strcmp(value, "user") == 0; |
| 419 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 420 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
Orion Hodson | 34397da | 2019-02-04 09:36:10 +0000 | [diff] [blame] | 421 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 422 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 423 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
Ady Abraham | adb9a99 | 2019-09-19 21:21:55 +0000 | [diff] [blame] | 424 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 425 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 426 | bool supportsBlurs = atoi(value); |
Lucas Dupin | 00f1642 | 2020-03-11 11:33:04 -0700 | [diff] [blame] | 427 | mSupportsBlur = supportsBlurs; |
| 428 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 429 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 430 | const size_t defaultListSize = MAX_LAYERS; |
Dan Stoza | 0a0158c | 2018-03-16 13:38:54 -0700 | [diff] [blame] | 431 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 432 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
Alec Mouri | 601393f | 2020-02-21 13:26:52 -0800 | [diff] [blame] | 433 | mGraphicBufferProducerListSizeLogThreshold = |
| 434 | std::max(static_cast<int>(0.95 * |
| 435 | static_cast<double>(mMaxGraphicBufferProducerListSize)), |
| 436 | 1); |
Dan Stoza | 0a0158c | 2018-03-16 13:38:54 -0700 | [diff] [blame] | 437 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 438 | property_get("debug.sf.luma_sampling", value, "1"); |
| 439 | mLumaSampling = atoi(value); |
| 440 | |
Vishnu Nair | b2a999b | 2020-01-23 13:43:02 -0800 | [diff] [blame] | 441 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 442 | mDisableClientCompositionCache = atoi(value); |
| 443 | |
Vishnu Nair | 3539d81 | 2022-02-26 09:20:17 -0800 | [diff] [blame] | 444 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 445 | mPredictCompositionStrategy = atoi(value); |
| 446 | |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 447 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 448 | mTreat170mAsSrgb = atoi(value); |
| 449 | |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 450 | mIgnoreHwcPhysicalDisplayOrientation = |
| 451 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 452 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 453 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 454 | // but since /data may be encrypted, we need to wait until after vold |
| 455 | // comes online to attempt to read the property. The property is |
| 456 | // instead read after the boot animation |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 457 | |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 458 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 459 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 460 | // services that are not listed in the manifests. Considered |
| 461 | // deriving the setting from the set service name, but it |
| 462 | // would be brittle if the name that's not 'default' is used |
| 463 | // for production purposes later on. |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 464 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 465 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 466 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 467 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 468 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
Ady Abraham | 0aa373a | 2022-11-22 13:56:50 -0800 | [diff] [blame] | 469 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 470 | mRefreshRateOverlayRenderRate = |
| 471 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
Yifei Zhang | cfb7bb3 | 2023-01-12 16:17:14 -0800 | [diff] [blame] | 472 | mRefreshRateOverlayShowInMiddle = |
| 473 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 474 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 475 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
| 476 | mTransactionTracing.emplace(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 477 | } |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 478 | |
| 479 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 480 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 481 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | 593b4cb | 2023-03-02 16:16:33 -0800 | [diff] [blame] | 482 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, false); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 483 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
Vishnu Nair | 3e76a50 | 2023-03-05 20:01:14 +0000 | [diff] [blame] | 484 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 488 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 489 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 490 | } |
| 491 | |
Ady Abraham | fb67be1 | 2022-08-10 10:46:22 -0700 | [diff] [blame] | 492 | if (base::GetBoolProperty("debug.sf.latch_unsignaled"s, false)) { |
| 493 | return LatchUnsignaledConfig::Always; |
| 494 | } |
| 495 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 496 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 499 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 500 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 501 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 502 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 503 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 504 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 505 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 506 | // Sever the link to inputflinger since it's gone as well. |
| 507 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 508 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 509 | initializeDisplays(); |
| 510 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 511 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 512 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 515 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 516 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 519 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 520 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 521 | // onTransact already checks for some permissions, but adding an additional check here. |
| 522 | // This is to ensure that only system and graphics can request to create a secure |
| 523 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 524 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 525 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 526 | ALOGE("Only privileged processes can create a secure display"); |
| 527 | return nullptr; |
| 528 | } |
| 529 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 530 | class DisplayToken : public BBinder { |
| 531 | sp<SurfaceFlinger> flinger; |
| 532 | virtual ~DisplayToken() { |
| 533 | // no more references, this display must be terminated |
| 534 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 535 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 536 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 537 | } |
| 538 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 539 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 540 | : flinger(flinger) { |
| 541 | } |
| 542 | }; |
| 543 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 544 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 545 | |
| 546 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 547 | // Display ID is assigned when virtual display is allocated by HWC. |
| 548 | DisplayDeviceState state; |
| 549 | state.isSecure = secure; |
| 550 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 551 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 552 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 553 | return token; |
| 554 | } |
| 555 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 556 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 557 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 558 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 559 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 560 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 561 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 562 | return; |
| 563 | } |
| 564 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 565 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 566 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 567 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 568 | return; |
| 569 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 570 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 571 | setTransactionFlags(eDisplayTransactionNeeded); |
| 572 | } |
| 573 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 574 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 575 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 576 | if (!generator && enable) { |
| 577 | ALOGI("Enabling HAL virtual displays"); |
| 578 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 579 | } else if (generator && !enable) { |
| 580 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 581 | generator.reset(); |
| 582 | } |
| 583 | } |
| 584 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 585 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 586 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 587 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 588 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 589 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 590 | return *id; |
| 591 | } |
| 592 | |
| 593 | generator->releaseId(*id); |
| 594 | } else { |
| 595 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 596 | } |
| 597 | |
| 598 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 599 | } |
| 600 | |
| 601 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 602 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 603 | return *id; |
| 604 | } |
| 605 | |
| 606 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 607 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 608 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 609 | generator->releaseId(*id); |
| 610 | } |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 615 | LOG_ALWAYS_FATAL_IF(!id); |
| 616 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 617 | } |
| 618 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 619 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 620 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 621 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 622 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 623 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 624 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 625 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 626 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 627 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 628 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 629 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 630 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 631 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 632 | return displayIds; |
| 633 | } |
| 634 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 635 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 636 | const sp<display::DisplayToken>& displayToken) const { |
| 637 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 638 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 639 | } |
| 640 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 641 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 642 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 643 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 646 | status_t SurfaceFlinger::getColorManagement(bool* outGetColorManagement) const { |
| 647 | if (!outGetColorManagement) { |
| 648 | return BAD_VALUE; |
| 649 | } |
| 650 | *outGetColorManagement = useColorManagement; |
| 651 | return NO_ERROR; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 654 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 655 | return mCompositionEngine->getHwComposer(); |
| 656 | } |
| 657 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 658 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 659 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 662 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 663 | return *mCompositionEngine.get(); |
| 664 | } |
| 665 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 666 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 667 | if (mBootFinished == true) { |
| 668 | ALOGE("Extra call to bootFinished"); |
| 669 | return; |
| 670 | } |
| 671 | mBootFinished = true; |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 672 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 673 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 674 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 675 | |
| 676 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 677 | mRenderEnginePrimeCacheFuture.get(); |
| 678 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | const nsecs_t now = systemTime(); |
| 680 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 681 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 682 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 683 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 684 | mFrameTimeline->onBootFinished(); |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 685 | getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 686 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 687 | // wait patiently for the window manager death |
| 688 | const String16 name("window"); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 689 | mWindowManager = defaultServiceManager()->getService(name); |
| 690 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 691 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 695 | // formerly we would just kill the process, but we now ask it to exit so it |
| 696 | // can choose where to stop the animation. |
| 697 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 698 | |
| 699 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 700 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 701 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 702 | |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 703 | sp<IBinder> input(defaultServiceManager()->getService(String16("inputflinger"))); |
| 704 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 705 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 706 | if (input == nullptr) { |
| 707 | ALOGE("Failed to link to input service"); |
| 708 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 709 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 710 | } |
| 711 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 712 | readPersistentProperties(); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 713 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 714 | const bool hintSessionEnabled = mFlagManager.use_adpf_cpu_hint(); |
| 715 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 716 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 717 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 718 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 719 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 720 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 721 | std::vector<int32_t> tidList; |
| 722 | tidList.emplace_back(gettid()); |
| 723 | if (renderEngineTid.has_value()) { |
| 724 | tidList.emplace_back(*renderEngineTid); |
| 725 | } |
| 726 | if (!mPowerAdvisor->startPowerHintSession(tidList)) { |
| 727 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 728 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 731 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 732 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 733 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 734 | ftl::FakeGuard guard(mStateLock); |
| 735 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 736 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 737 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 740 | uint32_t SurfaceFlinger::getNewTexture() { |
| 741 | { |
| 742 | std::lock_guard lock(mTexturePoolMutex); |
| 743 | if (!mTexturePool.empty()) { |
| 744 | uint32_t name = mTexturePool.back(); |
| 745 | mTexturePool.pop_back(); |
| 746 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
| 747 | return name; |
| 748 | } |
| 749 | |
| 750 | // The pool was too small, so increase it for the future |
| 751 | ++mTexturePoolSize; |
| 752 | } |
| 753 | |
| 754 | // The pool was empty, so we need to get a new texture name directly using a |
| 755 | // blocking call to the main thread |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 756 | auto genTextures = [this] { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 757 | uint32_t name = 0; |
| 758 | getRenderEngine().genTextures(1, &name); |
| 759 | return name; |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 760 | }; |
| 761 | if (std::this_thread::get_id() == mMainThreadId) { |
| 762 | return genTextures(); |
| 763 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 764 | return mScheduler->schedule(genTextures).get(); |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 765 | } |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 768 | void SurfaceFlinger::deleteTextureAsync(uint32_t texture) { |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 769 | std::lock_guard lock(mTexturePoolMutex); |
| 770 | // We don't change the pool size, so the fix-up logic in postComposition will decide whether |
| 771 | // to actually delete this or not based on mTexturePoolSize |
| 772 | mTexturePool.push_back(texture); |
| 773 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 776 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 777 | chooseRenderEngineTypeViaSysProp() { |
| 778 | char prop[PROPERTY_VALUE_MAX]; |
| 779 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
| 780 | |
| 781 | if (strcmp(prop, "gles") == 0) { |
| 782 | return renderengine::RenderEngine::RenderEngineType::GLES; |
| 783 | } else if (strcmp(prop, "threaded") == 0) { |
| 784 | return renderengine::RenderEngine::RenderEngineType::THREADED; |
| 785 | } else if (strcmp(prop, "skiagl") == 0) { |
| 786 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 787 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 788 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 789 | } else if (strcmp(prop, "skiavk") == 0) { |
| 790 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 791 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
| 792 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK_THREADED; |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 793 | } else { |
| 794 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 795 | return {}; |
| 796 | } |
| 797 | } |
| 798 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 799 | // Do not call property_set on main thread which will be blocked by init |
| 800 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 801 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 802 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 803 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 804 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 805 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 806 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 807 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 808 | // 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] | 809 | // 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] | 810 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 811 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 812 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
| 813 | .setUseColorManagerment(useColorManagement) |
| 814 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 815 | .setPrecacheToneMapperShaderOnly(false) |
| 816 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 817 | .setContextPriority( |
| 818 | useContextPriority |
| 819 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 820 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
| 821 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 822 | builder.setRenderEngineType(type.value()); |
| 823 | } |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 824 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 825 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 826 | mMaxRenderTargetSize = |
| 827 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 828 | |
| 829 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 830 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 831 | ALOGW("Failed to set main task profile"); |
| 832 | } |
| 833 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 834 | mCompositionEngine->setTimeStats(mTimeStats); |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 835 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 836 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 837 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 838 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 839 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 840 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 841 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 842 | enableHalVirtualDisplays(true); |
| 843 | } |
| 844 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 845 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 846 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 847 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 848 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 849 | // Commit primary display. |
| 850 | sp<const DisplayDevice> display; |
| 851 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 852 | const auto& displays = mCurrentState.displays; |
| 853 | |
| 854 | const auto& token = displays.keyAt(*indexOpt); |
| 855 | const auto& state = displays.valueAt(*indexOpt); |
| 856 | |
| 857 | processDisplayAdded(token, state); |
| 858 | mDrawingState.displays.add(token, state); |
| 859 | |
| 860 | display = getDefaultDisplayDeviceLocked(); |
| 861 | } |
| 862 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 863 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 864 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 865 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 866 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 867 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 868 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 869 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 870 | initScheduler(display); |
| 871 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
| 872 | |
| 873 | // Commit secondary display(s). |
| 874 | processDisplayChangesLocked(); |
| 875 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 876 | // initialize our drawing state |
| 877 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 878 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 879 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 880 | |
| 881 | static_cast<void>(mScheduler->schedule( |
| 882 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 883 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 884 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 885 | |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 886 | char primeShaderCache[PROPERTY_VALUE_MAX]; |
| 887 | property_get("service.sf.prime_shader_cache", primeShaderCache, "1"); |
| 888 | if (atoi(primeShaderCache)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 889 | if (setSchedFifo(false) != NO_ERROR) { |
| 890 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 891 | } |
| 892 | |
| 893 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(); |
| 894 | |
| 895 | if (setSchedFifo(true) != NO_ERROR) { |
| 896 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 897 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 898 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 899 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 900 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 901 | |
| 902 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 903 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 904 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 905 | |
| 906 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 907 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 908 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 910 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 913 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 914 | Mutex::Autolock _l(mStateLock); |
| 915 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 916 | char value[PROPERTY_VALUE_MAX]; |
| 917 | |
| 918 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 919 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 920 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 921 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 922 | |
| 923 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 924 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 925 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 926 | mForceColorMode = |
| 927 | static_cast<ui::ColorMode>(base::GetIntProperty("persist.sys.sf.color_mode"s, 0)); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 930 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 931 | // Start boot animation service by setting a property mailbox |
| 932 | // 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] | 933 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 934 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 935 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 936 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 937 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 938 | } |
| 939 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 941 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 942 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 943 | std::vector<FrameEvent>* outSupported) const { |
| 944 | *outSupported = { |
| 945 | FrameEvent::REQUESTED_PRESENT, |
| 946 | FrameEvent::ACQUIRE, |
| 947 | FrameEvent::LATCH, |
| 948 | FrameEvent::FIRST_REFRESH_START, |
| 949 | FrameEvent::LAST_REFRESH_START, |
| 950 | FrameEvent::GPU_COMPOSITION_DONE, |
| 951 | FrameEvent::DEQUEUE_READY, |
| 952 | FrameEvent::RELEASE, |
| 953 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 954 | |
| 955 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 956 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 957 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 958 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 959 | } |
| 960 | return NO_ERROR; |
| 961 | } |
| 962 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 963 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 964 | if (!displayToken || !state) { |
| 965 | return BAD_VALUE; |
| 966 | } |
| 967 | |
| 968 | Mutex::Autolock lock(mStateLock); |
| 969 | |
| 970 | const auto display = getDisplayDeviceLocked(displayToken); |
| 971 | if (!display) { |
| 972 | return NAME_NOT_FOUND; |
| 973 | } |
| 974 | |
| 975 | state->layerStack = display->getLayerStack(); |
| 976 | state->orientation = display->getOrientation(); |
| 977 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 978 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 979 | state->layerStackSpaceRect = |
| 980 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 981 | |
| 982 | return NO_ERROR; |
| 983 | } |
| 984 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 985 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 986 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 987 | return BAD_VALUE; |
| 988 | } |
| 989 | |
| 990 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 991 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 992 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 993 | |
| 994 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 995 | return NAME_NOT_FOUND; |
| 996 | } |
| 997 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 998 | const auto& [display, snapshotRef] = *displayOpt; |
| 999 | const auto& snapshot = snapshotRef.get(); |
| 1000 | |
| 1001 | info->connectionType = snapshot.connectionType(); |
| 1002 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1003 | |
| 1004 | if (mEmulatedDisplayDensity) { |
| 1005 | info->density = mEmulatedDisplayDensity; |
| 1006 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1007 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1008 | ? mInternalDisplayDensity |
| 1009 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1010 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1011 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1012 | |
| 1013 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1014 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1015 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1016 | return NO_ERROR; |
| 1017 | } |
| 1018 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1019 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1020 | const sp<DisplayDevice>& display, |
| 1021 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1022 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1023 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1024 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1025 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1026 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1027 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1028 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1029 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1030 | auto [width, height] = mode->getResolution(); |
| 1031 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1032 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1033 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1034 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1035 | std::swap(width, height); |
| 1036 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1039 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1040 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1041 | outMode.xDpi = xDpi; |
| 1042 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1043 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1044 | const nsecs_t period = mode->getVsyncPeriod(); |
| 1045 | outMode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1046 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 1047 | const auto vsyncConfigSet = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1048 | mVsyncConfiguration->getConfigsForRefreshRate(Fps::fromValue(outMode.refreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1049 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1050 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1051 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1052 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1053 | // This is how far in advance a buffer must be queued for |
| 1054 | // presentation at a given time. If you want a buffer to appear |
| 1055 | // on the screen at time N, you must submit the buffer before |
| 1056 | // (N - presentationDeadline). |
| 1057 | // |
| 1058 | // Normally it's one full refresh period (to give SF a chance to |
| 1059 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1060 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1061 | // composer or panel must be accounted for here. |
| 1062 | // |
| 1063 | // We add an additional 1ms to allow for processing time and |
| 1064 | // differences between the ideal and actual refresh rate. |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1065 | outMode.presentationDeadline = period - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1066 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1067 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1068 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1071 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
| 1072 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1073 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1074 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1075 | const auto mode = display->refreshRateSelector().getActiveMode(); |
| 1076 | info->activeDisplayModeId = mode.modePtr->getId().value(); |
| 1077 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1078 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1079 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1080 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1081 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1082 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1083 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1084 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1085 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1086 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1087 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1088 | |
| 1089 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1090 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1091 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1092 | info->preferredBootDisplayMode = modeId->value(); |
| 1093 | } |
| 1094 | } |
| 1095 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1096 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1097 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1098 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1099 | ui::DynamicDisplayInfo* info) { |
| 1100 | if (!info) { |
| 1101 | return BAD_VALUE; |
| 1102 | } |
| 1103 | |
| 1104 | Mutex::Autolock lock(mStateLock); |
| 1105 | |
| 1106 | const auto id_ = |
| 1107 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1108 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1109 | |
| 1110 | if (!displayOpt) { |
| 1111 | return NAME_NOT_FOUND; |
| 1112 | } |
| 1113 | |
| 1114 | const auto& [display, snapshotRef] = *displayOpt; |
| 1115 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1116 | return NO_ERROR; |
| 1117 | } |
| 1118 | |
| 1119 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1120 | ui::DynamicDisplayInfo* info) { |
| 1121 | if (!displayToken || !info) { |
| 1122 | return BAD_VALUE; |
| 1123 | } |
| 1124 | |
| 1125 | Mutex::Autolock lock(mStateLock); |
| 1126 | |
| 1127 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1128 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1129 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1130 | |
| 1131 | if (!displayOpt) { |
| 1132 | return NAME_NOT_FOUND; |
| 1133 | } |
| 1134 | |
| 1135 | const auto& [display, snapshotRef] = *displayOpt; |
| 1136 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1137 | return NO_ERROR; |
| 1138 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1139 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1140 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1141 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1142 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1143 | return BAD_VALUE; |
| 1144 | } |
| 1145 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1146 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1147 | { |
| 1148 | Mutex::Autolock lock(mStateLock); |
| 1149 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1150 | } |
| 1151 | |
Leon Scroggins III | f527295 | 2023-04-06 14:55:22 -0400 | [diff] [blame] | 1152 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1153 | // want, rather than us picking an arbitrary one (the pacesetter, in this |
| 1154 | // case). |
| 1155 | if (displayToken && !displayIdOpt) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1156 | ALOGE("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1157 | return NAME_NOT_FOUND; |
| 1158 | } |
| 1159 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1160 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1161 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1162 | return NO_ERROR; |
| 1163 | } |
| 1164 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1165 | void SurfaceFlinger::setDesiredActiveMode(display::DisplayModeRequest&& request, bool force) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1166 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1167 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1168 | const auto displayId = request.mode.modePtr->getPhysicalDisplayId(); |
| 1169 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1170 | if (!display) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1171 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1172 | return; |
| 1173 | } |
| 1174 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1175 | const auto mode = request.mode; |
| 1176 | const bool emitEvent = request.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1177 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1178 | switch (display->setDesiredActiveMode(DisplayDevice::ActiveModeInfo(std::move(request)), |
| 1179 | force)) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1180 | case DisplayDevice::DesiredActiveModeAction::InitiateDisplayModeSwitch: |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1181 | // Set the render rate as setDesiredActiveMode updated it. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1182 | mScheduler->setRenderRate(displayId, |
| 1183 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1184 | |
| 1185 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1186 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1187 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1188 | // Start receiving vsync samples now, so that we can detect a period |
| 1189 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1190 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
| 1191 | mode.modePtr->getFps()); |
| 1192 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1193 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1194 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1195 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1196 | updatePhaseConfiguration(mode.fps); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1197 | mScheduler->setModeChangePending(true); |
| 1198 | break; |
| 1199 | case DisplayDevice::DesiredActiveModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1200 | mScheduler->setRenderRate(displayId, mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1201 | updatePhaseConfiguration(mode.fps); |
| 1202 | mRefreshRateStats->setRefreshRate(mode.fps); |
| 1203 | if (display->getPhysicalId() == mActiveDisplayId && emitEvent) { |
| 1204 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, mode); |
| 1205 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1206 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1207 | break; |
| 1208 | case DisplayDevice::DesiredActiveModeAction::None: |
| 1209 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1210 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1213 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
| 1214 | DisplayModeId modeId) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1215 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1216 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1217 | if (!displayToken) { |
| 1218 | return BAD_VALUE; |
| 1219 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1220 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1221 | const char* const whence = __func__; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1222 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1223 | const auto displayOpt = |
| 1224 | FTL_FAKE_GUARD(mStateLock, |
| 1225 | ftl::find_if(mPhysicalDisplays, |
| 1226 | PhysicalDisplay::hasToken(displayToken)) |
| 1227 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1228 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1229 | if (!displayOpt) { |
| 1230 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1231 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1232 | } |
| 1233 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1234 | const auto& [display, snapshotRef] = *displayOpt; |
| 1235 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1236 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1237 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
| 1238 | [](const DisplayModePtr& mode) { return mode->getFps(); }); |
| 1239 | |
| 1240 | if (!fpsOpt) { |
| 1241 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1242 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1243 | return BAD_VALUE; |
| 1244 | } |
| 1245 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1246 | const Fps fps = *fpsOpt; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1247 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1248 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1249 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1250 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1251 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1252 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1253 | {fps, fps}, |
| 1254 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1255 | |
| 1256 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1257 | }); |
| 1258 | |
| 1259 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1260 | } |
| 1261 | |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1262 | void SurfaceFlinger::updateInternalStateWithChangedMode() { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1263 | ATRACE_CALL(); |
| 1264 | |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1265 | const auto display = getDefaultDisplayDeviceLocked(); |
| 1266 | if (!display) { |
| 1267 | return; |
| 1268 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1269 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 1270 | const auto upcomingModeInfo = display->getUpcomingActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1271 | if (!upcomingModeInfo.modeOpt) { |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1272 | // There is no pending mode change. This can happen if the active |
| 1273 | // display changed and the mode change happened on a different display. |
| 1274 | return; |
| 1275 | } |
| 1276 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1277 | if (display->getActiveMode().modePtr->getResolution() != |
| 1278 | upcomingModeInfo.modeOpt->modePtr->getResolution()) { |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1279 | auto& state = mCurrentState.displays.editValueFor(display->getDisplayToken()); |
| 1280 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1281 | // way the framebuffer). |
| 1282 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1283 | state.physical->activeMode = upcomingModeInfo.modeOpt->modePtr.get(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1284 | processDisplayChangesLocked(); |
| 1285 | |
| 1286 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1287 | return; |
| 1288 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1289 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1290 | mPhysicalDisplays.get(display->getPhysicalId()) |
| 1291 | .transform(&PhysicalDisplay::snapshotRef) |
| 1292 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 1293 | FTL_FAKE_GUARD(kMainThreadContext, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1294 | display->setActiveMode(upcomingModeInfo.modeOpt->modePtr->getId(), |
| 1295 | upcomingModeInfo.modeOpt->modePtr->getFps(), |
| 1296 | upcomingModeInfo.modeOpt->fps)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1297 | })); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1298 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1299 | const Fps refreshRate = upcomingModeInfo.modeOpt->fps; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1300 | mRefreshRateStats->setRefreshRate(refreshRate); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 1301 | updatePhaseConfiguration(refreshRate); |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1302 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1303 | if (upcomingModeInfo.event != scheduler::DisplayModeEvent::None) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1304 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, *upcomingModeInfo.modeOpt); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1305 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1308 | void SurfaceFlinger::clearDesiredActiveModeState(const sp<DisplayDevice>& display) { |
| 1309 | display->clearDesiredActiveModeState(); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1310 | if (display->getPhysicalId() == mActiveDisplayId) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1311 | mScheduler->setModeChangePending(false); |
| 1312 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1315 | void SurfaceFlinger::desiredActiveModeChangeDone(const sp<DisplayDevice>& display) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1316 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1317 | const auto& modeOpt = desiredActiveMode->modeOpt; |
| 1318 | const auto displayId = modeOpt->modePtr->getPhysicalDisplayId(); |
| 1319 | const auto displayFps = modeOpt->modePtr->getFps(); |
| 1320 | const auto renderFps = modeOpt->fps; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1321 | clearDesiredActiveModeState(display); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1322 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, displayFps); |
| 1323 | mScheduler->setRenderRate(displayId, renderFps); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1324 | updatePhaseConfiguration(renderFps); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1325 | } |
| 1326 | |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1327 | void SurfaceFlinger::setActiveModeInHwcIfNeeded() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1328 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1329 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1330 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1331 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1332 | for (const auto& [id, physical] : mPhysicalDisplays) { |
| 1333 | const auto& snapshot = physical.snapshot(); |
| 1334 | |
| 1335 | if (snapshot.connectionType() != ui::DisplayConnectionType::Internal) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1336 | continue; |
| 1337 | } |
| 1338 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1339 | const auto display = getDisplayDeviceLocked(id); |
| 1340 | if (!display) continue; |
| 1341 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1342 | // Store the local variable to release the lock. |
| 1343 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1344 | if (!desiredActiveMode) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1345 | // No desired active mode pending to be applied. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1346 | continue; |
| 1347 | } |
| 1348 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1349 | if (id != mActiveDisplayId) { |
| 1350 | // Display is no longer the active display, so abort the mode change. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1351 | clearDesiredActiveModeState(display); |
| 1352 | continue; |
| 1353 | } |
| 1354 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1355 | const auto desiredModeId = desiredActiveMode->modeOpt->modePtr->getId(); |
| 1356 | const auto displayModePtrOpt = snapshot.displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1357 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1358 | if (!displayModePtrOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1359 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1360 | desiredModeId.value()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1361 | clearDesiredActiveModeState(display); |
| 1362 | continue; |
| 1363 | } |
| 1364 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1365 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, desiredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1366 | to_string(displayModePtrOpt->get()->getFps()).c_str(), |
| 1367 | to_string(display->getId()).c_str()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1368 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1369 | if (display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1370 | // 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] | 1371 | desiredActiveModeChangeDone(display); |
| 1372 | continue; |
| 1373 | } |
| 1374 | |
| 1375 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1376 | // allowed modes might have changed by the time we process the refresh. |
| 1377 | // Make sure the desired mode is still allowed |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1378 | const auto displayModeAllowed = |
| 1379 | display->refreshRateSelector().isModeAllowed(*desiredActiveMode->modeOpt); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1380 | if (!displayModeAllowed) { |
Marin Shalamanov | dd00c00 | 2021-11-04 16:54:38 +0100 | [diff] [blame] | 1381 | clearDesiredActiveModeState(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1382 | continue; |
| 1383 | } |
| 1384 | |
| 1385 | // TODO(b/142753666) use constrains |
| 1386 | hal::VsyncPeriodChangeConstraints constraints; |
| 1387 | constraints.desiredTimeNanos = systemTime(); |
| 1388 | constraints.seamlessRequired = false; |
| 1389 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1390 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 1391 | const auto status = |
| 1392 | display->initiateModeChange(*desiredActiveMode, constraints, &outTimeline); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1393 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1394 | if (status != NO_ERROR) { |
| 1395 | // initiateModeChange may fail if a hotplug event is just about |
| 1396 | // to be sent. We just log the error in this case. |
| 1397 | ALOGW("initiateModeChange failed: %d", status); |
| 1398 | continue; |
| 1399 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1400 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1401 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1402 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1403 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1404 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1405 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1406 | mSetActiveModePending = true; |
| 1407 | } else { |
| 1408 | // Updating the internal state should be done outside the loop, |
| 1409 | // because it can recreate a DisplayDevice and modify mDisplays |
| 1410 | // which will invalidate the iterator. |
| 1411 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | if (displayToUpdateImmediately) { |
| 1416 | updateInternalStateWithChangedMode(); |
| 1417 | |
| 1418 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
| 1419 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1420 | if (desiredActiveMode && display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1421 | desiredActiveModeChangeDone(display); |
| 1422 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1423 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1424 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1425 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1426 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1427 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1428 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1429 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1430 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1431 | for (const auto& [_, display] : mDisplays) { |
| 1432 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1433 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1434 | } |
| 1435 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1436 | }); |
| 1437 | |
| 1438 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1441 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1442 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1443 | if (!displayToken) { |
| 1444 | return BAD_VALUE; |
| 1445 | } |
| 1446 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1447 | Mutex::Autolock lock(mStateLock); |
| 1448 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1449 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1450 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1451 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1452 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1455 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1456 | return INVALID_OPERATION; |
| 1457 | } |
| 1458 | |
| 1459 | // TODO(b/229846990): For now, assume that all internal displays have the same primaries. |
| 1460 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1461 | return NO_ERROR; |
| 1462 | } |
| 1463 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1464 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1465 | if (!displayToken) { |
| 1466 | return BAD_VALUE; |
| 1467 | } |
| 1468 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1469 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1470 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1471 | const auto displayOpt = |
| 1472 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1473 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1474 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1475 | |
| 1476 | if (!displayOpt) { |
| 1477 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1478 | return NAME_NOT_FOUND; |
| 1479 | } |
| 1480 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1481 | const auto& [display, snapshotRef] = *displayOpt; |
| 1482 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1483 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1484 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1485 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1486 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1487 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1488 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1489 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1490 | return BAD_VALUE; |
| 1491 | } |
| 1492 | |
| 1493 | display->getCompositionDisplay()->setColorProfile( |
| 1494 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC, Dataspace::UNKNOWN}); |
| 1495 | |
| 1496 | return NO_ERROR; |
| 1497 | }); |
| 1498 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1499 | // TODO(b/195698395): Propagate error. |
| 1500 | future.wait(); |
| 1501 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1502 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1503 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1504 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1505 | auto future = mScheduler->schedule( |
| 1506 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1507 | |
| 1508 | *outSupport = future.get(); |
| 1509 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1512 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1513 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1514 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1515 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1516 | for (const auto& combination : aidlProperties.combinations) { |
| 1517 | std::vector<int32_t> pixelFormats; |
| 1518 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1519 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1520 | std::back_inserter(pixelFormats), |
| 1521 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1522 | std::vector<int32_t> standards; |
| 1523 | standards.reserve(combination.standards.size()); |
| 1524 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1525 | std::back_inserter(standards), |
| 1526 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1527 | std::vector<int32_t> transfers; |
| 1528 | transfers.reserve(combination.transfers.size()); |
| 1529 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1530 | std::back_inserter(transfers), |
| 1531 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1532 | std::vector<int32_t> ranges; |
| 1533 | ranges.reserve(combination.ranges.size()); |
| 1534 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1535 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1536 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1537 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1538 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1539 | outCombination.standards = std::move(standards); |
| 1540 | outCombination.transfers = std::move(transfers); |
| 1541 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1542 | outProperties->combinations.emplace_back(outCombination); |
| 1543 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1544 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1545 | return NO_ERROR; |
| 1546 | } |
| 1547 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1548 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1549 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1550 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1551 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1552 | const auto snapshotOpt = |
| 1553 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1554 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1555 | .transform(&PhysicalDisplay::snapshotRef); |
| 1556 | |
| 1557 | if (!snapshotOpt) { |
| 1558 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1559 | return NAME_NOT_FOUND; |
| 1560 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1561 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1562 | const auto& snapshot = snapshotOpt->get(); |
| 1563 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1564 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1565 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1566 | if (!hwcIdOpt) { |
| 1567 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1568 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1569 | return BAD_VALUE; |
| 1570 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1571 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1572 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1573 | }); |
| 1574 | return future.get(); |
| 1575 | } |
| 1576 | |
| 1577 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1578 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1579 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1580 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1581 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1582 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1583 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1584 | return BAD_VALUE; |
| 1585 | } |
| 1586 | }); |
| 1587 | return future.get(); |
| 1588 | } |
| 1589 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1590 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1591 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1592 | bool hdrOutputConversionSupport; |
| 1593 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1594 | if (hdrOutputConversionSupport == false) { |
| 1595 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1596 | return INVALID_OPERATION; |
| 1597 | } |
| 1598 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1599 | for (auto capability : aidlConversionCapability) { |
| 1600 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1601 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1602 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1603 | tempCapability.addsLatency = capability.addsLatency; |
| 1604 | hdrConversionCapabilities->push_back(tempCapability); |
| 1605 | } |
| 1606 | return NO_ERROR; |
| 1607 | } |
| 1608 | |
| 1609 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1610 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1611 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1612 | bool hdrOutputConversionSupport; |
| 1613 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1614 | if (hdrOutputConversionSupport == false) { |
| 1615 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1616 | return INVALID_OPERATION; |
| 1617 | } |
| 1618 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
| 1619 | using AidlHdrConversionStrategy = |
| 1620 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1621 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1622 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1623 | status_t status; |
| 1624 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1625 | switch (hdrConversionStrategy.getTag()) { |
| 1626 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1627 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1628 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1629 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1630 | &aidlPreferredHdrOutputType); |
| 1631 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1632 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1633 | } |
| 1634 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1635 | auto autoHdrTypes = |
| 1636 | hdrConversionStrategy |
| 1637 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1638 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1639 | for (auto type : autoHdrTypes) { |
| 1640 | aidlAutoHdrTypes.push_back( |
| 1641 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1642 | } |
| 1643 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1644 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1645 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1646 | &aidlPreferredHdrOutputType); |
| 1647 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1648 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1649 | } |
| 1650 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1651 | auto forceHdrConversion = |
| 1652 | hdrConversionStrategy |
| 1653 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1654 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1655 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1656 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1657 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1658 | &aidlPreferredHdrOutputType); |
| 1659 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1660 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | }); |
| 1664 | return future.get(); |
| 1665 | } |
| 1666 | |
| 1667 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1668 | auto future = mScheduler->schedule([this] { |
| 1669 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1670 | }); |
| 1671 | |
| 1672 | *outSupport = future.get(); |
| 1673 | return NO_ERROR; |
| 1674 | } |
| 1675 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1676 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1677 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1678 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1679 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1680 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1681 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1682 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1683 | } |
| 1684 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1687 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1688 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1689 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1690 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1691 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1692 | getHwComposer().setContentType(*displayId, type); |
| 1693 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1694 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1695 | } |
| 1696 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1697 | } |
| 1698 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1699 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1700 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1701 | Mutex::Autolock lock(mStateLock); |
| 1702 | |
| 1703 | auto display = getDisplayDeviceLocked(displayToken); |
| 1704 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1705 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1706 | return NAME_NOT_FOUND; |
| 1707 | } |
| 1708 | |
| 1709 | display->overrideHdrTypes(hdrTypes); |
| 1710 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true /* connected */); |
| 1711 | return NO_ERROR; |
| 1712 | } |
| 1713 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1714 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1715 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1716 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1717 | return NO_ERROR; |
| 1718 | } |
| 1719 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1720 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1721 | ui::PixelFormat* outFormat, |
| 1722 | ui::Dataspace* outDataspace, |
| 1723 | uint8_t* outComponentMask) const { |
| 1724 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1725 | return BAD_VALUE; |
| 1726 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1727 | |
| 1728 | Mutex::Autolock lock(mStateLock); |
| 1729 | |
| 1730 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1731 | if (!displayId) { |
| 1732 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1733 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1734 | |
| 1735 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1736 | outDataspace, outComponentMask); |
| 1737 | } |
| 1738 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1739 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1740 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1741 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1742 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1743 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1744 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1745 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1746 | componentMask, maxFrames); |
| 1747 | } else { |
| 1748 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1749 | return NAME_NOT_FOUND; |
| 1750 | } |
| 1751 | }); |
| 1752 | |
| 1753 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1754 | } |
| 1755 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1756 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1757 | uint64_t maxFrames, uint64_t timestamp, |
| 1758 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1759 | Mutex::Autolock lock(mStateLock); |
| 1760 | |
| 1761 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1762 | if (!displayId) { |
| 1763 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1766 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1769 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1770 | if (!outSupported) { |
| 1771 | return BAD_VALUE; |
| 1772 | } |
| 1773 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1774 | return NO_ERROR; |
| 1775 | } |
| 1776 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1777 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1778 | bool* outIsWideColorDisplay) const { |
| 1779 | if (!displayToken || !outIsWideColorDisplay) { |
| 1780 | return BAD_VALUE; |
| 1781 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1782 | |
| 1783 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1784 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1785 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1786 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1787 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1788 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1789 | *outIsWideColorDisplay = |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1790 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1791 | return NO_ERROR; |
| 1792 | } |
| 1793 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1794 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1795 | outLayers->clear(); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1796 | auto future = mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1797 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1798 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1799 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1800 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1801 | }); |
| 1802 | |
| 1803 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1804 | return NO_ERROR; |
| 1805 | } |
| 1806 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1807 | status_t SurfaceFlinger::getCompositionPreference( |
| 1808 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1809 | Dataspace* outWideColorGamutDataspace, |
| 1810 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1811 | *outDataspace = mDefaultCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1812 | *outPixelFormat = defaultCompositionPixelFormat; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 1813 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1814 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1815 | return NO_ERROR; |
| 1816 | } |
| 1817 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1818 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1819 | const sp<IBinder>& stopLayerHandle, |
| 1820 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1821 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1822 | return BAD_VALUE; |
| 1823 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1824 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1825 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1826 | // the layer here since the caller has a strong ref to the layer's handle. |
Vishnu Nair | 9d77a5c | 2022-10-28 06:31:21 +0000 | [diff] [blame] | 1827 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1828 | mRegionSamplingThread->addListener(samplingArea, |
| 1829 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1830 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1831 | return NO_ERROR; |
| 1832 | } |
| 1833 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1834 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1835 | if (!listener) { |
| 1836 | return BAD_VALUE; |
| 1837 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1838 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1839 | return NO_ERROR; |
| 1840 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1841 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1842 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1843 | if (!listener) { |
| 1844 | return BAD_VALUE; |
| 1845 | } |
| 1846 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1847 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1848 | return NO_ERROR; |
| 1849 | } |
| 1850 | |
| 1851 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1852 | if (!listener) { |
| 1853 | return BAD_VALUE; |
| 1854 | } |
| 1855 | mFpsReporter->removeListener(listener); |
| 1856 | return NO_ERROR; |
| 1857 | } |
| 1858 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1859 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1860 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1861 | if (!listener) { |
| 1862 | return BAD_VALUE; |
| 1863 | } |
| 1864 | |
| 1865 | mTunnelModeEnabledReporter->addListener(listener); |
| 1866 | return NO_ERROR; |
| 1867 | } |
| 1868 | |
| 1869 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1870 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1871 | if (!listener) { |
| 1872 | return BAD_VALUE; |
| 1873 | } |
| 1874 | |
| 1875 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1876 | return NO_ERROR; |
| 1877 | } |
| 1878 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1879 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1880 | bool* outSupport) const { |
| 1881 | if (!displayToken || !outSupport) { |
| 1882 | return BAD_VALUE; |
| 1883 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1884 | |
| 1885 | Mutex::Autolock lock(mStateLock); |
| 1886 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1887 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1888 | if (!displayId) { |
| 1889 | return NAME_NOT_FOUND; |
| 1890 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1891 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1892 | return NO_ERROR; |
| 1893 | } |
| 1894 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1895 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1896 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1897 | if (!displayToken) { |
| 1898 | return BAD_VALUE; |
| 1899 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1900 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1901 | const char* const whence = __func__; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1902 | return ftl::Future(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1903 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1904 | const bool supportsDisplayBrightnessCommand = |
| 1905 | getHwComposer().getComposer()->isSupported( |
| 1906 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1907 | // If we support applying display brightness as a command, then we also support |
| 1908 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1909 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1910 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1911 | float currentDimmingRatio = |
| 1912 | compositionDisplay->editState().sdrWhitePointNits / |
| 1913 | compositionDisplay->editState().displayBrightnessNits; |
| 1914 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1915 | brightness.displayBrightnessNits); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1916 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1917 | display->stageBrightness(brightness.displayBrightness)); |
| 1918 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1919 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1920 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1921 | scheduleComposite(FrameHint::kNone); |
| 1922 | } else { |
| 1923 | scheduleCommit(FrameHint::kNone); |
| 1924 | } |
| 1925 | return ftl::yield<status_t>(OK); |
| 1926 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1927 | return getHwComposer() |
| 1928 | .setDisplayBrightness(display->getPhysicalId(), |
| 1929 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1930 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1931 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1932 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1933 | } |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1934 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1935 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1936 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 1937 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1938 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 1939 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1940 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1941 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1944 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 1945 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1946 | if (!displayToken) { |
| 1947 | return BAD_VALUE; |
| 1948 | } |
| 1949 | |
| 1950 | Mutex::Autolock lock(mStateLock); |
| 1951 | |
| 1952 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1953 | if (!display) { |
| 1954 | return NAME_NOT_FOUND; |
| 1955 | } |
| 1956 | const auto displayId = display->getId(); |
| 1957 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1958 | if (!hdrInfoReporter) { |
| 1959 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 1960 | } |
| 1961 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 1962 | |
| 1963 | |
| 1964 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1965 | return OK; |
| 1966 | } |
| 1967 | |
| 1968 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 1969 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1970 | if (!displayToken) { |
| 1971 | return BAD_VALUE; |
| 1972 | } |
| 1973 | |
| 1974 | Mutex::Autolock lock(mStateLock); |
| 1975 | |
| 1976 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1977 | if (!display) { |
| 1978 | return NAME_NOT_FOUND; |
| 1979 | } |
| 1980 | const auto displayId = display->getId(); |
| 1981 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1982 | if (hdrInfoReporter) { |
| 1983 | hdrInfoReporter->removeListener(listener); |
| 1984 | } |
| 1985 | return OK; |
| 1986 | } |
| 1987 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1988 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1989 | using hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1990 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1991 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1992 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1993 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | return NO_ERROR; |
| 1997 | } |
| 1998 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 1999 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2000 | const sp<IBinder>& displayToken, |
| 2001 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2002 | if (!displayToken || !outSupport) { |
| 2003 | return BAD_VALUE; |
| 2004 | } |
| 2005 | |
| 2006 | Mutex::Autolock lock(mStateLock); |
| 2007 | |
| 2008 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2009 | if (!displayId) { |
| 2010 | return NAME_NOT_FOUND; |
| 2011 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2012 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2013 | return NO_ERROR; |
| 2014 | } |
| 2015 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2016 | // ---------------------------------------------------------------------------- |
| 2017 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2018 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2019 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2020 | const sp<IBinder>& layerHandle) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2021 | const auto& handle = |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 2022 | vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2023 | ? mSfConnectionHandle |
| 2024 | : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2025 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2026 | return mScheduler->createDisplayEventConnection(handle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2029 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2030 | if (hint == FrameHint::kActive) { |
| 2031 | mScheduler->resetIdleTimer(); |
| 2032 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2033 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2034 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2035 | } |
| 2036 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2037 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2038 | mMustComposite = true; |
| 2039 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void SurfaceFlinger::scheduleRepaint() { |
| 2043 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2044 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2047 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2048 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2049 | } |
| 2050 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2051 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2052 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2053 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2054 | } |
| 2055 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2056 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2059 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2060 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2061 | ATRACE_NAME(vsyncPeriod |
| 2062 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2063 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2064 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2065 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2066 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2067 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2068 | // period flushed |
| 2069 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2070 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2071 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2074 | void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, |
| 2075 | hal::Connection connection) { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2076 | { |
| 2077 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2078 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2079 | } |
| 2080 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2081 | if (mScheduler) { |
| 2082 | mScheduler->scheduleConfigure(); |
| 2083 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2086 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2087 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2088 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2089 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2090 | |
| 2091 | if (timeline.refreshRequired) { |
| 2092 | scheduleComposite(FrameHint::kNone); |
| 2093 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2096 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2097 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2098 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2099 | } |
| 2100 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2101 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2102 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2103 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2104 | } |
| 2105 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2106 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2107 | ATRACE_CALL(); |
| 2108 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2109 | } |
| 2110 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2111 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2112 | ATRACE_CALL(); |
| 2113 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
| 2114 | const Fps fps = Fps::fromPeriodNsecs(data.vsyncPeriodNanos); |
| 2115 | ATRACE_FORMAT("%s Fps %d", __func__, fps.getIntValue()); |
| 2116 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
| 2117 | { |
| 2118 | { |
| 2119 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2120 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2121 | display->updateRefreshRateOverlayRate(fps, |
| 2122 | display->getActiveMode() |
| 2123 | .fps, |
| 2124 | /* setByHwc */ true)); |
| 2125 | } |
| 2126 | } |
| 2127 | })); |
| 2128 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2129 | } |
| 2130 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2131 | void SurfaceFlinger::setVsyncEnabled(PhysicalDisplayId id, bool enabled) { |
| 2132 | const char* const whence = __func__; |
| 2133 | ATRACE_FORMAT("%s (%d) for %" PRIu64, whence, enabled, id.value); |
Ady Abraham | 9ba2512 | 2019-06-03 17:10:55 -0700 | [diff] [blame] | 2134 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 2135 | // On main thread to avoid race conditions with display power state. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2136 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 2137 | { |
| 2138 | ftl::FakeGuard guard(kMainThreadContext); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2139 | mScheduler->getVsyncSchedule(id)->setPendingHardwareVsyncState(enabled); |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 2140 | } |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 2141 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2142 | ATRACE_FORMAT("%s (%d) for %" PRIu64 " (main thread)", whence, enabled, id.value); |
| 2143 | if (const auto display = getDisplayDeviceLocked(id); display && display->isPoweredOn()) { |
| 2144 | setHWCVsyncEnabled(id, enabled); |
Ady Abraham | 9ba2512 | 2019-06-03 17:10:55 -0700 | [diff] [blame] | 2145 | } |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 2146 | })); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2149 | bool SurfaceFlinger::wouldPresentEarly(TimePoint frameTime, Period vsyncPeriod) const { |
| 2150 | const bool isThreeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod; |
| 2151 | return isThreeVsyncsAhead || |
Dominik Laskowski | 5123e68 | 2023-04-20 10:15:09 -0400 | [diff] [blame] | 2152 | getPreviousPresentFence(frameTime, vsyncPeriod)->getSignalTime() != |
| 2153 | Fence::SIGNAL_TIME_PENDING; |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) const |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2157 | -> const FenceTimePtr& { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2158 | const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2159 | const size_t i = static_cast<size_t>(isTwoVsyncsAhead); |
| 2160 | return mPreviousPresentFences[i].fenceTime; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2163 | bool SurfaceFlinger::isFencePending(const FenceTimePtr& fence, int graceTimeMs) { |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2164 | ATRACE_CALL(); |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 2165 | if (fence == FenceTime::NO_FENCE) { |
Ady Abraham | 1157930 | 2019-09-19 12:35:58 -0700 | [diff] [blame] | 2166 | return false; |
| 2167 | } |
| 2168 | |
Dan Stoza | 5908305 | 2020-04-28 10:13:20 -0700 | [diff] [blame] | 2169 | const status_t status = fence->wait(graceTimeMs); |
| 2170 | // This is the same as Fence::Status::Unsignaled, but it saves a getStatus() call, |
| 2171 | // which calls wait(0) again internally |
| 2172 | return status == -ETIME; |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2175 | TimePoint SurfaceFlinger::calculateExpectedPresentTime(TimePoint frameTime) const { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2176 | const auto& schedule = mScheduler->getVsyncSchedule(); |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2177 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2178 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(frameTime); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 2179 | if (mScheduler->vsyncModulator().getVsyncConfig().sfOffset > 0) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2180 | return vsyncDeadline; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2183 | // Inflate the expected present time if we're targeting the next vsync. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2184 | return vsyncDeadline + schedule->period(); |
Alec Mouri | aa61419 | 2019-06-06 13:28:34 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2187 | void SurfaceFlinger::configure() FTL_FAKE_GUARD(kMainThreadContext) { |
| 2188 | Mutex::Autolock lock(mStateLock); |
| 2189 | if (configureLocked()) { |
| 2190 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2191 | } |
| 2192 | } |
| 2193 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2194 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, frontend::Update& update, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2195 | bool transactionsFlushed, |
| 2196 | bool& outTransactionsAreEmpty) { |
| 2197 | bool needsTraversal = false; |
| 2198 | if (transactionsFlushed) { |
| 2199 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2200 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2201 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2202 | } |
| 2203 | outTransactionsAreEmpty = !needsTraversal; |
| 2204 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2205 | if (shouldCommit) { |
| 2206 | commitTransactions(); |
| 2207 | } |
| 2208 | |
| 2209 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2210 | updateLayerGeometry(); |
| 2211 | return mustComposite; |
| 2212 | } |
| 2213 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2214 | void SurfaceFlinger::updateLayerHistory(const frontend::LayerSnapshot& snapshot) { |
| 2215 | using Changes = frontend::RequestedLayerState::Changes; |
| 2216 | if (snapshot.path.isClone() || |
| 2217 | !snapshot.changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation)) { |
| 2218 | return; |
| 2219 | } |
| 2220 | |
| 2221 | const auto layerProps = scheduler::LayerProps{ |
| 2222 | .visible = snapshot.isVisible, |
| 2223 | .bounds = snapshot.geomLayerBounds, |
| 2224 | .transform = snapshot.geomLayerTransform, |
| 2225 | .setFrameRateVote = snapshot.frameRate, |
| 2226 | .frameRateSelectionPriority = snapshot.frameRateSelectionPriority, |
| 2227 | }; |
| 2228 | |
| 2229 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 2230 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 2231 | snapshot.getDebugString().c_str()); |
| 2232 | |
| 2233 | if (snapshot.changes.test(Changes::Animation)) { |
| 2234 | it->second->recordLayerHistoryAnimationTx(layerProps); |
| 2235 | } |
| 2236 | |
| 2237 | if (snapshot.changes.test(Changes::FrameRate)) { |
| 2238 | it->second->setFrameRateForLayerTree(snapshot.frameRate, layerProps); |
| 2239 | } |
| 2240 | |
| 2241 | if (snapshot.changes.test(Changes::Buffer)) { |
| 2242 | it->second->recordLayerHistoryBufferUpdate(layerProps); |
| 2243 | } |
| 2244 | } |
| 2245 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2246 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, frontend::Update& update, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2247 | bool transactionsFlushed, bool& outTransactionsAreEmpty) { |
| 2248 | using Changes = frontend::RequestedLayerState::Changes; |
| 2249 | ATRACE_NAME("updateLayerSnapshots"); |
| 2250 | { |
| 2251 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
| 2252 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2253 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2254 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2255 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2256 | if (layer) { |
| 2257 | mLegacyLayers[layer->sequence] = layer; |
| 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | if (mLayerLifecycleManager.getGlobalChanges().test(Changes::Hierarchy)) { |
| 2262 | ATRACE_NAME("LayerHierarchyBuilder:update"); |
| 2263 | mLayerHierarchyBuilder.update(mLayerLifecycleManager.getLayers(), |
| 2264 | mLayerLifecycleManager.getDestroyedLayers()); |
| 2265 | } |
| 2266 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2267 | bool mustComposite = false; |
| 2268 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2269 | |
| 2270 | { |
| 2271 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2272 | frontend::LayerSnapshotBuilder::Args |
| 2273 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2274 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2275 | .displays = mFrontEndDisplayInfos, |
| 2276 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2277 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
| 2278 | .supportsBlur = mSupportsBlur, |
| 2279 | .forceFullDamage = mForceFullDamage, |
| 2280 | .supportedLayerGenericMetadata = |
| 2281 | getHwComposer().getSupportedLayerGenericMetadata(), |
| 2282 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2283 | mLayerSnapshotBuilder.update(args); |
| 2284 | } |
| 2285 | |
| 2286 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2287 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2288 | mUpdateInputInfo = true; |
| 2289 | } |
| 2290 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
| 2291 | Changes::Visibility)) { |
| 2292 | mVisibleRegionsDirty = true; |
| 2293 | } |
| 2294 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2295 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2296 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2297 | bool newDataLatched = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2298 | if (!mLegacyFrontEndEnabled) { |
| 2299 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
| 2300 | applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2301 | const nsecs_t latchTime = systemTime(); |
| 2302 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2303 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2304 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2305 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2306 | layer->bgColorLayer) { |
| 2307 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2308 | LayerCreationArgs(this, nullptr, layer->name, |
| 2309 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
| 2310 | std::make_optional(layer->parentId), true)); |
| 2311 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2312 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2313 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
| 2314 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) continue; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2315 | |
| 2316 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2317 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2318 | layer->getDebugString().c_str()); |
| 2319 | const bool bgColorOnly = |
| 2320 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2321 | if (willReleaseBufferOnLatch) { |
| 2322 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2323 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2324 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2325 | mLayersWithQueuedFrames.emplace(it->second); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | for (auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2329 | updateLayerHistory(*snapshot); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2330 | if (!snapshot->hasReadyFrame) continue; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2331 | newDataLatched = true; |
| 2332 | if (!snapshot->isVisible) break; |
| 2333 | |
| 2334 | Region visibleReg; |
| 2335 | visibleReg.set(snapshot->transformedBoundsWithoutTransparentRegion); |
| 2336 | invalidateLayerStack(snapshot->outputFilter, visibleReg); |
| 2337 | } |
| 2338 | |
| 2339 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2340 | mLegacyLayers.erase(destroyedLayer->id); |
| 2341 | } |
| 2342 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2343 | { |
| 2344 | ATRACE_NAME("LLM:commitChanges"); |
| 2345 | mLayerLifecycleManager.commitChanges(); |
| 2346 | } |
| 2347 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 2348 | commitTransactions(); |
| 2349 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2350 | // enter boot animation on first buffer latch |
| 2351 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2352 | ALOGI("Enter boot animation"); |
| 2353 | mBootStage = BootStage::BOOTANIMATION; |
| 2354 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2355 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2356 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2357 | return mustComposite; |
| 2358 | } |
| 2359 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2360 | bool SurfaceFlinger::commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2361 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2362 | // The expectedVsyncTime, which was predicted when this frame was scheduled, is normally in the |
| 2363 | // future relative to frameTime, but may not be for delayed frames. Adjust mExpectedPresentTime |
| 2364 | // accordingly, but not mScheduledPresentTime. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2365 | const TimePoint lastScheduledPresentTime = mScheduledPresentTime; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2366 | mScheduledPresentTime = expectedVsyncTime; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2367 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2368 | // Calculate the expected present time once and use the cached value throughout this frame to |
| 2369 | // make sure all layers are seeing this same value. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2370 | mExpectedPresentTime = expectedVsyncTime >= frameTime ? expectedVsyncTime |
| 2371 | : calculateExpectedPresentTime(frameTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2372 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2373 | ATRACE_FORMAT("%s %" PRId64 " vsyncIn %.2fms%s", __func__, vsyncId.value, |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2374 | ticks<std::milli, float>(mExpectedPresentTime - TimePoint::now()), |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2375 | mExpectedPresentTime == expectedVsyncTime ? "" : " (adjusted)"); |
Ady Abraham | 893c99d | 2021-04-30 16:00:23 -0700 | [diff] [blame] | 2376 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2377 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2378 | const FenceTimePtr& previousPresentFence = getPreviousPresentFence(frameTime, vsyncPeriod); |
| 2379 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2380 | // When backpressure propagation is enabled, we want to give a small grace period of 1ms |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2381 | // for the present fence to fire instead of just giving up on this frame to handle cases |
| 2382 | // where present fence is just about to get signaled. |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2383 | const int graceTimeForPresentFenceMs = static_cast<int>( |
| 2384 | mBackpressureGpuComposition || !mCompositionCoverage.test(CompositionCoverage::Gpu)); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2385 | |
| 2386 | // Pending frames may trigger backpressure propagation. |
| 2387 | const TracedOrdinal<bool> framePending = {"PrevFramePending", |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2388 | isFencePending(previousPresentFence, |
| 2389 | graceTimeForPresentFenceMs)}; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2390 | |
| 2391 | // Frame missed counts for metrics tracking. |
| 2392 | // A frame is missed if the prior frame is still pending. If no longer pending, |
| 2393 | // then we still count the frame as missed if the predicted present time |
| 2394 | // was further in the past than when the fence actually fired. |
| 2395 | |
| 2396 | // Add some slop to correct for drift. This should generally be |
| 2397 | // smaller than a typical frame duration, but should not be so small |
| 2398 | // that it reports reasonable drift as a missed frame. |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2399 | const nsecs_t frameMissedSlop = vsyncPeriod.ns() / 2; |
| 2400 | const nsecs_t previousPresentTime = previousPresentFence->getSignalTime(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2401 | const TracedOrdinal<bool> frameMissed = {"PrevFrameMissed", |
| 2402 | framePending || |
| 2403 | (previousPresentTime >= 0 && |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2404 | (lastScheduledPresentTime.ns() < |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2405 | previousPresentTime - frameMissedSlop))}; |
| 2406 | const TracedOrdinal<bool> hwcFrameMissed = {"PrevHwcFrameMissed", |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2407 | frameMissed && |
| 2408 | mCompositionCoverage.test( |
| 2409 | CompositionCoverage::Hwc)}; |
| 2410 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2411 | const TracedOrdinal<bool> gpuFrameMissed = {"PrevGpuFrameMissed", |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2412 | frameMissed && |
| 2413 | mCompositionCoverage.test( |
| 2414 | CompositionCoverage::Gpu)}; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2415 | |
| 2416 | if (frameMissed) { |
| 2417 | mFrameMissedCount++; |
| 2418 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | if (hwcFrameMissed) { |
| 2422 | mHwcFrameMissedCount++; |
| 2423 | } |
| 2424 | |
| 2425 | if (gpuFrameMissed) { |
| 2426 | mGpuFrameMissedCount++; |
| 2427 | } |
| 2428 | |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 2429 | if (mTracingEnabledChanged) { |
| 2430 | mLayerTracingEnabled = mLayerTracing.isEnabled(); |
| 2431 | mTracingEnabledChanged = false; |
| 2432 | } |
| 2433 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2434 | // 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] | 2435 | // fired yet just wait for the next commit. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2436 | if (mSetActiveModePending) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2437 | if (framePending) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2438 | mScheduler->scheduleFrame(); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2439 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | // 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] | 2443 | // the mode, hence we update SF. |
| 2444 | mSetActiveModePending = false; |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2445 | { |
| 2446 | Mutex::Autolock lock(mStateLock); |
| 2447 | updateInternalStateWithChangedMode(); |
| 2448 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
John Reck | 2ec5391 | 2020-07-07 16:53:55 -0700 | [diff] [blame] | 2451 | if (framePending) { |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2452 | if (mBackpressureGpuComposition || (hwcFrameMissed && !gpuFrameMissed)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2453 | scheduleCommit(FrameHint::kNone); |
| 2454 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2458 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2459 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2460 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2461 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2462 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2463 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2464 | mPowerAdvisor->setCommitStart(frameTime); |
| 2465 | mPowerAdvisor->setExpectedPresentTime(mExpectedPresentTime); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2466 | |
| 2467 | // Frame delay is how long we should have minus how long we actually have. |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 2468 | const Duration idealSfWorkDuration = |
| 2469 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2470 | const Duration frameDelay = idealSfWorkDuration - (mExpectedPresentTime - frameTime); |
| 2471 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2472 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2473 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2474 | mPowerAdvisor->updateTargetWorkDuration(vsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2477 | if (mRefreshRateOverlaySpinner) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2478 | Mutex::Autolock lock(mStateLock); |
| 2479 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2480 | display->animateRefreshRateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2484 | // Composite if transactions were committed, or if requested by HWC. |
| 2485 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2486 | { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2487 | mFrameTimeline->setSfWakeUp(vsyncId.value, frameTime.ns(), |
| 2488 | Fps::fromPeriodNsecs(vsyncPeriod.ns())); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2489 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2490 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2491 | frontend::Update updates; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2492 | if (flushTransactions) { |
| 2493 | updates = flushLifecycleUpdates(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2494 | if (mTransactionTracing) { |
| 2495 | mTransactionTracing->addCommittedTransactions(vsyncId.value, frameTime.ns(), |
| 2496 | updates, mFrontEndDisplayInfos, |
| 2497 | mFrontEndDisplayInfosChanged); |
| 2498 | } |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2499 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2500 | bool transactionsAreEmpty; |
| 2501 | if (mLegacyFrontEndEnabled) { |
| 2502 | mustComposite |= updateLayerSnapshotsLegacy(vsyncId, updates, flushTransactions, |
| 2503 | transactionsAreEmpty); |
| 2504 | } |
| 2505 | if (mLayerLifecycleManagerEnabled) { |
| 2506 | mustComposite |= |
| 2507 | updateLayerSnapshots(vsyncId, updates, flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | if (transactionFlushNeeded()) { |
| 2511 | setTransactionFlags(eTransactionFlushNeeded); |
| 2512 | } |
| 2513 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2514 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2515 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2516 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2517 | // Invoke empty transaction callbacks early. |
| 2518 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2519 | } else { |
| 2520 | // Invoke OnCommit callbacks. |
| 2521 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2522 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | // Layers need to get updated (in the previous line) before we can use them for |
| 2526 | // choosing the refresh rate. |
| 2527 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2528 | // and may eventually call to ~Layer() if it holds the last reference |
| 2529 | { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2530 | Mutex::Autolock lock(mStateLock); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2531 | mScheduler->chooseRefreshRateForContent(); |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2532 | setActiveModeInHwcIfNeeded(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2535 | updateCursorAsync(); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2536 | updateInputFlinger(); |
| 2537 | |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2538 | if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
| 2539 | // This will block and tracing should only be enabled for debugging. |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2540 | addToLayerTracing(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2541 | } |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2542 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2543 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2544 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2545 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2546 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2549 | void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2550 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2551 | ATRACE_FORMAT("%s %" PRId64, __func__, vsyncId.value); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2552 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2553 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2554 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2555 | refreshArgs.outputs.reserve(displays.size()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2556 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2557 | for (const auto& [_, display] : displays) { |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 2558 | bool dropFrame = false; |
| 2559 | if (display->isVirtual()) { |
| 2560 | Fps refreshRate = display->getAdjustedRefreshRate(); |
| 2561 | using fps_approx_ops::operator>; |
| 2562 | dropFrame = (refreshRate > 0_Hz) && !mScheduler->isVsyncInPhase(frameTime, refreshRate); |
| 2563 | } |
| 2564 | if (!dropFrame) { |
| 2565 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
| 2566 | } |
Ady Abraham | 6645272 | 2023-03-14 17:41:47 -0700 | [diff] [blame] | 2567 | display->tracePowerMode(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2568 | displayIds.push_back(display->getId()); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2569 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2570 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2571 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2572 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2573 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2574 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2575 | updateLayerMetadataSnapshot(); |
| 2576 | mLayerMetadataSnapshotNeeded = false; |
| 2577 | } |
| 2578 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2579 | if (DOES_CONTAIN_BORDER) { |
| 2580 | refreshArgs.borderInfoList.clear(); |
| 2581 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2582 | if (layer->isBorderEnabled()) { |
| 2583 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2584 | info.width = layer->getBorderWidth(); |
| 2585 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2586 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2587 | info.layerIds.push_back(ilayer->getSequence()); |
| 2588 | }); |
| 2589 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2590 | } |
| 2591 | }); |
| 2592 | } |
| 2593 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2594 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2595 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2596 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2597 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2598 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2599 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2600 | } |
| 2601 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2602 | refreshArgs.outputColorSetting = useColorManagement |
| 2603 | ? mDisplayColorSetting |
| 2604 | : compositionengine::OutputColorSetting::kUnmanaged; |
| 2605 | refreshArgs.colorSpaceAgnosticDataspace = mColorSpaceAgnosticDataspace; |
| 2606 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2607 | |
| 2608 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2609 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 2610 | refreshArgs.internalDisplayRotationFlags = DisplayDevice::getPrimaryDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2611 | |
| 2612 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2613 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2614 | mDrawingState.colorMatrixChanged = false; |
| 2615 | } |
| 2616 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2617 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2618 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2619 | if (mDebugFlashDelay != 0) { |
| 2620 | refreshArgs.devOptForceClientComposition = true; |
| 2621 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2622 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2623 | |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2624 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2625 | |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2626 | if (!getHwComposer().getComposer()->isSupported( |
| 2627 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && |
| 2628 | wouldPresentEarly(frameTime, vsyncPeriod)) { |
| 2629 | const auto prevVsyncTime = mExpectedPresentTime - vsyncPeriod; |
| 2630 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2631 | |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2632 | refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration; |
| 2633 | } |
| 2634 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2635 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2636 | refreshArgs.expectedPresentTime = mExpectedPresentTime.ns(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2637 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 2638 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2639 | // Store the present time just before calling to the composition engine so we could notify |
| 2640 | // the scheduler. |
| 2641 | const auto presentTime = systemTime(); |
| 2642 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2643 | std::vector<std::pair<Layer*, LayerFE*>> layers = |
| 2644 | moveSnapshotsToCompositionArgs(refreshArgs, /*cursorOnly=*/false, vsyncId.value); |
| 2645 | mCompositionEngine->present(refreshArgs); |
| 2646 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2647 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2648 | for (auto [layer, layerFE] : layers) { |
| 2649 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2650 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2651 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2652 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2653 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2654 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2655 | } |
| 2656 | if (compositionResult.lastClientCompositionFence) { |
| 2657 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2658 | } |
| 2659 | } |
| 2660 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2661 | mTimeStats->recordFrameDuration(frameTime.ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2662 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2663 | // Send a power hint hint after presentation is finished |
| 2664 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 5123e68 | 2023-04-20 10:15:09 -0400 | [diff] [blame] | 2665 | const nsecs_t pastPresentTime = |
| 2666 | getPreviousPresentFence(frameTime, vsyncPeriod)->getSignalTime(); |
| 2667 | |
| 2668 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(pastPresentTime), TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2669 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2672 | if (mScheduler->onPostComposition(presentTime)) { |
| 2673 | scheduleComposite(FrameHint::kNone); |
| 2674 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2675 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2676 | postComposition(presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2677 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2678 | const bool hadGpuComposited = mCompositionCoverage.test(CompositionCoverage::Gpu); |
| 2679 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2680 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2681 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
| 2682 | for (const auto& [_, display] : displays) { |
| 2683 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2684 | |
| 2685 | if (state.usesDeviceComposition) { |
| 2686 | mCompositionCoverage |= CompositionCoverage::Hwc; |
| 2687 | } |
| 2688 | |
| 2689 | if (state.reusedClientComposition) { |
| 2690 | mCompositionCoverage |= CompositionCoverage::GpuReuse; |
| 2691 | } else if (state.usesClientComposition) { |
| 2692 | mCompositionCoverage |= CompositionCoverage::Gpu; |
| 2693 | } |
| 2694 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2695 | clientCompositionRecord.predicted |= |
| 2696 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2697 | clientCompositionRecord.predictionSucceeded |= |
| 2698 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2701 | const bool hasGpuComposited = mCompositionCoverage.test(CompositionCoverage::Gpu); |
| 2702 | |
| 2703 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
| 2704 | clientCompositionRecord.reused = mCompositionCoverage.test(CompositionCoverage::GpuReuse); |
| 2705 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2706 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2707 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2708 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2709 | using namespace ftl::flag_operators; |
| 2710 | |
| 2711 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2712 | const bool hasGpuUseOrReuse = |
| 2713 | mCompositionCoverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2714 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2715 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2716 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2717 | if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2718 | // This will block and should only be used for debugging. |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 2719 | addToLayerTracing(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | df52905 | 2019-06-07 14:53:14 -0700 | [diff] [blame] | 2720 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2721 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2722 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2723 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2724 | |
| 2725 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2726 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2727 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2728 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2729 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2730 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2731 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2732 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2733 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2734 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2735 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2736 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2737 | if (mVisibleRegionsDirty) { |
| 2738 | computeLayerBounds(); |
| 2739 | } |
| 2740 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2741 | for (auto& layer : mLayersPendingRefresh) { |
| 2742 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2743 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2744 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2745 | } |
| 2746 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2749 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2750 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2751 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2752 | // reduce power consumption during camera recording |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2753 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2754 | if (snapshot.externalTexture && |
| 2755 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2756 | return false; |
| 2757 | } |
| 2758 | } |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2759 | if (isHdrDataspace(snapshot.dataspace)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2760 | return true; |
| 2761 | } |
| 2762 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2763 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2764 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2765 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2766 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2767 | return true; |
| 2768 | } |
| 2769 | // RANGE_EXTENDED layers may identify themselves as being "HDR" via a desired sdr/hdr ratio |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2770 | if ((snapshot.dataspace & (int32_t)Dataspace::RANGE_MASK) == |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2771 | (int32_t)Dataspace::RANGE_EXTENDED && |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 2772 | snapshot.desiredHdrSdrRatio > 1.01f) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2773 | return true; |
| 2774 | } |
| 2775 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2776 | } |
| 2777 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2778 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2779 | bool isPrimary) const { |
| 2780 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2781 | if (!id) { |
| 2782 | return ui::ROTATION_0; |
| 2783 | } |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2784 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
| 2785 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2786 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2787 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2788 | case Hwc2::AidlTransform::ROT_90: |
| 2789 | return ui::ROTATION_90; |
| 2790 | case Hwc2::AidlTransform::ROT_180: |
| 2791 | return ui::ROTATION_180; |
| 2792 | case Hwc2::AidlTransform::ROT_270: |
| 2793 | return ui::ROTATION_270; |
| 2794 | default: |
| 2795 | return ui::ROTATION_0; |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | if (isPrimary) { |
| 2800 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2801 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2802 | case Values::ORIENTATION_90: |
| 2803 | return ui::ROTATION_90; |
| 2804 | case Values::ORIENTATION_180: |
| 2805 | return ui::ROTATION_180; |
| 2806 | case Values::ORIENTATION_270: |
| 2807 | return ui::ROTATION_270; |
| 2808 | default: |
| 2809 | break; |
| 2810 | } |
| 2811 | } |
| 2812 | return ui::ROTATION_0; |
| 2813 | } |
| 2814 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2815 | void SurfaceFlinger::postComposition(nsecs_t callTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2816 | ATRACE_CALL(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2817 | ALOGV(__func__); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2818 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2819 | const auto* defaultDisplay = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2820 | |
| 2821 | std::shared_ptr<FenceTime> glCompositionDoneFenceTime; |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2822 | if (defaultDisplay && |
| 2823 | defaultDisplay->getCompositionDisplay()->getState().usesClientComposition) { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2824 | glCompositionDoneFenceTime = |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2825 | std::make_shared<FenceTime>(defaultDisplay->getCompositionDisplay() |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2826 | ->getRenderSurface() |
| 2827 | ->getClientTargetAcquireFence()); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2828 | } else { |
| 2829 | glCompositionDoneFenceTime = FenceTime::NO_FENCE; |
| 2830 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2831 | |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 2832 | mPreviousPresentFences[1] = mPreviousPresentFences[0]; |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 2833 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2834 | auto presentFence = defaultDisplay |
| 2835 | ? getHwComposer().getPresentFence(defaultDisplay->getPhysicalId()) |
| 2836 | : Fence::NO_FENCE; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2837 | |
| 2838 | auto presentFenceTime = std::make_shared<FenceTime>(presentFence); |
| 2839 | mPreviousPresentFences[0] = {presentFence, presentFenceTime}; |
| 2840 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2841 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 2842 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2843 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 2844 | // information from previous' frame classification is already available when sending jank info |
| 2845 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2846 | mFrameTimeline->setSfPresent(presentTime.ns(), presentFenceTime, glCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2847 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2848 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 2849 | // 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] | 2850 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2851 | const TimePoint compositeTime = |
| 2852 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 2853 | const Duration presentLatency = |
Theodore Dubois | 205c6dd | 2022-11-23 15:06:33 -0800 | [diff] [blame] | 2854 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 2855 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, presentFenceTime) |
| 2856 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2857 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2858 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 2859 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 2860 | const Period vsyncPeriod = schedule->period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2861 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2862 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2863 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2864 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2865 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2866 | display::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
| 2867 | { |
| 2868 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 2869 | Mutex::Autolock lock(mStateLock); |
| 2870 | for (const auto& [token, display] : mDisplays) { |
| 2871 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 2872 | } |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame^] | 2877 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 2878 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 2879 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 2880 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2881 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 2882 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 2883 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 2884 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 2885 | ui::INVALID_LAYER_STACK); |
| 2886 | } |
| 2887 | } |
| 2888 | layer->releasePendingBuffer(presentTime.ns()); |
| 2889 | } |
| 2890 | mLayersWithBuffersRemoved.clear(); |
| 2891 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2892 | for (const auto& layer: mLayersWithQueuedFrames) { |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2893 | layer->onPostComposition(defaultDisplay, glCompositionDoneFenceTime, presentFenceTime, |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2894 | compositorTiming); |
| 2895 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2896 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2897 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2898 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 2899 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2900 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2901 | { |
| 2902 | Mutex::Autolock lock(mStateLock); |
| 2903 | if (mFpsReporter) { |
| 2904 | mFpsReporter->dispatchLayerFps(); |
| 2905 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 2906 | |
| 2907 | if (mTunnelModeEnabledReporter) { |
| 2908 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 2909 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2910 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 2911 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 2912 | if (reporter && reporter->hasListeners()) { |
| 2913 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 2914 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2918 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 2919 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2920 | } |
| 2921 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2922 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2923 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 2924 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 2925 | int32_t maxArea = 0; |
| 2926 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 2927 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2928 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 2929 | if (snapshot.isVisible && |
| 2930 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 2931 | if (isHdrLayer(snapshot)) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2932 | const auto* outputLayer = |
| 2933 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 2934 | if (outputLayer) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 2935 | const float desiredHdrSdrRatio = snapshot.desiredHdrSdrRatio <= 1.f |
Alec Mouri | c68c61a | 2023-02-09 17:35:36 +0000 | [diff] [blame] | 2936 | ? std::numeric_limits<float>::infinity() |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 2937 | : snapshot.desiredHdrSdrRatio; |
Alec Mouri | c68c61a | 2023-02-09 17:35:36 +0000 | [diff] [blame] | 2938 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2939 | info.numberOfHdrLayers++; |
| 2940 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 2941 | const int32_t area = displayFrame.width() * displayFrame.height(); |
| 2942 | if (area > maxArea) { |
| 2943 | maxArea = area; |
| 2944 | info.maxW = displayFrame.width(); |
| 2945 | info.maxH = displayFrame.height(); |
| 2946 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 2947 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2948 | } |
| 2949 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2950 | }); |
| 2951 | listener->dispatchHdrLayerInfo(info); |
| 2952 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2953 | } |
| 2954 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2955 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2956 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2957 | mTransactionCallbackInvoker.addPresentFence(std::move(presentFence)); |
| 2958 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2959 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 2960 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2961 | mTimeStats->incrementTotalFrames(); |
| 2962 | mTimeStats->setPresentFenceGlobal(presentFenceTime); |
| 2963 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2964 | { |
| 2965 | ftl::FakeGuard guard(mStateLock); |
| 2966 | for (const auto& [id, physicalDisplay] : mPhysicalDisplays) { |
| 2967 | if (auto displayDevice = getDisplayDeviceLocked(id); |
| 2968 | displayDevice && displayDevice->isPoweredOn() && physicalDisplay.isInternal()) { |
| 2969 | auto presentFenceTimeI = defaultDisplay && defaultDisplay->getPhysicalId() == id |
| 2970 | ? std::move(presentFenceTime) |
| 2971 | : std::make_shared<FenceTime>(getHwComposer().getPresentFence(id)); |
| 2972 | if (presentFenceTimeI->isValid()) { |
| 2973 | mScheduler->addPresentFence(id, std::move(presentFenceTimeI)); |
| 2974 | } |
| 2975 | } |
| 2976 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2979 | const bool isDisplayConnected = |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2980 | defaultDisplay && getHwComposer().isConnected(defaultDisplay->getPhysicalId()); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2981 | |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 2982 | if (!hasSyncFramework) { |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2983 | if (isDisplayConnected && defaultDisplay->isPoweredOn()) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2984 | mScheduler->enableHardwareVsync(defaultDisplay->getPhysicalId()); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 2988 | const size_t sfConnections = mScheduler->getEventThreadConnectionCount(mSfConnectionHandle); |
| 2989 | const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle); |
| 2990 | mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections); |
| 2991 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2992 | if (isDisplayConnected && !defaultDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 2993 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2994 | return; |
| 2995 | } |
| 2996 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2997 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 2998 | getRenderEngine().cleanupPostRender(); |
| 2999 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 3000 | { |
| 3001 | std::lock_guard lock(mTexturePoolMutex); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 3002 | if (mTexturePool.size() < mTexturePoolSize) { |
| 3003 | const size_t refillCount = mTexturePoolSize - mTexturePool.size(); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 3004 | const size_t offset = mTexturePool.size(); |
| 3005 | mTexturePool.resize(mTexturePoolSize); |
| 3006 | getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset); |
| 3007 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 3008 | } else if (mTexturePool.size() > mTexturePoolSize) { |
| 3009 | const size_t deleteCount = mTexturePool.size() - mTexturePoolSize; |
| 3010 | const size_t offset = mTexturePoolSize; |
| 3011 | getRenderEngine().deleteTextures(deleteCount, mTexturePool.data() + offset); |
| 3012 | mTexturePool.resize(mTexturePoolSize); |
| 3013 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 3014 | } |
| 3015 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 3016 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3017 | if (mNumTrustedPresentationListeners > 0) { |
| 3018 | // We avoid any reverse traversal upwards so this shouldn't be too expensive |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3019 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3020 | if (!layer->hasTrustedPresentationListener()) { |
| 3021 | return; |
| 3022 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3023 | const frontend::LayerSnapshot* snapshot = (mLayerLifecycleManagerEnabled) |
| 3024 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3025 | : layer->getLayerSnapshot(); |
| 3026 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3027 | if (snapshot) { |
| 3028 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3029 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3030 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3031 | layer->updateTrustedPresentationState(display, snapshot, |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 3032 | nanoseconds_to_milliseconds(callTime), false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3033 | }); |
| 3034 | } |
| 3035 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3036 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3037 | // side-effect of getTotalSize(), so we check that again here |
| 3038 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3039 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3040 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3041 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3042 | |
| 3043 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3046 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3047 | const ui::Size maxSize = [this] { |
| 3048 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3049 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3050 | // The LayerTraceGenerator tool runs without displays. |
| 3051 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3052 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3053 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3054 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3055 | const auto& display = pair.second; |
| 3056 | return {std::max(size.getWidth(), display->getWidth()), |
| 3057 | std::max(size.getHeight(), display->getHeight())}; |
| 3058 | }); |
| 3059 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3060 | |
| 3061 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3062 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3063 | const float xMax = maxSize.getWidth() * 10.f; |
| 3064 | const float yMax = maxSize.getHeight() * 10.f; |
| 3065 | |
| 3066 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3070 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3071 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3072 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3076 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3077 | ATRACE_CALL(); |
| 3078 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3079 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3080 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3081 | // effects of the State assignment don't happen with mStateLock held, |
| 3082 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3083 | State drawingState(mDrawingState); |
| 3084 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3085 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3086 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3088 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3089 | // so we can call commitTransactionsLocked unconditionally. |
| 3090 | // We clear the flags with mStateLock held to guarantee that |
| 3091 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3092 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3093 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3094 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3095 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3098 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3099 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3100 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 3101 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3102 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3103 | int attempt = 0; |
| 3104 | constexpr int kMaxAttempts = 3; |
| 3105 | do { |
| 3106 | hwcModes = getHwComposer().getModes(displayId); |
| 3107 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3108 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3109 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3110 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3111 | }; |
| 3112 | |
| 3113 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3114 | break; |
| 3115 | } |
| 3116 | } while (++attempt < kMaxAttempts); |
| 3117 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3118 | if (attempt == kMaxAttempts) { |
| 3119 | const std::string activeMode = |
| 3120 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 3121 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3122 | "hwcModes={%s}", |
| 3123 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3124 | return {}; |
| 3125 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3126 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3127 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3128 | .transform([](const PhysicalDisplay& display) { |
| 3129 | return display.snapshot().displayModes(); |
| 3130 | }) |
| 3131 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3132 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3133 | ui::DisplayModeId nextModeId = 1 + |
| 3134 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 3135 | [](ui::DisplayModeId max, const auto& pair) { |
| 3136 | return std::max(max, pair.first.value()); |
| 3137 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3138 | |
| 3139 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3140 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3141 | const DisplayModeId id{nextModeId++}; |
| 3142 | newModes.try_emplace(id, |
| 3143 | DisplayMode::Builder(hwcMode.hwcId) |
| 3144 | .setId(id) |
| 3145 | .setPhysicalDisplayId(displayId) |
| 3146 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3147 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
| 3148 | .setDpiX(hwcMode.dpiX) |
| 3149 | .setDpiY(hwcMode.dpiY) |
| 3150 | .setGroup(hwcMode.configGroup) |
| 3151 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3154 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3155 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3156 | [](const auto& lhs, const auto& rhs) { |
| 3157 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3158 | }); |
| 3159 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3160 | // Keep IDs if modes have not changed. |
| 3161 | const auto& modes = sameModes ? oldModes : newModes; |
| 3162 | const DisplayModePtr activeMode = |
| 3163 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 3164 | return pair.second->getHwcId() == activeModeHwcId; |
| 3165 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3166 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3167 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3170 | bool SurfaceFlinger::configureLocked() { |
| 3171 | std::vector<HotplugEvent> events; |
| 3172 | { |
| 3173 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3174 | events = std::move(mPendingHotplugEvents); |
| 3175 | } |
| 3176 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3177 | for (const auto [hwcDisplayId, connection] : events) { |
| 3178 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3179 | const auto displayId = info->id; |
| 3180 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3181 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3182 | if (const char* const log = |
| 3183 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3184 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3185 | hwcDisplayId); |
| 3186 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3187 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3188 | } |
| 3189 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3190 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3191 | } |
| 3192 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3193 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3194 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3195 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3196 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3197 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3198 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3199 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3200 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3201 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3202 | mCurrentState.displays.removeItemsAt(index); |
| 3203 | } |
| 3204 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3205 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3206 | return "Disconnecting"; |
| 3207 | } |
| 3208 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3209 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3210 | if (!activeMode) { |
| 3211 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 3212 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 3213 | getHwComposer().disconnectDisplay(displayId); |
| 3214 | return nullptr; |
| 3215 | } |
| 3216 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3217 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3218 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3219 | if (displayOpt) { |
| 3220 | const auto& display = displayOpt->get(); |
| 3221 | const auto& snapshot = display.snapshot(); |
| 3222 | |
| 3223 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3224 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3225 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3226 | } else { |
| 3227 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3228 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3229 | |
| 3230 | const auto it = |
| 3231 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3232 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3233 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3234 | |
| 3235 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3236 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3237 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3238 | return "Reconnecting"; |
| 3239 | } |
| 3240 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3241 | const sp<IBinder> token = sp<BBinder>::make(); |
| 3242 | |
| 3243 | mPhysicalDisplays.try_emplace(displayId, token, displayId, |
| 3244 | getHwComposer().getDisplayConnectionType(displayId), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3245 | std::move(displayModes), std::move(colorModes), |
| 3246 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3247 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3248 | DisplayDeviceState state; |
| 3249 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3250 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3251 | .activeMode = std::move(activeMode)}; |
| 3252 | state.isSecure = true; // All physical displays are currently considered secure. |
| 3253 | state.displayName = std::move(info.name); |
| 3254 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3255 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3256 | return "Connecting"; |
| 3257 | } |
| 3258 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3259 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 3260 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 3261 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 3262 | } |
| 3263 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3264 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3265 | const wp<IBinder>& displayToken, |
| 3266 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3267 | const DisplayDeviceState& state, |
| 3268 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3269 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3270 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3271 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3272 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3273 | creationArgs.isSecure = state.isSecure; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3274 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3275 | creationArgs.hasWideColorGamut = false; |
| 3276 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3277 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3278 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3279 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3280 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3281 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3282 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3283 | using Config = scheduler::RefreshRateSelector::Config; |
| 3284 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3285 | ? Config::FrameRateOverride::Enabled |
| 3286 | : Config::FrameRateOverride::Disabled; |
Ady Abraham | 0d4b41c | 2023-02-14 23:28:40 +0000 | [diff] [blame] | 3287 | Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3288 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3289 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 3290 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3291 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3292 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3293 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3294 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3295 | mPhysicalDisplays.get(physical->id) |
| 3296 | .transform(&PhysicalDisplay::snapshotRef) |
| 3297 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3298 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3299 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3300 | creationArgs.activeModeId, |
| 3301 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3302 | }) |
| 3303 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3304 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3305 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3306 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3307 | if (useColorManagement) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3308 | mPhysicalDisplays.get(physical->id) |
| 3309 | .transform(&PhysicalDisplay::snapshotRef) |
| 3310 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3311 | for (const auto mode : snapshot.colorModes()) { |
| 3312 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3313 | creationArgs.hwcColorModes |
| 3314 | .emplace(mode, |
| 3315 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3316 | } |
| 3317 | })); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3318 | } |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3319 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3320 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3321 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3322 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3323 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3324 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3325 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3326 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3327 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3328 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3329 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3330 | // Make sure that composition can never be stalled by a virtual display |
| 3331 | // 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] | 3332 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3333 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3334 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3335 | } |
| 3336 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3337 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3338 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3339 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3340 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3341 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 3342 | creationArgs.initialPowerMode = |
| 3343 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3344 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3345 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3346 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3347 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3348 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3349 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3350 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3351 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3352 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3353 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3354 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3355 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3356 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3357 | display->getCompositionDisplay()->setColorProfile( |
| 3358 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
| 3359 | RenderIntent::COLORIMETRIC, |
| 3360 | Dataspace::UNKNOWN}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3361 | |
| 3362 | if (const auto& physical = state.physical) { |
| 3363 | mPhysicalDisplays.get(physical->id) |
| 3364 | .transform(&PhysicalDisplay::snapshotRef) |
| 3365 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3366 | FTL_FAKE_GUARD(kMainThreadContext, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3367 | display->setActiveMode(physical->activeMode->getId(), |
| 3368 | physical->activeMode->getFps(), |
| 3369 | physical->activeMode->getFps())); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3370 | })); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3371 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3372 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3373 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3374 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3375 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3376 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3377 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3378 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3379 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3380 | } |
| 3381 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3382 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3383 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3384 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3385 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3386 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3387 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3388 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3389 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3390 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3391 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3392 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3393 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3394 | int format; |
| 3395 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3396 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3397 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3398 | } else { |
| 3399 | // Virtual displays without a surface are dormant: |
| 3400 | // they have external state (layer stack, projection, |
| 3401 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3402 | return; |
| 3403 | } |
| 3404 | |
| 3405 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3406 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3407 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3408 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3409 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3410 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3411 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3412 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3413 | builder.setIsSecure(state.isSecure); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3414 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3415 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3416 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 3417 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3418 | |
| 3419 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3420 | sp<IGraphicBufferProducer> producer; |
| 3421 | sp<IGraphicBufferProducer> bqProducer; |
| 3422 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3423 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3424 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3425 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3426 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3427 | LOG_FATAL_IF(!displayId); |
| 3428 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
| 3429 | bqProducer, bqConsumer, state.displayName); |
| 3430 | displaySurface = surface; |
| 3431 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3432 | } else { |
| 3433 | ALOGE_IF(state.surface != nullptr, |
| 3434 | "adding a supported display, but rendering " |
| 3435 | "surface is provided (%p), ignoring it", |
| 3436 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3437 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3438 | LOG_FATAL_IF(!displayId); |
| 3439 | displaySurface = |
| 3440 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3441 | state.physical->activeMode->getResolution(), |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3442 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3443 | producer = bqProducer; |
| 3444 | } |
| 3445 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3446 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3447 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3448 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3449 | |
| 3450 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3451 | const auto displayId = display->getPhysicalId(); |
| 3452 | { |
Dominik Laskowski | 59db956 | 2022-10-27 16:18:53 -0400 | [diff] [blame] | 3453 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3454 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3455 | |
| 3456 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3457 | mScheduler->registerDisplay(displayId, display->holdRefreshRateSelector()); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3458 | } |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 3459 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3460 | dispatchDisplayHotplugEvent(displayId, true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3461 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3462 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3463 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3464 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3467 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3471 | auto display = getDisplayDeviceLocked(displayToken); |
| 3472 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3473 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3474 | |
| 3475 | if (display->isVirtual()) { |
| 3476 | releaseVirtualDisplay(display->getVirtualId()); |
| 3477 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3478 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3479 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3484 | |
| 3485 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3486 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3487 | // Destroy the display without holding the mStateLock. |
| 3488 | // This is a temporary solution until we can manage transaction queues without |
| 3489 | // holding the mStateLock. |
| 3490 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3491 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3492 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3493 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3494 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3495 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3496 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3497 | // not be accessible. |
| 3498 | })); |
| 3499 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3503 | const DisplayDeviceState& currentState, |
| 3504 | const DisplayDeviceState& drawingState) { |
| 3505 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3506 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3507 | |
| 3508 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3509 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | 23c31af | 2020-09-09 15:01:47 +0200 | [diff] [blame] | 3510 | getRenderEngine().cleanFramebufferCache(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3511 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3512 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3513 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3514 | if (display->isVirtual()) { |
| 3515 | releaseVirtualDisplay(display->getVirtualId()); |
| 3516 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3517 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3518 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3519 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3520 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3521 | if (const auto& physical = currentState.physical) { |
| 3522 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3523 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3524 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3525 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3526 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3527 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3528 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3529 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3530 | |
| 3531 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3532 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3533 | resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3534 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3535 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3536 | return; |
| 3537 | } |
| 3538 | |
| 3539 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3540 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3541 | display->setLayerFilter( |
| 3542 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3543 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3544 | if (currentState.flags != drawingState.flags) { |
| 3545 | display->setFlags(currentState.flags); |
| 3546 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3547 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3548 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3549 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3550 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3551 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3552 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3553 | mActiveDisplayTransformHint = display->getTransformHint(); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3554 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3555 | } |
| 3556 | if (currentState.width != drawingState.width || |
| 3557 | currentState.height != drawingState.height) { |
| 3558 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3559 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3560 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3561 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | } |
| 3565 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3566 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3567 | void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) { |
| 3568 | // Cancel the pending refresh rate change, if any, before updating the phase configuration. |
| 3569 | mScheduler->vsyncModulator().cancelRefreshRateChange(); |
| 3570 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3571 | mVsyncConfiguration->reset(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3572 | updatePhaseConfiguration(refreshRate); |
| 3573 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3574 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3575 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3576 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3577 | // here we take advantage of Vector's copy-on-write semantics to |
| 3578 | // improve performance by skipping the transaction entirely when |
| 3579 | // know that the lists are identical |
| 3580 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3581 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3582 | if (!curr.isIdenticalTo(draw)) { |
| 3583 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3584 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3585 | |
| 3586 | // find the displays that were removed |
| 3587 | // (ie: in drawing state but not in current state) |
| 3588 | // also handle displays that changed |
| 3589 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3590 | for (size_t i = 0; i < draw.size(); i++) { |
| 3591 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3592 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3593 | if (j < 0) { |
| 3594 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3595 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3596 | } else { |
| 3597 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3598 | const DisplayDeviceState& currentState = curr[j]; |
| 3599 | const DisplayDeviceState& drawingState = draw[i]; |
| 3600 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3601 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | // find displays that were added |
| 3605 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3606 | for (size_t i = 0; i < curr.size(); i++) { |
| 3607 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3608 | if (draw.indexOfKey(displayToken) < 0) { |
| 3609 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3613 | |
| 3614 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3615 | } |
| 3616 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3617 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3618 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3619 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3620 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
| 3621 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3622 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3623 | mFrontEndDisplayInfos.clear(); |
| 3624 | for (const auto& [_, display] : mDisplays) { |
| 3625 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3626 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3627 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3628 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3630 | if (mSomeChildrenChanged) { |
| 3631 | mVisibleRegionsDirty = true; |
| 3632 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3633 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3636 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3637 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3638 | // 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] | 3639 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3640 | // 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] | 3641 | // the hint is set before we acquire a buffer from the surface texture. |
| 3642 | // |
| 3643 | // NOTE: layer transactions have taken place already, so we use their |
| 3644 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3645 | // happened yet, so we must use the current state layer list |
| 3646 | // (soon to become the drawing state list). |
| 3647 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3648 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3649 | ui::LayerStack layerStack; |
| 3650 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3651 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3652 | // NOTE: we rely on the fact that layers are sorted by |
| 3653 | // layerStack first (so we don't have to traverse the list |
| 3654 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3655 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3656 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3657 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3658 | |
| 3659 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3660 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3661 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3662 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3663 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3664 | |
| 3665 | // Pick the primary display if another display mirrors the layer. |
| 3666 | if (hintDisplay) { |
| 3667 | hintDisplay = nullptr; |
| 3668 | break; |
| 3669 | } |
| 3670 | |
| 3671 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3672 | } |
| 3673 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3674 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3675 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3676 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3677 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3678 | // could be null when this layer is using a layerStack |
| 3679 | // that is not visible on any display. Also can occur at |
| 3680 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3681 | // U Update: Don't provide stale hints to the clients. For |
| 3682 | // special cases where we want the app to draw its |
| 3683 | // first frame before the display is available, we rely |
| 3684 | // on WMS and DMS to provide the right information |
| 3685 | // so the client can calculate the hint. |
| 3686 | ALOGV("Skipping reporting transform hint update for %s", layer->getDebugName()); |
| 3687 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3688 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3689 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3690 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3691 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3692 | } |
| 3693 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3694 | if (mLayersAdded) { |
| 3695 | mLayersAdded = false; |
| 3696 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3697 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3698 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | // some layers might have been removed, so |
| 3702 | // we need to update the regions they're exposing. |
| 3703 | if (mLayersRemoved) { |
| 3704 | mLayersRemoved = false; |
| 3705 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3706 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3707 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3708 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3709 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3710 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3711 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3712 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3713 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3714 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3717 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3718 | mUpdateInputInfo = true; |
| 3719 | } |
| 3720 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3721 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3724 | void SurfaceFlinger::updateInputFlinger() { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3725 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3726 | return; |
| 3727 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3728 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3729 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3730 | std::vector<WindowInfo> windowInfos; |
| 3731 | std::vector<DisplayInfo> displayInfos; |
| 3732 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3733 | if (mUpdateInputInfo) { |
| 3734 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3735 | updateWindowInfo = true; |
| 3736 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3737 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3738 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3739 | std::unordered_set<int32_t> visibleWindowIds; |
| 3740 | for (WindowInfo& windowInfo : windowInfos) { |
| 3741 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 3742 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3743 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3744 | } |
| 3745 | bool visibleWindowsChanged = false; |
| 3746 | if (visibleWindowIds != mVisibleWindowIds) { |
| 3747 | visibleWindowsChanged = true; |
| 3748 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3749 | } |
| 3750 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3751 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3752 | windowInfos = std::move(windowInfos), |
| 3753 | displayInfos = std::move(displayInfos), |
| 3754 | inputWindowCommands = |
| 3755 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3756 | inputFlinger = mInputFlinger, this, |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3757 | visibleWindowsChanged]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3758 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3759 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3760 | mWindowInfosListenerInvoker |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3761 | ->windowInfosChanged(std::move(windowInfos), std::move(displayInfos), |
| 3762 | std::move( |
| 3763 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3764 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3765 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3766 | } else { |
| 3767 | // If there are listeners but no changes to input windows, call the listeners |
| 3768 | // immediately. |
| 3769 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3770 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3771 | listener->onWindowInfosReported(); |
| 3772 | } |
| 3773 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3774 | } |
| 3775 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3776 | inputFlinger->setFocusedWindow(focusRequest); |
| 3777 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3778 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3779 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3780 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3783 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3784 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3785 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3786 | if (!supportsDisplayBrightnessCommand) { |
| 3787 | return; |
| 3788 | } |
| 3789 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3790 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3791 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3792 | if (!needsComposite) { |
| 3793 | const status_t error = |
| 3794 | getHwComposer() |
| 3795 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3796 | display->getCompositionDisplay() |
| 3797 | ->getState() |
| 3798 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3799 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3800 | .applyImmediately = true}) |
| 3801 | .get(); |
| 3802 | |
| 3803 | ALOGE_IF(error != NO_ERROR, |
| 3804 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 3805 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3806 | } |
| 3807 | display->persistBrightness(needsComposite); |
| 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3812 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 3813 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3814 | static size_t sNumWindowInfos = 0; |
| 3815 | outWindowInfos.reserve(sNumWindowInfos); |
| 3816 | sNumWindowInfos = 0; |
| 3817 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3818 | if (mLayerLifecycleManagerEnabled) { |
| 3819 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 3820 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 3821 | outWindowInfos.push_back(snapshot.inputInfo); |
| 3822 | }); |
| 3823 | } else { |
| 3824 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 3825 | if (!layer->needsInputInfo()) return; |
| 3826 | const auto opt = |
| 3827 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 3828 | .transform([](const frontend::DisplayInfo& info) { |
| 3829 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 3830 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3831 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3832 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 3833 | }); |
| 3834 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3835 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3836 | sNumWindowInfos = outWindowInfos.size(); |
| 3837 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3838 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 3839 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3840 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3841 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3844 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3845 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3846 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3847 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3848 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3849 | } |
| 3850 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3851 | auto layers = moveSnapshotsToCompositionArgs(refreshArgs, /*cursorOnly=*/true, 0); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3852 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3853 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3854 | } |
| 3855 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3856 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3857 | if (mBootStage != BootStage::FINISHED) { |
| 3858 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 3859 | return; |
| 3860 | } |
| 3861 | |
| 3862 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3863 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3864 | // If this is called from the main thread mStateLock must be locked before |
| 3865 | // 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] | 3866 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3867 | |
| 3868 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3869 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3870 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3871 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3872 | |
| 3873 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 3874 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3875 | |
| 3876 | if (!display) continue; |
| 3877 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3878 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 3879 | .transform(&PhysicalDisplay::isInternal) |
| 3880 | .value_or(false); |
| 3881 | |
| 3882 | if (isInternalDisplay && displayId != mActiveDisplayId) { |
| 3883 | ALOGV("%s(%s): Inactive display", __func__, to_string(displayId).c_str()); |
| 3884 | continue; |
| 3885 | } |
| 3886 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3887 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3888 | setDesiredActiveMode(std::move(request)); |
| 3889 | } else { |
| 3890 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, modePtr->getId().value(), |
| 3891 | to_string(display->getId()).c_str()); |
| 3892 | } |
| 3893 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 3894 | } |
| 3895 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3896 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 3897 | PhysicalDisplayId displayId = [&]() { |
| 3898 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 3899 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 3900 | }(); |
| 3901 | |
| 3902 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 3903 | } |
| 3904 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3905 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3906 | using namespace scheduler; |
| 3907 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3908 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 3909 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3910 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 3911 | const Fps activeRefreshRate = activeMode.fps; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3912 | mRefreshRateStats = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3913 | std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3914 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3915 | mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 3916 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3917 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3918 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3919 | if (sysprop::use_content_detection_for_refresh_rate(false)) { |
| 3920 | features |= Feature::kContentDetection; |
| 3921 | } |
| 3922 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 3923 | features |= Feature::kTracePredictedVsync; |
| 3924 | } |
| 3925 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 3926 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3927 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3928 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3929 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 3930 | features |= Feature::kKernelIdleTimer; |
| 3931 | } |
| 3932 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3933 | auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
| 3934 | |
| 3935 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 3936 | static_cast<ISchedulerCallback&>(*this), features, |
| 3937 | std::move(modulatorPtr)); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3938 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3939 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3940 | setVsyncEnabled(display->getPhysicalId(), false); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3941 | mScheduler->startTimers(); |
| 3942 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 3943 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3944 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3945 | mAppConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3946 | mScheduler->createEventThread(Scheduler::Cycle::Render, |
| 3947 | mFrameTimeline->getTokenManager(), |
| 3948 | /* workDuration */ configs.late.appWorkDuration, |
| 3949 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3950 | mSfConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3951 | mScheduler->createEventThread(Scheduler::Cycle::LastComposite, |
| 3952 | mFrameTimeline->getTokenManager(), |
| 3953 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 3954 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3955 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3956 | mScheduler->initVsync(mScheduler->getVsyncSchedule()->getDispatch(), |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3957 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3958 | |
| 3959 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3960 | sp<RegionSamplingThread>::make(*this, |
| 3961 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 3962 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3965 | void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 3966 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3967 | mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(), |
| 3968 | refreshRate.getPeriod()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3971 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 3972 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3974 | if (!mLayersPendingRemoval.isEmpty()) { |
| 3975 | // Notify removed layers now that they can't be drawn from |
| 3976 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3977 | // Ensure any buffers set to display on any children are released. |
| 3978 | if (l->isRemovedFromCurrentState()) { |
| 3979 | l->latchAndReleaseBuffer(); |
| 3980 | } |
| 3981 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 3982 | // If a layer has a parent, we allow it to out-live it's handle |
| 3983 | // with the idea that the parent holds a reference and will eventually |
| 3984 | // be cleaned up. However no one cleans up the top-level so we do so |
| 3985 | // here. |
| 3986 | if (l->isAtRoot()) { |
| 3987 | l->setIsAtRoot(false); |
| 3988 | mCurrentState.layersSortedByZ.remove(l); |
| 3989 | } |
| 3990 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3991 | // If the layer has been removed and has no parent, then it will not be reachable |
| 3992 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 3993 | // ensure we can copy its current to drawing state. |
| 3994 | if (!l->getParent()) { |
| 3995 | mOffscreenLayers.emplace(l.get()); |
| 3996 | } |
| 3997 | } |
| 3998 | mLayersPendingRemoval.clear(); |
| 3999 | } |
| 4000 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4001 | mDrawingState = mCurrentState; |
| 4002 | // clear the "changed" flags in current state |
| 4003 | mCurrentState.colorMatrixChanged = false; |
| 4004 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4005 | if (mVisibleRegionsDirty) { |
| 4006 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4007 | rootLayer->commitChildList(); |
| 4008 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4009 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4010 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4011 | commitOffscreenLayers(); |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4012 | if (mNumClones > 0) { |
| 4013 | mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); }); |
| 4014 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4017 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4018 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4019 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4020 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4021 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4022 | layer->commitChildList(); |
| 4023 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4024 | }); |
| 4025 | } |
| 4026 | } |
| 4027 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4028 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4029 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4030 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4031 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4032 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4033 | } |
| 4034 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4037 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4038 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4039 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4040 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4041 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4042 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4043 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4044 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4045 | |
| 4046 | // Store the set of layers that need updates. This set must not change as |
| 4047 | // buffers are being latched, as this could result in a deadlock. |
| 4048 | // Example: Two producers share the same command stream and: |
| 4049 | // 1.) Layer 0 is latched |
| 4050 | // 2.) Layer 0 gets a new frame |
| 4051 | // 2.) Layer 1 gets a new frame |
| 4052 | // 3.) Layer 1 is latched. |
| 4053 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4054 | // 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] | 4055 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4056 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4057 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4058 | if (flags & Layer::eVisibleRegion) { |
| 4059 | mVisibleRegionsDirty = true; |
| 4060 | } |
| 4061 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4062 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4063 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4064 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4065 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4066 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4067 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4068 | if (!layer->hasBuffer()) { |
| 4069 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4070 | // instead of a missed frame. This is used to identify scenarios where we |
| 4071 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4072 | // We only update the latch time for buffer less layers here, the latch time |
| 4073 | // is updated for buffer layers when the buffer is latched. |
| 4074 | layer->updateLastLatchTime(latchTime); |
| 4075 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4076 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4077 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4078 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4079 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4080 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4081 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4082 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4083 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4084 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4085 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4086 | } |
| 4087 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4088 | if (!mLayersWithQueuedFrames.empty()) { |
| 4089 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4090 | // writes to Layer current state. See also b/119481871 |
| 4091 | Mutex::Autolock lock(mStateLock); |
| 4092 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4093 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4094 | if (layer->willReleaseBufferOnLatch()) { |
| 4095 | mLayersWithBuffersRemoved.emplace(layer); |
| 4096 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4097 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4098 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4099 | newDataLatched = true; |
| 4100 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4101 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4102 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4103 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4104 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4105 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4106 | |
| 4107 | // If we will need to wake up at some time in the future to deal with a |
| 4108 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4109 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4110 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4111 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4112 | } |
| 4113 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4114 | // enter boot animation on first buffer latch |
| 4115 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4116 | ALOGI("Enter boot animation"); |
| 4117 | mBootStage = BootStage::BOOTANIMATION; |
| 4118 | } |
| 4119 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4120 | if (mNumClones > 0) { |
| 4121 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4122 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4123 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4124 | // 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] | 4125 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4126 | } |
| 4127 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4128 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4129 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4130 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4131 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4132 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4133 | MAX_LAYERS); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4134 | static_cast<void>(mScheduler->schedule([=] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4135 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4136 | bool leakingParentLayerFound = false; |
| 4137 | mDrawingState.traverse([&](Layer* layer) { |
| 4138 | if (leakingParentLayerFound) { |
| 4139 | return; |
| 4140 | } |
| 4141 | if (layer->getChildrenCount() > 20) { |
| 4142 | leakingParentLayerFound = true; |
| 4143 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4144 | while (parent) { |
| 4145 | ALOGE("Parent Layer: %s handleIsAlive: %s", parent->getName().c_str(), |
| 4146 | std::to_string(parent->isHandleAlive()).c_str()); |
| 4147 | parent = parent->getParent(); |
| 4148 | } |
| 4149 | // Sample up to 100 layers |
| 4150 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4151 | layer->getChildrenCount()); |
| 4152 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4153 | layer->traverseChildren([&](Layer* layer) { |
| 4154 | if (rand() % sampleSize == 0) { |
| 4155 | ALOGE("Child Layer: %s", layer->getName().c_str()); |
| 4156 | } |
| 4157 | }); |
| 4158 | } |
| 4159 | }); |
| 4160 | |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4161 | ALOGE("Dumping random sampling of on-screen layers: "); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4162 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4163 | // Aim to dump about 200 layers to avoid totally trashing |
| 4164 | // logcat. On the other hand, if there really are 4096 layers |
| 4165 | // something has gone totally wrong its probably the most |
| 4166 | // useful information in logcat. |
| 4167 | if (rand() % 20 == 13) { |
| 4168 | ALOGE("Layer: %s", layer->getName().c_str()); |
| 4169 | } |
| 4170 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4171 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4172 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4173 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4174 | if (rand() % 20 == 13) { |
| 4175 | ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str()); |
| 4176 | } |
| 4177 | } |
| 4178 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4179 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4180 | } |
| 4181 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4182 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4183 | if (outTransformHint) { |
| 4184 | *outTransformHint = mActiveDisplayTransformHint; |
| 4185 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4186 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4187 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4188 | { |
| 4189 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4190 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4191 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4192 | args.mirrorLayerHandle.clear(); |
| 4193 | args.parentHandle.clear(); |
| 4194 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4195 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4196 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4197 | setTransactionFlags(eTransactionNeeded); |
| 4198 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4199 | } |
| 4200 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4201 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4202 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4205 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4206 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4207 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4208 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | } |
| 4210 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4211 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4212 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4213 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4214 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4215 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4216 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4217 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4218 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4219 | } else if (frameHint == FrameHint::kActive) { |
| 4220 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4221 | // as a new activity just happened. |
| 4222 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4223 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | } |
| 4225 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4226 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4227 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4228 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4229 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4230 | TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
| 4231 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4232 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4233 | // for stability reasons. |
| 4234 | if (!transaction.isAutoTimestamp && desiredPresentTime >= mExpectedPresentTime && |
| 4235 | desiredPresentTime < mExpectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4236 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
| 4237 | desiredPresentTime, mExpectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4238 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4239 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4240 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 4241 | if (!mScheduler->isVsyncValid(mExpectedPresentTime, transaction.originUid)) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4242 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", |
| 4243 | mExpectedPresentTime, transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4244 | return TransactionReadiness::NotReady; |
| 4245 | } |
| 4246 | |
| 4247 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4248 | // expected present time of this transaction. |
| 4249 | if (transaction.isAutoTimestamp && |
| 4250 | frameIsEarly(mExpectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4251 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
| 4252 | transaction.frameTimelineInfo.vsyncId, mExpectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4253 | return TransactionReadiness::NotReady; |
| 4254 | } |
| 4255 | return TransactionReadiness::Ready; |
| 4256 | } |
| 4257 | |
| 4258 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4259 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4260 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4261 | auto ready = TransactionReadiness::Ready; |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4262 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const layer_state_t& s, |
| 4263 | const std::shared_ptr< |
| 4264 | renderengine:: |
| 4265 | ExternalTexture>& |
| 4266 | externalTexture) |
| 4267 | -> bool { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4268 | sp<Layer> layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4269 | const auto& transaction = *flushState.transaction; |
| 4270 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4271 | if (s.bufferData->hasBarrier) { |
| 4272 | // The current producerId is already a newer producer than the buffer that has a |
| 4273 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4274 | // don't wait on the barrier since we know that's stale information. |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4275 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4276 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4277 | externalTexture->getBuffer(), |
| 4278 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4279 | s.bufferData->acquireFence); |
| 4280 | // Delete the entire state at this point and not just release the buffer because |
| 4281 | // everything associated with the Layer in this Transaction is now out of date. |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4282 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4283 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4284 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4285 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4286 | } |
| 4287 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4288 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4289 | const bool willApplyBarrierFrame = |
| 4290 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4291 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4292 | s.bufferData->barrierFrameNumber)); |
| 4293 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4294 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4295 | layer->getDebugName(), |
| 4296 | layer->getDrawingState().barrierFrameNumber, |
| 4297 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4298 | ready = TransactionReadiness::NotReadyBarrier; |
| 4299 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4300 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4305 | // the transaction in the queue. |
| 4306 | const bool hasPendingBuffer = |
| 4307 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4308 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4309 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4310 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4311 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4314 | // ignore the acquire fence if LatchUnsignaledConfig::Always is set. |
| 4315 | const bool checkAcquireFence = enableLatchUnsignaledConfig != LatchUnsignaledConfig::Always; |
| 4316 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4317 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4318 | s.bufferData->acquireFence; |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4319 | const bool fenceSignaled = !checkAcquireFence || !acquireFenceAvailable || |
| 4320 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4321 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4322 | // check fence status |
| 4323 | const bool allowLatchUnsignaled = |
| 4324 | shouldLatchUnsignaled(layer, s, transaction.states.size(), |
| 4325 | flushState.firstTransaction); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4326 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4327 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4328 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4329 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4330 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4331 | ready = TransactionReadiness::NotReady; |
| 4332 | auto& listener = s.bufferData->releaseBufferListener; |
| 4333 | if (listener && |
| 4334 | (flushState.queueProcessTime - transaction.postTime) > |
| 4335 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4336 | mTransactionHandler |
| 4337 | .onTransactionQueueStalled(transaction.id, listener, |
| 4338 | "Buffer processing hung up due to stuck " |
| 4339 | "fence. Indicates GPU hang"); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4340 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4341 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4342 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4343 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4344 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4345 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4346 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4347 | return ready; |
| 4348 | } |
| 4349 | |
| 4350 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4351 | mTransactionHandler.addTransactionReadyFilter( |
| 4352 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
| 4353 | mTransactionHandler.addTransactionReadyFilter( |
| 4354 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, std::placeholders::_1)); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4355 | } |
| 4356 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4357 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4358 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4359 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4360 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4363 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4364 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4365 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4366 | return applyTransactionsLocked(transactions, vsyncId); |
| 4367 | } |
| 4368 | |
| 4369 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4370 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4371 | bool needsTraversal = false; |
| 4372 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4373 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4374 | needsTraversal |= |
| 4375 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4376 | transaction.displays, transaction.flags, |
| 4377 | transaction.inputWindowCommands, |
| 4378 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4379 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4380 | transaction.permissions, transaction.hasListenerCallbacks, |
| 4381 | transaction.listenerCallbacks, transaction.originPid, |
| 4382 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4383 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4384 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4388 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4391 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4392 | const auto prediction = |
| 4393 | mFrameTimeline->getTokenManager()->getPredictionsForToken(vsyncId.value); |
| 4394 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4395 | return false; |
| 4396 | } |
| 4397 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4398 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4399 | |
| 4400 | // The duration for which SF can delay a frame if it is considered early based on the |
Dominik Laskowski | 933f8de | 2023-01-20 13:15:51 -0500 | [diff] [blame] | 4401 | // VsyncConfig::appWorkDuration. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4402 | if (constexpr std::chrono::nanoseconds kEarlyLatchMaxThreshold = 100ms; |
| 4403 | std::chrono::abs(predictedPresentTime - expectedPresentTime) >= kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4404 | return false; |
| 4405 | } |
| 4406 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4407 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->period() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4408 | |
| 4409 | return predictedPresentTime >= expectedPresentTime && |
| 4410 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4411 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4412 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4413 | bool SurfaceFlinger::shouldLatchUnsignaled(const sp<Layer>& layer, const layer_state_t& state, |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4414 | size_t numStates, bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4415 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
| 4416 | ALOGV("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
| 4417 | return false; |
| 4418 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4419 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4420 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Always) { |
| 4421 | ALOGV("%s: true (LatchUnsignaledConfig::Always)", __func__); |
| 4422 | return true; |
| 4423 | } |
| 4424 | |
| 4425 | // We only want to latch unsignaled when a single layer is updated in this |
| 4426 | // transaction (i.e. not a blast sync transaction). |
| 4427 | if (numStates != 1) { |
| 4428 | ALOGV("%s: false (numStates=%zu)", __func__, numStates); |
| 4429 | return false; |
| 4430 | } |
| 4431 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4432 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4433 | if (!firstTransaction) { |
| 4434 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first transaction)", |
| 4435 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4436 | return false; |
| 4437 | } |
| 4438 | |
| 4439 | // We don't want to latch unsignaled if are in early / client composition |
| 4440 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4441 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 4442 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
| 4443 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; isVsyncConfigEarly)", |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4444 | __func__); |
| 4445 | return false; |
| 4446 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | if (!layer->simpleBufferUpdate(state)) { |
| 4450 | ALOGV("%s: false (!simpleBufferUpdate)", __func__); |
| 4451 | return false; |
| 4452 | } |
| 4453 | |
| 4454 | ALOGV("%s: true", __func__); |
| 4455 | return true; |
| 4456 | } |
| 4457 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4458 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4459 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4460 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
| 4461 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4462 | bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffers, |
| 4463 | bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4464 | uint64_t transactionId) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 4465 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4466 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4467 | uint32_t permissions = |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4468 | callingThreadHasUnscopedSurfaceFlingerAccess() ? |
| 4469 | layer_state_t::Permission::ACCESS_SURFACE_FLINGER : 0; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4470 | // Avoid checking for rotation permissions if the caller already has ACCESS_SURFACE_FLINGER |
| 4471 | // permissions. |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4472 | if ((permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4473 | callingThreadHasPermission(sRotateSurfaceFlinger)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4474 | permissions |= layer_state_t::Permission::ROTATE_SURFACE_FLINGER; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4475 | } |
| 4476 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4477 | if (callingThreadHasPermission(sInternalSystemWindow)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4478 | permissions |= layer_state_t::Permission::INTERNAL_SYSTEM_WINDOW; |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4481 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4482 | const bool hasPermission = |
| 4483 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4484 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4485 | if (!hasPermission) { |
| 4486 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4487 | "eEarlyWakeup[Start|End] flags"); |
| 4488 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4489 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4490 | } |
| 4491 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4492 | const int64_t postTime = systemTime(); |
| 4493 | |
| 4494 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4495 | const int originPid = ipc->getCallingPid(); |
| 4496 | const int originUid = ipc->getCallingUid(); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4497 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4498 | std::vector<uint64_t> uncacheBufferIds; |
| 4499 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4500 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4501 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4502 | if (buffer != nullptr) { |
| 4503 | uncacheBufferIds.push_back(buffer->getId()); |
| 4504 | } |
| 4505 | } |
| 4506 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4507 | std::vector<ResolvedComposerState> resolvedStates; |
| 4508 | resolvedStates.reserve(states.size()); |
| 4509 | for (auto& state : states) { |
| 4510 | resolvedStates.emplace_back(std::move(state)); |
| 4511 | auto& resolvedState = resolvedStates.back(); |
| 4512 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4513 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4514 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4515 | std::string layerName = (layer) ? |
| 4516 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4517 | resolvedState.externalTexture = |
| 4518 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4519 | layerName.c_str(), transactionId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4520 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 4521 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4522 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 4523 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4524 | resolvedState.parentId = |
| 4525 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4526 | } |
| 4527 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4528 | resolvedState.relativeParentId = |
| 4529 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4530 | } |
| 4531 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4532 | wp<IBinder>& touchableRegionCropHandle = |
| 4533 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4534 | resolvedState.touchCropId = |
| 4535 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4536 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4537 | } |
| 4538 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4539 | TransactionState state{frameTimelineInfo, |
| 4540 | resolvedStates, |
| 4541 | displays, |
| 4542 | flags, |
| 4543 | applyToken, |
| 4544 | inputWindowCommands, |
| 4545 | desiredPresentTime, |
| 4546 | isAutoTimestamp, |
| 4547 | std::move(uncacheBufferIds), |
| 4548 | postTime, |
| 4549 | permissions, |
| 4550 | hasListenerCallbacks, |
| 4551 | listenerCallbacks, |
| 4552 | originPid, |
| 4553 | originUid, |
| 4554 | transactionId}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4555 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4556 | if (mTransactionTracing) { |
| 4557 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4558 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4559 | |
| 4560 | const auto schedule = [](uint32_t flags) { |
| 4561 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4562 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4563 | return TransactionSchedule::Late; |
| 4564 | }(state.flags); |
| 4565 | |
| 4566 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4567 | mTransactionHandler.queueTransaction(std::move(state)); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4568 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4569 | return NO_ERROR; |
| 4570 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4571 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4572 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4573 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4574 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4575 | const InputWindowCommands& inputWindowCommands, |
| 4576 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4577 | const std::vector<uint64_t>& uncacheBufferIds, |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4578 | const int64_t postTime, uint32_t permissions, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4579 | bool hasListenerCallbacks, |
| 4580 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4581 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4582 | uint32_t transactionFlags = 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4583 | if (!mLayerLifecycleManagerEnabled) { |
| 4584 | for (DisplayState& display : displays) { |
| 4585 | display.sanitize(permissions); |
| 4586 | transactionFlags |= setDisplayStateLocked(display); |
| 4587 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4590 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4591 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4592 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4593 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4594 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4597 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4598 | for (auto& resolvedState : states) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4599 | if (mLegacyFrontEndEnabled) { |
| 4600 | clientStateFlags |= |
| 4601 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
| 4602 | isAutoTimestamp, postTime, permissions, transactionId); |
| 4603 | |
| 4604 | } else /*mLayerLifecycleManagerEnabled*/ { |
| 4605 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 4606 | desiredPresentTime, isAutoTimestamp, |
| 4607 | postTime, permissions, transactionId); |
| 4608 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4609 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 4610 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 4611 | const auto layerProps = scheduler::LayerProps{ |
| 4612 | .visible = layer->isVisible(), |
| 4613 | .bounds = layer->getBounds(), |
| 4614 | .transform = layer->getTransform(), |
| 4615 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 4616 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 4617 | }; |
| 4618 | layer->recordLayerHistoryAnimationTx(layerProps); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4619 | } |
| 4620 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4623 | transactionFlags |= clientStateFlags; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 4624 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4625 | if (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 4626 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
| 4627 | } else if (!inputWindowCommands.empty()) { |
| 4628 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4629 | } |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4630 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4631 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 4632 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4635 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4636 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4637 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4638 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 4639 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4640 | transactionFlags = eTransactionNeeded; |
| 4641 | } |
| 4642 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4643 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4644 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4645 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4646 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4647 | if (transactionFlags & eTraversalNeeded) { |
| 4648 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4649 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4650 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4651 | if (transactionFlags) { |
| 4652 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4653 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4655 | |
| 4656 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | } |
| 4658 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4659 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 4660 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4661 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4662 | bool needsTraversal = false; |
| 4663 | uint32_t transactionFlags = 0; |
| 4664 | for (auto& transaction : transactions) { |
| 4665 | for (DisplayState& display : transaction.displays) { |
| 4666 | display.sanitize(transaction.permissions); |
| 4667 | transactionFlags |= setDisplayStateLocked(display); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | if (transactionFlags) { |
| 4672 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4673 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 4674 | if (transactionFlags & eTraversalNeeded) { |
| 4675 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 4676 | needsTraversal = true; |
| 4677 | } |
| 4678 | if (transactionFlags) { |
| 4679 | setTransactionFlags(transactionFlags); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
| 4684 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
| 4685 | processDisplayChangesLocked(); |
| 4686 | mFrontEndDisplayInfos.clear(); |
| 4687 | for (const auto& [_, display] : mDisplays) { |
| 4688 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4689 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4690 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | return needsTraversal; |
| 4694 | } |
| 4695 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4696 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4697 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4698 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4699 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4700 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4701 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4702 | |
| 4703 | const uint32_t what = s.what; |
| 4704 | if (what & DisplayState::eSurfaceChanged) { |
| 4705 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4706 | state.surface = s.surface; |
| 4707 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4708 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4709 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4710 | if (what & DisplayState::eLayerStackChanged) { |
| 4711 | if (state.layerStack != s.layerStack) { |
| 4712 | state.layerStack = s.layerStack; |
| 4713 | flags |= eDisplayTransactionNeeded; |
| 4714 | } |
| 4715 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4716 | if (what & DisplayState::eFlagsChanged) { |
| 4717 | if (state.flags != s.flags) { |
| 4718 | state.flags = s.flags; |
| 4719 | flags |= eDisplayTransactionNeeded; |
| 4720 | } |
| 4721 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4722 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4723 | if (state.orientation != s.orientation) { |
| 4724 | state.orientation = s.orientation; |
| 4725 | flags |= eDisplayTransactionNeeded; |
| 4726 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4727 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4728 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4729 | flags |= eDisplayTransactionNeeded; |
| 4730 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4731 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 4732 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4733 | flags |= eDisplayTransactionNeeded; |
| 4734 | } |
| 4735 | } |
| 4736 | if (what & DisplayState::eDisplaySizeChanged) { |
| 4737 | if (state.width != s.width) { |
| 4738 | state.width = s.width; |
| 4739 | flags |= eDisplayTransactionNeeded; |
| 4740 | } |
| 4741 | if (state.height != s.height) { |
| 4742 | state.height = s.height; |
| 4743 | flags |= eDisplayTransactionNeeded; |
| 4744 | } |
| 4745 | } |
| 4746 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4747 | return flags; |
| 4748 | } |
| 4749 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4750 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4751 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4752 | const int pid = ipc->getCallingPid(); |
| 4753 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4754 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4755 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 4756 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4757 | return false; |
| 4758 | } |
| 4759 | return true; |
| 4760 | } |
| 4761 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4762 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4763 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4764 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4765 | int64_t postTime, uint32_t permissions, |
| 4766 | uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4767 | layer_state_t& s = composerState.state; |
| 4768 | s.sanitize(permissions); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4769 | |
| 4770 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4771 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4772 | // Starts a registration but separates the callback ids according to callback type. This |
| 4773 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4774 | // note that startRegistration will not re-register if the listener has |
| 4775 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4776 | |
| 4777 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 4778 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4779 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 4783 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4784 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4785 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4788 | const uint64_t what = s.what; |
| 4789 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4790 | sp<Layer> layer = nullptr; |
| 4791 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4792 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4793 | } else { |
| 4794 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 4795 | ALOGW("Attempt to set client state with a null layer handle"); |
| 4796 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4797 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4798 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 4799 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 4800 | callbackIds, |
| 4801 | s.surface), |
| 4802 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 4803 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4804 | return 0; |
| 4805 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 4806 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4807 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 4808 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 4809 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 4810 | // Only set by BLAST adapter layers |
| 4811 | if (what & layer_state_t::eProducerDisconnect) { |
| 4812 | layer->onDisconnect(); |
| 4813 | } |
| 4814 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4815 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 4816 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4817 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4818 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4819 | } |
| 4820 | if (what & layer_state_t::eLayerChanged) { |
| 4821 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4822 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4823 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 4824 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4825 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4826 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4827 | mCurrentState.layersSortedByZ.add(layer); |
| 4828 | // we need traversal (state changed) |
| 4829 | // AND transaction (list changed) |
| 4830 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4831 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4832 | } else { |
| 4833 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4834 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4835 | } |
| 4836 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4837 | } |
| 4838 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4839 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4840 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4841 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 4842 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4843 | if (p == nullptr) { |
| 4844 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4845 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 4846 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4847 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4848 | mCurrentState.layersSortedByZ.add(layer); |
| 4849 | // we need traversal (state changed) |
| 4850 | // AND transaction (list changed) |
| 4851 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4852 | } |
| 4853 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4854 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4855 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4856 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4857 | } |
| 4858 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4859 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4860 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4861 | } |
| 4862 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4863 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4864 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 4865 | if (what & layer_state_t::eColorTransformChanged) { |
| 4866 | if (layer->setColorTransform(s.colorTransform)) { |
| 4867 | flags |= eTraversalNeeded; |
| 4868 | } |
| 4869 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 4870 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4871 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 4872 | flags |= eTraversalNeeded; |
| 4873 | } |
| 4874 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4875 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4876 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4877 | } |
| 4878 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 4879 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 4880 | flags |= eTraversalNeeded; |
| 4881 | } |
| 4882 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4883 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4884 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 4885 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 4886 | if (layer->setCornerRadius(s.cornerRadius)) |
| 4887 | flags |= eTraversalNeeded; |
| 4888 | } |
Galia Peycheva | 33713f7 | 2021-05-27 10:24:20 +0200 | [diff] [blame] | 4889 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4890 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 4891 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 4892 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4893 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 4894 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4895 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 4896 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4897 | flags |= eTraversalNeeded; |
| 4898 | } |
| 4899 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4900 | if (what & layer_state_t::eLayerStackChanged) { |
| 4901 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 4902 | // We only allow setting layer stacks for top level layers, |
| 4903 | // everything else inherits layer stack from its parent. |
| 4904 | if (layer->hasParent()) { |
| 4905 | 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] | 4906 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4907 | } else if (idx < 0) { |
| 4908 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4909 | "that also does not appear in the top level layer list. Something" |
| 4910 | " has gone wrong.", |
| 4911 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4912 | } else if (layer->setLayerStack(s.layerStack)) { |
| 4913 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4914 | mCurrentState.layersSortedByZ.add(layer); |
| 4915 | // we need traversal (state changed) |
| 4916 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4917 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4918 | } |
| 4919 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4920 | if (what & layer_state_t::eBufferTransformChanged) { |
| 4921 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4922 | } |
| 4923 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 4924 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 4925 | flags |= eTraversalNeeded; |
| 4926 | } |
| 4927 | if (what & layer_state_t::eCropChanged) { |
| 4928 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 4929 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4930 | if (what & layer_state_t::eDataspaceChanged) { |
| 4931 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 4932 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4933 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 4934 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 4935 | } |
| 4936 | if (what & layer_state_t::eApiChanged) { |
| 4937 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 4938 | } |
| 4939 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 4940 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 4941 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4942 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4943 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 4944 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4945 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 4946 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4947 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4948 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4949 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4950 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 4951 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4952 | // The transaction will be received on the Task layer and needs to be applied to all |
| 4953 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 4954 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4955 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4956 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4957 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 4958 | if (layer->setMetadata(s.metadata)) { |
| 4959 | flags |= eTraversalNeeded; |
| 4960 | mLayerMetadataSnapshotNeeded = true; |
| 4961 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4962 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 4963 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 4964 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 4965 | flags |= eTraversalNeeded; |
| 4966 | } |
| 4967 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 4968 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 4969 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 4970 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 4971 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 4972 | const auto compatibility = |
| 4973 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 4974 | |
| 4975 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 4976 | flags |= eTraversalNeeded; |
| 4977 | } |
| 4978 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4979 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4980 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4981 | flags |= eTraversalNeeded; |
| 4982 | } |
| 4983 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4984 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4985 | const auto compatibility = |
| 4986 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 4987 | const auto strategy = |
| 4988 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 4989 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4990 | if (layer->setFrameRate( |
| 4991 | Layer::FrameRate(Fps::fromValue(s.frameRate), compatibility, strategy))) { |
| 4992 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 4993 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4994 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4995 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 4996 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 4997 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 4998 | } |
| 4999 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5000 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5001 | layer->setAutoRefresh(s.autoRefresh); |
| 5002 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5003 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5004 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5005 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5006 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5007 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5008 | flags |= eTraversalNeeded; |
| 5009 | } |
| 5010 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5011 | if (what & layer_state_t::eCachingHintChanged) { |
| 5012 | if (layer->setCachingHint(s.cachingHint)) { |
| 5013 | flags |= eTraversalNeeded; |
| 5014 | } |
| 5015 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5016 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5017 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5018 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5019 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5020 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5021 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5022 | } |
| 5023 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5024 | if (what & layer_state_t::eStretchChanged) { |
| 5025 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5026 | flags |= eTraversalNeeded; |
| 5027 | } |
| 5028 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5029 | if (what & layer_state_t::eBufferCropChanged) { |
| 5030 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5031 | flags |= eTraversalNeeded; |
| 5032 | } |
| 5033 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5034 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5035 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5036 | flags |= eTraversalNeeded; |
| 5037 | } |
| 5038 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5039 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5040 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5041 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5042 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5043 | } |
| 5044 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5045 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5046 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5047 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5048 | // lose its relative z order. |
| 5049 | if (what & layer_state_t::eReparent) { |
| 5050 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5051 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5052 | ? s.parentSurfaceControlForChild->getHandle() |
| 5053 | : nullptr; |
| 5054 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5055 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5056 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5057 | mCurrentState.layersSortedByZ.remove(layer); |
| 5058 | } |
| 5059 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5060 | } |
| 5061 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5062 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5063 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5064 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5065 | callbackHandles.emplace_back( |
| 5066 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5067 | } |
| 5068 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5069 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5070 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5071 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5072 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5073 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5074 | flags |= eTraversalNeeded; |
| 5075 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5076 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5077 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5078 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5079 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5080 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5081 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5082 | } |
| 5083 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5084 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5085 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5086 | s.trustedPresentationListener)) { |
| 5087 | flags |= eTraversalNeeded; |
| 5088 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5091 | if (what & layer_state_t::eFlushJankData) { |
| 5092 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5093 | } |
| 5094 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5095 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5096 | layer->willPresentCurrentTransaction() || |
| 5097 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5098 | flags |= eTraversalNeeded; |
| 5099 | } |
| 5100 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5101 | // Do not put anything that updates layer state or modifies flags after |
| 5102 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5103 | |
| 5104 | // if the layer has been parented on to a new display, update its transform hint. |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5105 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5106 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5107 | flags |= eTransformHintUpdateNeeded; |
| 5108 | } |
| 5109 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5110 | return flags; |
| 5111 | } |
| 5112 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5113 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5114 | ResolvedComposerState& composerState, |
| 5115 | int64_t desiredPresentTime, |
| 5116 | bool isAutoTimestamp, int64_t postTime, |
| 5117 | uint32_t permissions, |
| 5118 | uint64_t transactionId) { |
| 5119 | layer_state_t& s = composerState.state; |
| 5120 | s.sanitize(permissions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5121 | |
| 5122 | std::vector<ListenerCallbacks> filteredListeners; |
| 5123 | for (auto& listener : s.listeners) { |
| 5124 | // Starts a registration but separates the callback ids according to callback type. This |
| 5125 | // allows the callback invoker to send on latch callbacks earlier. |
| 5126 | // note that startRegistration will not re-register if the listener has |
| 5127 | // already be registered for a prior surface control |
| 5128 | |
| 5129 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5130 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5131 | filteredListeners.push_back(onCommitCallbacks); |
| 5132 | } |
| 5133 | |
| 5134 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5135 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5136 | filteredListeners.push_back(onCompleteCallbacks); |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | const uint64_t what = s.what; |
| 5141 | uint32_t flags = 0; |
| 5142 | sp<Layer> layer = nullptr; |
| 5143 | if (s.surface) { |
| 5144 | layer = LayerHandle::getLayer(s.surface); |
| 5145 | } else { |
| 5146 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5147 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5148 | } |
| 5149 | if (layer == nullptr) { |
| 5150 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5151 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5152 | callbackIds, |
| 5153 | s.surface), |
| 5154 | std::vector<JankData>()); |
| 5155 | } |
| 5156 | return 0; |
| 5157 | } |
| 5158 | if (what & layer_state_t::eProducerDisconnect) { |
| 5159 | layer->onDisconnect(); |
| 5160 | } |
| 5161 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5162 | if (what & layer_state_t::eMetadataChanged) { |
| 5163 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5164 | } |
| 5165 | |
| 5166 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5167 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5168 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5169 | callbackHandles.emplace_back( |
| 5170 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5171 | } |
| 5172 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5173 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5174 | // requires to read drawing state from binder thread. So we need to fix that |
| 5175 | // before removing this. |
| 5176 | if (what & layer_state_t::eCropChanged) { |
| 5177 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5178 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5179 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5180 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5181 | } |
| 5182 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5183 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5184 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5185 | if (snapshot) { |
| 5186 | transformHint = snapshot->transformHint; |
| 5187 | } |
| 5188 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5189 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5190 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5191 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5192 | flags |= eTraversalNeeded; |
| 5193 | } |
| 5194 | mLayersWithQueuedFrames.emplace(layer); |
| 5195 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5196 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5197 | } |
| 5198 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5199 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5200 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5201 | } |
| 5202 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5203 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5204 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5205 | s.trustedPresentationListener)) { |
| 5206 | flags |= eTraversalNeeded; |
| 5207 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5210 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5211 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5212 | (requestedLayerState->hasReadyFrame() || |
| 5213 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5214 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5215 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5216 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5217 | return flags; |
| 5218 | } |
| 5219 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5220 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5221 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5222 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5223 | } |
| 5224 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5225 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5226 | const sp<IBinder>& mirrorFromHandle, |
| 5227 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5228 | if (!mirrorFromHandle) { |
| 5229 | return NAME_NOT_FOUND; |
| 5230 | } |
| 5231 | |
| 5232 | sp<Layer> mirrorLayer; |
| 5233 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5234 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5235 | { |
| 5236 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5237 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5238 | if (!mirrorFrom) { |
| 5239 | return NAME_NOT_FOUND; |
| 5240 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5241 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5242 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5243 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5244 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5245 | if (result != NO_ERROR) { |
| 5246 | return result; |
| 5247 | } |
| 5248 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 5249 | mirrorLayer->setClonedChild(mirrorFrom->createClone()); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5252 | outResult.layerId = mirrorLayer->sequence; |
| 5253 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5254 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5255 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5256 | } |
| 5257 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5258 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5259 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5260 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5261 | const int uid = ipc->getCallingUid(); |
| 5262 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5263 | ALOGE("Permission denied when trying to mirror display"); |
| 5264 | return PERMISSION_DENIED; |
| 5265 | } |
| 5266 | |
| 5267 | ui::LayerStack layerStack; |
| 5268 | sp<Layer> rootMirrorLayer; |
| 5269 | status_t result = 0; |
| 5270 | |
| 5271 | { |
| 5272 | Mutex::Autolock lock(mStateLock); |
| 5273 | |
| 5274 | const auto display = getDisplayDeviceLocked(displayId); |
| 5275 | if (!display) { |
| 5276 | return NAME_NOT_FOUND; |
| 5277 | } |
| 5278 | |
| 5279 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5280 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5281 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5282 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5283 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5284 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5285 | outResult.layerId = rootMirrorLayer->sequence; |
| 5286 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5287 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5288 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | if (result != NO_ERROR) { |
| 5292 | return result; |
| 5293 | } |
| 5294 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 5295 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5296 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5297 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | setTransactionFlags(eTransactionFlushNeeded); |
| 5301 | return NO_ERROR; |
| 5302 | } |
| 5303 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5304 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5305 | status_t result = NO_ERROR; |
| 5306 | |
| 5307 | sp<Layer> layer; |
| 5308 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5309 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5310 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5311 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5312 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5313 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 5314 | FMT_FALLTHROUGH; |
| 5315 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5316 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5317 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5318 | if (pendingBufferCounter) { |
| 5319 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5320 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5321 | pendingBufferCounter); |
| 5322 | } |
| 5323 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5324 | default: |
| 5325 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | break; |
| 5327 | } |
| 5328 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5329 | if (result != NO_ERROR) { |
| 5330 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5332 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5333 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5334 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5335 | // to the layer's handle inside this scope. |
| 5336 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5337 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5338 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5339 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5340 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5341 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5342 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5343 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5344 | if (result != NO_ERROR) { |
| 5345 | return result; |
| 5346 | } |
| 5347 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5348 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5349 | outResult.layerId = layer->sequence; |
| 5350 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5351 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
| 5353 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5354 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5355 | sp<Layer>* outLayer) { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 5356 | args.textureName = getNewTexture(); |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5357 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5358 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5359 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5362 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5363 | sp<Layer>* outLayer) { |
| 5364 | *outLayer = getFactory().createEffectLayer(args); |
| 5365 | *handle = (*outLayer)->getHandle(); |
| 5366 | return NO_ERROR; |
| 5367 | } |
| 5368 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5369 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5370 | mLayersPendingRemoval.add(layer); |
| 5371 | mLayersRemoved = true; |
| 5372 | setTransactionFlags(eTransactionNeeded); |
| 5373 | } |
| 5374 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5375 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5376 | { |
| 5377 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 5378 | mDestroyedHandles.emplace_back(layerId); |
| 5379 | } |
| 5380 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5381 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5382 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5383 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5384 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5385 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5386 | |
| 5387 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5390 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5391 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5392 | if (!display) return; |
| 5393 | |
| 5394 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 5395 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5396 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5397 | TransactionState state; |
| 5398 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5399 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5400 | state.desiredPresentTime = now; |
| 5401 | state.postTime = now; |
| 5402 | state.permissions = layer_state_t::ACCESS_SURFACE_FLINGER; |
| 5403 | state.originPid = mPid; |
| 5404 | state.originUid = static_cast<int>(getuid()); |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5405 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5406 | state.id = transactionId; |
| 5407 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5408 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5409 | Vector<DisplayState> displays; |
| 5410 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5411 | d.what = DisplayState::eDisplayProjectionChanged | |
| 5412 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5413 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 5414 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5415 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5416 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 5417 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5418 | d.width = 0; |
| 5419 | d.height = 0; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5420 | state.displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5421 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5422 | std::vector<TransactionState> transactions; |
| 5423 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5424 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5425 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5426 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5427 | } else { |
| 5428 | applyAndCommitDisplayTransactionStates(transactions); |
| 5429 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5430 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5431 | { |
| 5432 | ftl::FakeGuard guard(mStateLock); |
| 5433 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 5434 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5437 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5438 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5439 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5440 | return; |
| 5441 | } |
| 5442 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5443 | const auto displayId = display->getPhysicalId(); |
| 5444 | 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] | 5445 | |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5446 | const auto currentModeOpt = display->getPowerMode(); |
| 5447 | if (currentModeOpt == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5448 | return; |
| 5449 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5450 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5451 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5452 | .transform(&PhysicalDisplay::isInternal) |
| 5453 | .value_or(false); |
| 5454 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5455 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5456 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5457 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5458 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5459 | "Trying to change power mode on inactive display without powering off active display"); |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5460 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5461 | display->setPowerMode(mode); |
| 5462 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 5463 | const auto refreshRate = display->refreshRateSelector().getActiveMode().modePtr->getFps(); |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5464 | if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5465 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5466 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5467 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5468 | // outer display of a foldable is powered on. This condition relies on the above |
| 5469 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5470 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5471 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5472 | // |
| 5473 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5474 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5475 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5476 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5477 | |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5478 | // Keep uclamp in a separate syscall and set it before changing to RT due to b/190237315. |
| 5479 | // We can merge the syscall later. |
| 5480 | if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) { |
| 5481 | ALOGW("Couldn't set uclamp.min on display on: %s\n", strerror(errno)); |
| 5482 | } |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 5483 | if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) { |
| 5484 | ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno)); |
| 5485 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5486 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5487 | if (displayId == mActiveDisplayId && mode != hal::PowerMode::DOZE_SUSPEND) { |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 5488 | setHWCVsyncEnabled(displayId, |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5489 | mScheduler->getVsyncSchedule(displayId) |
| 5490 | ->getPendingHardwareVsyncState()); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5491 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5492 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5493 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5494 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5495 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5496 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5497 | } else if (mode == hal::PowerMode::OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5498 | // Turn off the display |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 5499 | if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) { |
| 5500 | 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] | 5501 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5502 | if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { |
| 5503 | ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); |
| 5504 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5505 | if (displayId == mActiveDisplayId && *currentModeOpt != hal::PowerMode::DOZE_SUSPEND) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5506 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5507 | mScheduler->enableSyntheticVsync(); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5508 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5509 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 5510 | // Make sure HWVsync is disabled before turning off the display |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 5511 | setHWCVsyncEnabled(displayId, false); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 5512 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5513 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5514 | mVisibleRegionsDirty = true; |
| 5515 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5516 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5517 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5518 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5519 | if (displayId == mActiveDisplayId && *currentModeOpt == hal::PowerMode::DOZE_SUSPEND) { |
Yifei Zhang | f0bd62e | 2021-06-16 15:27:05 -0700 | [diff] [blame] | 5520 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5521 | mVisibleRegionsDirty = true; |
| 5522 | scheduleRepaint(); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5523 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5524 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5525 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5526 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5527 | // Leave display going to doze |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5528 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5529 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5530 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5531 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5532 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5533 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 5534 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5535 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5536 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5537 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5538 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 5539 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5540 | mRefreshRateStats->setPowerMode(mode); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5541 | mScheduler->setDisplayPowerMode(displayId, mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5544 | 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] | 5545 | } |
| 5546 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5547 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5548 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 5549 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 5550 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5551 | if (!display) { |
| 5552 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 5553 | displayToken.get()); |
| 5554 | } else if (display->isVirtual()) { |
| 5555 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 5556 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5557 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5558 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5559 | }); |
| 5560 | |
| 5561 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 5562 | } |
| 5563 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5564 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5565 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 5566 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5567 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5568 | const int pid = ipc->getCallingPid(); |
| 5569 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 5570 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5571 | if ((uid != AID_SHELL) && |
| 5572 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5573 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 5574 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5576 | static const std::unordered_map<std::string, Dumper> dumpers = { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5577 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5578 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5579 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5580 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5581 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 5582 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 5583 | {"--hwclayers"s, dumper(&SurfaceFlinger::dumpHwcLayersMinidumpLocked)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5584 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 5585 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 5586 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5587 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5588 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5589 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5590 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5591 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 5592 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5593 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5594 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5595 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5596 | // Traversal of drawing state must happen on the main thread. |
| 5597 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 5598 | // traversals, which can result in use-after-frees. |
| 5599 | std::string compositionLayers; |
| 5600 | mScheduler |
| 5601 | ->schedule([&] { |
| 5602 | StringAppendF(&compositionLayers, "Composition layers\n"); |
| 5603 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 5604 | auto* compositionState = layer->getCompositionState(); |
| 5605 | if (!compositionState || !compositionState->isVisible) return; |
| 5606 | |
| 5607 | android::base::StringAppendF(&compositionLayers, "* Layer %p (%s)\n", layer, |
| 5608 | layer->getDebugName() ? layer->getDebugName() |
| 5609 | : "<unknown>"); |
| 5610 | compositionState->dump(compositionLayers); |
| 5611 | }); |
| 5612 | }) |
| 5613 | .get(); |
| 5614 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5615 | bool dumpLayers = true; |
| 5616 | { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5617 | TimedLock lock(mStateLock, s2ns(1), __func__); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5618 | if (!lock.locked()) { |
| 5619 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 5620 | strerror(-lock.status), lock.status); |
| 5621 | } |
| 5622 | |
| 5623 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 5624 | (it->second)(args, asProto, result); |
| 5625 | dumpLayers = false; |
| 5626 | } else if (!asProto) { |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5627 | dumpAllLocked(args, compositionLayers, result); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5628 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 5629 | } |
| 5630 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5631 | if (dumpLayers) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5632 | LayersTraceFileProto traceFileProto = mLayerTracing.createTraceFileProto(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5633 | LayersTraceProto* layersTrace = traceFileProto.add_entry(); |
| 5634 | LayersProto layersProto = dumpProtoFromMainThread(); |
| 5635 | layersTrace->mutable_layers()->Swap(&layersProto); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5636 | auto displayProtos = dumpDisplayProto(); |
| 5637 | layersTrace->mutable_displays()->Swap(&displayProtos); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5638 | |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5639 | if (asProto) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5640 | result.append(traceFileProto.SerializeAsString()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5641 | } else { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5642 | // Dump info that we need to access from the main thread |
chaviw | a2b9fab | 2021-09-08 14:46:30 -0500 | [diff] [blame] | 5643 | const auto layerTree = LayerProtoParser::generateLayerTree(layersTrace->layers()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5644 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
| 5645 | result.append("\n"); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5646 | dumpOffscreenLayers(result); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5647 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5648 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5650 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | return NO_ERROR; |
| 5652 | } |
| 5653 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5654 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5655 | return doDump(fd, DumpArgs(), asProto); |
| 5656 | } |
| 5657 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5658 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5659 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5660 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5661 | } |
| 5662 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5663 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5664 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5665 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 5666 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5667 | const auto name = String8(args[1]); |
| 5668 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
| 5669 | if (layer->getName() == name.string()) { |
| 5670 | layer->dumpFrameStats(result); |
| 5671 | } |
| 5672 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5673 | } |
| 5674 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5675 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5676 | const bool clearAll = args.size() < 2; |
| 5677 | const auto name = clearAll ? String8() : String8(args[1]); |
| 5678 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 5679 | mCurrentState.traverse([&](Layer* layer) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5680 | if (clearAll || layer->getName() == name.string()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 5681 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5682 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 5683 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5684 | } |
| 5685 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5686 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 5687 | mTimeStats->parseArgs(asProto, args, result); |
| 5688 | } |
| 5689 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 5690 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 5691 | mFrameTimeline->parseArgs(args, result); |
| 5692 | } |
| 5693 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5694 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5695 | static TimePoint sTimestamp = now; |
| 5696 | if (now - sTimestamp < 30min) return; |
| 5697 | sTimestamp = now; |
| 5698 | |
| 5699 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5700 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5703 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5704 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 5705 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5706 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 5707 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5708 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 5709 | getHwComposer().getMaxVirtualDisplayDimension()); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5710 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
| 5711 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
| 5712 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5713 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5714 | } |
| 5715 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5716 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 5717 | utils::Dumper dumper{result}; |
| 5718 | |
| 5719 | mScheduler->dump(dumper); |
| 5720 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5721 | // TODO(b/241285876): Move to DisplayModeController. |
| 5722 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 5723 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5724 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5725 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5726 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5727 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 5728 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5729 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5730 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 5731 | " ns\n\n", |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5732 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5733 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5734 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5735 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5736 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 5740 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5741 | } |
| 5742 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5743 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 5744 | for (const auto& [token, display] : mDisplays) { |
| 5745 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 5746 | compositionDisplay->dumpPlannerInfo(args, result); |
| 5747 | } |
| 5748 | } |
| 5749 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5750 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 5751 | for (const auto& [token, display] : mDisplays) { |
| 5752 | display->getCompositionDisplay()->dump(result); |
| 5753 | result += '\n'; |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5758 | utils::Dumper dumper{result}; |
| 5759 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5760 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5761 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 5762 | |
| 5763 | display.snapshot().dump(dumper); |
| 5764 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5765 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5766 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5767 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5768 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5769 | |
| 5770 | for (const auto& [token, display] : mDisplays) { |
| 5771 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5772 | const auto displayId = display->getId(); |
| 5773 | utils::Dumper::Section section(dumper, |
| 5774 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5775 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5776 | } |
| 5777 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5780 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 5781 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5782 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5783 | if (!displayId) { |
| 5784 | continue; |
| 5785 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5786 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5787 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5788 | continue; |
| 5789 | } |
| 5790 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5791 | StringAppendF(&result, |
| 5792 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 5793 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5794 | uint8_t port; |
| 5795 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5796 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5797 | result.append("no identification data\n"); |
| 5798 | continue; |
| 5799 | } |
| 5800 | |
| 5801 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5802 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5803 | continue; |
| 5804 | } |
| 5805 | |
| 5806 | const auto edid = parseEdid(data); |
| 5807 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5808 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5809 | continue; |
| 5810 | } |
| 5811 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5812 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5813 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 5814 | result.append("\"\n"); |
| 5815 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5816 | } |
| 5817 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5818 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 5819 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 5820 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5821 | uint8_t port; |
| 5822 | DisplayIdentificationData data; |
| 5823 | |
| 5824 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 5825 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 5826 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 5827 | } |
| 5828 | } |
| 5829 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5830 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5831 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5832 | StringAppendF(&result, "Device uses color management: %d\n", useColorManagement); |
| 5833 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 5834 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5835 | |
| 5836 | // TODO: print out if wide-color mode is active or not |
| 5837 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5838 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 5839 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 5840 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5841 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5842 | } |
| 5843 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5844 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 5845 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 5846 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 5847 | decodeColorMode(currentMode).c_str(), currentMode); |
| 5848 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5849 | } |
| 5850 | result.append("\n"); |
| 5851 | } |
| 5852 | |
Dominik Laskowski | 542c9dc | 2020-04-10 12:42:02 -0700 | [diff] [blame] | 5853 | LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 5854 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 5855 | |
| 5856 | // Determine if virtual layers display should be skipped |
| 5857 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 5858 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 5859 | if (display->isVirtual()) { |
| 5860 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 5861 | } |
| 5862 | } |
| 5863 | } |
| 5864 | |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 5865 | if (mLegacyFrontEndEnabled) { |
| 5866 | LayersProto layersProto; |
| 5867 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 5868 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 5869 | continue; |
| 5870 | } |
| 5871 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 5872 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 5873 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 5874 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5875 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 5876 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 5877 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 5878 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5879 | } |
| 5880 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5881 | google::protobuf::RepeatedPtrField<DisplayProto> SurfaceFlinger::dumpDisplayProto() const { |
| 5882 | google::protobuf::RepeatedPtrField<DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5883 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5884 | DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5885 | displayProto->set_id(display->getId().value); |
| 5886 | displayProto->set_name(display->getDisplayName()); |
| 5887 | displayProto->set_layer_stack(display->getLayerStack().id); |
| 5888 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 5889 | [&]() { return displayProto->mutable_size(); }); |
| 5890 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 5891 | return displayProto->mutable_layer_stack_space_rect(); |
| 5892 | }); |
| 5893 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 5894 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 5895 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5896 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5897 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5898 | } |
| 5899 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5900 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 5901 | getHwComposer().dump(result); |
| 5902 | } |
| 5903 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5904 | void SurfaceFlinger::dumpOffscreenLayersProto(LayersProto& layersProto, uint32_t traceFlags) const { |
| 5905 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 5906 | // it. |
| 5907 | LayerProto* rootProto = layersProto.add_layers(); |
| 5908 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 5909 | rootProto->set_id(offscreenRootLayerId); |
| 5910 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 5911 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5912 | |
| 5913 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5914 | // Add layer as child of the fake root |
| 5915 | rootProto->add_children(offscreenLayer->sequence); |
| 5916 | |
| 5917 | // Add layer |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5918 | LayerProto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5919 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5920 | } |
| 5921 | } |
| 5922 | |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5923 | LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5924 | return mScheduler->schedule([=] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5925 | } |
| 5926 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5927 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5928 | auto future = mScheduler->schedule([this] { |
| 5929 | std::string result; |
| 5930 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5931 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 5932 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5933 | } |
| 5934 | return result; |
| 5935 | }); |
| 5936 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5937 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5938 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5941 | void SurfaceFlinger::dumpHwcLayersMinidumpLocked(std::string& result) const { |
| 5942 | for (const auto& [token, display] : mDisplays) { |
| 5943 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 5944 | if (!displayId) { |
| 5945 | continue; |
| 5946 | } |
| 5947 | |
| 5948 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5949 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5950 | Layer::miniDumpHeader(result); |
| 5951 | |
| 5952 | const DisplayDevice& ref = *display; |
Leon Scroggins III | 140c6a4 | 2022-11-09 14:41:33 -0500 | [diff] [blame] | 5953 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDump(result, ref); }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5954 | result.append("\n"); |
| 5955 | } |
| 5956 | } |
| 5957 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5958 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, const std::string& compositionLayers, |
| 5959 | std::string& result) const { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5960 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5961 | Colorizer colorizer(colorize); |
| 5962 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5963 | // figure out if we're stuck somewhere |
| 5964 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5965 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5966 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 5967 | |
| 5968 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5969 | * Dump library configuration. |
| 5970 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5971 | |
| 5972 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5973 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5974 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5975 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5976 | result.append("\n"); |
| 5977 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5978 | result.append("\nDisplay identification data:\n"); |
| 5979 | dumpDisplayIdentificationData(result); |
| 5980 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5981 | result.append("\nWide-Color information:\n"); |
| 5982 | dumpWideColorInfo(result); |
| 5983 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5984 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5985 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5986 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5987 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5988 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5989 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5990 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5991 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5992 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5993 | dumpScheduler(result); |
| 5994 | dumpEvents(result); |
| 5995 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 5996 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5997 | |
Alec Mouri | 40189b0 | 2019-03-05 15:07:54 -0800 | [diff] [blame] | 5998 | StringAppendF(&result, "Total missed frame count: %u\n", mFrameMissedCount.load()); |
| 5999 | StringAppendF(&result, "HWC missed frame count: %u\n", mHwcFrameMissedCount.load()); |
| 6000 | StringAppendF(&result, "GPU missed frame count: %u\n\n", mGpuFrameMissedCount.load()); |
Marissa Wall | cfcdaa5 | 2018-05-21 15:45:59 -0700 | [diff] [blame] | 6001 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6002 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6003 | * Dump the visible layer list |
| 6004 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6005 | colorizer.bold(result); |
chaviw | eadf0d4 | 2019-08-12 13:28:29 -0700 | [diff] [blame] | 6006 | StringAppendF(&result, "Visible layers (count = %zu)\n", mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6007 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6008 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6009 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6010 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6011 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6012 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6013 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6014 | dumpDisplays(result); |
| 6015 | dumpCompositionDisplays(result); |
| 6016 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6017 | |
| 6018 | mCompositionEngine->dump(result); |
| 6019 | |
| 6020 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6021 | * Dump SurfaceFlinger global state |
| 6022 | */ |
| 6023 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6024 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6025 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6026 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6027 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6028 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6029 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6030 | result.append("ClientCache state:\n"); |
| 6031 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6032 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6033 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6034 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6035 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6036 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6037 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6038 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6039 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6040 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6041 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6042 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6043 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6044 | if (const auto activeModePtr = |
| 6045 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6046 | fps = to_string(activeModePtr->getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6047 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6048 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6049 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6050 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6051 | } else { |
| 6052 | fps = "unknown"; |
| 6053 | xDpi = "unknown"; |
| 6054 | yDpi = "unknown"; |
| 6055 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6056 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6057 | " refresh-rate : %s\n" |
| 6058 | " x-dpi : %s\n" |
| 6059 | " y-dpi : %s\n", |
| 6060 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6061 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6062 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6063 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6064 | |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 6065 | /* |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6066 | * Tracing state |
| 6067 | */ |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6068 | mLayerTracing.dump(result); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6069 | |
| 6070 | result.append("\nTransaction tracing: "); |
| 6071 | if (mTransactionTracing) { |
| 6072 | result.append("enabled\n"); |
| 6073 | mTransactionTracing->dump(result); |
| 6074 | } else { |
| 6075 | result.append("disabled\n"); |
| 6076 | } |
| 6077 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6078 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6079 | dumpHwcLayersMinidumpLocked(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6080 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6081 | { |
| 6082 | DumpArgs plannerArgs; |
| 6083 | plannerArgs.add(); // first argument is ignored |
| 6084 | plannerArgs.add(String16("--layers")); |
| 6085 | dumpPlannerInfo(plannerArgs, result); |
| 6086 | } |
| 6087 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6088 | /* |
| 6089 | * Dump HWComposer state |
| 6090 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6091 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6092 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6093 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6094 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6095 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6096 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6097 | |
| 6098 | /* |
| 6099 | * Dump gralloc state |
| 6100 | */ |
| 6101 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6102 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6103 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6104 | /* |
| 6105 | * Dump flag/property manager state |
| 6106 | */ |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 6107 | mFlagManager.dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6108 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6109 | result.append(mTimeStats->miniDump()); |
| 6110 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6111 | } |
| 6112 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6113 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6114 | if (saturation == 1) { |
| 6115 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6118 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6119 | luminance *= 1.0f - saturation; |
| 6120 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6121 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6122 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6123 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6124 | return saturationMatrix; |
| 6125 | } |
| 6126 | |
| 6127 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6128 | mat4 colorMatrix = |
| 6129 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6130 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6131 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6132 | mCurrentState.colorMatrix = colorMatrix; |
| 6133 | mCurrentState.colorMatrixChanged = true; |
| 6134 | setTransactionFlags(eTransactionNeeded); |
| 6135 | } |
| 6136 | } |
| 6137 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6138 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6139 | #pragma clang diagnostic push |
| 6140 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6141 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6142 | // These methods should at minimum make sure that the client requested |
| 6143 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6144 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6145 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6146 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6147 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6148 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6149 | // permission dynamically. Don't use the permission cache for this check. |
| 6150 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6151 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6152 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6153 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6154 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6155 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6157 | return OK; |
| 6158 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6159 | // The following calls are currently used by clients that do not |
| 6160 | // request necessary permissions. However, they do not expose any secret |
| 6161 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6162 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6163 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6164 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6165 | case GET_DISPLAY_MODES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6166 | // Calling setTransactionState is safe, because you need to have been |
| 6167 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6168 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6169 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6170 | return OK; |
| 6171 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6172 | case BOOT_FINISHED: |
| 6173 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6174 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6175 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6176 | case CREATE_DISPLAY: |
| 6177 | case DESTROY_DISPLAY: |
| 6178 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6179 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6180 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6181 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6182 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6183 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6184 | case GET_DISPLAY_STATE: |
| 6185 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6186 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6187 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6188 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6189 | case SET_ACTIVE_COLOR_MODE: |
| 6190 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6191 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6192 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6193 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6194 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6195 | case CAPTURE_LAYERS: |
| 6196 | case CAPTURE_DISPLAY: |
| 6197 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6198 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6199 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6200 | case OVERRIDE_HDR_TYPES: |
| 6201 | case ON_PULL_ATOM: |
| 6202 | case ENABLE_VSYNC_INJECTIONS: |
| 6203 | case INJECT_VSYNC: |
| 6204 | case GET_LAYER_DEBUG_INFO: |
| 6205 | case GET_COLOR_MANAGEMENT: |
| 6206 | case GET_COMPOSITION_PREFERENCE: |
| 6207 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6208 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6209 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6210 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6211 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6212 | case ADD_REGION_SAMPLING_LISTENER: |
| 6213 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6214 | case ADD_FPS_LISTENER: |
| 6215 | case REMOVE_FPS_LISTENER: |
| 6216 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6217 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6218 | case ADD_WINDOW_INFOS_LISTENER: |
| 6219 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6220 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6221 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6222 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6223 | case SET_DISPLAY_BRIGHTNESS: |
| 6224 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6225 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6226 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6227 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6228 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6229 | case SET_FRAME_RATE: |
| 6230 | case SET_OVERRIDE_FRAME_RATE: |
| 6231 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6232 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6233 | case GET_GPU_CONTEXT_PRIORITY: |
| 6234 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6235 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6236 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6237 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6238 | |
| 6239 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6240 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6241 | // We let them pass by default. |
| 6242 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6243 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6244 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6245 | return OK; |
| 6246 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6247 | // Numbers from 1000 to 1042 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6248 | // 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] | 6249 | if (code >= 1000 && code <= 1042) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6250 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6251 | return OK; |
| 6252 | } |
| 6253 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6254 | return PERMISSION_DENIED; |
| 6255 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6256 | } |
| 6257 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6258 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6259 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6260 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6261 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6262 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6263 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6265 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6266 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6267 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6268 | const int uid = ipc->getCallingUid(); |
| 6269 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6270 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6271 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6272 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6273 | "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] | 6274 | return PERMISSION_DENIED; |
| 6275 | } |
| 6276 | int n; |
| 6277 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6278 | case 1000: // Unused. |
| 6279 | case 1001: |
| 6280 | return NAME_NOT_FOUND; |
| 6281 | case 1002: // Toggle flashing on surface damage. |
| 6282 | if (const int delay = data.readInt32(); delay > 0) { |
| 6283 | mDebugFlashDelay = delay; |
| 6284 | } else { |
| 6285 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 6286 | } |
| 6287 | scheduleRepaint(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6288 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6289 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6290 | case 1006: |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6291 | scheduleComposite(FrameHint::kActive); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6293 | case 1005: { // Force commit ahead of next VSYNC. |
| 6294 | Mutex::Autolock lock(mStateLock); |
| 6295 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | |
| 6296 | eTraversalNeeded); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6297 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6299 | case 1007: // Unused. |
| 6300 | return NAME_NOT_FOUND; |
| 6301 | case 1008: // Toggle forced GPU composition. |
| 6302 | mDebugDisableHWC = data.readInt32() != 0; |
| 6303 | scheduleRepaint(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6304 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6305 | case 1009: // Toggle use of transform hint. |
| 6306 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6307 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6308 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6309 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6310 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6312 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6313 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6314 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6316 | case 1013: // Unused. |
| 6317 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6318 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6319 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6320 | // daltonize |
| 6321 | n = data.readInt32(); |
| 6322 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6323 | case 1: |
| 6324 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6325 | break; |
| 6326 | case 2: |
| 6327 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6328 | break; |
| 6329 | case 3: |
| 6330 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6331 | break; |
| 6332 | default: |
| 6333 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6334 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6335 | } |
| 6336 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6337 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6338 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6339 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6340 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6341 | |
| 6342 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6343 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6345 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6346 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6347 | // apply a color matrix |
| 6348 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6349 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6350 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6351 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6352 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6353 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6354 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6355 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6356 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6357 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6358 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6359 | |
| 6360 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6361 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6362 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6363 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6364 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6365 | } |
| 6366 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6367 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6368 | return NO_ERROR; |
| 6369 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6370 | case 1016: { // Unused. |
| 6371 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6372 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6373 | case 1017: { |
| 6374 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6375 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6376 | return NO_ERROR; |
| 6377 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6378 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6379 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6380 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6381 | return NO_ERROR; |
| 6382 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6383 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6384 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6385 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6386 | return NO_ERROR; |
| 6387 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6388 | case 1020: { // Unused |
| 6389 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6390 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6391 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6392 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6393 | static_cast<void>( |
| 6394 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6395 | return NO_ERROR; |
| 6396 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6397 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6398 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6399 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6400 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6401 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6402 | return NO_ERROR; |
| 6403 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6404 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6405 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6406 | |
| 6407 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6408 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6409 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6410 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6411 | return NO_ERROR; |
| 6412 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6413 | // Deprecate, use 1030 to check whether the device is color managed. |
| 6414 | case 1024: { |
| 6415 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6416 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6417 | case 1025: { // Set layer tracing |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6418 | n = data.readInt32(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6419 | bool tracingEnabledChanged; |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6420 | if (n == 1) { |
| 6421 | int64_t fixedStartingTime = data.readInt64(); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6422 | ALOGD("LayerTracing enabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6423 | tracingEnabledChanged = mLayerTracing.enable(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6424 | if (tracingEnabledChanged) { |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 6425 | int64_t startingTime = |
| 6426 | (fixedStartingTime) ? fixedStartingTime : systemTime(); |
| 6427 | mScheduler |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6428 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 6429 | kMainThreadContext) { |
| 6430 | addToLayerTracing(true /* visibleRegionDirty */, startingTime, |
| 6431 | mLastCommittedVsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 6432 | }) |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6433 | .wait(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6434 | } |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6435 | } else if (n == 2) { |
| 6436 | std::string filename = std::string(data.readCString()); |
| 6437 | ALOGD("LayerTracing disabled. Trace wrote to %s", filename.c_str()); |
| 6438 | tracingEnabledChanged = mLayerTracing.disable(filename.c_str()); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6439 | } else { |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6440 | ALOGD("LayerTracing disabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6441 | tracingEnabledChanged = mLayerTracing.disable(); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6442 | } |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6443 | mTracingEnabledChanged = tracingEnabledChanged; |
| 6444 | reply->writeInt32(NO_ERROR); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6445 | return NO_ERROR; |
| 6446 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6447 | case 1026: { // Get layer tracing status |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6448 | reply->writeBool(mLayerTracing.isEnabled()); |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6449 | return NO_ERROR; |
| 6450 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6451 | // Is a DisplayColorSetting supported? |
| 6452 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6453 | const auto display = getDefaultDisplayDevice(); |
| 6454 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6455 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6456 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6457 | |
| 6458 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 6459 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6460 | case DisplayColorSetting::kManaged: |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6461 | reply->writeBool(useColorManagement); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6462 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6463 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6464 | reply->writeBool(true); |
| 6465 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6466 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6467 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6468 | break; |
| 6469 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6470 | reply->writeBool( |
| 6471 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6472 | break; |
| 6473 | } |
| 6474 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6475 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 6476 | case 1028: { // Unused. |
| 6477 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 6478 | } |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6479 | // Set buffer size for SF tracing (value in KB) |
| 6480 | case 1029: { |
| 6481 | n = data.readInt32(); |
| 6482 | if (n <= 0 || n > MAX_TRACING_MEMORY) { |
| 6483 | ALOGW("Invalid buffer size: %d KB", n); |
| 6484 | reply->writeInt32(BAD_VALUE); |
| 6485 | return BAD_VALUE; |
| 6486 | } |
| 6487 | |
| 6488 | ALOGD("Updating trace buffer to %d KB", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6489 | mLayerTracing.setBufferSize(n * 1024); |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6490 | reply->writeInt32(NO_ERROR); |
| 6491 | return NO_ERROR; |
| 6492 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6493 | // Is device color managed? |
| 6494 | case 1030: { |
| 6495 | reply->writeBool(useColorManagement); |
| 6496 | return NO_ERROR; |
| 6497 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6498 | // Override default composition data space |
| 6499 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 6500 | // && adb shell stop zygote && adb shell start zygote |
| 6501 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 6502 | // adb shell stop zygote && adb shell start zygote |
| 6503 | case 1031: { |
| 6504 | Mutex::Autolock _l(mStateLock); |
| 6505 | n = data.readInt32(); |
| 6506 | if (n) { |
| 6507 | n = data.readInt32(); |
| 6508 | if (n) { |
| 6509 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6510 | if (!validateCompositionDataspace(dataspace)) { |
| 6511 | return BAD_VALUE; |
| 6512 | } |
| 6513 | mDefaultCompositionDataspace = dataspace; |
| 6514 | } |
| 6515 | n = data.readInt32(); |
| 6516 | if (n) { |
| 6517 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6518 | if (!validateCompositionDataspace(dataspace)) { |
| 6519 | return BAD_VALUE; |
| 6520 | } |
| 6521 | mWideColorGamutCompositionDataspace = dataspace; |
| 6522 | } |
| 6523 | } else { |
| 6524 | // restore composition data space. |
| 6525 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 6526 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
| 6527 | } |
| 6528 | return NO_ERROR; |
| 6529 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6530 | // Set trace flags |
| 6531 | case 1033: { |
| 6532 | n = data.readUint32(); |
| 6533 | ALOGD("Updating trace flags to 0x%x", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6534 | mLayerTracing.setTraceFlags(n); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6535 | reply->writeInt32(NO_ERROR); |
| 6536 | return NO_ERROR; |
| 6537 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6538 | case 1034: { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6539 | auto future = mScheduler->schedule( |
| 6540 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6541 | switch (n = data.readInt32()) { |
| 6542 | case 0: |
| 6543 | case 1: |
| 6544 | enableRefreshRateOverlay(static_cast<bool>(n)); |
| 6545 | break; |
| 6546 | default: |
| 6547 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 6548 | } |
| 6549 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6550 | |
| 6551 | future.wait(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6552 | return NO_ERROR; |
| 6553 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6554 | case 1035: { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6555 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6556 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6557 | const auto display = [&]() -> sp<IBinder> { |
| 6558 | uint64_t value; |
| 6559 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6560 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6561 | } |
| 6562 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6563 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 6564 | return getPhysicalDisplayToken(*id); |
| 6565 | } |
| 6566 | |
| 6567 | ALOGE("Invalid physical display ID"); |
| 6568 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6569 | }(); |
| 6570 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 6571 | mDebugDisplayModeSetByBackdoor = false; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6572 | const status_t result = setActiveModeFromBackdoor(display, DisplayModeId{modeId}); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6573 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 6574 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6575 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6576 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 6577 | // manager frame rate policy a new policy which allows switching between all refresh |
| 6578 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6579 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6580 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6581 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6582 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6583 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6584 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6585 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6586 | // This is a little racy, but not in a way that hurts anything. As |
| 6587 | // we grab the defaultMode from the display manager policy, we could |
| 6588 | // be setting a new display manager policy, leaving us using a stale |
| 6589 | // defaultMode. The defaultMode doesn't matter for the override |
| 6590 | // policy though, since we set allowGroupSwitching to true, so it's |
| 6591 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6592 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 6593 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6594 | .getDisplayManagerPolicy() |
| 6595 | .defaultMode; |
| 6596 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6597 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6598 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6599 | .get(); |
| 6600 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6601 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6602 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6603 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6604 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6605 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6606 | display, |
| 6607 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6608 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6609 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6610 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6611 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6612 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 6613 | // reallocate the display state including framebuffers. |
| 6614 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6615 | const hal::HWDisplayId hwcId = |
| 6616 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 6617 | |
| 6618 | onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6619 | return NO_ERROR; |
| 6620 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 6621 | // Modify the max number of display frames stored within FrameTimeline |
| 6622 | case 1038: { |
| 6623 | n = data.readInt32(); |
| 6624 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 6625 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 6626 | return BAD_VALUE; |
| 6627 | } |
| 6628 | if (n == 0) { |
| 6629 | // restore to default |
| 6630 | mFrameTimeline->reset(); |
| 6631 | return NO_ERROR; |
| 6632 | } |
| 6633 | mFrameTimeline->setMaxDisplayFrames(n); |
| 6634 | return NO_ERROR; |
| 6635 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6636 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 6637 | PhysicalDisplayId displayId = [&]() { |
| 6638 | Mutex::Autolock lock(mStateLock); |
| 6639 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 6640 | }(); |
| 6641 | |
| 6642 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 6643 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 6644 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 6645 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6646 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 6647 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6648 | // Toggle caching feature |
| 6649 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 6650 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 6651 | // caching to a particular physical display |
| 6652 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6653 | auto future = mScheduler->schedule([&] { |
| 6654 | n = data.readInt32(); |
| 6655 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 6656 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 6657 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 6658 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 6659 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 6660 | return NAME_NOT_FOUND; |
| 6661 | } |
| 6662 | } |
| 6663 | { |
| 6664 | Mutex::Autolock lock(mStateLock); |
| 6665 | mLayerCachingEnabled = n != 0; |
| 6666 | for (const auto& [_, display] : mDisplays) { |
| 6667 | if (!inputId || *inputId == display->getPhysicalId()) { |
| 6668 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6669 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6670 | } |
| 6671 | } |
| 6672 | return OK; |
| 6673 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6674 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6675 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6676 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6677 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6678 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6679 | return NO_ERROR; |
| 6680 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6681 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6682 | if (mTransactionTracing) { |
| 6683 | if (data.readInt32()) { |
| 6684 | // Transaction tracing is always running but allow the user to temporarily |
| 6685 | // increase the buffer when actively debugging. |
| 6686 | mTransactionTracing->setBufferSize( |
| 6687 | TransactionTracing::ACTIVE_TRACING_BUFFER_SIZE); |
| 6688 | } else { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6689 | mTransactionTracing->writeToFile(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6690 | mTransactionTracing->setBufferSize( |
| 6691 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6692 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6693 | } |
| 6694 | reply->writeInt32(NO_ERROR); |
| 6695 | return NO_ERROR; |
| 6696 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6697 | case 1042: { // Write layers trace or transaction trace to file |
| 6698 | if (mTransactionTracing) { |
| 6699 | mTransactionTracing->writeToFile(); |
| 6700 | } |
| 6701 | if (mLayerTracingEnabled) { |
| 6702 | mLayerTracing.writeToFile(); |
| 6703 | } |
| 6704 | reply->writeInt32(NO_ERROR); |
| 6705 | return NO_ERROR; |
| 6706 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | } |
| 6708 | } |
| 6709 | return err; |
| 6710 | } |
| 6711 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6712 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 6713 | static bool updateOverlay = |
| 6714 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6715 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6716 | |
| 6717 | // Update the overlay on the main thread to avoid race conditions with |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6718 | // RefreshRateSelector::getActiveMode |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6719 | static_cast<void>(mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6720 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6721 | if (!display) { |
| 6722 | ALOGW("%s: default display is null", __func__); |
| 6723 | return; |
| 6724 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 6725 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6726 | |
| 6727 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 6728 | const std::optional<DisplayModeId> desiredModeId = desiredActiveMode |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6729 | ? std::make_optional(desiredActiveMode->modeOpt->modePtr->getId()) |
| 6730 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6731 | : std::nullopt; |
| 6732 | |
| 6733 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 6734 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 6735 | if (display->onKernelTimerChanged(desiredModeId, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6736 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6737 | } |
| 6738 | })); |
| 6739 | } |
| 6740 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6741 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 6742 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 6743 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 6744 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 6745 | const auto timeout = getIdleTimerTimeout(displayId); |
| 6746 | if (isKernelIdleTimerHwcSupported) { |
| 6747 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 6748 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 6749 | // In order to decide if we can use the HWC api for idle timer |
| 6750 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 6751 | // without relying on hasDisplayCapability. |
| 6752 | // hasDisplayCapability relies on DisplayCapabilities |
| 6753 | // which are updated after we set the PowerMode::ON. |
| 6754 | // DISPLAY_IDLE_TIMER is a display driver property |
| 6755 | // and is available before the PowerMode::ON |
| 6756 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 6757 | } |
| 6758 | return {std::nullopt, timeout}; |
| 6759 | } |
| 6760 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 6761 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 6762 | } |
| 6763 | |
| 6764 | return {std::nullopt, timeout}; |
| 6765 | } |
| 6766 | |
| 6767 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 6768 | KernelIdleTimerController controller, |
| 6769 | PhysicalDisplayId displayId) { |
| 6770 | switch (controller) { |
| 6771 | case KernelIdleTimerController::HwcApi: { |
| 6772 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 6773 | break; |
| 6774 | } |
| 6775 | case KernelIdleTimerController::Sysprop: { |
| 6776 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 6777 | break; |
| 6778 | } |
| 6779 | } |
| 6780 | } |
| 6781 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6782 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6783 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6784 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6785 | const auto display = getDefaultDisplayDeviceLocked(); |
| 6786 | if (!display) { |
| 6787 | ALOGW("%s: default display is null", __func__); |
| 6788 | return; |
| 6789 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6790 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6791 | // If the support for kernel idle timer is disabled for the active display, |
| 6792 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6793 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6794 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6795 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6796 | return; |
| 6797 | } |
| 6798 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6799 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6800 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6801 | switch (action) { |
| 6802 | case KernelIdleTimerAction::TurnOff: |
| 6803 | if (mKernelIdleTimerEnabled) { |
| 6804 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6805 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 6806 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 6807 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6808 | mKernelIdleTimerEnabled = false; |
| 6809 | } |
| 6810 | break; |
| 6811 | case KernelIdleTimerAction::TurnOn: |
| 6812 | if (!mKernelIdleTimerEnabled) { |
| 6813 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6814 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6815 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6816 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 6817 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6818 | mKernelIdleTimerEnabled = true; |
| 6819 | } |
| 6820 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6821 | } |
| 6822 | } |
| 6823 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6824 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 6825 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6826 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6827 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 6828 | ~WindowDisconnector() { |
| 6829 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6830 | } |
| 6831 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6832 | private: |
| 6833 | ANativeWindow* mWindow; |
| 6834 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6835 | }; |
| 6836 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6837 | static bool hasCaptureBlackoutContentPermission() { |
| 6838 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6839 | const int pid = ipc->getCallingPid(); |
| 6840 | const int uid = ipc->getCallingUid(); |
| 6841 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 6842 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 6843 | } |
| 6844 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6845 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 6846 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6847 | const int pid = ipc->getCallingPid(); |
| 6848 | const int uid = ipc->getCallingUid(); |
| 6849 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 6850 | return OK; |
| 6851 | } |
| 6852 | |
| 6853 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 6854 | // itself, we allow it to continue. |
| 6855 | if (captureArgs.uid == uid) { |
| 6856 | return OK; |
| 6857 | } |
| 6858 | |
| 6859 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 6860 | return PERMISSION_DENIED; |
| 6861 | } |
| 6862 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6863 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 6864 | static constexpr int kFifoPriority = 2; |
| 6865 | static constexpr int kOtherPriority = 0; |
| 6866 | |
| 6867 | struct sched_param param = {0}; |
| 6868 | int sched_policy; |
| 6869 | if (enabled) { |
| 6870 | sched_policy = SCHED_FIFO; |
| 6871 | param.sched_priority = kFifoPriority; |
| 6872 | } else { |
| 6873 | sched_policy = SCHED_OTHER; |
| 6874 | param.sched_priority = kOtherPriority; |
| 6875 | } |
| 6876 | |
| 6877 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 6878 | return -errno; |
| 6879 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6880 | |
| 6881 | return NO_ERROR; |
| 6882 | } |
| 6883 | |
| 6884 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 6885 | static const unsigned int kUclampMin = |
| 6886 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 6887 | |
| 6888 | if (!kUclampMin) { |
| 6889 | // uclamp.min set to 0 (default), skip setting |
| 6890 | return NO_ERROR; |
| 6891 | } |
| 6892 | |
| 6893 | // Currently, there is no wrapper in bionic: b/183240349. |
| 6894 | struct sched_attr { |
| 6895 | uint32_t size; |
| 6896 | uint32_t sched_policy; |
| 6897 | uint64_t sched_flags; |
| 6898 | int32_t sched_nice; |
| 6899 | uint32_t sched_priority; |
| 6900 | uint64_t sched_runtime; |
| 6901 | uint64_t sched_deadline; |
| 6902 | uint64_t sched_period; |
| 6903 | uint32_t sched_util_min; |
| 6904 | uint32_t sched_util_max; |
| 6905 | }; |
| 6906 | |
| 6907 | sched_attr attr = {}; |
| 6908 | attr.size = sizeof(attr); |
| 6909 | |
| 6910 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 6911 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 6912 | attr.sched_util_max = 1024; |
| 6913 | |
| 6914 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 6915 | return -errno; |
| 6916 | } |
| 6917 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6918 | return NO_ERROR; |
| 6919 | } |
| 6920 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6921 | status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6922 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6923 | ATRACE_CALL(); |
| 6924 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6925 | status_t validate = validateScreenshotPermissions(args); |
| 6926 | if (validate != OK) { |
| 6927 | return validate; |
| 6928 | } |
| 6929 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6930 | if (!args.displayToken) return BAD_VALUE; |
| 6931 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6932 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6933 | ui::LayerStack layerStack; |
| 6934 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 6935 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6936 | ui::Dataspace dataspace; |
| 6937 | { |
| 6938 | Mutex::Autolock lock(mStateLock); |
| 6939 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
| 6940 | if (!display) return NAME_NOT_FOUND; |
| 6941 | displayWeak = display; |
| 6942 | layerStack = display->getLayerStack(); |
| 6943 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6944 | // 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] | 6945 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6946 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6947 | } |
| 6948 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 6949 | for (const auto& handle : args.excludeHandles) { |
| 6950 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 6951 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 6952 | excludeLayerIds.emplace(excludeLayer); |
| 6953 | } else { |
| 6954 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
| 6955 | return NAME_NOT_FOUND; |
| 6956 | } |
| 6957 | } |
| 6958 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6959 | // Allow the caller to specify a dataspace regardless of the display's color mode, e.g. if |
| 6960 | // it wants sRGB regardless of the display's wide color mode. |
| 6961 | dataspace = args.dataspace == ui::Dataspace::UNKNOWN |
| 6962 | ? ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode) |
| 6963 | : args.dataspace; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6964 | } |
| 6965 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6966 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6967 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 6968 | args.useIdentityTransform, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6969 | }); |
| 6970 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6971 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 6972 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 6973 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 6974 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6975 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 6976 | auto traverseLayers = [this, args, excludeLayerIds, |
| 6977 | layerStack](const LayerVector::Visitor& visitor) { |
| 6978 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6979 | }; |
| 6980 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 6981 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6982 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 6983 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6984 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 6985 | captureListener); |
| 6986 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6987 | } |
| 6988 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6989 | status_t SurfaceFlinger::captureDisplay(DisplayId displayId, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6990 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6991 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6992 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6993 | ui::Size size; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6994 | ui::Dataspace dataspace; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6995 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6996 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6997 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6998 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6999 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7000 | return NAME_NOT_FOUND; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7001 | } |
| 7002 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7003 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7004 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7005 | size = display->getLayerStackSpaceRect().getSize(); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7006 | dataspace = ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7007 | } |
| 7008 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7009 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 7010 | return DisplayRenderArea::create(displayWeak, Rect(), size, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 7011 | false /* useIdentityTransform */, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7012 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7013 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7014 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7015 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 7016 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7017 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7018 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7019 | } else { |
| 7020 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7021 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7022 | }; |
| 7023 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7024 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7025 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7026 | if (captureListener == nullptr) { |
| 7027 | ALOGE("capture screen must provide a capture listener callback"); |
| 7028 | return BAD_VALUE; |
| 7029 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7030 | |
| 7031 | constexpr bool kAllowProtected = false; |
| 7032 | constexpr bool kGrayscale = false; |
| 7033 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7034 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7035 | ui::PixelFormat::RGBA_8888, kAllowProtected, kGrayscale, |
| 7036 | captureListener); |
| 7037 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7038 | } |
| 7039 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7040 | status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 7041 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7042 | ATRACE_CALL(); |
| 7043 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7044 | status_t validate = validateScreenshotPermissions(args); |
| 7045 | if (validate != OK) { |
| 7046 | return validate; |
| 7047 | } |
| 7048 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7049 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7050 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7051 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7052 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7053 | ui::Dataspace dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7054 | |
| 7055 | // Call this before holding mStateLock to avoid any deadlocking. |
| 7056 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
| 7057 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7058 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7059 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7060 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7061 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7062 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7063 | ALOGE("captureLayers called with an invalid or removed parent"); |
| 7064 | return NAME_NOT_FOUND; |
| 7065 | } |
| 7066 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7067 | if (!canCaptureBlackoutContent && |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7068 | parent->getDrawingState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7069 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
| 7070 | return PERMISSION_DENIED; |
| 7071 | } |
| 7072 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7073 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7074 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7075 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7076 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7077 | } |
| 7078 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7079 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7080 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7081 | crop.bottom = parentSourceBounds.getHeight(); |
| 7082 | } |
| 7083 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7084 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7085 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7086 | // crop was not specified, or an invalid frame scale was provided. |
| 7087 | return BAD_VALUE; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7088 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7089 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7090 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7091 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7092 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7093 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7094 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7095 | } else { |
| 7096 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
| 7097 | return NAME_NOT_FOUND; |
| 7098 | } |
| 7099 | } |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 7100 | |
arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 7101 | // The dataspace is depended on the color mode of display, that could use non-native mode |
| 7102 | // (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes, |
| 7103 | // and failed if display is not in native mode. This provide a way to force using native |
| 7104 | // colors when capture. |
Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 7105 | dataspace = args.dataspace; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7106 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7107 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7108 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7109 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7110 | ALOGW("Failed to captureLayes: crop or scale too small"); |
| 7111 | return BAD_VALUE; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7114 | bool childrenOnly = args.childrenOnly; |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7115 | RenderAreaFuture renderAreaFuture = ftl::defer([=]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7116 | ui::Transform layerTransform; |
| 7117 | Rect layerBufferSize; |
| 7118 | if (mLayerLifecycleManagerEnabled) { |
| 7119 | frontend::LayerSnapshot* snapshot = |
| 7120 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 7121 | if (!snapshot) { |
| 7122 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 7123 | } else { |
| 7124 | layerTransform = snapshot->localTransform; |
| 7125 | layerBufferSize = snapshot->bufferSize; |
| 7126 | } |
| 7127 | } else { |
| 7128 | layerTransform = parent->getTransform(); |
| 7129 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 7130 | } |
| 7131 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7132 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7133 | childrenOnly, args.captureSecureLayers, |
| 7134 | layerTransform, layerBufferSize); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7135 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7136 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 7137 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7138 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 7139 | if (args.childrenOnly) { |
| 7140 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7141 | : crop.toFloatRect(); |
| 7142 | } |
| 7143 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7144 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 7145 | std::move(excludeLayerIds), |
| 7146 | args.childrenOnly, parentCrop); |
| 7147 | } else { |
| 7148 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 7149 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 7150 | if (!layer->isVisible()) { |
| 7151 | return; |
| 7152 | } else if (args.childrenOnly && layer == parent.get()) { |
| 7153 | return; |
| 7154 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7155 | return; |
| 7156 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7157 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7158 | auto p = sp<Layer>::fromExisting(layer); |
| 7159 | while (p != nullptr) { |
| 7160 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7161 | return; |
| 7162 | } |
| 7163 | p = p->getParent(); |
| 7164 | } |
| 7165 | |
| 7166 | visitor(layer); |
| 7167 | }); |
| 7168 | }; |
| 7169 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7170 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7171 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7172 | if (captureListener == nullptr) { |
| 7173 | ALOGE("capture screen must provide a capture listener callback"); |
| 7174 | return BAD_VALUE; |
| 7175 | } |
| 7176 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7177 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7178 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 7179 | captureListener); |
| 7180 | return fenceStatus(future.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7181 | } |
| 7182 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7183 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7184 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7185 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, bool allowProtected, bool grayscale, |
| 7186 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7187 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7188 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7189 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7190 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7191 | ") that exceeds render target size limit.", |
| 7192 | bufferSize.getWidth(), bufferSize.getHeight()); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7193 | return ftl::yield<FenceResult>(base::unexpected(BAD_VALUE)).share(); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7196 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7197 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7198 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7199 | // application to avoid being screenshot or drawn via unsecure display. |
| 7200 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7201 | bool hasProtectedLayer = false; |
| 7202 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7203 | hasProtectedLayer = mScheduler |
| 7204 | ->schedule([=]() { |
| 7205 | bool protectedLayerFound = false; |
| 7206 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7207 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7208 | protectedLayerFound |= |
| 7209 | (layerFe->mSnapshot->isVisible && |
| 7210 | layerFe->mSnapshot->hasProtectedContent); |
| 7211 | } |
| 7212 | return protectedLayerFound; |
| 7213 | }) |
| 7214 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7215 | } |
| 7216 | |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 7217 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7218 | GRALLOC_USAGE_HW_TEXTURE | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7219 | (hasProtectedLayer && allowProtected && supportsProtected |
| 7220 | ? GRALLOC_USAGE_PROTECTED |
| 7221 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7222 | sp<GraphicBuffer> buffer = |
| 7223 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7224 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7225 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7226 | |
| 7227 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7228 | if (bufferStatus != OK) { |
| 7229 | // Animations may end up being really janky, but don't crash here. |
| 7230 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7231 | // too much. |
| 7232 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 7233 | return ftl::yield<FenceResult>(base::unexpected(bufferStatus)).share(); |
| 7234 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7235 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7236 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7237 | renderengine::impl::ExternalTexture::Usage:: |
| 7238 | WRITEABLE); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7239 | return captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
Derek Sollenberger | 3425788 | 2021-04-06 18:32:34 +0000 | [diff] [blame] | 7240 | false /* regionSampling */, grayscale, captureListener); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7241 | } |
| 7242 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7243 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7244 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7245 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 7246 | bool grayscale, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7247 | ATRACE_CALL(); |
| 7248 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7249 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 7250 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7251 | auto future = mScheduler->schedule( |
| 7252 | [=, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
| 7253 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 7254 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 7255 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7256 | if (!renderArea) { |
| 7257 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 7258 | if (captureListener) { |
| 7259 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7260 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7261 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7262 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7263 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7264 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7265 | ftl::SharedFuture<FenceResult> renderFuture; |
| 7266 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7267 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7268 | canCaptureBlackoutContent, regionSampling, |
| 7269 | grayscale, captureResults); |
| 7270 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7271 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7272 | if (captureListener) { |
| 7273 | // Defer blocking on renderFuture back to the Binder thread. |
| 7274 | return ftl::Future(std::move(renderFuture)) |
| 7275 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 7276 | FenceResult fenceResult) mutable -> FenceResult { |
| 7277 | captureResults.fenceResult = std::move(fenceResult); |
| 7278 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7279 | return base::unexpected(NO_ERROR); |
| 7280 | }) |
| 7281 | .share(); |
| 7282 | } |
| 7283 | return renderFuture; |
| 7284 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7285 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7286 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7287 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 7288 | return future; |
| 7289 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7290 | |
| 7291 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7292 | } |
| 7293 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7294 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7295 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7296 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 7297 | bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, |
| 7298 | ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 7299 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7300 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7301 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7302 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7303 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 7304 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 7305 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 7306 | layerFE->mSnapshot->geomLayerTransform = |
| 7307 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 7308 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 7309 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7310 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7311 | |
| 7312 | // We allow the system server to take screenshots of secure layers for |
| 7313 | // use in situations like the Screen-rotation animation and place |
| 7314 | // the impetus on WindowManager to not persist them. |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7315 | if (captureResults.capturedSecureLayers && !canCaptureBlackoutContent) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7316 | ALOGW("FB is protected: PERMISSION_DENIED"); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7317 | return ftl::yield<FenceResult>(base::unexpected(PERMISSION_DENIED)).share(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7318 | } |
| 7319 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7320 | captureResults.buffer = buffer->getBuffer(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7321 | auto dataspace = renderArea->getReqDataSpace(); |
| 7322 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7323 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7324 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 7325 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 7326 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7327 | if (dataspace == ui::Dataspace::UNKNOWN && parent) { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7328 | Mutex::Autolock lock(mStateLock); |
| 7329 | auto display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 7330 | return display.getLayerStack() == layerStack; |
| 7331 | }); |
| 7332 | if (!display) { |
| 7333 | // If the layer is not on a display, use the dataspace for the default display. |
| 7334 | display = getDefaultDisplayDeviceLocked(); |
| 7335 | } |
| 7336 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7337 | dataspace = ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7338 | renderIntent = display->getCompositionDisplay()->getState().renderIntent; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7339 | sdrWhitePointNits = display->getCompositionDisplay()->getState().sdrWhitePointNits; |
| 7340 | displayBrightnessNits = display->getCompositionDisplay()->getState().displayBrightnessNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7341 | } |
| 7342 | captureResults.capturedDataspace = dataspace; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7343 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7344 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 7345 | if (!layers.empty()) { |
| 7346 | const sp<LayerFE>& layerFE = layers.back().second; |
| 7347 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 7348 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 7349 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7350 | auto copyLayerFEs = [&layers]() { |
| 7351 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 7352 | layerFEs.reserve(layers.size()); |
| 7353 | for (const auto& [_, layerFE] : layers) { |
| 7354 | layerFEs.push_back(layerFE); |
| 7355 | } |
| 7356 | return layerFEs; |
| 7357 | }; |
| 7358 | |
| 7359 | auto present = [this, buffer = std::move(buffer), dataspace, sdrWhitePointNits, |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 7360 | displayBrightnessNits, grayscale, layerFEs = copyLayerFEs(), layerStack, |
| 7361 | regionSampling, renderArea = std::move(renderArea), |
| 7362 | renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7363 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
| 7364 | mFactory.createCompositionEngine(); |
| 7365 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 7366 | |
| 7367 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 7368 | .renderIntent = renderIntent}; |
| 7369 | |
| 7370 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 7371 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 7372 | .colorProfile = colorProfile, |
| 7373 | .renderArea = *renderArea, |
| 7374 | .layerStack = layerStack, |
| 7375 | .buffer = std::move(buffer), |
| 7376 | .sdrWhitePointNits = sdrWhitePointNits, |
| 7377 | .displayBrightnessNits = displayBrightnessNits, |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7378 | .regionSampling = regionSampling}); |
| 7379 | |
| 7380 | const float colorSaturation = grayscale ? 0 : 1; |
| 7381 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 7382 | .outputs = {output}, |
| 7383 | .layers = std::move(layerFEs), |
| 7384 | .updatingOutputGeometryThisFrame = true, |
| 7385 | .updatingGeometryThisFrame = true, |
| 7386 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 7387 | }; |
| 7388 | compositionEngine->present(refreshArgs); |
| 7389 | |
| 7390 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 7391 | }; |
| 7392 | |
| 7393 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 7394 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 7395 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 7396 | // immediately. |
| 7397 | // |
| 7398 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 7399 | // to CompositionEngine::present. |
| 7400 | const bool renderEngineIsThreaded = [&]() { |
| 7401 | using Type = renderengine::RenderEngine::RenderEngineType; |
| 7402 | const auto type = mRenderEngine->getRenderEngineType(); |
| 7403 | return type == Type::THREADED || type == Type::SKIA_GL_THREADED; |
| 7404 | }(); |
| 7405 | auto presentFuture = renderEngineIsThreaded ? ftl::defer(std::move(present)).share() |
| 7406 | : ftl::yield(present()).share(); |
| 7407 | |
| 7408 | for (auto& [layer, layerFE] : layers) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 7409 | layer->onLayerDisplayed(ftl::Future(presentFuture) |
| 7410 | .then([layerFE = std::move(layerFE)](FenceResult) { |
| 7411 | return layerFE->stealCompositionResult() |
| 7412 | .releaseFences.back() |
| 7413 | .first.get(); |
| 7414 | }) |
| 7415 | .share(), |
| 7416 | ui::INVALID_LAYER_STACK); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 7420 | } |
| 7421 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7422 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
| 7423 | if (mLayerLifecycleManagerEnabled) { |
| 7424 | for (auto& layer : mLegacyLayers) { |
| 7425 | visitor(layer.second.get()); |
| 7426 | } |
| 7427 | } else { |
| 7428 | mDrawingState.traverse(visitor); |
| 7429 | } |
| 7430 | } |
| 7431 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7432 | // --------------------------------------------------------------------------- |
| 7433 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 7434 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 7435 | layersSortedByZ.traverse(visitor); |
| 7436 | } |
| 7437 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7438 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 7439 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7440 | } |
| 7441 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7442 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 7443 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7444 | } |
| 7445 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7446 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7447 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7448 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7449 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 7450 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7451 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7452 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7453 | continue; |
| 7454 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 7455 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7456 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7457 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 7458 | return; |
| 7459 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7460 | if (!layer->isVisible()) { |
| 7461 | return; |
| 7462 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7463 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 7464 | return; |
| 7465 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7466 | |
| 7467 | if (!excludeLayerIds.empty()) { |
| 7468 | auto p = sp<Layer>::fromExisting(layer); |
| 7469 | while (p != nullptr) { |
| 7470 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7471 | return; |
| 7472 | } |
| 7473 | p = p->getParent(); |
| 7474 | } |
| 7475 | } |
| 7476 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7477 | visitor(layer); |
| 7478 | }); |
| 7479 | } |
| 7480 | } |
| 7481 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7482 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7483 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 7484 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7485 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7486 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7487 | } |
| 7488 | |
| 7489 | return mPhysicalDisplays.get(displayId) |
| 7490 | .transform(&PhysicalDisplay::snapshotRef) |
| 7491 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 7492 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 7493 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7494 | .transform([](const DisplayModePtr& modePtr) { |
| 7495 | return scheduler::FrameRateMode{modePtr->getFps(), ftl::as_non_null(modePtr)}; |
| 7496 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7499 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7500 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7501 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7502 | const auto displayId = display->getPhysicalId(); |
| 7503 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7504 | Mutex::Autolock lock(mStateLock); |
| 7505 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7506 | if (mDebugDisplayModeSetByBackdoor) { |
| 7507 | // ignore this request as mode is overridden by backdoor |
| 7508 | return NO_ERROR; |
| 7509 | } |
| 7510 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7511 | auto& selector = display->refreshRateSelector(); |
| 7512 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7513 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7514 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7515 | case SetPolicyResult::Invalid: |
| 7516 | return BAD_VALUE; |
| 7517 | case SetPolicyResult::Unchanged: |
| 7518 | return NO_ERROR; |
| 7519 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7520 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7521 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7522 | |
| 7523 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 7524 | .transform(&PhysicalDisplay::isInternal) |
| 7525 | .value_or(false); |
| 7526 | |
| 7527 | if (isInternalDisplay && displayId != mActiveDisplayId) { |
| 7528 | // The policy will be be applied when the display becomes active. |
| 7529 | ALOGV("%s(%s): Inactive display", __func__, to_string(displayId).c_str()); |
| 7530 | return NO_ERROR; |
| 7531 | } |
| 7532 | |
| 7533 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7534 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7535 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7536 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7537 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7538 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7539 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 7540 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7541 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 7542 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7543 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
| 7544 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7545 | toggleKernelIdleTimer(); |
| 7546 | } else { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7547 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7548 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 7549 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7550 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7551 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7552 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 7553 | return NAME_NOT_FOUND; |
| 7554 | } |
| 7555 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7556 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7557 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 7558 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7559 | ALOGV("Switching to Scheduler preferred mode %d (%s)", preferredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7560 | to_string(preferredMode.fps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7561 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7562 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7563 | ALOGE("%s: Preferred mode %d is disallowed", __func__, preferredModeId.value()); |
| 7564 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 7565 | } |
| 7566 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7567 | setDesiredActiveMode({std::move(preferredMode), .emitEvent = true}, force); |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 7568 | return NO_ERROR; |
| 7569 | } |
| 7570 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7571 | namespace { |
| 7572 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 7573 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 7574 | } |
| 7575 | |
| 7576 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 7577 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 7578 | } |
| 7579 | |
| 7580 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 7581 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 7582 | aidlRange.min = range.min.getValue(); |
| 7583 | aidlRange.max = range.max.getValue(); |
| 7584 | return aidlRange; |
| 7585 | } |
| 7586 | |
| 7587 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 7588 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 7589 | aidlRanges.physical = translate(ranges.physical); |
| 7590 | aidlRanges.render = translate(ranges.render); |
| 7591 | return aidlRanges; |
| 7592 | } |
| 7593 | |
| 7594 | } // namespace |
| 7595 | |
| 7596 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 7597 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7598 | ATRACE_CALL(); |
| 7599 | |
| 7600 | if (!displayToken) { |
| 7601 | return BAD_VALUE; |
| 7602 | } |
| 7603 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7604 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7605 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7606 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7607 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7608 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7609 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7610 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7611 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7612 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7613 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7614 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7615 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 7616 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7617 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7618 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7619 | } |
| 7620 | }); |
| 7621 | |
| 7622 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7623 | } |
| 7624 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 7625 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7626 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7627 | ATRACE_CALL(); |
| 7628 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7629 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7630 | return BAD_VALUE; |
| 7631 | } |
| 7632 | |
| 7633 | Mutex::Autolock lock(mStateLock); |
| 7634 | const auto display = getDisplayDeviceLocked(displayToken); |
| 7635 | if (!display) { |
| 7636 | return NAME_NOT_FOUND; |
| 7637 | } |
| 7638 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7639 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7640 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7641 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7642 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7643 | scheduler::RefreshRateSelector::Policy policy = |
| 7644 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7645 | outSpecs->defaultMode = policy.defaultMode.value(); |
| 7646 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 7647 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 7648 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7649 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7650 | } |
| 7651 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 7652 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7653 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 7654 | if (!layer->isRemovedFromCurrentState()) { |
| 7655 | mScheduler->registerLayer(layer); |
| 7656 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
| 7659 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 7660 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7661 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 7662 | if (!layer->isRemovedFromCurrentState()) { |
| 7663 | mScheduler->deregisterLayer(layer); |
| 7664 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7665 | if (mTransactionTracing) { |
| 7666 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 7667 | } |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7668 | } |
| 7669 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7670 | void SurfaceFlinger::onLayerUpdate() { |
| 7671 | scheduleCommit(FrameHint::kActive); |
| 7672 | } |
| 7673 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7674 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 7675 | // Here we add children in the current state to offscreen layers and remove the |
| 7676 | // layer itself from the offscreen layer list. Since |
| 7677 | // this is the dtor, it is safe to access the current state. This keeps us |
| 7678 | // from dangling children layers such that they are not reachable from the |
| 7679 | // Drawing state nor the offscreen layer list |
| 7680 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7681 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7682 | for (auto& child : layer->getCurrentChildren()) { |
| 7683 | mOffscreenLayers.emplace(child.get()); |
| 7684 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7685 | mOffscreenLayers.erase(layer); |
| 7686 | } |
| 7687 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7688 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 7689 | mOffscreenLayers.erase(layer); |
| 7690 | } |
| 7691 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 7692 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 7693 | float lightPosY, float lightPosZ, |
| 7694 | float lightRadius) { |
| 7695 | Mutex::Autolock _l(mStateLock); |
| 7696 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 7697 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 7698 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 7699 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 7700 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 7701 | |
| 7702 | // these values are overridden when calculating the shadow settings for a layer. |
| 7703 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 7704 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 7705 | return NO_ERROR; |
| 7706 | } |
| 7707 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7708 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 7709 | const { |
| 7710 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 7711 | // on the work to remove the table in that bug rather than adding more to |
| 7712 | // it. |
| 7713 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7714 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 7715 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7716 | }; |
| 7717 | return genericLayerMetadataKeyMap; |
| 7718 | } |
| 7719 | |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 7720 | status_t SurfaceFlinger::setOverrideFrameRate(uid_t uid, float frameRate) { |
| 7721 | PhysicalDisplayId displayId = [&]() { |
| 7722 | Mutex::Autolock lock(mStateLock); |
| 7723 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7724 | }(); |
| 7725 | |
| 7726 | mScheduler->setGameModeRefreshRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 7727 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 7728 | return NO_ERROR; |
| 7729 | } |
| 7730 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7731 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7732 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7733 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 7734 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7735 | if (setByHwc) { |
| 7736 | const auto status = |
| 7737 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 7738 | if (status != NO_ERROR) { |
| 7739 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 7740 | return; |
| 7741 | } |
| 7742 | } |
| 7743 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7744 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7745 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
Yifei Zhang | cfb7bb3 | 2023-01-12 16:17:14 -0800 | [diff] [blame] | 7746 | mRefreshRateOverlayRenderRate, |
| 7747 | mRefreshRateOverlayShowInMiddle); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7748 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7749 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 7750 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7753 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 7754 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 7755 | } |
| 7756 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7757 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
| 7758 | std::chrono::nanoseconds presentLatency) { |
| 7759 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 7760 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7761 | pipelineDepth++; |
| 7762 | } |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7763 | return std::max(1ll, pipelineDepth - 1); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7764 | } |
| 7765 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7766 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7767 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7768 | |
| 7769 | if (!getHwComposer().isHeadless()) { |
| 7770 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7771 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7772 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
| 7775 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7776 | return NO_ERROR; |
| 7777 | } |
| 7778 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 7779 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7780 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7781 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7782 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 7783 | refreshRate = *frameRateOverride; |
| 7784 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7785 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7786 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7787 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7788 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7789 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7790 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 7791 | } |
| 7792 | |
| 7793 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 7794 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 7795 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 7796 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 7797 | } |
| 7798 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7799 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7800 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7801 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7802 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 7803 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7804 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 7805 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7806 | |
| 7807 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7808 | bool addToRoot = state.addToRoot; |
| 7809 | if (state.initialParent != nullptr) { |
| 7810 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7811 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7812 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 7813 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7814 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7815 | } |
| 7816 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 7817 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 7818 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7819 | mCurrentState.layersSortedByZ.add(layer); |
| 7820 | } else if (parent == nullptr) { |
| 7821 | layer->onRemovedFromCurrentState(); |
| 7822 | } else if (parent->isRemovedFromCurrentState()) { |
| 7823 | parent->addChild(layer); |
| 7824 | layer->onRemovedFromCurrentState(); |
| 7825 | } else { |
| 7826 | parent->addChild(layer); |
| 7827 | } |
| 7828 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 7829 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 7830 | sp<const DisplayDevice> hintDisplay; |
| 7831 | // Find the display that includes the layer. |
| 7832 | for (const auto& [token, display] : mDisplays) { |
| 7833 | if (display->getLayerStack() == layerStack) { |
| 7834 | hintDisplay = display; |
| 7835 | break; |
| 7836 | } |
| 7837 | } |
| 7838 | |
| 7839 | if (hintDisplay) { |
| 7840 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 7841 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7842 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7843 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7844 | void SurfaceFlinger::sample() { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7845 | if (!mLumaSampling || !mRegionSamplingThread) { |
| 7846 | return; |
| 7847 | } |
| 7848 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7849 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7850 | } |
| 7851 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7852 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 7853 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 7854 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7855 | } |
| 7856 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7857 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 7858 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7859 | ATRACE_CALL(); |
| 7860 | |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 7861 | // For the first display activated during boot, there is no need to force setDesiredActiveMode, |
| 7862 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 7863 | bool forceApplyPolicy = false; |
| 7864 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7865 | if (inactiveDisplayPtr) { |
| 7866 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 7867 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 7868 | } |
| 7869 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7870 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 7871 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 7872 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 7873 | resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
| 7874 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7875 | mScheduler->setModeChangePending(false); |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 7876 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 7877 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7878 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7879 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 7880 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 7881 | // The policy of the new active/pacesetter display may have changed while it was inactive. In |
| 7882 | // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In |
| 7883 | // either case, the Scheduler's cachedModeChangedParams must be initialized to the newly active |
| 7884 | // mode, and the kernel idle timer of the newly active display must be toggled. |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 7885 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 7886 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7887 | } |
| 7888 | |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7889 | status_t SurfaceFlinger::addWindowInfosListener( |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 7890 | const sp<IWindowInfosListener>& windowInfosListener) { |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7891 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 7892 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7893 | return NO_ERROR; |
| 7894 | } |
| 7895 | |
| 7896 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 7897 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 7898 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 7899 | return NO_ERROR; |
| 7900 | } |
| 7901 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7902 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7903 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 7904 | if (bufferData.buffer && |
| 7905 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 7906 | std::string errorMessage = |
| 7907 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 7908 | "layer %s that exceeds render target size limit of %u.", |
| 7909 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 7910 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 7911 | ALOGD("%s", errorMessage.c_str()); |
| 7912 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 7913 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 7914 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 7915 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7916 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7917 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7918 | |
| 7919 | bool cachedBufferChanged = |
| 7920 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 7921 | if (cachedBufferChanged && bufferData.buffer) { |
| 7922 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 7923 | if (result.ok()) { |
| 7924 | return result.value(); |
| 7925 | } |
| 7926 | |
| 7927 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 7928 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 7929 | |
| 7930 | if (bufferData.releaseBufferListener) { |
| 7931 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 7932 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 7933 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7934 | } |
| 7935 | |
| 7936 | return nullptr; |
| 7937 | } |
| 7938 | |
| 7939 | if (cachedBufferChanged) { |
| 7940 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 7941 | } |
| 7942 | |
| 7943 | if (bufferData.buffer) { |
| 7944 | return std::make_shared< |
| 7945 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 7946 | renderengine::impl::ExternalTexture::Usage:: |
| 7947 | READABLE); |
| 7948 | } |
| 7949 | |
| 7950 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7951 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7952 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7953 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7954 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 7955 | { |
| 7956 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 7957 | mirrorDisplays = std::move(mMirrorDisplays); |
| 7958 | mMirrorDisplays.clear(); |
| 7959 | if (mirrorDisplays.size() == 0) { |
| 7960 | return false; |
| 7961 | } |
| 7962 | } |
| 7963 | |
| 7964 | sp<IBinder> unused; |
| 7965 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 7966 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 7967 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7968 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7969 | rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 7970 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 7971 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 7972 | layer->isInternalDisplayOverlay()) { |
| 7973 | continue; |
| 7974 | } |
| 7975 | |
| 7976 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 7977 | ISurfaceComposerClient::eNoColorFill, |
| 7978 | gui::LayerMetadata()); |
| 7979 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 7980 | { |
| 7981 | Mutex::Autolock lock(mStateLock); |
| 7982 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 7983 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 7984 | childMirror->setClonedChild(layer->createClone()); |
| 7985 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 7986 | } |
| 7987 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 7988 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7989 | } |
| 7990 | } |
| 7991 | return true; |
| 7992 | } |
| 7993 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7994 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 7995 | std::vector<LayerCreatedState>& createdLayers) { |
| 7996 | if (createdLayers.size() == 0) { |
| 7997 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7998 | } |
| 7999 | |
| 8000 | Mutex::Autolock _l(mStateLock); |
| 8001 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 8002 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8003 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8004 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8005 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8006 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8007 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 8008 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 8009 | LayerMetadata parentMetadata; |
| 8010 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8011 | layer->updateMetadataSnapshot(parentMetadata); |
| 8012 | } |
| 8013 | |
| 8014 | std::unordered_set<Layer*> visited; |
| 8015 | mDrawingState.traverse([&visited](Layer* layer) { |
| 8016 | if (visited.find(layer) != visited.end()) { |
| 8017 | return; |
| 8018 | } |
| 8019 | |
| 8020 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 8021 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 8022 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 8023 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 8024 | if (layer->getDrawingState().isRelativeOf) { |
| 8025 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 8026 | return; |
| 8027 | } |
| 8028 | |
| 8029 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 8030 | }); |
| 8031 | } |
| 8032 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8033 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 8034 | compositionengine::CompositionRefreshArgs& refreshArgs, |
| 8035 | std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
| 8036 | if (mLayerLifecycleManagerEnabled) { |
| 8037 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 8038 | mLayerSnapshotBuilder.getSnapshots(); |
| 8039 | for (auto [_, layerFE] : layers) { |
| 8040 | auto i = layerFE->mSnapshot->globalZ; |
| 8041 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 8042 | } |
| 8043 | } |
| 8044 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
| 8045 | for (auto [layer, layerFE] : layers) { |
| 8046 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 8047 | } |
| 8048 | } |
| 8049 | } |
| 8050 | |
| 8051 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
| 8052 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly, int64_t vsyncId) { |
| 8053 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
| 8054 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8055 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8056 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8057 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 8058 | if (cursorOnly && |
| 8059 | snapshot->compositionType != |
| 8060 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 8061 | return; |
| 8062 | } |
| 8063 | |
| 8064 | if (!snapshot->hasSomethingToDraw()) { |
| 8065 | return; |
| 8066 | } |
| 8067 | |
| 8068 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8069 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8070 | "Couldnt find layer object for %s", |
| 8071 | snapshot->getDebugString().c_str()); |
| 8072 | auto& legacyLayer = it->second; |
| 8073 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8074 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8075 | layerFE->mSnapshot = std::move(snapshot); |
| 8076 | refreshArgs.layers.push_back(layerFE); |
| 8077 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 8078 | }); |
| 8079 | } |
| 8080 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
| 8081 | mDrawingState.traverseInZOrder([&refreshArgs, cursorOnly, &layers](Layer* layer) { |
| 8082 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 8083 | if (cursorOnly && |
| 8084 | layer->getLayerSnapshot()->compositionType != |
| 8085 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 8086 | return; |
| 8087 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 8088 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 8089 | refreshArgs.layers.push_back(layerFE); |
| 8090 | layers.emplace_back(layer, layerFE.get()); |
| 8091 | } |
| 8092 | }); |
| 8093 | } |
| 8094 | |
| 8095 | return layers; |
| 8096 | } |
| 8097 | |
| 8098 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8099 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 8100 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 8101 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 8102 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8103 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8104 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8105 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8106 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8107 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8108 | if (stopTraversal) { |
| 8109 | return; |
| 8110 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8111 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 8112 | return; |
| 8113 | } |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8114 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != uid) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8115 | return; |
| 8116 | } |
| 8117 | if (!snapshot->hasSomethingToDraw()) { |
| 8118 | return; |
| 8119 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8120 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 8121 | return; |
| 8122 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8123 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8124 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8125 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8126 | "Couldnt find layer object for %s", |
| 8127 | snapshot->getDebugString().c_str()); |
| 8128 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 8129 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 8130 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 8131 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 8132 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8133 | |
| 8134 | return layers; |
| 8135 | }; |
| 8136 | } |
| 8137 | |
| 8138 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8139 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 8140 | uint32_t uid, |
| 8141 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 8142 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 8143 | if (excludeLayerIds.empty()) { |
| 8144 | auto getLayerSnapshotsFn = |
| 8145 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8146 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8147 | return layers; |
| 8148 | } |
| 8149 | |
| 8150 | frontend::LayerSnapshotBuilder::Args |
| 8151 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 8152 | .layerLifecycleManager = mLayerLifecycleManager, |
| 8153 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 8154 | .displays = mFrontEndDisplayInfos, |
| 8155 | .displayChanges = true, |
| 8156 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
| 8157 | .supportsBlur = mSupportsBlur, |
| 8158 | .forceFullDamage = mForceFullDamage, |
| 8159 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8160 | .supportedLayerGenericMetadata = |
| 8161 | getHwComposer().getSupportedLayerGenericMetadata(), |
| 8162 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap()}; |
| 8163 | mLayerSnapshotBuilder.update(args); |
| 8164 | |
| 8165 | auto getLayerSnapshotsFn = |
| 8166 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8167 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8168 | |
| 8169 | args.excludeLayerIds.clear(); |
| 8170 | mLayerSnapshotBuilder.update(args); |
| 8171 | |
| 8172 | return layers; |
| 8173 | }; |
| 8174 | } |
| 8175 | |
| 8176 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8177 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 8178 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8179 | bool childrenOnly, |
| 8180 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8181 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8182 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8183 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8184 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8185 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8186 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8187 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8188 | .displays = mFrontEndDisplayInfos, |
| 8189 | .displayChanges = true, |
| 8190 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
| 8191 | .supportsBlur = mSupportsBlur, |
| 8192 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8193 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8194 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8195 | .supportedLayerGenericMetadata = |
| 8196 | getHwComposer().getSupportedLayerGenericMetadata(), |
| 8197 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8198 | mLayerSnapshotBuilder.update(args); |
| 8199 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8200 | auto getLayerSnapshotsFn = |
| 8201 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8202 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8203 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 8204 | args.parentCrop.reset(); |
| 8205 | args.excludeLayerIds.clear(); |
| 8206 | mLayerSnapshotBuilder.update(args); |
| 8207 | return layers; |
| 8208 | }; |
| 8209 | } |
| 8210 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8211 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 8212 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8213 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 8214 | // Locking: |
| 8215 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 8216 | // we must keep a copy of the transactions (specifically the composer |
| 8217 | // states) around outside the scope of the lock. |
| 8218 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 8219 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 8220 | // before committing the created layers. |
| 8221 | update.transactions = mTransactionHandler.flushTransactions(); |
| 8222 | { |
| 8223 | // TODO(b/238781169) lockless queue this and keep order. |
| 8224 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 8225 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 8226 | mCreatedLayers.clear(); |
| 8227 | update.newLayers = std::move(mNewLayers); |
| 8228 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8229 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 8230 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8231 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 8232 | mDestroyedHandles.clear(); |
| 8233 | } |
| 8234 | return update; |
| 8235 | } |
| 8236 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8237 | void SurfaceFlinger::addToLayerTracing(bool visibleRegionDirty, int64_t time, int64_t vsyncId) { |
| 8238 | const uint32_t tracingFlags = mLayerTracing.getFlags(); |
| 8239 | LayersProto layers(dumpDrawingStateProto(tracingFlags)); |
| 8240 | if (tracingFlags & LayerTracing::TRACE_EXTRA) { |
| 8241 | dumpOffscreenLayersProto(layers); |
| 8242 | } |
| 8243 | std::string hwcDump; |
| 8244 | if (tracingFlags & LayerTracing::TRACE_HWC) { |
| 8245 | dumpHwc(hwcDump); |
| 8246 | } |
| 8247 | auto displays = dumpDisplayProto(); |
| 8248 | mLayerTracing.notify(visibleRegionDirty, time, vsyncId, &layers, std::move(hwcDump), &displays); |
| 8249 | } |
| 8250 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8251 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8252 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8253 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 8254 | status_t status = checkAccessPermission(); |
| 8255 | if (status != OK) { |
| 8256 | return binderStatusFromStatusT(status); |
| 8257 | } |
| 8258 | mFlinger->bootFinished(); |
| 8259 | return binder::Status::ok(); |
| 8260 | } |
| 8261 | |
| 8262 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 8263 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8264 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8265 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8266 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8267 | if (conn == nullptr) { |
| 8268 | *outConnection = nullptr; |
| 8269 | return binderStatusFromStatusT(BAD_VALUE); |
| 8270 | } else { |
| 8271 | *outConnection = conn; |
| 8272 | return binder::Status::ok(); |
| 8273 | } |
| 8274 | } |
| 8275 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8276 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 8277 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8278 | if (client->initCheck() == NO_ERROR) { |
| 8279 | *outClient = client; |
| 8280 | return binder::Status::ok(); |
| 8281 | } else { |
| 8282 | *outClient = nullptr; |
| 8283 | return binderStatusFromStatusT(BAD_VALUE); |
| 8284 | } |
| 8285 | } |
| 8286 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8287 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8288 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8289 | sp<IBinder>* outDisplay) { |
| 8290 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8291 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8292 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8293 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8294 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8295 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8296 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 8300 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8301 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8302 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8303 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8304 | mFlinger->destroyDisplay(display); |
| 8305 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8306 | } |
| 8307 | |
| 8308 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 8309 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 8310 | std::vector<int64_t> displayIds; |
| 8311 | displayIds.reserve(physicalDisplayIds.size()); |
| 8312 | for (auto item : physicalDisplayIds) { |
| 8313 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 8314 | } |
| 8315 | *outDisplayIds = displayIds; |
| 8316 | return binder::Status::ok(); |
| 8317 | } |
| 8318 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8319 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 8320 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8321 | status_t status = checkAccessPermission(); |
| 8322 | if (status != OK) { |
| 8323 | return binderStatusFromStatusT(status); |
| 8324 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8325 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 8326 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 8327 | return binder::Status::ok(); |
| 8328 | } |
| 8329 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8330 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 8331 | status_t status = checkAccessPermission(); |
| 8332 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8333 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8334 | } |
| 8335 | mFlinger->setPowerMode(display, mode); |
| 8336 | return binder::Status::ok(); |
| 8337 | } |
| 8338 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8339 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 8340 | std::vector<FrameEvent>* outSupported) { |
| 8341 | status_t status; |
| 8342 | if (!outSupported) { |
| 8343 | status = UNEXPECTED_NULL; |
| 8344 | } else { |
| 8345 | outSupported->clear(); |
| 8346 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 8347 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8348 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8349 | } |
| 8350 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8351 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 8352 | gui::DisplayStatInfo* outStatInfo) { |
| 8353 | DisplayStatInfo statInfo; |
| 8354 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 8355 | if (status == NO_ERROR) { |
| 8356 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 8357 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 8358 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8359 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8360 | } |
| 8361 | |
| 8362 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 8363 | gui::DisplayState* outState) { |
| 8364 | ui::DisplayState state; |
| 8365 | status_t status = mFlinger->getDisplayState(display, &state); |
| 8366 | if (status == NO_ERROR) { |
| 8367 | outState->layerStack = state.layerStack.id; |
| 8368 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 8369 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 8370 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 8371 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8372 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8373 | } |
| 8374 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8375 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8376 | gui::StaticDisplayInfo* outInfo) { |
| 8377 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 8378 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8379 | |
| 8380 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8381 | if (status == NO_ERROR) { |
| 8382 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 8383 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 8384 | outInfo->density = info.density; |
| 8385 | outInfo->secure = info.secure; |
| 8386 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 8387 | |
| 8388 | gui::DeviceProductInfo dinfo; |
| 8389 | std::optional<DeviceProductInfo> dpi = info.deviceProductInfo; |
| 8390 | dinfo.name = std::move(dpi->name); |
| 8391 | dinfo.manufacturerPnpId = |
| 8392 | std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), dpi->manufacturerPnpId.end()); |
| 8393 | dinfo.productId = dpi->productId; |
Kriti Dang | 1de958d | 2022-05-30 15:26:58 +0200 | [diff] [blame] | 8394 | dinfo.relativeAddress = |
| 8395 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8396 | if (const auto* model = |
| 8397 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 8398 | gui::DeviceProductInfo::ModelYear modelYear; |
| 8399 | modelYear.year = model->year; |
| 8400 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 8401 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 8402 | &dpi->manufactureOrModelDate)) { |
| 8403 | gui::DeviceProductInfo::ManufactureYear date; |
| 8404 | date.modelYear.year = manufacture->year; |
| 8405 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 8406 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 8407 | &dpi->manufactureOrModelDate)) { |
| 8408 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 8409 | date.manufactureYear.modelYear.year = manufacture->year; |
| 8410 | date.week = manufacture->week; |
| 8411 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 8412 | } |
| 8413 | |
| 8414 | outInfo->deviceProductInfo = dinfo; |
| 8415 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8416 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8417 | } |
| 8418 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8419 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 8420 | gui::DynamicDisplayInfo*& outInfo) { |
| 8421 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 8422 | outInfo->supportedDisplayModes.clear(); |
| 8423 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 8424 | for (const auto& mode : info.supportedDisplayModes) { |
| 8425 | gui::DisplayMode outMode; |
| 8426 | outMode.id = mode.id; |
| 8427 | outMode.resolution.width = mode.resolution.width; |
| 8428 | outMode.resolution.height = mode.resolution.height; |
| 8429 | outMode.xDpi = mode.xDpi; |
| 8430 | outMode.yDpi = mode.yDpi; |
| 8431 | outMode.refreshRate = mode.refreshRate; |
| 8432 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 8433 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 8434 | outMode.presentationDeadline = mode.presentationDeadline; |
| 8435 | outMode.group = mode.group; |
| 8436 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 8437 | std::back_inserter(outMode.supportedHdrTypes), |
| 8438 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 8439 | outInfo->supportedDisplayModes.push_back(outMode); |
| 8440 | } |
| 8441 | |
| 8442 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 8443 | outInfo->renderFrameRate = info.renderFrameRate; |
| 8444 | |
| 8445 | outInfo->supportedColorModes.clear(); |
| 8446 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 8447 | for (const auto& cmode : info.supportedColorModes) { |
| 8448 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 8449 | } |
| 8450 | |
| 8451 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 8452 | |
| 8453 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 8454 | hdrCapabilities.supportedHdrTypes.clear(); |
| 8455 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 8456 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 8457 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 8458 | } |
| 8459 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 8460 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 8461 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 8462 | |
| 8463 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 8464 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 8465 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 8466 | } |
| 8467 | |
| 8468 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 8469 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8470 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8471 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8472 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8473 | getDynamicDisplayInfoInternal(info, outInfo); |
| 8474 | } |
| 8475 | return binderStatusFromStatusT(status); |
| 8476 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 8477 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8478 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 8479 | gui::DynamicDisplayInfo* outInfo) { |
| 8480 | ui::DynamicDisplayInfo info; |
| 8481 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 8482 | if (status == NO_ERROR) { |
| 8483 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8484 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8485 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8486 | } |
| 8487 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8488 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 8489 | gui::DisplayPrimaries* outPrimaries) { |
| 8490 | ui::DisplayPrimaries primaries; |
| 8491 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 8492 | if (status == NO_ERROR) { |
| 8493 | outPrimaries->red.X = primaries.red.X; |
| 8494 | outPrimaries->red.Y = primaries.red.Y; |
| 8495 | outPrimaries->red.Z = primaries.red.Z; |
| 8496 | |
| 8497 | outPrimaries->green.X = primaries.green.X; |
| 8498 | outPrimaries->green.Y = primaries.green.Y; |
| 8499 | outPrimaries->green.Z = primaries.green.Z; |
| 8500 | |
| 8501 | outPrimaries->blue.X = primaries.blue.X; |
| 8502 | outPrimaries->blue.Y = primaries.blue.Y; |
| 8503 | outPrimaries->blue.Z = primaries.blue.Z; |
| 8504 | |
| 8505 | outPrimaries->white.X = primaries.white.X; |
| 8506 | outPrimaries->white.Y = primaries.white.Y; |
| 8507 | outPrimaries->white.Z = primaries.white.Z; |
| 8508 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8509 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8510 | } |
| 8511 | |
| 8512 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 8513 | status_t status = checkAccessPermission(); |
| 8514 | if (status == OK) { |
| 8515 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 8516 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8517 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 8521 | int displayModeId) { |
| 8522 | status_t status = checkAccessPermission(); |
| 8523 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8524 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8525 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8526 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8527 | } |
| 8528 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8529 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 8530 | status_t status = checkAccessPermission(); |
| 8531 | if (status == OK) { |
| 8532 | status = mFlinger->clearBootDisplayMode(display); |
| 8533 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8534 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8535 | } |
| 8536 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 8537 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 8538 | status_t status = checkAccessPermission(); |
| 8539 | if (status == OK) { |
| 8540 | status = mFlinger->getOverlaySupport(outProperties); |
| 8541 | } |
| 8542 | return binderStatusFromStatusT(status); |
| 8543 | } |
| 8544 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8545 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 8546 | status_t status = checkAccessPermission(); |
| 8547 | if (status == OK) { |
| 8548 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 8549 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8550 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8551 | } |
| 8552 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8553 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 8554 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 8555 | status_t status = checkAccessPermission(); |
| 8556 | if (status == OK) { |
| 8557 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 8558 | } |
| 8559 | return binderStatusFromStatusT(status); |
| 8560 | } |
| 8561 | |
| 8562 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8563 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 8564 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8565 | status_t status = checkAccessPermission(); |
| 8566 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8567 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 8568 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8569 | } |
| 8570 | return binderStatusFromStatusT(status); |
| 8571 | } |
| 8572 | |
| 8573 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 8574 | status_t status = checkAccessPermission(); |
| 8575 | if (status == OK) { |
| 8576 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 8577 | } |
| 8578 | return binderStatusFromStatusT(status); |
| 8579 | } |
| 8580 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8581 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 8582 | status_t status = checkAccessPermission(); |
| 8583 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8584 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8585 | } |
| 8586 | mFlinger->setAutoLowLatencyMode(display, on); |
| 8587 | return binder::Status::ok(); |
| 8588 | } |
| 8589 | |
| 8590 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 8591 | status_t status = checkAccessPermission(); |
| 8592 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8593 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8594 | } |
| 8595 | mFlinger->setGameContentType(display, on); |
| 8596 | return binder::Status::ok(); |
| 8597 | } |
| 8598 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8599 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 8600 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 8601 | status_t status = mFlinger->captureDisplay(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8602 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8603 | } |
| 8604 | |
| 8605 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
| 8606 | int64_t displayId, const sp<IScreenCaptureListener>& captureListener) { |
| 8607 | status_t status; |
| 8608 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8609 | const int uid = ipc->getCallingUid(); |
| 8610 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 8611 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
| 8612 | status = mFlinger->captureDisplay(*id, captureListener); |
| 8613 | } else { |
| 8614 | status = PERMISSION_DENIED; |
| 8615 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8616 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8617 | } |
| 8618 | |
| 8619 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 8620 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 8621 | status_t status = mFlinger->captureLayers(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8622 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8623 | } |
| 8624 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8625 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 8626 | const std::vector<int32_t>& hdrTypes) { |
| 8627 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 8628 | // permission dynamically. Don't use the permission cache for this check. |
| 8629 | status_t status = checkAccessPermission(false); |
| 8630 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8631 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8632 | } |
| 8633 | |
| 8634 | std::vector<ui::Hdr> hdrTypesVector; |
| 8635 | for (int32_t i : hdrTypes) { |
| 8636 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 8637 | } |
| 8638 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8639 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8640 | } |
| 8641 | |
| 8642 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 8643 | status_t status; |
| 8644 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 8645 | if (uid != AID_SYSTEM) { |
| 8646 | status = PERMISSION_DENIED; |
| 8647 | } else { |
| 8648 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 8649 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8650 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8651 | } |
| 8652 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8653 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 8654 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8655 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8656 | } |
| 8657 | |
| 8658 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8659 | const int pid = ipc->getCallingPid(); |
| 8660 | const int uid = ipc->getCallingUid(); |
| 8661 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 8662 | 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] | 8663 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8664 | } |
| 8665 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8666 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | binder::Status SurfaceComposerAIDL::getColorManagement(bool* outGetColorManagement) { |
| 8670 | status_t status = mFlinger->getColorManagement(outGetColorManagement); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8671 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8672 | } |
| 8673 | |
| 8674 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 8675 | ui::Dataspace dataspace; |
| 8676 | ui::PixelFormat pixelFormat; |
| 8677 | ui::Dataspace wideColorGamutDataspace; |
| 8678 | ui::PixelFormat wideColorGamutPixelFormat; |
| 8679 | status_t status = |
| 8680 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 8681 | &wideColorGamutPixelFormat); |
| 8682 | if (status == NO_ERROR) { |
| 8683 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 8684 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 8685 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 8686 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 8687 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8688 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8689 | } |
| 8690 | |
| 8691 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 8692 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 8693 | status_t status = checkAccessPermission(); |
| 8694 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8695 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8696 | } |
| 8697 | |
| 8698 | ui::PixelFormat format; |
| 8699 | ui::Dataspace dataspace; |
| 8700 | uint8_t componentMask; |
| 8701 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 8702 | &componentMask); |
| 8703 | if (status == NO_ERROR) { |
| 8704 | outAttrs->format = static_cast<int32_t>(format); |
| 8705 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 8706 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 8707 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8708 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8709 | } |
| 8710 | |
| 8711 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 8712 | bool enable, |
| 8713 | int8_t componentMask, |
| 8714 | int64_t maxFrames) { |
| 8715 | status_t status = checkAccessPermission(); |
| 8716 | if (status == OK) { |
| 8717 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 8718 | static_cast<uint8_t>(componentMask), |
| 8719 | static_cast<uint64_t>(maxFrames)); |
| 8720 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8721 | return binderStatusFromStatusT(status); |
| 8722 | } |
| 8723 | |
| 8724 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 8725 | int64_t maxFrames, int64_t timestamp, |
| 8726 | gui::DisplayedFrameStats* outStats) { |
| 8727 | if (!outStats) { |
| 8728 | return binderStatusFromStatusT(BAD_VALUE); |
| 8729 | } |
| 8730 | |
| 8731 | status_t status = checkAccessPermission(); |
| 8732 | if (status != OK) { |
| 8733 | return binderStatusFromStatusT(status); |
| 8734 | } |
| 8735 | |
| 8736 | DisplayedFrameStats stats; |
| 8737 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 8738 | static_cast<uint64_t>(timestamp), &stats); |
| 8739 | if (status == NO_ERROR) { |
| 8740 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 8741 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 8742 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 8743 | for (const auto& s : stats.component_0_sample) { |
| 8744 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 8745 | } |
| 8746 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 8747 | for (const auto& s : stats.component_1_sample) { |
| 8748 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 8749 | } |
| 8750 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 8751 | for (const auto& s : stats.component_2_sample) { |
| 8752 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 8753 | } |
| 8754 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 8755 | for (const auto& s : stats.component_3_sample) { |
| 8756 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 8757 | } |
| 8758 | } |
| 8759 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8760 | } |
| 8761 | |
| 8762 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 8763 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8764 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8765 | } |
| 8766 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8767 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 8768 | bool* outIsWideColorDisplay) { |
| 8769 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8770 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8771 | } |
| 8772 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8773 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 8774 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 8775 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8776 | status_t status = checkReadFrameBufferPermission(); |
| 8777 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8778 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8779 | } |
| 8780 | android::Rect rect; |
| 8781 | rect.left = samplingArea.left; |
| 8782 | rect.top = samplingArea.top; |
| 8783 | rect.right = samplingArea.right; |
| 8784 | rect.bottom = samplingArea.bottom; |
| 8785 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8786 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8787 | } |
| 8788 | |
| 8789 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 8790 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8791 | status_t status = checkReadFrameBufferPermission(); |
| 8792 | if (status == OK) { |
| 8793 | status = mFlinger->removeRegionSamplingListener(listener); |
| 8794 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8795 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8796 | } |
| 8797 | |
| 8798 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 8799 | const sp<gui::IFpsListener>& listener) { |
| 8800 | status_t status = checkReadFrameBufferPermission(); |
| 8801 | if (status == OK) { |
| 8802 | status = mFlinger->addFpsListener(taskId, listener); |
| 8803 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8804 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 8808 | status_t status = checkReadFrameBufferPermission(); |
| 8809 | if (status == OK) { |
| 8810 | status = mFlinger->removeFpsListener(listener); |
| 8811 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8812 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8813 | } |
| 8814 | |
| 8815 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 8816 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8817 | status_t status = checkAccessPermission(); |
| 8818 | if (status == OK) { |
| 8819 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 8820 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8821 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8822 | } |
| 8823 | |
| 8824 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 8825 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8826 | status_t status = checkAccessPermission(); |
| 8827 | if (status == OK) { |
| 8828 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 8829 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8830 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8831 | } |
| 8832 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8833 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8834 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8835 | status_t status = checkAccessPermission(); |
| 8836 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8837 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8838 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8839 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8840 | } |
| 8841 | |
| 8842 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8843 | gui::DisplayModeSpecs* outSpecs) { |
| 8844 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8845 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8846 | } |
| 8847 | |
| 8848 | status_t status = checkAccessPermission(); |
| 8849 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8850 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8851 | } |
| 8852 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8853 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8854 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8855 | } |
| 8856 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8857 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 8858 | bool* outSupport) { |
| 8859 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8860 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8861 | } |
| 8862 | |
| 8863 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 8864 | const gui::DisplayBrightness& brightness) { |
| 8865 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8866 | if (status == OK) { |
| 8867 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 8868 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8869 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8870 | } |
| 8871 | |
| 8872 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 8873 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 8874 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8875 | if (status == OK) { |
| 8876 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 8877 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8878 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 8882 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 8883 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8884 | if (status == OK) { |
| 8885 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 8886 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8887 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8888 | } |
| 8889 | |
| 8890 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 8891 | status_t status = checkAccessPermission(); |
| 8892 | if (status == OK) { |
| 8893 | status = mFlinger->notifyPowerBoost(boostId); |
| 8894 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8895 | return binderStatusFromStatusT(status); |
| 8896 | } |
| 8897 | |
| 8898 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 8899 | const gui::Color& spotColor, |
| 8900 | float lightPosY, float lightPosZ, |
| 8901 | float lightRadius) { |
| 8902 | status_t status = checkAccessPermission(); |
| 8903 | if (status != OK) { |
| 8904 | return binderStatusFromStatusT(status); |
| 8905 | } |
| 8906 | |
| 8907 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 8908 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 8909 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 8910 | lightPosZ, lightRadius); |
| 8911 | return binderStatusFromStatusT(status); |
| 8912 | } |
| 8913 | |
| 8914 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 8915 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 8916 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 8917 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 8918 | if (status != NO_ERROR) { |
| 8919 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 8920 | return binderStatusFromStatusT(status); |
| 8921 | } |
| 8922 | |
| 8923 | if (!support || !support.has_value()) { |
| 8924 | outSupport->reset(); |
| 8925 | } else { |
| 8926 | outSupport->emplace(); |
| 8927 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 8928 | outSupport->value().alphaInterpretation = |
| 8929 | static_cast<int32_t>(support->alphaInterpretation); |
| 8930 | } |
| 8931 | |
| 8932 | return binder::Status::ok(); |
| 8933 | } |
| 8934 | |
| 8935 | binder::Status SurfaceComposerAIDL::setOverrideFrameRate(int32_t uid, float frameRate) { |
| 8936 | status_t status; |
| 8937 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 8938 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 8939 | status = mFlinger->setOverrideFrameRate(uid, frameRate); |
| 8940 | } else { |
| 8941 | ALOGE("setOverrideFrameRate() permission denied for uid: %d", c_uid); |
| 8942 | status = PERMISSION_DENIED; |
| 8943 | } |
| 8944 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8945 | } |
| 8946 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8947 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 8948 | *outPriority = mFlinger->getGpuContextPriority(); |
| 8949 | return binder::Status::ok(); |
| 8950 | } |
| 8951 | |
| 8952 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 8953 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8954 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8955 | } |
| 8956 | |
| 8957 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
| 8958 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 8959 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8960 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8961 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8962 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 8963 | // WindowInfosListeners |
| 8964 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 8965 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8966 | status = mFlinger->addWindowInfosListener(windowInfosListener); |
| 8967 | } else { |
| 8968 | status = PERMISSION_DENIED; |
| 8969 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8970 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8971 | } |
| 8972 | |
| 8973 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 8974 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 8975 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8976 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8977 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8978 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 8979 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8980 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 8981 | } else { |
| 8982 | status = PERMISSION_DENIED; |
| 8983 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8984 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8985 | } |
| 8986 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8987 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 8988 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 8989 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8990 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 8991 | ipc->getCallingUid()); |
| 8992 | return PERMISSION_DENIED; |
| 8993 | } |
| 8994 | return OK; |
| 8995 | } |
| 8996 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8997 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 8998 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8999 | const int pid = ipc->getCallingPid(); |
| 9000 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 9001 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9002 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 9003 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 9004 | return PERMISSION_DENIED; |
| 9005 | } |
| 9006 | return OK; |
| 9007 | } |
| 9008 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9009 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 9010 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9011 | const int pid = ipc->getCallingPid(); |
| 9012 | const int uid = ipc->getCallingUid(); |
| 9013 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 9014 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 9015 | return PERMISSION_DENIED; |
| 9016 | } |
| 9017 | return OK; |
| 9018 | } |
| 9019 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 9020 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 9021 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 9022 | } |
| 9023 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 9024 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 9025 | for (const auto& [_, display] : mDisplays) { |
| 9026 | if (display->getLayerStack() == layerStack) { |
| 9027 | return display.get(); |
| 9028 | } |
| 9029 | } |
| 9030 | return nullptr; |
| 9031 | } |
| 9032 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 9033 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 9034 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 9035 | #if defined(__gl_h_) |
| 9036 | #error "don't include gl/gl.h in this file" |
| 9037 | #endif |
| 9038 | |
| 9039 | #if defined(__gl2_h_) |
| 9040 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 9041 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 9042 | |
| 9043 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 9044 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |