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 | |
| 481 | // Power hint session mode, representing which hint(s) to send: early, late, or both) |
| 482 | mPowerHintSessionMode = |
| 483 | {.late = base::GetBoolProperty("debug.sf.send_late_power_session_hint"s, true), |
Matt Buckley | 58a3645 | 2022-07-20 20:53:32 +0000 | [diff] [blame] | 484 | .early = base::GetBoolProperty("debug.sf.send_early_power_session_hint"s, false)}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 485 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | 593b4cb | 2023-03-02 16:16:33 -0800 | [diff] [blame] | 486 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, false); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 487 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
Vishnu Nair | 3e76a50 | 2023-03-05 20:01:14 +0000 | [diff] [blame] | 488 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 492 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 493 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 494 | } |
| 495 | |
Ady Abraham | fb67be1 | 2022-08-10 10:46:22 -0700 | [diff] [blame] | 496 | if (base::GetBoolProperty("debug.sf.latch_unsignaled"s, false)) { |
| 497 | return LatchUnsignaledConfig::Always; |
| 498 | } |
| 499 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 500 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 503 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 504 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 505 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 506 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 507 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 508 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 509 | // Sever the link to inputflinger since it's gone as well. |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 510 | static_cast<void>(mScheduler->schedule( |
Ady Abraham | 8101553 | 2022-08-02 16:27:53 +0000 | [diff] [blame] | 511 | [this] { mInputFlinger.clear(); })); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 512 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 513 | // restore initial conditions (default device unblank, etc) |
| 514 | initializeDisplays(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 515 | |
| 516 | // restart the boot-animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 517 | startBootAnim(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 520 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 521 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 524 | sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure, |
| 525 | float requestedRefreshRate) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 526 | // onTransact already checks for some permissions, but adding an additional check here. |
| 527 | // This is to ensure that only system and graphics can request to create a secure |
| 528 | // display. Secure displays can show secure content so we add an additional restriction on it. |
| 529 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 530 | if (secure && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
| 531 | ALOGE("Only privileged processes can create a secure display"); |
| 532 | return nullptr; |
| 533 | } |
| 534 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 535 | class DisplayToken : public BBinder { |
| 536 | sp<SurfaceFlinger> flinger; |
| 537 | virtual ~DisplayToken() { |
| 538 | // no more references, this display must be terminated |
| 539 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 540 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 541 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 542 | } |
| 543 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 544 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 545 | : flinger(flinger) { |
| 546 | } |
| 547 | }; |
| 548 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 549 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 550 | |
| 551 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 552 | // Display ID is assigned when virtual display is allocated by HWC. |
| 553 | DisplayDeviceState state; |
| 554 | state.isSecure = secure; |
| 555 | state.displayName = displayName; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 556 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 557 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 558 | return token; |
| 559 | } |
| 560 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 561 | void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 562 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 563 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 564 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 565 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 566 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 567 | return; |
| 568 | } |
| 569 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 570 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 571 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 572 | ALOGE("%s: Invalid operation on physical display", __func__); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 573 | return; |
| 574 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 575 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 576 | setTransactionFlags(eDisplayTransactionNeeded); |
| 577 | } |
| 578 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 579 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 580 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 581 | if (!generator && enable) { |
| 582 | ALOGI("Enabling HAL virtual displays"); |
| 583 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 584 | } else if (generator && !enable) { |
| 585 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 586 | generator.reset(); |
| 587 | } |
| 588 | } |
| 589 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 590 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 591 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 592 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 593 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 594 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 595 | return *id; |
| 596 | } |
| 597 | |
| 598 | generator->releaseId(*id); |
| 599 | } else { |
| 600 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 601 | } |
| 602 | |
| 603 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 604 | } |
| 605 | |
| 606 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 607 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 608 | return *id; |
| 609 | } |
| 610 | |
| 611 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 612 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 613 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 614 | generator->releaseId(*id); |
| 615 | } |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 620 | LOG_ALWAYS_FATAL_IF(!id); |
| 621 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 622 | } |
| 623 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 624 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 625 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 626 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 627 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 628 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 629 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 630 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 631 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 632 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 633 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 634 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 635 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 636 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 637 | return displayIds; |
| 638 | } |
| 639 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 640 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 641 | const sp<display::DisplayToken>& displayToken) const { |
| 642 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 643 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 644 | } |
| 645 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 646 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 647 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 648 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 651 | status_t SurfaceFlinger::getColorManagement(bool* outGetColorManagement) const { |
| 652 | if (!outGetColorManagement) { |
| 653 | return BAD_VALUE; |
| 654 | } |
| 655 | *outGetColorManagement = useColorManagement; |
| 656 | return NO_ERROR; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 659 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 660 | return mCompositionEngine->getHwComposer(); |
| 661 | } |
| 662 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 663 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 664 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 667 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 668 | return *mCompositionEngine.get(); |
| 669 | } |
| 670 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 671 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 672 | if (mBootFinished == true) { |
| 673 | ALOGE("Extra call to bootFinished"); |
| 674 | return; |
| 675 | } |
| 676 | mBootFinished = true; |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 677 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 678 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 679 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 680 | |
| 681 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 682 | mRenderEnginePrimeCacheFuture.get(); |
| 683 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | const nsecs_t now = systemTime(); |
| 685 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 686 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 687 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 688 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 689 | mFrameTimeline->onBootFinished(); |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 690 | getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 691 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 692 | // wait patiently for the window manager death |
| 693 | const String16 name("window"); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 694 | mWindowManager = defaultServiceManager()->getService(name); |
| 695 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 696 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 700 | // formerly we would just kill the process, but we now ask it to exit so it |
| 701 | // can choose where to stop the animation. |
| 702 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 703 | |
| 704 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 705 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 706 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 707 | |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 708 | sp<IBinder> input(defaultServiceManager()->getService(String16("inputflinger"))); |
| 709 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 710 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 711 | if (input == nullptr) { |
| 712 | ALOGE("Failed to link to input service"); |
| 713 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 714 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 715 | } |
| 716 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 717 | readPersistentProperties(); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 718 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 719 | const bool powerHintEnabled = mFlagManager.use_adpf_cpu_hint(); |
| 720 | mPowerAdvisor->enablePowerHint(powerHintEnabled); |
| 721 | const bool powerHintUsed = mPowerAdvisor->usePowerHintSession(); |
| 722 | ALOGD("Power hint is %s", |
| 723 | powerHintUsed ? "supported" : (powerHintEnabled ? "unsupported" : "disabled")); |
| 724 | if (powerHintUsed) { |
| 725 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 726 | std::vector<int32_t> tidList; |
| 727 | tidList.emplace_back(gettid()); |
| 728 | if (renderEngineTid.has_value()) { |
| 729 | tidList.emplace_back(*renderEngineTid); |
| 730 | } |
| 731 | if (!mPowerAdvisor->startPowerHintSession(tidList)) { |
| 732 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 733 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 736 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 737 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 738 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 739 | ftl::FakeGuard guard(mStateLock); |
| 740 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 741 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 742 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 745 | uint32_t SurfaceFlinger::getNewTexture() { |
| 746 | { |
| 747 | std::lock_guard lock(mTexturePoolMutex); |
| 748 | if (!mTexturePool.empty()) { |
| 749 | uint32_t name = mTexturePool.back(); |
| 750 | mTexturePool.pop_back(); |
| 751 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
| 752 | return name; |
| 753 | } |
| 754 | |
| 755 | // The pool was too small, so increase it for the future |
| 756 | ++mTexturePoolSize; |
| 757 | } |
| 758 | |
| 759 | // The pool was empty, so we need to get a new texture name directly using a |
| 760 | // blocking call to the main thread |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 761 | auto genTextures = [this] { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 762 | uint32_t name = 0; |
| 763 | getRenderEngine().genTextures(1, &name); |
| 764 | return name; |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 765 | }; |
| 766 | if (std::this_thread::get_id() == mMainThreadId) { |
| 767 | return genTextures(); |
| 768 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 769 | return mScheduler->schedule(genTextures).get(); |
Robert Carr | cdd7df9 | 2021-04-12 15:32:09 -0700 | [diff] [blame] | 770 | } |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 773 | void SurfaceFlinger::deleteTextureAsync(uint32_t texture) { |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 774 | std::lock_guard lock(mTexturePoolMutex); |
| 775 | // We don't change the pool size, so the fix-up logic in postComposition will decide whether |
| 776 | // to actually delete this or not based on mTexturePoolSize |
| 777 | mTexturePool.push_back(texture); |
| 778 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 781 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 782 | chooseRenderEngineTypeViaSysProp() { |
| 783 | char prop[PROPERTY_VALUE_MAX]; |
| 784 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
| 785 | |
| 786 | if (strcmp(prop, "gles") == 0) { |
| 787 | return renderengine::RenderEngine::RenderEngineType::GLES; |
| 788 | } else if (strcmp(prop, "threaded") == 0) { |
| 789 | return renderengine::RenderEngine::RenderEngineType::THREADED; |
| 790 | } else if (strcmp(prop, "skiagl") == 0) { |
| 791 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 792 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 793 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 794 | } else if (strcmp(prop, "skiavk") == 0) { |
| 795 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 796 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
| 797 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK_THREADED; |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 798 | } else { |
| 799 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 800 | return {}; |
| 801 | } |
| 802 | } |
| 803 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 804 | // Do not call property_set on main thread which will be blocked by init |
| 805 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 806 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 807 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 808 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 809 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 810 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 811 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 812 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 813 | // 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] | 814 | // 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] | 815 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 816 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 817 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
| 818 | .setUseColorManagerment(useColorManagement) |
| 819 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 820 | .setPrecacheToneMapperShaderOnly(false) |
| 821 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 822 | .setContextPriority( |
| 823 | useContextPriority |
| 824 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 825 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
| 826 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 827 | builder.setRenderEngineType(type.value()); |
| 828 | } |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 829 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 830 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 831 | mMaxRenderTargetSize = |
| 832 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 833 | |
| 834 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 835 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 836 | ALOGW("Failed to set main task profile"); |
| 837 | } |
| 838 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 839 | mCompositionEngine->setTimeStats(mTimeStats); |
Dominik Laskowski | f06d68e | 2021-03-24 19:40:03 -0700 | [diff] [blame] | 840 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 841 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 842 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 843 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 844 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 845 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 846 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 847 | enableHalVirtualDisplays(true); |
| 848 | } |
| 849 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 850 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 851 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 852 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 853 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 854 | // Commit primary display. |
| 855 | sp<const DisplayDevice> display; |
| 856 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 857 | const auto& displays = mCurrentState.displays; |
| 858 | |
| 859 | const auto& token = displays.keyAt(*indexOpt); |
| 860 | const auto& state = displays.valueAt(*indexOpt); |
| 861 | |
| 862 | processDisplayAdded(token, state); |
| 863 | mDrawingState.displays.add(token, state); |
| 864 | |
| 865 | display = getDefaultDisplayDeviceLocked(); |
| 866 | } |
| 867 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 868 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 869 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 870 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 871 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 872 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 873 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 874 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 875 | initScheduler(display); |
| 876 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
| 877 | |
| 878 | // Commit secondary display(s). |
| 879 | processDisplayChangesLocked(); |
| 880 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 881 | // initialize our drawing state |
| 882 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 883 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 884 | onActiveDisplayChangedLocked(nullptr, *display); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 885 | initializeDisplays(); |
| 886 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 887 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 888 | |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 889 | char primeShaderCache[PROPERTY_VALUE_MAX]; |
| 890 | property_get("service.sf.prime_shader_cache", primeShaderCache, "1"); |
| 891 | if (atoi(primeShaderCache)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 892 | if (setSchedFifo(false) != NO_ERROR) { |
| 893 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 894 | } |
| 895 | |
| 896 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(); |
| 897 | |
| 898 | if (setSchedFifo(true) != NO_ERROR) { |
| 899 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 900 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 901 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 902 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 903 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 904 | |
| 905 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 906 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 907 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 908 | |
| 909 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 910 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 911 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 913 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 916 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 917 | Mutex::Autolock _l(mStateLock); |
| 918 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 919 | char value[PROPERTY_VALUE_MAX]; |
| 920 | |
| 921 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 922 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 923 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 924 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 925 | |
| 926 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 927 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 928 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 929 | mForceColorMode = |
| 930 | 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] | 931 | } |
| 932 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 933 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 934 | // Start boot animation service by setting a property mailbox |
| 935 | // 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] | 936 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 937 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 938 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 939 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 940 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 941 | } |
| 942 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 944 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 945 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 946 | std::vector<FrameEvent>* outSupported) const { |
| 947 | *outSupported = { |
| 948 | FrameEvent::REQUESTED_PRESENT, |
| 949 | FrameEvent::ACQUIRE, |
| 950 | FrameEvent::LATCH, |
| 951 | FrameEvent::FIRST_REFRESH_START, |
| 952 | FrameEvent::LAST_REFRESH_START, |
| 953 | FrameEvent::GPU_COMPOSITION_DONE, |
| 954 | FrameEvent::DEQUEUE_READY, |
| 955 | FrameEvent::RELEASE, |
| 956 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 957 | |
| 958 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 959 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 960 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 961 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 962 | } |
| 963 | return NO_ERROR; |
| 964 | } |
| 965 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 966 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 967 | if (!displayToken || !state) { |
| 968 | return BAD_VALUE; |
| 969 | } |
| 970 | |
| 971 | Mutex::Autolock lock(mStateLock); |
| 972 | |
| 973 | const auto display = getDisplayDeviceLocked(displayToken); |
| 974 | if (!display) { |
| 975 | return NAME_NOT_FOUND; |
| 976 | } |
| 977 | |
| 978 | state->layerStack = display->getLayerStack(); |
| 979 | state->orientation = display->getOrientation(); |
| 980 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 981 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 982 | state->layerStackSpaceRect = |
| 983 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 984 | |
| 985 | return NO_ERROR; |
| 986 | } |
| 987 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 988 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 989 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 990 | return BAD_VALUE; |
| 991 | } |
| 992 | |
| 993 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 994 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 995 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 996 | |
| 997 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 998 | return NAME_NOT_FOUND; |
| 999 | } |
| 1000 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1001 | const auto& [display, snapshotRef] = *displayOpt; |
| 1002 | const auto& snapshot = snapshotRef.get(); |
| 1003 | |
| 1004 | info->connectionType = snapshot.connectionType(); |
| 1005 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1006 | |
| 1007 | if (mEmulatedDisplayDensity) { |
| 1008 | info->density = mEmulatedDisplayDensity; |
| 1009 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1010 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1011 | ? mInternalDisplayDensity |
| 1012 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1013 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1014 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1015 | |
| 1016 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1017 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1018 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1019 | return NO_ERROR; |
| 1020 | } |
| 1021 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1022 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1023 | const sp<DisplayDevice>& display, |
| 1024 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1025 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1026 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1027 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1028 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1029 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1030 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1031 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1032 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1033 | auto [width, height] = mode->getResolution(); |
| 1034 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1035 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1036 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1037 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1038 | std::swap(width, height); |
| 1039 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1042 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1043 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1044 | outMode.xDpi = xDpi; |
| 1045 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1046 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1047 | const nsecs_t period = mode->getVsyncPeriod(); |
| 1048 | outMode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1049 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 1050 | const auto vsyncConfigSet = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1051 | mVsyncConfiguration->getConfigsForRefreshRate(Fps::fromValue(outMode.refreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1052 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1053 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1054 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1055 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1056 | // This is how far in advance a buffer must be queued for |
| 1057 | // presentation at a given time. If you want a buffer to appear |
| 1058 | // on the screen at time N, you must submit the buffer before |
| 1059 | // (N - presentationDeadline). |
| 1060 | // |
| 1061 | // Normally it's one full refresh period (to give SF a chance to |
| 1062 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1063 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1064 | // composer or panel must be accounted for here. |
| 1065 | // |
| 1066 | // We add an additional 1ms to allow for processing time and |
| 1067 | // differences between the ideal and actual refresh rate. |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1068 | outMode.presentationDeadline = period - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1069 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1070 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1071 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1074 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
| 1075 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1076 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1077 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1078 | const auto mode = display->refreshRateSelector().getActiveMode(); |
| 1079 | info->activeDisplayModeId = mode.modePtr->getId().value(); |
| 1080 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1081 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1082 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1083 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1084 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1085 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1086 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1087 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1088 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1089 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1090 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1091 | |
| 1092 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1093 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1094 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1095 | info->preferredBootDisplayMode = modeId->value(); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1099 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1100 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1101 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1102 | ui::DynamicDisplayInfo* info) { |
| 1103 | if (!info) { |
| 1104 | return BAD_VALUE; |
| 1105 | } |
| 1106 | |
| 1107 | Mutex::Autolock lock(mStateLock); |
| 1108 | |
| 1109 | const auto id_ = |
| 1110 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1111 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1112 | |
| 1113 | if (!displayOpt) { |
| 1114 | return NAME_NOT_FOUND; |
| 1115 | } |
| 1116 | |
| 1117 | const auto& [display, snapshotRef] = *displayOpt; |
| 1118 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1119 | return NO_ERROR; |
| 1120 | } |
| 1121 | |
| 1122 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1123 | ui::DynamicDisplayInfo* info) { |
| 1124 | if (!displayToken || !info) { |
| 1125 | return BAD_VALUE; |
| 1126 | } |
| 1127 | |
| 1128 | Mutex::Autolock lock(mStateLock); |
| 1129 | |
| 1130 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1131 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1132 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1133 | |
| 1134 | if (!displayOpt) { |
| 1135 | return NAME_NOT_FOUND; |
| 1136 | } |
| 1137 | |
| 1138 | const auto& [display, snapshotRef] = *displayOpt; |
| 1139 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1140 | return NO_ERROR; |
| 1141 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1142 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1143 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1144 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1145 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1146 | return BAD_VALUE; |
| 1147 | } |
| 1148 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1149 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1150 | { |
| 1151 | Mutex::Autolock lock(mStateLock); |
| 1152 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1153 | } |
| 1154 | |
| 1155 | if (!displayIdOpt) { |
| 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 | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2149 | auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2150 | -> const FenceTimePtr& { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2151 | const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2152 | const size_t i = static_cast<size_t>(isTwoVsyncsAhead); |
| 2153 | return mPreviousPresentFences[i].fenceTime; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2156 | bool SurfaceFlinger::isFencePending(const FenceTimePtr& fence, int graceTimeMs) { |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2157 | ATRACE_CALL(); |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 2158 | if (fence == FenceTime::NO_FENCE) { |
Ady Abraham | 1157930 | 2019-09-19 12:35:58 -0700 | [diff] [blame] | 2159 | return false; |
| 2160 | } |
| 2161 | |
Dan Stoza | 5908305 | 2020-04-28 10:13:20 -0700 | [diff] [blame] | 2162 | const status_t status = fence->wait(graceTimeMs); |
| 2163 | // This is the same as Fence::Status::Unsignaled, but it saves a getStatus() call, |
| 2164 | // which calls wait(0) again internally |
| 2165 | return status == -ETIME; |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2168 | TimePoint SurfaceFlinger::calculateExpectedPresentTime(TimePoint frameTime) const { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2169 | const auto& schedule = mScheduler->getVsyncSchedule(); |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2170 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2171 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(frameTime); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 2172 | if (mScheduler->vsyncModulator().getVsyncConfig().sfOffset > 0) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2173 | return vsyncDeadline; |
Alec Mouri | 6d414b5 | 2020-03-17 11:18:05 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2176 | // 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] | 2177 | return vsyncDeadline + schedule->period(); |
Alec Mouri | aa61419 | 2019-06-06 13:28:34 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2180 | void SurfaceFlinger::configure() FTL_FAKE_GUARD(kMainThreadContext) { |
| 2181 | Mutex::Autolock lock(mStateLock); |
| 2182 | if (configureLocked()) { |
| 2183 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2184 | } |
| 2185 | } |
| 2186 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2187 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, frontend::Update& update, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2188 | bool transactionsFlushed, |
| 2189 | bool& outTransactionsAreEmpty) { |
| 2190 | bool needsTraversal = false; |
| 2191 | if (transactionsFlushed) { |
| 2192 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2193 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2194 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2195 | } |
| 2196 | outTransactionsAreEmpty = !needsTraversal; |
| 2197 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2198 | if (shouldCommit) { |
| 2199 | commitTransactions(); |
| 2200 | } |
| 2201 | |
| 2202 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2203 | updateLayerGeometry(); |
| 2204 | return mustComposite; |
| 2205 | } |
| 2206 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2207 | void SurfaceFlinger::updateLayerHistory(const frontend::LayerSnapshot& snapshot) { |
| 2208 | using Changes = frontend::RequestedLayerState::Changes; |
| 2209 | if (snapshot.path.isClone() || |
| 2210 | !snapshot.changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation)) { |
| 2211 | return; |
| 2212 | } |
| 2213 | |
| 2214 | const auto layerProps = scheduler::LayerProps{ |
| 2215 | .visible = snapshot.isVisible, |
| 2216 | .bounds = snapshot.geomLayerBounds, |
| 2217 | .transform = snapshot.geomLayerTransform, |
| 2218 | .setFrameRateVote = snapshot.frameRate, |
| 2219 | .frameRateSelectionPriority = snapshot.frameRateSelectionPriority, |
| 2220 | }; |
| 2221 | |
| 2222 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 2223 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 2224 | snapshot.getDebugString().c_str()); |
| 2225 | |
| 2226 | if (snapshot.changes.test(Changes::Animation)) { |
| 2227 | it->second->recordLayerHistoryAnimationTx(layerProps); |
| 2228 | } |
| 2229 | |
| 2230 | if (snapshot.changes.test(Changes::FrameRate)) { |
| 2231 | it->second->setFrameRateForLayerTree(snapshot.frameRate, layerProps); |
| 2232 | } |
| 2233 | |
| 2234 | if (snapshot.changes.test(Changes::Buffer)) { |
| 2235 | it->second->recordLayerHistoryBufferUpdate(layerProps); |
| 2236 | } |
| 2237 | } |
| 2238 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2239 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, frontend::Update& update, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2240 | bool transactionsFlushed, bool& outTransactionsAreEmpty) { |
| 2241 | using Changes = frontend::RequestedLayerState::Changes; |
| 2242 | ATRACE_NAME("updateLayerSnapshots"); |
| 2243 | { |
| 2244 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
| 2245 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2246 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2247 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2248 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2249 | if (layer) { |
| 2250 | mLegacyLayers[layer->sequence] = layer; |
| 2251 | } |
| 2252 | } |
| 2253 | } |
| 2254 | if (mLayerLifecycleManager.getGlobalChanges().test(Changes::Hierarchy)) { |
| 2255 | ATRACE_NAME("LayerHierarchyBuilder:update"); |
| 2256 | mLayerHierarchyBuilder.update(mLayerLifecycleManager.getLayers(), |
| 2257 | mLayerLifecycleManager.getDestroyedLayers()); |
| 2258 | } |
| 2259 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2260 | bool mustComposite = false; |
| 2261 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2262 | |
| 2263 | { |
| 2264 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2265 | frontend::LayerSnapshotBuilder::Args |
| 2266 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2267 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2268 | .displays = mFrontEndDisplayInfos, |
| 2269 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2270 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
| 2271 | .supportsBlur = mSupportsBlur, |
| 2272 | .forceFullDamage = mForceFullDamage, |
| 2273 | .supportedLayerGenericMetadata = |
| 2274 | getHwComposer().getSupportedLayerGenericMetadata(), |
| 2275 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2276 | mLayerSnapshotBuilder.update(args); |
| 2277 | } |
| 2278 | |
| 2279 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2280 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2281 | mUpdateInputInfo = true; |
| 2282 | } |
| 2283 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
| 2284 | Changes::Visibility)) { |
| 2285 | mVisibleRegionsDirty = true; |
| 2286 | } |
| 2287 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2288 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2289 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2290 | bool newDataLatched = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2291 | if (!mLegacyFrontEndEnabled) { |
| 2292 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
| 2293 | applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2294 | const nsecs_t latchTime = systemTime(); |
| 2295 | bool unused = false; |
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 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2298 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2299 | layer->bgColorLayer) { |
| 2300 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2301 | LayerCreationArgs(this, nullptr, layer->name, |
| 2302 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
| 2303 | std::make_optional(layer->parentId), true)); |
| 2304 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2305 | } |
| 2306 | if (!layer->hasReadyFrame()) continue; |
| 2307 | |
| 2308 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2309 | 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] | 2310 | layer->getDebugString().c_str()); |
| 2311 | const bool bgColorOnly = |
| 2312 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 2313 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2314 | mLayersWithQueuedFrames.emplace(it->second); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | for (auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2318 | updateLayerHistory(*snapshot); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2319 | if (!snapshot->hasReadyFrame) continue; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2320 | newDataLatched = true; |
| 2321 | if (!snapshot->isVisible) break; |
| 2322 | |
| 2323 | Region visibleReg; |
| 2324 | visibleReg.set(snapshot->transformedBoundsWithoutTransparentRegion); |
| 2325 | invalidateLayerStack(snapshot->outputFilter, visibleReg); |
| 2326 | } |
| 2327 | |
| 2328 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2329 | mLegacyLayers.erase(destroyedLayer->id); |
| 2330 | } |
| 2331 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2332 | { |
| 2333 | ATRACE_NAME("LLM:commitChanges"); |
| 2334 | mLayerLifecycleManager.commitChanges(); |
| 2335 | } |
| 2336 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 2337 | commitTransactions(); |
| 2338 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2339 | // enter boot animation on first buffer latch |
| 2340 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2341 | ALOGI("Enter boot animation"); |
| 2342 | mBootStage = BootStage::BOOTANIMATION; |
| 2343 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2344 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2345 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2346 | return mustComposite; |
| 2347 | } |
| 2348 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2349 | bool SurfaceFlinger::commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2350 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2351 | // The expectedVsyncTime, which was predicted when this frame was scheduled, is normally in the |
| 2352 | // future relative to frameTime, but may not be for delayed frames. Adjust mExpectedPresentTime |
| 2353 | // accordingly, but not mScheduledPresentTime. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2354 | const TimePoint lastScheduledPresentTime = mScheduledPresentTime; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2355 | mScheduledPresentTime = expectedVsyncTime; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2356 | |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2357 | // Calculate the expected present time once and use the cached value throughout this frame to |
| 2358 | // make sure all layers are seeing this same value. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2359 | mExpectedPresentTime = expectedVsyncTime >= frameTime ? expectedVsyncTime |
| 2360 | : calculateExpectedPresentTime(frameTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2361 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2362 | ATRACE_FORMAT("%s %" PRId64 " vsyncIn %.2fms%s", __func__, vsyncId.value, |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2363 | ticks<std::milli, float>(mExpectedPresentTime - TimePoint::now()), |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2364 | mExpectedPresentTime == expectedVsyncTime ? "" : " (adjusted)"); |
Ady Abraham | 893c99d | 2021-04-30 16:00:23 -0700 | [diff] [blame] | 2365 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2366 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2367 | const FenceTimePtr& previousPresentFence = getPreviousPresentFence(frameTime, vsyncPeriod); |
| 2368 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2369 | // 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] | 2370 | // for the present fence to fire instead of just giving up on this frame to handle cases |
| 2371 | // where present fence is just about to get signaled. |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2372 | const int graceTimeForPresentFenceMs = static_cast<int>( |
| 2373 | mBackpressureGpuComposition || !mCompositionCoverage.test(CompositionCoverage::Gpu)); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2374 | |
| 2375 | // Pending frames may trigger backpressure propagation. |
| 2376 | const TracedOrdinal<bool> framePending = {"PrevFramePending", |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2377 | isFencePending(previousPresentFence, |
| 2378 | graceTimeForPresentFenceMs)}; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2379 | |
| 2380 | // Frame missed counts for metrics tracking. |
| 2381 | // A frame is missed if the prior frame is still pending. If no longer pending, |
| 2382 | // then we still count the frame as missed if the predicted present time |
| 2383 | // was further in the past than when the fence actually fired. |
| 2384 | |
| 2385 | // Add some slop to correct for drift. This should generally be |
| 2386 | // smaller than a typical frame duration, but should not be so small |
| 2387 | // that it reports reasonable drift as a missed frame. |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2388 | const nsecs_t frameMissedSlop = vsyncPeriod.ns() / 2; |
| 2389 | const nsecs_t previousPresentTime = previousPresentFence->getSignalTime(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2390 | const TracedOrdinal<bool> frameMissed = {"PrevFrameMissed", |
| 2391 | framePending || |
| 2392 | (previousPresentTime >= 0 && |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2393 | (lastScheduledPresentTime.ns() < |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2394 | previousPresentTime - frameMissedSlop))}; |
| 2395 | const TracedOrdinal<bool> hwcFrameMissed = {"PrevHwcFrameMissed", |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2396 | frameMissed && |
| 2397 | mCompositionCoverage.test( |
| 2398 | CompositionCoverage::Hwc)}; |
| 2399 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2400 | const TracedOrdinal<bool> gpuFrameMissed = {"PrevGpuFrameMissed", |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2401 | frameMissed && |
| 2402 | mCompositionCoverage.test( |
| 2403 | CompositionCoverage::Gpu)}; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2404 | |
| 2405 | if (frameMissed) { |
| 2406 | mFrameMissedCount++; |
| 2407 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | if (hwcFrameMissed) { |
| 2411 | mHwcFrameMissedCount++; |
| 2412 | } |
| 2413 | |
| 2414 | if (gpuFrameMissed) { |
| 2415 | mGpuFrameMissedCount++; |
| 2416 | } |
| 2417 | |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 2418 | if (mTracingEnabledChanged) { |
| 2419 | mLayerTracingEnabled = mLayerTracing.isEnabled(); |
| 2420 | mTracingEnabledChanged = false; |
| 2421 | } |
| 2422 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2423 | // 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] | 2424 | // fired yet just wait for the next commit. |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 2425 | if (mSetActiveModePending) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2426 | if (framePending) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2427 | mScheduler->scheduleFrame(); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2428 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | // 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] | 2432 | // the mode, hence we update SF. |
| 2433 | mSetActiveModePending = false; |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2434 | { |
| 2435 | Mutex::Autolock lock(mStateLock); |
| 2436 | updateInternalStateWithChangedMode(); |
| 2437 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
John Reck | 2ec5391 | 2020-07-07 16:53:55 -0700 | [diff] [blame] | 2440 | if (framePending) { |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2441 | if (mBackpressureGpuComposition || (hwcFrameMissed && !gpuFrameMissed)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2442 | scheduleCommit(FrameHint::kNone); |
| 2443 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2444 | } |
| 2445 | } |
| 2446 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2447 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2448 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2449 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2450 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2451 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2452 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2453 | mPowerAdvisor->setCommitStart(frameTime); |
| 2454 | mPowerAdvisor->setExpectedPresentTime(mExpectedPresentTime); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2455 | |
| 2456 | // 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] | 2457 | const Duration idealSfWorkDuration = |
| 2458 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2459 | const Duration frameDelay = idealSfWorkDuration - (mExpectedPresentTime - frameTime); |
| 2460 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2461 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2462 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 2463 | |
| 2464 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2465 | const Period vsyncPeriod = display->getActiveMode().fps.getPeriod(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2466 | mPowerAdvisor->setTargetWorkDuration(vsyncPeriod); |
| 2467 | |
| 2468 | // Send early hint here to make sure there's not another frame pending |
| 2469 | if (mPowerHintSessionMode.early) { |
| 2470 | // Send a rough prediction for this frame based on last frame's timing info |
| 2471 | mPowerAdvisor->sendPredictedWorkDuration(); |
| 2472 | } |
| 2473 | } |
| 2474 | |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2475 | if (mRefreshRateOverlaySpinner) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2476 | Mutex::Autolock lock(mStateLock); |
| 2477 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2478 | display->animateRefreshRateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2482 | // Composite if transactions were committed, or if requested by HWC. |
| 2483 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2484 | { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2485 | mFrameTimeline->setSfWakeUp(vsyncId.value, frameTime.ns(), |
| 2486 | Fps::fromPeriodNsecs(vsyncPeriod.ns())); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2487 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2488 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2489 | frontend::Update updates; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2490 | if (flushTransactions) { |
| 2491 | updates = flushLifecycleUpdates(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2492 | if (mTransactionTracing) { |
| 2493 | mTransactionTracing->addCommittedTransactions(vsyncId.value, frameTime.ns(), |
| 2494 | updates, mFrontEndDisplayInfos, |
| 2495 | mFrontEndDisplayInfosChanged); |
| 2496 | } |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2497 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2498 | bool transactionsAreEmpty; |
| 2499 | if (mLegacyFrontEndEnabled) { |
| 2500 | mustComposite |= updateLayerSnapshotsLegacy(vsyncId, updates, flushTransactions, |
| 2501 | transactionsAreEmpty); |
| 2502 | } |
| 2503 | if (mLayerLifecycleManagerEnabled) { |
| 2504 | mustComposite |= |
| 2505 | updateLayerSnapshots(vsyncId, updates, flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | if (transactionFlushNeeded()) { |
| 2509 | setTransactionFlags(eTransactionFlushNeeded); |
| 2510 | } |
| 2511 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2512 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2513 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2514 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2515 | // Invoke empty transaction callbacks early. |
| 2516 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2517 | } else { |
| 2518 | // Invoke OnCommit callbacks. |
| 2519 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2520 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | // Layers need to get updated (in the previous line) before we can use them for |
| 2524 | // choosing the refresh rate. |
| 2525 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2526 | // and may eventually call to ~Layer() if it holds the last reference |
| 2527 | { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2528 | Mutex::Autolock lock(mStateLock); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2529 | mScheduler->chooseRefreshRateForContent(); |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2530 | setActiveModeInHwcIfNeeded(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2533 | updateCursorAsync(); |
| 2534 | updateInputFlinger(); |
| 2535 | |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2536 | if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
| 2537 | // This will block and tracing should only be enabled for debugging. |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2538 | addToLayerTracing(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2539 | } |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2540 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2541 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2542 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2543 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2544 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2547 | void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2548 | FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2549 | ATRACE_FORMAT("%s %" PRId64, __func__, vsyncId.value); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2550 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2551 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2552 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2553 | refreshArgs.outputs.reserve(displays.size()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2554 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2555 | for (const auto& [_, display] : displays) { |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 2556 | bool dropFrame = false; |
| 2557 | if (display->isVirtual()) { |
| 2558 | Fps refreshRate = display->getAdjustedRefreshRate(); |
| 2559 | using fps_approx_ops::operator>; |
| 2560 | dropFrame = (refreshRate > 0_Hz) && !mScheduler->isVsyncInPhase(frameTime, refreshRate); |
| 2561 | } |
| 2562 | if (!dropFrame) { |
| 2563 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
| 2564 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2565 | displayIds.push_back(display->getId()); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2566 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2567 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2568 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2569 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2570 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2571 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2572 | updateLayerMetadataSnapshot(); |
| 2573 | mLayerMetadataSnapshotNeeded = false; |
| 2574 | } |
| 2575 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2576 | if (DOES_CONTAIN_BORDER) { |
| 2577 | refreshArgs.borderInfoList.clear(); |
| 2578 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2579 | if (layer->isBorderEnabled()) { |
| 2580 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2581 | info.width = layer->getBorderWidth(); |
| 2582 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2583 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2584 | info.layerIds.push_back(ilayer->getSequence()); |
| 2585 | }); |
| 2586 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2587 | } |
| 2588 | }); |
| 2589 | } |
| 2590 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2591 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2592 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2593 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2594 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2595 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2596 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2597 | } |
| 2598 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2599 | refreshArgs.outputColorSetting = useColorManagement |
| 2600 | ? mDisplayColorSetting |
| 2601 | : compositionengine::OutputColorSetting::kUnmanaged; |
| 2602 | refreshArgs.colorSpaceAgnosticDataspace = mColorSpaceAgnosticDataspace; |
| 2603 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2604 | |
| 2605 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2606 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 2607 | refreshArgs.internalDisplayRotationFlags = DisplayDevice::getPrimaryDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2608 | |
| 2609 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2610 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2611 | mDrawingState.colorMatrixChanged = false; |
| 2612 | } |
| 2613 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2614 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2615 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2616 | if (mDebugFlashDelay != 0) { |
| 2617 | refreshArgs.devOptForceClientComposition = true; |
| 2618 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2619 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2620 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2621 | const auto prevVsyncTime = mExpectedPresentTime - mScheduler->getVsyncSchedule()->period(); |
Ady Abraham | caba298 | 2021-06-16 16:45:04 -0700 | [diff] [blame] | 2622 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2623 | |
Ady Abraham | caba298 | 2021-06-16 16:45:04 -0700 | [diff] [blame] | 2624 | refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration; |
Ady Abraham | ec7aa8a | 2021-06-28 12:37:09 -0700 | [diff] [blame] | 2625 | refreshArgs.previousPresentFence = mPreviousPresentFences[0].fenceTime; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2626 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2627 | refreshArgs.expectedPresentTime = mExpectedPresentTime.ns(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2628 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 2629 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2630 | // Store the present time just before calling to the composition engine so we could notify |
| 2631 | // the scheduler. |
| 2632 | const auto presentTime = systemTime(); |
| 2633 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2634 | std::vector<std::pair<Layer*, LayerFE*>> layers = |
| 2635 | moveSnapshotsToCompositionArgs(refreshArgs, /*cursorOnly=*/false, vsyncId.value); |
| 2636 | mCompositionEngine->present(refreshArgs); |
| 2637 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2638 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2639 | for (auto [layer, layerFE] : layers) { |
| 2640 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2641 | layer->onPreComposition(compositionResult.refreshStartTime); |
| 2642 | for (auto releaseFence : compositionResult.releaseFences) { |
| 2643 | layer->onLayerDisplayed(releaseFence); |
| 2644 | } |
| 2645 | if (compositionResult.lastClientCompositionFence) { |
| 2646 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2647 | } |
| 2648 | } |
| 2649 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2650 | mTimeStats->recordFrameDuration(frameTime.ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2651 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2652 | // Send a power hint hint after presentation is finished |
| 2653 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2654 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(mPreviousPresentFences[0] |
| 2655 | .fenceTime->getSignalTime()), |
| 2656 | TimePoint::now()); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2657 | if (mPowerHintSessionMode.late) { |
| 2658 | mPowerAdvisor->sendActualWorkDuration(); |
| 2659 | } |
| 2660 | } |
| 2661 | |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2662 | if (mScheduler->onPostComposition(presentTime)) { |
| 2663 | scheduleComposite(FrameHint::kNone); |
| 2664 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2665 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2666 | postComposition(presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2667 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2668 | const bool hadGpuComposited = mCompositionCoverage.test(CompositionCoverage::Gpu); |
| 2669 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2670 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2671 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
| 2672 | for (const auto& [_, display] : displays) { |
| 2673 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2674 | |
| 2675 | if (state.usesDeviceComposition) { |
| 2676 | mCompositionCoverage |= CompositionCoverage::Hwc; |
| 2677 | } |
| 2678 | |
| 2679 | if (state.reusedClientComposition) { |
| 2680 | mCompositionCoverage |= CompositionCoverage::GpuReuse; |
| 2681 | } else if (state.usesClientComposition) { |
| 2682 | mCompositionCoverage |= CompositionCoverage::Gpu; |
| 2683 | } |
| 2684 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2685 | clientCompositionRecord.predicted |= |
| 2686 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2687 | clientCompositionRecord.predictionSucceeded |= |
| 2688 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2691 | const bool hasGpuComposited = mCompositionCoverage.test(CompositionCoverage::Gpu); |
| 2692 | |
| 2693 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
| 2694 | clientCompositionRecord.reused = mCompositionCoverage.test(CompositionCoverage::GpuReuse); |
| 2695 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2696 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2697 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2698 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2699 | using namespace ftl::flag_operators; |
| 2700 | |
| 2701 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2702 | const bool hasGpuUseOrReuse = |
| 2703 | mCompositionCoverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2704 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2705 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2706 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2707 | if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2708 | // This will block and should only be used for debugging. |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 2709 | addToLayerTracing(mVisibleRegionsDirty, frameTime.ns(), vsyncId.value); |
Vishnu Nair | df52905 | 2019-06-07 14:53:14 -0700 | [diff] [blame] | 2710 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2711 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2712 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2713 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2714 | |
| 2715 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2716 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2717 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2718 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2719 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2720 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2721 | } |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2722 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2723 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2724 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2725 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2726 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2727 | if (mVisibleRegionsDirty) { |
| 2728 | computeLayerBounds(); |
| 2729 | } |
| 2730 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2731 | for (auto& layer : mLayersPendingRefresh) { |
| 2732 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2733 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2734 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2735 | } |
| 2736 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2739 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2740 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2741 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2742 | // reduce power consumption during camera recording |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2743 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2744 | if (snapshot.externalTexture && |
| 2745 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2746 | return false; |
| 2747 | } |
| 2748 | } |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2749 | if (isHdrDataspace(snapshot.dataspace)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2750 | return true; |
| 2751 | } |
| 2752 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2753 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2754 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2755 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2756 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2757 | return true; |
| 2758 | } |
| 2759 | // 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] | 2760 | if ((snapshot.dataspace & (int32_t)Dataspace::RANGE_MASK) == |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2761 | (int32_t)Dataspace::RANGE_EXTENDED && |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2762 | snapshot.desiredSdrHdrRatio > 1.01f) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2763 | return true; |
| 2764 | } |
| 2765 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2766 | } |
| 2767 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2768 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2769 | bool isPrimary) const { |
| 2770 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2771 | if (!id) { |
| 2772 | return ui::ROTATION_0; |
| 2773 | } |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2774 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
| 2775 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2776 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2777 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2778 | case Hwc2::AidlTransform::ROT_90: |
| 2779 | return ui::ROTATION_90; |
| 2780 | case Hwc2::AidlTransform::ROT_180: |
| 2781 | return ui::ROTATION_180; |
| 2782 | case Hwc2::AidlTransform::ROT_270: |
| 2783 | return ui::ROTATION_270; |
| 2784 | default: |
| 2785 | return ui::ROTATION_0; |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | if (isPrimary) { |
| 2790 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2791 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2792 | case Values::ORIENTATION_90: |
| 2793 | return ui::ROTATION_90; |
| 2794 | case Values::ORIENTATION_180: |
| 2795 | return ui::ROTATION_180; |
| 2796 | case Values::ORIENTATION_270: |
| 2797 | return ui::ROTATION_270; |
| 2798 | default: |
| 2799 | break; |
| 2800 | } |
| 2801 | } |
| 2802 | return ui::ROTATION_0; |
| 2803 | } |
| 2804 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2805 | void SurfaceFlinger::postComposition(nsecs_t callTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2806 | ATRACE_CALL(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2807 | ALOGV(__func__); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2808 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2809 | const auto* defaultDisplay = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2810 | |
| 2811 | std::shared_ptr<FenceTime> glCompositionDoneFenceTime; |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2812 | if (defaultDisplay && |
| 2813 | defaultDisplay->getCompositionDisplay()->getState().usesClientComposition) { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2814 | glCompositionDoneFenceTime = |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2815 | std::make_shared<FenceTime>(defaultDisplay->getCompositionDisplay() |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 2816 | ->getRenderSurface() |
| 2817 | ->getClientTargetAcquireFence()); |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2818 | } else { |
| 2819 | glCompositionDoneFenceTime = FenceTime::NO_FENCE; |
| 2820 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2821 | |
Ady Abraham | be0f948 | 2019-04-24 15:41:53 -0700 | [diff] [blame] | 2822 | mPreviousPresentFences[1] = mPreviousPresentFences[0]; |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 2823 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2824 | auto presentFence = defaultDisplay |
| 2825 | ? getHwComposer().getPresentFence(defaultDisplay->getPhysicalId()) |
| 2826 | : Fence::NO_FENCE; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2827 | |
| 2828 | auto presentFenceTime = std::make_shared<FenceTime>(presentFence); |
| 2829 | mPreviousPresentFences[0] = {presentFence, presentFenceTime}; |
| 2830 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2831 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 2832 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2833 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 2834 | // information from previous' frame classification is already available when sending jank info |
| 2835 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2836 | mFrameTimeline->setSfPresent(presentTime.ns(), presentFenceTime, glCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2837 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2838 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 2839 | // 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] | 2840 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2841 | const TimePoint compositeTime = |
| 2842 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 2843 | const Duration presentLatency = |
Theodore Dubois | 205c6dd | 2022-11-23 15:06:33 -0800 | [diff] [blame] | 2844 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 2845 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, presentFenceTime) |
| 2846 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2847 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2848 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 2849 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 2850 | const Period vsyncPeriod = schedule->period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2851 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2852 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2853 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2854 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2855 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2856 | for (const auto& layer: mLayersWithQueuedFrames) { |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2857 | layer->onPostComposition(defaultDisplay, glCompositionDoneFenceTime, presentFenceTime, |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2858 | compositorTiming); |
| 2859 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2860 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2861 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2862 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 2863 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2864 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2865 | { |
| 2866 | Mutex::Autolock lock(mStateLock); |
| 2867 | if (mFpsReporter) { |
| 2868 | mFpsReporter->dispatchLayerFps(); |
| 2869 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 2870 | |
| 2871 | if (mTunnelModeEnabledReporter) { |
| 2872 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 2873 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2874 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 2875 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 2876 | if (reporter && reporter->hasListeners()) { |
| 2877 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 2878 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2882 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 2883 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2884 | } |
| 2885 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2886 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2887 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 2888 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 2889 | int32_t maxArea = 0; |
| 2890 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 2891 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2892 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 2893 | if (snapshot.isVisible && |
| 2894 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 2895 | if (isHdrLayer(snapshot)) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2896 | const auto* outputLayer = |
| 2897 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 2898 | if (outputLayer) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2899 | info.mergeDesiredRatio(snapshot.desiredSdrHdrRatio); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2900 | info.numberOfHdrLayers++; |
| 2901 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 2902 | const int32_t area = displayFrame.width() * displayFrame.height(); |
| 2903 | if (area > maxArea) { |
| 2904 | maxArea = area; |
| 2905 | info.maxW = displayFrame.width(); |
| 2906 | info.maxH = displayFrame.height(); |
| 2907 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 2908 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2909 | } |
| 2910 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2911 | }); |
| 2912 | listener->dispatchHdrLayerInfo(info); |
| 2913 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2914 | } |
| 2915 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2916 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2917 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2918 | mTransactionCallbackInvoker.addPresentFence(std::move(presentFence)); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 2919 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 2920 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
Valerie Hau | 4b67844 | 2020-04-14 10:50:42 -0700 | [diff] [blame] | 2921 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2922 | mTimeStats->incrementTotalFrames(); |
| 2923 | mTimeStats->setPresentFenceGlobal(presentFenceTime); |
| 2924 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2925 | { |
| 2926 | ftl::FakeGuard guard(mStateLock); |
| 2927 | for (const auto& [id, physicalDisplay] : mPhysicalDisplays) { |
| 2928 | if (auto displayDevice = getDisplayDeviceLocked(id); |
| 2929 | displayDevice && displayDevice->isPoweredOn() && physicalDisplay.isInternal()) { |
| 2930 | auto presentFenceTimeI = defaultDisplay && defaultDisplay->getPhysicalId() == id |
| 2931 | ? std::move(presentFenceTime) |
| 2932 | : std::make_shared<FenceTime>(getHwComposer().getPresentFence(id)); |
| 2933 | if (presentFenceTimeI->isValid()) { |
| 2934 | mScheduler->addPresentFence(id, std::move(presentFenceTimeI)); |
| 2935 | } |
| 2936 | } |
| 2937 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2940 | const bool isDisplayConnected = |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2941 | defaultDisplay && getHwComposer().isConnected(defaultDisplay->getPhysicalId()); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2942 | |
Fabien Sanglard | cbf153b | 2017-03-10 17:57:12 -0800 | [diff] [blame] | 2943 | if (!hasSyncFramework) { |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2944 | if (isDisplayConnected && defaultDisplay->isPoweredOn()) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2945 | mScheduler->enableHardwareVsync(defaultDisplay->getPhysicalId()); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 2949 | const size_t sfConnections = mScheduler->getEventThreadConnectionCount(mSfConnectionHandle); |
| 2950 | const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle); |
| 2951 | mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections); |
| 2952 | |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2953 | if (isDisplayConnected && !defaultDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 2954 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 2955 | return; |
| 2956 | } |
| 2957 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2958 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 2959 | getRenderEngine().cleanupPostRender(); |
| 2960 | |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2961 | { |
| 2962 | std::lock_guard lock(mTexturePoolMutex); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 2963 | if (mTexturePool.size() < mTexturePoolSize) { |
| 2964 | const size_t refillCount = mTexturePoolSize - mTexturePool.size(); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2965 | const size_t offset = mTexturePool.size(); |
| 2966 | mTexturePool.resize(mTexturePoolSize); |
| 2967 | getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset); |
| 2968 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 2969 | } else if (mTexturePool.size() > mTexturePoolSize) { |
| 2970 | const size_t deleteCount = mTexturePool.size() - mTexturePoolSize; |
| 2971 | const size_t offset = mTexturePoolSize; |
| 2972 | getRenderEngine().deleteTextures(deleteCount, mTexturePool.data() + offset); |
| 2973 | mTexturePool.resize(mTexturePoolSize); |
| 2974 | ATRACE_INT("TexturePoolSize", mTexturePool.size()); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 2975 | } |
| 2976 | } |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 2977 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2978 | if (mNumTrustedPresentationListeners > 0) { |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 2979 | display::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
| 2980 | { |
| 2981 | Mutex::Autolock lock(mStateLock); |
| 2982 | for (const auto& [token, display] : mDisplays) { |
| 2983 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 2984 | } |
| 2985 | } |
| 2986 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2987 | // 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] | 2988 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 2989 | if (!layer->hasTrustedPresentationListener()) { |
| 2990 | return; |
| 2991 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2992 | const frontend::LayerSnapshot* snapshot = (mLayerLifecycleManagerEnabled) |
| 2993 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 2994 | : layer->getLayerSnapshot(); |
| 2995 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 2996 | if (snapshot) { |
| 2997 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 2998 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 2999 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3000 | layer->updateTrustedPresentationState(display, snapshot, |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 3001 | nanoseconds_to_milliseconds(callTime), false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3002 | }); |
| 3003 | } |
| 3004 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3005 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3006 | // side-effect of getTotalSize(), so we check that again here |
| 3007 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3008 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3009 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3010 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3011 | |
| 3012 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3015 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3016 | const ui::Size maxSize = [this] { |
| 3017 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3018 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3019 | // The LayerTraceGenerator tool runs without displays. |
| 3020 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3021 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3022 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3023 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3024 | const auto& display = pair.second; |
| 3025 | return {std::max(size.getWidth(), display->getWidth()), |
| 3026 | std::max(size.getHeight(), display->getHeight())}; |
| 3027 | }); |
| 3028 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3029 | |
| 3030 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3031 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3032 | const float xMax = maxSize.getWidth() * 10.f; |
| 3033 | const float yMax = maxSize.getHeight() * 10.f; |
| 3034 | |
| 3035 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3039 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3040 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3041 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3042 | } |
| 3043 | } |
| 3044 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3045 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3046 | ATRACE_CALL(); |
| 3047 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3048 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3049 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3050 | // effects of the State assignment don't happen with mStateLock held, |
| 3051 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3052 | State drawingState(mDrawingState); |
| 3053 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3054 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3055 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3057 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3058 | // so we can call commitTransactionsLocked unconditionally. |
| 3059 | // We clear the flags with mStateLock held to guarantee that |
| 3060 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3061 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3062 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3063 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3064 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3067 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3068 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3069 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 3070 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3071 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3072 | int attempt = 0; |
| 3073 | constexpr int kMaxAttempts = 3; |
| 3074 | do { |
| 3075 | hwcModes = getHwComposer().getModes(displayId); |
| 3076 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3077 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3078 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3079 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3080 | }; |
| 3081 | |
| 3082 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3083 | break; |
| 3084 | } |
| 3085 | } while (++attempt < kMaxAttempts); |
| 3086 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3087 | if (attempt == kMaxAttempts) { |
| 3088 | const std::string activeMode = |
| 3089 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 3090 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3091 | "hwcModes={%s}", |
| 3092 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3093 | return {}; |
| 3094 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3095 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3096 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3097 | .transform([](const PhysicalDisplay& display) { |
| 3098 | return display.snapshot().displayModes(); |
| 3099 | }) |
| 3100 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3101 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3102 | ui::DisplayModeId nextModeId = 1 + |
| 3103 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 3104 | [](ui::DisplayModeId max, const auto& pair) { |
| 3105 | return std::max(max, pair.first.value()); |
| 3106 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3107 | |
| 3108 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3109 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3110 | const DisplayModeId id{nextModeId++}; |
| 3111 | newModes.try_emplace(id, |
| 3112 | DisplayMode::Builder(hwcMode.hwcId) |
| 3113 | .setId(id) |
| 3114 | .setPhysicalDisplayId(displayId) |
| 3115 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3116 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
| 3117 | .setDpiX(hwcMode.dpiX) |
| 3118 | .setDpiY(hwcMode.dpiY) |
| 3119 | .setGroup(hwcMode.configGroup) |
| 3120 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3121 | } |
| 3122 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3123 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3124 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3125 | [](const auto& lhs, const auto& rhs) { |
| 3126 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3127 | }); |
| 3128 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3129 | // Keep IDs if modes have not changed. |
| 3130 | const auto& modes = sameModes ? oldModes : newModes; |
| 3131 | const DisplayModePtr activeMode = |
| 3132 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 3133 | return pair.second->getHwcId() == activeModeHwcId; |
| 3134 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3135 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3136 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3137 | } |
| 3138 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3139 | bool SurfaceFlinger::configureLocked() { |
| 3140 | std::vector<HotplugEvent> events; |
| 3141 | { |
| 3142 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3143 | events = std::move(mPendingHotplugEvents); |
| 3144 | } |
| 3145 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3146 | for (const auto [hwcDisplayId, connection] : events) { |
| 3147 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3148 | const auto displayId = info->id; |
| 3149 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3150 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3151 | if (const char* const log = |
| 3152 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3153 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3154 | hwcDisplayId); |
| 3155 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3156 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3157 | } |
| 3158 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3159 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3160 | } |
| 3161 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3162 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3163 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3164 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3165 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3166 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3167 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3168 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3169 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3170 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3171 | mCurrentState.displays.removeItemsAt(index); |
| 3172 | } |
| 3173 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3174 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3175 | return "Disconnecting"; |
| 3176 | } |
| 3177 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3178 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3179 | if (!activeMode) { |
| 3180 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 3181 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 3182 | getHwComposer().disconnectDisplay(displayId); |
| 3183 | return nullptr; |
| 3184 | } |
| 3185 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3186 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3187 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3188 | if (displayOpt) { |
| 3189 | const auto& display = displayOpt->get(); |
| 3190 | const auto& snapshot = display.snapshot(); |
| 3191 | |
| 3192 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3193 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3194 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3195 | } else { |
| 3196 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3197 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3198 | |
| 3199 | const auto it = |
| 3200 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3201 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3202 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3203 | |
| 3204 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3205 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3206 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3207 | return "Reconnecting"; |
| 3208 | } |
| 3209 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3210 | const sp<IBinder> token = sp<BBinder>::make(); |
| 3211 | |
| 3212 | mPhysicalDisplays.try_emplace(displayId, token, displayId, |
| 3213 | getHwComposer().getDisplayConnectionType(displayId), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3214 | std::move(displayModes), std::move(colorModes), |
| 3215 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3216 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3217 | DisplayDeviceState state; |
| 3218 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3219 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3220 | .activeMode = std::move(activeMode)}; |
| 3221 | state.isSecure = true; // All physical displays are currently considered secure. |
| 3222 | state.displayName = std::move(info.name); |
| 3223 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3224 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3225 | return "Connecting"; |
| 3226 | } |
| 3227 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3228 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 3229 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 3230 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 3231 | } |
| 3232 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3233 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3234 | const wp<IBinder>& displayToken, |
| 3235 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3236 | const DisplayDeviceState& state, |
| 3237 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3238 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3239 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3240 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3241 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3242 | creationArgs.isSecure = state.isSecure; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3243 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3244 | creationArgs.hasWideColorGamut = false; |
| 3245 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3246 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3247 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3248 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3249 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3250 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3251 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3252 | using Config = scheduler::RefreshRateSelector::Config; |
| 3253 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3254 | ? Config::FrameRateOverride::Enabled |
| 3255 | : Config::FrameRateOverride::Disabled; |
Ady Abraham | 0d4b41c | 2023-02-14 23:28:40 +0000 | [diff] [blame] | 3256 | Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3257 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3258 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 3259 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3260 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3261 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3262 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3263 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3264 | mPhysicalDisplays.get(physical->id) |
| 3265 | .transform(&PhysicalDisplay::snapshotRef) |
| 3266 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3267 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3268 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3269 | creationArgs.activeModeId, |
| 3270 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3271 | }) |
| 3272 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3273 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3274 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3275 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3276 | if (useColorManagement) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3277 | mPhysicalDisplays.get(physical->id) |
| 3278 | .transform(&PhysicalDisplay::snapshotRef) |
| 3279 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3280 | for (const auto mode : snapshot.colorModes()) { |
| 3281 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3282 | creationArgs.hwcColorModes |
| 3283 | .emplace(mode, |
| 3284 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3285 | } |
| 3286 | })); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3287 | } |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3288 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3289 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3290 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3291 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3292 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3293 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3294 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3295 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3296 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3297 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3298 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3299 | // Make sure that composition can never be stalled by a virtual display |
| 3300 | // 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] | 3301 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3302 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3303 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3304 | } |
| 3305 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3306 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3307 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3308 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3309 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3310 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 3311 | creationArgs.initialPowerMode = |
| 3312 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3313 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3314 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3315 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3316 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3317 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3318 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3319 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3320 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3321 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3322 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3323 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3324 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3325 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3326 | display->getCompositionDisplay()->setColorProfile( |
| 3327 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
| 3328 | RenderIntent::COLORIMETRIC, |
| 3329 | Dataspace::UNKNOWN}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3330 | |
| 3331 | if (const auto& physical = state.physical) { |
| 3332 | mPhysicalDisplays.get(physical->id) |
| 3333 | .transform(&PhysicalDisplay::snapshotRef) |
| 3334 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3335 | FTL_FAKE_GUARD(kMainThreadContext, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3336 | display->setActiveMode(physical->activeMode->getId(), |
| 3337 | physical->activeMode->getFps(), |
| 3338 | physical->activeMode->getFps())); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3339 | })); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3340 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3341 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3342 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3343 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3344 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3345 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3346 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3347 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3348 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3349 | } |
| 3350 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3351 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3352 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3353 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3354 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3355 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3356 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3357 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3358 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3359 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3360 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3361 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3362 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3363 | int format; |
| 3364 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3365 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3366 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3367 | } else { |
| 3368 | // Virtual displays without a surface are dormant: |
| 3369 | // they have external state (layer stack, projection, |
| 3370 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3371 | return; |
| 3372 | } |
| 3373 | |
| 3374 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3375 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3376 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3377 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3378 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3379 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3380 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3381 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3382 | builder.setIsSecure(state.isSecure); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3383 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3384 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3385 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 3386 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3387 | |
| 3388 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3389 | sp<IGraphicBufferProducer> producer; |
| 3390 | sp<IGraphicBufferProducer> bqProducer; |
| 3391 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3392 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3393 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3394 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3395 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3396 | LOG_FATAL_IF(!displayId); |
| 3397 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
| 3398 | bqProducer, bqConsumer, state.displayName); |
| 3399 | displaySurface = surface; |
| 3400 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3401 | } else { |
| 3402 | ALOGE_IF(state.surface != nullptr, |
| 3403 | "adding a supported display, but rendering " |
| 3404 | "surface is provided (%p), ignoring it", |
| 3405 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3406 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3407 | LOG_FATAL_IF(!displayId); |
| 3408 | displaySurface = |
| 3409 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3410 | state.physical->activeMode->getResolution(), |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3411 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3412 | producer = bqProducer; |
| 3413 | } |
| 3414 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3415 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3416 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3417 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3418 | |
| 3419 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3420 | const auto displayId = display->getPhysicalId(); |
| 3421 | { |
Dominik Laskowski | 59db956 | 2022-10-27 16:18:53 -0400 | [diff] [blame] | 3422 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3423 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3424 | |
| 3425 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3426 | mScheduler->registerDisplay(displayId, display->holdRefreshRateSelector()); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3427 | } |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 3428 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3429 | dispatchDisplayHotplugEvent(displayId, true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3430 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3431 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3432 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3433 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3436 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3440 | auto display = getDisplayDeviceLocked(displayToken); |
| 3441 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3442 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3443 | |
| 3444 | if (display->isVirtual()) { |
| 3445 | releaseVirtualDisplay(display->getVirtualId()); |
| 3446 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3447 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3448 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3453 | |
| 3454 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3455 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3456 | // Destroy the display without holding the mStateLock. |
| 3457 | // This is a temporary solution until we can manage transaction queues without |
| 3458 | // holding the mStateLock. |
| 3459 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3460 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3461 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3462 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3463 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3464 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3465 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3466 | // not be accessible. |
| 3467 | })); |
| 3468 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3472 | const DisplayDeviceState& currentState, |
| 3473 | const DisplayDeviceState& drawingState) { |
| 3474 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3475 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3476 | |
| 3477 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3478 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | 23c31af | 2020-09-09 15:01:47 +0200 | [diff] [blame] | 3479 | getRenderEngine().cleanFramebufferCache(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3480 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3481 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3482 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3483 | if (display->isVirtual()) { |
| 3484 | releaseVirtualDisplay(display->getVirtualId()); |
| 3485 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3486 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3487 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3488 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3489 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3490 | if (const auto& physical = currentState.physical) { |
| 3491 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3492 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3493 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3494 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3495 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3496 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3497 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3498 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3499 | |
| 3500 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3501 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3502 | updateActiveDisplayVsyncLocked(*display); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3503 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3504 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3505 | return; |
| 3506 | } |
| 3507 | |
| 3508 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3509 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3510 | display->setLayerFilter( |
| 3511 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3512 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3513 | if (currentState.flags != drawingState.flags) { |
| 3514 | display->setFlags(currentState.flags); |
| 3515 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3516 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3517 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3518 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3519 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3520 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3521 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3522 | mActiveDisplayTransformHint = display->getTransformHint(); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3523 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3524 | } |
| 3525 | if (currentState.width != drawingState.width || |
| 3526 | currentState.height != drawingState.height) { |
| 3527 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3528 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3529 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3530 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3535 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3536 | void SurfaceFlinger::updateActiveDisplayVsyncLocked(const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3537 | mVsyncConfiguration->reset(); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3538 | const Fps refreshRate = activeDisplay.getActiveMode().fps; |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3539 | updatePhaseConfiguration(refreshRate); |
| 3540 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3541 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3542 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3543 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3544 | // here we take advantage of Vector's copy-on-write semantics to |
| 3545 | // improve performance by skipping the transaction entirely when |
| 3546 | // know that the lists are identical |
| 3547 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3548 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3549 | if (!curr.isIdenticalTo(draw)) { |
| 3550 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3551 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3552 | |
| 3553 | // find the displays that were removed |
| 3554 | // (ie: in drawing state but not in current state) |
| 3555 | // also handle displays that changed |
| 3556 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3557 | for (size_t i = 0; i < draw.size(); i++) { |
| 3558 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3559 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3560 | if (j < 0) { |
| 3561 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3562 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3563 | } else { |
| 3564 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3565 | const DisplayDeviceState& currentState = curr[j]; |
| 3566 | const DisplayDeviceState& drawingState = draw[i]; |
| 3567 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3568 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | // find displays that were added |
| 3572 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3573 | for (size_t i = 0; i < curr.size(); i++) { |
| 3574 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3575 | if (draw.indexOfKey(displayToken) < 0) { |
| 3576 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3580 | |
| 3581 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3582 | } |
| 3583 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3584 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3585 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3586 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3587 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
| 3588 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3589 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3590 | mFrontEndDisplayInfos.clear(); |
| 3591 | for (const auto& [_, display] : mDisplays) { |
| 3592 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3593 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3594 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3595 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3597 | if (mSomeChildrenChanged) { |
| 3598 | mVisibleRegionsDirty = true; |
| 3599 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3600 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3603 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3604 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3605 | // 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] | 3606 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3607 | // 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] | 3608 | // the hint is set before we acquire a buffer from the surface texture. |
| 3609 | // |
| 3610 | // NOTE: layer transactions have taken place already, so we use their |
| 3611 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3612 | // happened yet, so we must use the current state layer list |
| 3613 | // (soon to become the drawing state list). |
| 3614 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3615 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3616 | ui::LayerStack layerStack; |
| 3617 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3618 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3619 | // NOTE: we rely on the fact that layers are sorted by |
| 3620 | // layerStack first (so we don't have to traverse the list |
| 3621 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3622 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3623 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3624 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3625 | |
| 3626 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3627 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3628 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3629 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3630 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3631 | |
| 3632 | // Pick the primary display if another display mirrors the layer. |
| 3633 | if (hintDisplay) { |
| 3634 | hintDisplay = nullptr; |
| 3635 | break; |
| 3636 | } |
| 3637 | |
| 3638 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3639 | } |
| 3640 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3641 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3642 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3643 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3644 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3645 | // could be null when this layer is using a layerStack |
| 3646 | // that is not visible on any display. Also can occur at |
| 3647 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3648 | // U Update: Don't provide stale hints to the clients. For |
| 3649 | // special cases where we want the app to draw its |
| 3650 | // first frame before the display is available, we rely |
| 3651 | // on WMS and DMS to provide the right information |
| 3652 | // so the client can calculate the hint. |
| 3653 | ALOGV("Skipping reporting transform hint update for %s", layer->getDebugName()); |
| 3654 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3655 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3656 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3657 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3658 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3659 | } |
| 3660 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3661 | if (mLayersAdded) { |
| 3662 | mLayersAdded = false; |
| 3663 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3664 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3665 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | // some layers might have been removed, so |
| 3669 | // we need to update the regions they're exposing. |
| 3670 | if (mLayersRemoved) { |
| 3671 | mLayersRemoved = false; |
| 3672 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3673 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3674 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3675 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3676 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3677 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3678 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3679 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3680 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3681 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | } |
| 3683 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3684 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3685 | mUpdateInputInfo = true; |
| 3686 | } |
| 3687 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3688 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3691 | void SurfaceFlinger::updateInputFlinger() { |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3692 | ATRACE_CALL(); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3693 | if (!mInputFlinger) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3694 | return; |
| 3695 | } |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3696 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3697 | std::vector<WindowInfo> windowInfos; |
| 3698 | std::vector<DisplayInfo> displayInfos; |
| 3699 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3700 | if (mUpdateInputInfo) { |
| 3701 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3702 | updateWindowInfo = true; |
| 3703 | buildWindowInfos(windowInfos, displayInfos); |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3704 | } else if (mInputWindowCommands.empty()) { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3705 | return; |
| 3706 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3707 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3708 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3709 | windowInfos = std::move(windowInfos), |
| 3710 | displayInfos = std::move(displayInfos), |
| 3711 | inputWindowCommands = |
| 3712 | std::move(mInputWindowCommands), |
| 3713 | inputFlinger = mInputFlinger, this]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3714 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3715 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3716 | mWindowInfosListenerInvoker |
| 3717 | ->windowInfosChanged(windowInfos, displayInfos, |
| 3718 | inputWindowCommands.windowInfosReportedListeners); |
| 3719 | } else { |
| 3720 | // If there are listeners but no changes to input windows, call the listeners |
| 3721 | // immediately. |
| 3722 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3723 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3724 | listener->onWindowInfosReported(); |
| 3725 | } |
| 3726 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3727 | } |
| 3728 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3729 | inputFlinger->setFocusedWindow(focusRequest); |
| 3730 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3731 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3732 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3733 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3734 | } |
| 3735 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3736 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3737 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3738 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3739 | if (!supportsDisplayBrightnessCommand) { |
| 3740 | return; |
| 3741 | } |
| 3742 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3743 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3744 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3745 | if (!needsComposite) { |
| 3746 | const status_t error = |
| 3747 | getHwComposer() |
| 3748 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3749 | display->getCompositionDisplay() |
| 3750 | ->getState() |
| 3751 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3752 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3753 | .applyImmediately = true}) |
| 3754 | .get(); |
| 3755 | |
| 3756 | ALOGE_IF(error != NO_ERROR, |
| 3757 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 3758 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3759 | } |
| 3760 | display->persistBrightness(needsComposite); |
| 3761 | } |
| 3762 | } |
| 3763 | } |
| 3764 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3765 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 3766 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3767 | static size_t sNumWindowInfos = 0; |
| 3768 | outWindowInfos.reserve(sNumWindowInfos); |
| 3769 | sNumWindowInfos = 0; |
| 3770 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3771 | if (mLayerLifecycleManagerEnabled) { |
| 3772 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 3773 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 3774 | outWindowInfos.push_back(snapshot.inputInfo); |
| 3775 | }); |
| 3776 | } else { |
| 3777 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 3778 | if (!layer->needsInputInfo()) return; |
| 3779 | const auto opt = |
| 3780 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 3781 | .transform([](const frontend::DisplayInfo& info) { |
| 3782 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 3783 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3784 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3785 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 3786 | }); |
| 3787 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3788 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3789 | sNumWindowInfos = outWindowInfos.size(); |
| 3790 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3791 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 3792 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3793 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3794 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3797 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3798 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3799 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3800 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3801 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3802 | } |
| 3803 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3804 | auto layers = moveSnapshotsToCompositionArgs(refreshArgs, /*cursorOnly=*/true, 0); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3805 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3806 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3809 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3810 | if (mBootStage != BootStage::FINISHED) { |
| 3811 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 3812 | return; |
| 3813 | } |
| 3814 | |
| 3815 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3816 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3817 | // If this is called from the main thread mStateLock must be locked before |
| 3818 | // 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] | 3819 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3820 | |
| 3821 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3822 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3823 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3824 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3825 | |
| 3826 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 3827 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3828 | |
| 3829 | if (!display) continue; |
| 3830 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3831 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 3832 | .transform(&PhysicalDisplay::isInternal) |
| 3833 | .value_or(false); |
| 3834 | |
| 3835 | if (isInternalDisplay && displayId != mActiveDisplayId) { |
| 3836 | ALOGV("%s(%s): Inactive display", __func__, to_string(displayId).c_str()); |
| 3837 | continue; |
| 3838 | } |
| 3839 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3840 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3841 | setDesiredActiveMode(std::move(request)); |
| 3842 | } else { |
| 3843 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, modePtr->getId().value(), |
| 3844 | to_string(display->getId()).c_str()); |
| 3845 | } |
| 3846 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 3847 | } |
| 3848 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3849 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 3850 | PhysicalDisplayId displayId = [&]() { |
| 3851 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 3852 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 3853 | }(); |
| 3854 | |
| 3855 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 3856 | } |
| 3857 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3858 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3859 | using namespace scheduler; |
| 3860 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3861 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 3862 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3863 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 3864 | const Fps activeRefreshRate = activeMode.fps; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3865 | mRefreshRateStats = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3866 | std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3867 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3868 | mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 3869 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3870 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3871 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3872 | if (sysprop::use_content_detection_for_refresh_rate(false)) { |
| 3873 | features |= Feature::kContentDetection; |
| 3874 | } |
| 3875 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 3876 | features |= Feature::kTracePredictedVsync; |
| 3877 | } |
| 3878 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 3879 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3880 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3881 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3882 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 3883 | features |= Feature::kKernelIdleTimer; |
| 3884 | } |
| 3885 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3886 | auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
| 3887 | |
| 3888 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 3889 | static_cast<ISchedulerCallback&>(*this), features, |
| 3890 | std::move(modulatorPtr)); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3891 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3892 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3893 | setVsyncEnabled(display->getPhysicalId(), false); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3894 | mScheduler->startTimers(); |
| 3895 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 3896 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3897 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3898 | mAppConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3899 | mScheduler->createEventThread(Scheduler::Cycle::Render, |
| 3900 | mFrameTimeline->getTokenManager(), |
| 3901 | /* workDuration */ configs.late.appWorkDuration, |
| 3902 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3903 | mSfConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3904 | mScheduler->createEventThread(Scheduler::Cycle::LastComposite, |
| 3905 | mFrameTimeline->getTokenManager(), |
| 3906 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 3907 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3908 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3909 | mScheduler->initVsync(mScheduler->getVsyncSchedule()->getDispatch(), |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3910 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3911 | |
| 3912 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3913 | sp<RegionSamplingThread>::make(*this, |
| 3914 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 3915 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3918 | void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 3919 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3920 | mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(), |
| 3921 | refreshRate.getPeriod()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3924 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 3925 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3927 | if (!mLayersPendingRemoval.isEmpty()) { |
| 3928 | // Notify removed layers now that they can't be drawn from |
| 3929 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3930 | // Ensure any buffers set to display on any children are released. |
| 3931 | if (l->isRemovedFromCurrentState()) { |
| 3932 | l->latchAndReleaseBuffer(); |
| 3933 | } |
| 3934 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 3935 | // If a layer has a parent, we allow it to out-live it's handle |
| 3936 | // with the idea that the parent holds a reference and will eventually |
| 3937 | // be cleaned up. However no one cleans up the top-level so we do so |
| 3938 | // here. |
| 3939 | if (l->isAtRoot()) { |
| 3940 | l->setIsAtRoot(false); |
| 3941 | mCurrentState.layersSortedByZ.remove(l); |
| 3942 | } |
| 3943 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3944 | // If the layer has been removed and has no parent, then it will not be reachable |
| 3945 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 3946 | // ensure we can copy its current to drawing state. |
| 3947 | if (!l->getParent()) { |
| 3948 | mOffscreenLayers.emplace(l.get()); |
| 3949 | } |
| 3950 | } |
| 3951 | mLayersPendingRemoval.clear(); |
| 3952 | } |
| 3953 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3954 | mDrawingState = mCurrentState; |
| 3955 | // clear the "changed" flags in current state |
| 3956 | mCurrentState.colorMatrixChanged = false; |
| 3957 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 3958 | if (mVisibleRegionsDirty) { |
| 3959 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 3960 | rootLayer->commitChildList(); |
| 3961 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 3962 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 3963 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3964 | commitOffscreenLayers(); |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 3965 | if (mNumClones > 0) { |
| 3966 | mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); }); |
| 3967 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 3970 | void SurfaceFlinger::commitOffscreenLayers() { |
| 3971 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 3972 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3973 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 3974 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3975 | layer->commitChildList(); |
| 3976 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 3977 | }); |
| 3978 | } |
| 3979 | } |
| 3980 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3981 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3982 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3983 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3984 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3985 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 3986 | } |
| 3987 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3990 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 3991 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3992 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 3993 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3995 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 3996 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 3997 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 3998 | |
| 3999 | // Store the set of layers that need updates. This set must not change as |
| 4000 | // buffers are being latched, as this could result in a deadlock. |
| 4001 | // Example: Two producers share the same command stream and: |
| 4002 | // 1.) Layer 0 is latched |
| 4003 | // 2.) Layer 0 gets a new frame |
| 4004 | // 2.) Layer 1 gets a new frame |
| 4005 | // 3.) Layer 1 is latched. |
| 4006 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4007 | // 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] | 4008 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4009 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4010 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4011 | if (flags & Layer::eVisibleRegion) { |
| 4012 | mVisibleRegionsDirty = true; |
| 4013 | } |
| 4014 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4015 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4016 | if (layer->hasReadyFrame()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4017 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4018 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4019 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4020 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4021 | if (!layer->hasBuffer()) { |
| 4022 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4023 | // instead of a missed frame. This is used to identify scenarios where we |
| 4024 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4025 | // We only update the latch time for buffer less layers here, the latch time |
| 4026 | // is updated for buffer layers when the buffer is latched. |
| 4027 | layer->updateLastLatchTime(latchTime); |
| 4028 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4029 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4030 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4031 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4032 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4033 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4034 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4035 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4036 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4037 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4038 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4039 | } |
| 4040 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4041 | if (!mLayersWithQueuedFrames.empty()) { |
| 4042 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4043 | // writes to Layer current state. See also b/119481871 |
| 4044 | Mutex::Autolock lock(mStateLock); |
| 4045 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4046 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4047 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4048 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4049 | newDataLatched = true; |
| 4050 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4051 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4052 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4053 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4054 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4055 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4056 | |
| 4057 | // If we will need to wake up at some time in the future to deal with a |
| 4058 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4059 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4060 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4061 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4062 | } |
| 4063 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4064 | // enter boot animation on first buffer latch |
| 4065 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4066 | ALOGI("Enter boot animation"); |
| 4067 | mBootStage = BootStage::BOOTANIMATION; |
| 4068 | } |
| 4069 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4070 | if (mNumClones > 0) { |
| 4071 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4072 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4073 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4074 | // 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] | 4075 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4078 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4079 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4080 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4081 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4082 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4083 | MAX_LAYERS); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4084 | static_cast<void>(mScheduler->schedule([=] { |
| 4085 | ALOGE("Dumping random sampling of on-screen layers: "); |
| 4086 | mDrawingState.traverse([&](Layer *layer) { |
| 4087 | // Aim to dump about 200 layers to avoid totally trashing |
| 4088 | // logcat. On the other hand, if there really are 4096 layers |
| 4089 | // something has gone totally wrong its probably the most |
| 4090 | // useful information in logcat. |
| 4091 | if (rand() % 20 == 13) { |
| 4092 | ALOGE("Layer: %s", layer->getName().c_str()); |
| 4093 | } |
| 4094 | }); |
| 4095 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4096 | if (rand() % 20 == 13) { |
| 4097 | ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str()); |
| 4098 | } |
| 4099 | } |
| 4100 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4101 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4104 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4105 | if (outTransformHint) { |
| 4106 | *outTransformHint = mActiveDisplayTransformHint; |
| 4107 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4108 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4109 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4110 | { |
| 4111 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4112 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4113 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 4114 | args.mirrorLayerHandle.clear(); |
| 4115 | args.parentHandle.clear(); |
| 4116 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4117 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4118 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4119 | setTransactionFlags(eTransactionNeeded); |
| 4120 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4123 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4124 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4125 | } |
| 4126 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4127 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4128 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4129 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4130 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4133 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4134 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4135 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4136 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4137 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4138 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4139 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4140 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4141 | } else if (frameHint == FrameHint::kActive) { |
| 4142 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4143 | // as a new activity just happened. |
| 4144 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4145 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
| 4147 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4148 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4149 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4150 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4151 | const auto& transaction = *flushState.transaction; |
| 4152 | ATRACE_FORMAT("transactionIsReadyToBeApplied vsyncId: %" PRId64, |
| 4153 | transaction.frameTimelineInfo.vsyncId); |
| 4154 | TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
| 4155 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4156 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4157 | // for stability reasons. |
| 4158 | if (!transaction.isAutoTimestamp && desiredPresentTime >= mExpectedPresentTime && |
| 4159 | desiredPresentTime < mExpectedPresentTime + 1s) { |
| 4160 | ATRACE_NAME("not current"); |
| 4161 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4162 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4163 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 4164 | if (!mScheduler->isVsyncValid(mExpectedPresentTime, transaction.originUid)) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4165 | ATRACE_NAME("!isVsyncValid"); |
| 4166 | return TransactionReadiness::NotReady; |
| 4167 | } |
| 4168 | |
| 4169 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4170 | // expected present time of this transaction. |
| 4171 | if (transaction.isAutoTimestamp && |
| 4172 | frameIsEarly(mExpectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
| 4173 | ATRACE_NAME("frameIsEarly"); |
| 4174 | return TransactionReadiness::NotReady; |
| 4175 | } |
| 4176 | return TransactionReadiness::Ready; |
| 4177 | } |
| 4178 | |
| 4179 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4180 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4181 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4182 | auto ready = TransactionReadiness::Ready; |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4183 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const layer_state_t& s, |
| 4184 | const std::shared_ptr< |
| 4185 | renderengine:: |
| 4186 | ExternalTexture>& |
| 4187 | externalTexture) |
| 4188 | -> bool { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4189 | sp<Layer> layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4190 | const auto& transaction = *flushState.transaction; |
| 4191 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4192 | if (s.bufferData->hasBarrier) { |
| 4193 | // The current producerId is already a newer producer than the buffer that has a |
| 4194 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4195 | // don't wait on the barrier since we know that's stale information. |
| 4196 | if (layer->getDrawingState().producerId > s.bufferData->producerId) { |
| 4197 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4198 | externalTexture->getBuffer(), |
| 4199 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4200 | s.bufferData->acquireFence); |
| 4201 | // Delete the entire state at this point and not just release the buffer because |
| 4202 | // everything associated with the Layer in this Transaction is now out of date. |
| 4203 | ATRACE_NAME("DeleteStaleBuffer"); |
| 4204 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4205 | } |
| 4206 | |
| 4207 | if (layer->getDrawingState().frameNumber < s.bufferData->barrierFrameNumber) { |
| 4208 | const bool willApplyBarrierFrame = |
| 4209 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4210 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4211 | s.bufferData->barrierFrameNumber)); |
| 4212 | if (!willApplyBarrierFrame) { |
| 4213 | ATRACE_NAME("NotReadyBarrier"); |
| 4214 | ready = TransactionReadiness::NotReadyBarrier; |
| 4215 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4216 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4221 | // the transaction in the queue. |
| 4222 | const bool hasPendingBuffer = |
| 4223 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4224 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4225 | ATRACE_NAME("hasPendingBuffer"); |
| 4226 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4227 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | // check fence status |
| 4231 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(layer, s, transaction.states.size(), |
| 4232 | flushState.firstTransaction); |
| 4233 | ATRACE_FORMAT("%s allowLatchUnsignaled=%s", layer->getName().c_str(), |
| 4234 | allowLatchUnsignaled ? "true" : "false"); |
| 4235 | |
| 4236 | const bool acquireFenceChanged = s.bufferData && |
| 4237 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4238 | s.bufferData->acquireFence; |
| 4239 | const bool fenceSignaled = |
| 4240 | (!acquireFenceChanged || |
| 4241 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled); |
| 4242 | if (!fenceSignaled) { |
| 4243 | if (!allowLatchUnsignaled) { |
| 4244 | ready = TransactionReadiness::NotReady; |
| 4245 | auto& listener = s.bufferData->releaseBufferListener; |
| 4246 | if (listener && |
| 4247 | (flushState.queueProcessTime - transaction.postTime) > |
| 4248 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4249 | mTransactionHandler |
| 4250 | .onTransactionQueueStalled(transaction.id, listener, |
| 4251 | "Buffer processing hung up due to stuck " |
| 4252 | "fence. Indicates GPU hang"); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4253 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4254 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | ready = enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer |
| 4258 | ? TransactionReadiness::ReadyUnsignaledSingle |
| 4259 | : TransactionReadiness::ReadyUnsignaled; |
| 4260 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4261 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4262 | }); |
| 4263 | ATRACE_INT("TransactionReadiness", static_cast<int>(ready)); |
| 4264 | return ready; |
| 4265 | } |
| 4266 | |
| 4267 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4268 | mTransactionHandler.addTransactionReadyFilter( |
| 4269 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
| 4270 | mTransactionHandler.addTransactionReadyFilter( |
| 4271 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, std::placeholders::_1)); |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4272 | } |
| 4273 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4274 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4275 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4276 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4277 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4280 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4281 | VsyncId vsyncId) { |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4282 | Mutex::Autolock _l(mStateLock); |
| 4283 | return applyTransactionsLocked(transactions, vsyncId); |
| 4284 | } |
| 4285 | |
| 4286 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4287 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4288 | bool needsTraversal = false; |
| 4289 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4290 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4291 | needsTraversal |= |
| 4292 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4293 | transaction.displays, transaction.flags, |
| 4294 | transaction.inputWindowCommands, |
| 4295 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4296 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4297 | transaction.permissions, transaction.hasListenerCallbacks, |
| 4298 | transaction.listenerCallbacks, transaction.originPid, |
| 4299 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4300 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4301 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4305 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4308 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4309 | const auto prediction = |
| 4310 | mFrameTimeline->getTokenManager()->getPredictionsForToken(vsyncId.value); |
| 4311 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4312 | return false; |
| 4313 | } |
| 4314 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4315 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4316 | |
| 4317 | // 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] | 4318 | // VsyncConfig::appWorkDuration. |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4319 | if (constexpr std::chrono::nanoseconds kEarlyLatchMaxThreshold = 100ms; |
| 4320 | std::chrono::abs(predictedPresentTime - expectedPresentTime) >= kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4321 | return false; |
| 4322 | } |
| 4323 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4324 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->period() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4325 | |
| 4326 | return predictedPresentTime >= expectedPresentTime && |
| 4327 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4328 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4329 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4330 | bool SurfaceFlinger::shouldLatchUnsignaled(const sp<Layer>& layer, const layer_state_t& state, |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4331 | size_t numStates, bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4332 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
| 4333 | ALOGV("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
| 4334 | return false; |
| 4335 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4336 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4337 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Always) { |
| 4338 | ALOGV("%s: true (LatchUnsignaledConfig::Always)", __func__); |
| 4339 | return true; |
| 4340 | } |
| 4341 | |
| 4342 | // We only want to latch unsignaled when a single layer is updated in this |
| 4343 | // transaction (i.e. not a blast sync transaction). |
| 4344 | if (numStates != 1) { |
| 4345 | ALOGV("%s: false (numStates=%zu)", __func__, numStates); |
| 4346 | return false; |
| 4347 | } |
| 4348 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4349 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4350 | if (!firstTransaction) { |
| 4351 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first transaction)", |
| 4352 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4353 | return false; |
| 4354 | } |
| 4355 | |
| 4356 | // We don't want to latch unsignaled if are in early / client composition |
| 4357 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4358 | // or window animations being slow. |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4359 | const auto isDefaultVsyncConfig = mScheduler->vsyncModulator().isVsyncConfigDefault(); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4360 | if (!isDefaultVsyncConfig) { |
| 4361 | ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; !isDefaultVsyncConfig)", |
| 4362 | __func__); |
| 4363 | return false; |
| 4364 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | if (!layer->simpleBufferUpdate(state)) { |
| 4368 | ALOGV("%s: false (!simpleBufferUpdate)", __func__); |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | ALOGV("%s: true", __func__); |
| 4373 | return true; |
| 4374 | } |
| 4375 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4376 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4377 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4378 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
| 4379 | const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4380 | bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffers, |
| 4381 | bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4382 | uint64_t transactionId) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 4383 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4384 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4385 | uint32_t permissions = |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4386 | callingThreadHasUnscopedSurfaceFlingerAccess() ? |
| 4387 | layer_state_t::Permission::ACCESS_SURFACE_FLINGER : 0; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4388 | // Avoid checking for rotation permissions if the caller already has ACCESS_SURFACE_FLINGER |
| 4389 | // permissions. |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4390 | if ((permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4391 | callingThreadHasPermission(sRotateSurfaceFlinger)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4392 | permissions |= layer_state_t::Permission::ROTATE_SURFACE_FLINGER; |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4393 | } |
| 4394 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4395 | if (callingThreadHasPermission(sInternalSystemWindow)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4396 | permissions |= layer_state_t::Permission::INTERNAL_SYSTEM_WINDOW; |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4399 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4400 | const bool hasPermission = |
| 4401 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4402 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4403 | if (!hasPermission) { |
| 4404 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4405 | "eEarlyWakeup[Start|End] flags"); |
| 4406 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4407 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4408 | } |
| 4409 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4410 | const int64_t postTime = systemTime(); |
| 4411 | |
| 4412 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4413 | const int originPid = ipc->getCallingPid(); |
| 4414 | const int originUid = ipc->getCallingUid(); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4415 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4416 | std::vector<uint64_t> uncacheBufferIds; |
| 4417 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4418 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4419 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4420 | if (buffer != nullptr) { |
| 4421 | uncacheBufferIds.push_back(buffer->getId()); |
| 4422 | } |
| 4423 | } |
| 4424 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4425 | std::vector<ResolvedComposerState> resolvedStates; |
| 4426 | resolvedStates.reserve(states.size()); |
| 4427 | for (auto& state : states) { |
| 4428 | resolvedStates.emplace_back(std::move(state)); |
| 4429 | auto& resolvedState = resolvedStates.back(); |
| 4430 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4431 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4432 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4433 | std::string layerName = (layer) ? |
| 4434 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4435 | resolvedState.externalTexture = |
| 4436 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4437 | layerName.c_str(), transactionId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4438 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 4439 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4440 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 4441 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4442 | resolvedState.parentId = |
| 4443 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4444 | } |
| 4445 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4446 | resolvedState.relativeParentId = |
| 4447 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4448 | } |
| 4449 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4450 | wp<IBinder>& touchableRegionCropHandle = |
| 4451 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4452 | resolvedState.touchCropId = |
| 4453 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4454 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4457 | TransactionState state{frameTimelineInfo, |
| 4458 | resolvedStates, |
| 4459 | displays, |
| 4460 | flags, |
| 4461 | applyToken, |
| 4462 | inputWindowCommands, |
| 4463 | desiredPresentTime, |
| 4464 | isAutoTimestamp, |
| 4465 | std::move(uncacheBufferIds), |
| 4466 | postTime, |
| 4467 | permissions, |
| 4468 | hasListenerCallbacks, |
| 4469 | listenerCallbacks, |
| 4470 | originPid, |
| 4471 | originUid, |
| 4472 | transactionId}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4473 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4474 | if (mTransactionTracing) { |
| 4475 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4476 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4477 | |
| 4478 | const auto schedule = [](uint32_t flags) { |
| 4479 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4480 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4481 | return TransactionSchedule::Late; |
| 4482 | }(state.flags); |
| 4483 | |
| 4484 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4485 | mTransactionHandler.queueTransaction(std::move(state)); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4486 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4487 | return NO_ERROR; |
| 4488 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4489 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4490 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4491 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4492 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4493 | const InputWindowCommands& inputWindowCommands, |
| 4494 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4495 | const std::vector<uint64_t>& uncacheBufferIds, |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4496 | const int64_t postTime, uint32_t permissions, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4497 | bool hasListenerCallbacks, |
| 4498 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4499 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4500 | uint32_t transactionFlags = 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4501 | if (!mLayerLifecycleManagerEnabled) { |
| 4502 | for (DisplayState& display : displays) { |
| 4503 | display.sanitize(permissions); |
| 4504 | transactionFlags |= setDisplayStateLocked(display); |
| 4505 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4508 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4509 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4510 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4511 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4512 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4515 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4516 | for (auto& resolvedState : states) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4517 | if (mLegacyFrontEndEnabled) { |
| 4518 | clientStateFlags |= |
| 4519 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
| 4520 | isAutoTimestamp, postTime, permissions, transactionId); |
| 4521 | |
| 4522 | } else /*mLayerLifecycleManagerEnabled*/ { |
| 4523 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 4524 | desiredPresentTime, isAutoTimestamp, |
| 4525 | postTime, permissions, transactionId); |
| 4526 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4527 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 4528 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 4529 | const auto layerProps = scheduler::LayerProps{ |
| 4530 | .visible = layer->isVisible(), |
| 4531 | .bounds = layer->getBounds(), |
| 4532 | .transform = layer->getTransform(), |
| 4533 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 4534 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 4535 | }; |
| 4536 | layer->recordLayerHistoryAnimationTx(layerProps); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4537 | } |
| 4538 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4541 | transactionFlags |= clientStateFlags; |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 4542 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4543 | if (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) { |
Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 4544 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
| 4545 | } else if (!inputWindowCommands.empty()) { |
| 4546 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4547 | } |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4548 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4549 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 4550 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4553 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4554 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4555 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4556 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 4557 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4558 | transactionFlags = eTransactionNeeded; |
| 4559 | } |
| 4560 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4561 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4562 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4563 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4564 | // 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] | 4565 | if (transactionFlags & eTraversalNeeded) { |
| 4566 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4567 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4568 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4569 | if (transactionFlags) { |
| 4570 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4571 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4573 | |
| 4574 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | } |
| 4576 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4577 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 4578 | std::vector<TransactionState>& transactions) { |
| 4579 | Mutex::Autolock _l(mStateLock); |
| 4580 | bool needsTraversal = false; |
| 4581 | uint32_t transactionFlags = 0; |
| 4582 | for (auto& transaction : transactions) { |
| 4583 | for (DisplayState& display : transaction.displays) { |
| 4584 | display.sanitize(transaction.permissions); |
| 4585 | transactionFlags |= setDisplayStateLocked(display); |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | if (transactionFlags) { |
| 4590 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4591 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 4592 | if (transactionFlags & eTraversalNeeded) { |
| 4593 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 4594 | needsTraversal = true; |
| 4595 | } |
| 4596 | if (transactionFlags) { |
| 4597 | setTransactionFlags(transactionFlags); |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
| 4602 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
| 4603 | processDisplayChangesLocked(); |
| 4604 | mFrontEndDisplayInfos.clear(); |
| 4605 | for (const auto& [_, display] : mDisplays) { |
| 4606 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4607 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4608 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | return needsTraversal; |
| 4612 | } |
| 4613 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4614 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4615 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4616 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4617 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4618 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4619 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4620 | |
| 4621 | const uint32_t what = s.what; |
| 4622 | if (what & DisplayState::eSurfaceChanged) { |
| 4623 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4624 | state.surface = s.surface; |
| 4625 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4626 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4627 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4628 | if (what & DisplayState::eLayerStackChanged) { |
| 4629 | if (state.layerStack != s.layerStack) { |
| 4630 | state.layerStack = s.layerStack; |
| 4631 | flags |= eDisplayTransactionNeeded; |
| 4632 | } |
| 4633 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4634 | if (what & DisplayState::eFlagsChanged) { |
| 4635 | if (state.flags != s.flags) { |
| 4636 | state.flags = s.flags; |
| 4637 | flags |= eDisplayTransactionNeeded; |
| 4638 | } |
| 4639 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4640 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4641 | if (state.orientation != s.orientation) { |
| 4642 | state.orientation = s.orientation; |
| 4643 | flags |= eDisplayTransactionNeeded; |
| 4644 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4645 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4646 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4647 | flags |= eDisplayTransactionNeeded; |
| 4648 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4649 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 4650 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4651 | flags |= eDisplayTransactionNeeded; |
| 4652 | } |
| 4653 | } |
| 4654 | if (what & DisplayState::eDisplaySizeChanged) { |
| 4655 | if (state.width != s.width) { |
| 4656 | state.width = s.width; |
| 4657 | flags |= eDisplayTransactionNeeded; |
| 4658 | } |
| 4659 | if (state.height != s.height) { |
| 4660 | state.height = s.height; |
| 4661 | flags |= eDisplayTransactionNeeded; |
| 4662 | } |
| 4663 | } |
| 4664 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4665 | return flags; |
| 4666 | } |
| 4667 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4668 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4669 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4670 | const int pid = ipc->getCallingPid(); |
| 4671 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4672 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4673 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 4674 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4675 | return false; |
| 4676 | } |
| 4677 | return true; |
| 4678 | } |
| 4679 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4680 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4681 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4682 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4683 | int64_t postTime, uint32_t permissions, |
| 4684 | uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4685 | layer_state_t& s = composerState.state; |
| 4686 | s.sanitize(permissions); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4687 | |
| 4688 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4689 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4690 | // Starts a registration but separates the callback ids according to callback type. This |
| 4691 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4692 | // note that startRegistration will not re-register if the listener has |
| 4693 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4694 | |
| 4695 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 4696 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4697 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 4701 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4702 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4703 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4706 | const uint64_t what = s.what; |
| 4707 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4708 | sp<Layer> layer = nullptr; |
| 4709 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4710 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4711 | } else { |
| 4712 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 4713 | ALOGW("Attempt to set client state with a null layer handle"); |
| 4714 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4715 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4716 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 4717 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 4718 | callbackIds, |
| 4719 | s.surface), |
| 4720 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 4721 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4722 | return 0; |
| 4723 | } |
| 4724 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 4725 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 4726 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 4727 | // Only set by BLAST adapter layers |
| 4728 | if (what & layer_state_t::eProducerDisconnect) { |
| 4729 | layer->onDisconnect(); |
| 4730 | } |
| 4731 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4732 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 4733 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4734 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4735 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4736 | } |
| 4737 | if (what & layer_state_t::eLayerChanged) { |
| 4738 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4739 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4740 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 4741 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4742 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4743 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4744 | mCurrentState.layersSortedByZ.add(layer); |
| 4745 | // we need traversal (state changed) |
| 4746 | // AND transaction (list changed) |
| 4747 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4748 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4749 | } else { |
| 4750 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4751 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4752 | } |
| 4753 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4754 | } |
| 4755 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4756 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 4757 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4758 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 4759 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4760 | if (p == nullptr) { |
| 4761 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4762 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 4763 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4764 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4765 | mCurrentState.layersSortedByZ.add(layer); |
| 4766 | // we need traversal (state changed) |
| 4767 | // AND transaction (list changed) |
| 4768 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4769 | } |
| 4770 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 4771 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4772 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 4773 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4774 | } |
| 4775 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4776 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4777 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4778 | } |
| 4779 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4780 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4781 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 4782 | if (what & layer_state_t::eColorTransformChanged) { |
| 4783 | if (layer->setColorTransform(s.colorTransform)) { |
| 4784 | flags |= eTraversalNeeded; |
| 4785 | } |
| 4786 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 4787 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4788 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 4789 | flags |= eTraversalNeeded; |
| 4790 | } |
| 4791 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4792 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4793 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4794 | } |
| 4795 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 4796 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 4797 | flags |= eTraversalNeeded; |
| 4798 | } |
| 4799 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4800 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4801 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 4802 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 4803 | if (layer->setCornerRadius(s.cornerRadius)) |
| 4804 | flags |= eTraversalNeeded; |
| 4805 | } |
Galia Peycheva | 33713f7 | 2021-05-27 10:24:20 +0200 | [diff] [blame] | 4806 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4807 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 4808 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 4809 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4810 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 4811 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4812 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 4813 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 4814 | flags |= eTraversalNeeded; |
| 4815 | } |
| 4816 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4817 | if (what & layer_state_t::eLayerStackChanged) { |
| 4818 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 4819 | // We only allow setting layer stacks for top level layers, |
| 4820 | // everything else inherits layer stack from its parent. |
| 4821 | if (layer->hasParent()) { |
| 4822 | 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] | 4823 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4824 | } else if (idx < 0) { |
| 4825 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 4826 | "that also does not appear in the top level layer list. Something" |
| 4827 | " has gone wrong.", |
| 4828 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4829 | } else if (layer->setLayerStack(s.layerStack)) { |
| 4830 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 4831 | mCurrentState.layersSortedByZ.add(layer); |
| 4832 | // we need traversal (state changed) |
| 4833 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4834 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4835 | } |
| 4836 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 4837 | if (what & layer_state_t::eBufferTransformChanged) { |
| 4838 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4839 | } |
| 4840 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 4841 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 4842 | flags |= eTraversalNeeded; |
| 4843 | } |
| 4844 | if (what & layer_state_t::eCropChanged) { |
| 4845 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 4846 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4847 | if (what & layer_state_t::eDataspaceChanged) { |
| 4848 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 4849 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4850 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 4851 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 4852 | } |
| 4853 | if (what & layer_state_t::eApiChanged) { |
| 4854 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 4855 | } |
| 4856 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 4857 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 4858 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4859 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4860 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 4861 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4862 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 4863 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4864 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4865 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4866 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 4867 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 4868 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4869 | // The transaction will be received on the Task layer and needs to be applied to all |
| 4870 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 4871 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4872 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 4873 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4874 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 4875 | if (layer->setMetadata(s.metadata)) { |
| 4876 | flags |= eTraversalNeeded; |
| 4877 | mLayerMetadataSnapshotNeeded = true; |
| 4878 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 4879 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 4880 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 4881 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 4882 | flags |= eTraversalNeeded; |
| 4883 | } |
| 4884 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 4885 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 4886 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 4887 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 4888 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 4889 | const auto compatibility = |
| 4890 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 4891 | |
| 4892 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 4893 | flags |= eTraversalNeeded; |
| 4894 | } |
| 4895 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4896 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4897 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 4898 | flags |= eTraversalNeeded; |
| 4899 | } |
| 4900 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4901 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4902 | const auto compatibility = |
| 4903 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 4904 | const auto strategy = |
| 4905 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 4906 | |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4907 | if (layer->setFrameRate( |
| 4908 | Layer::FrameRate(Fps::fromValue(s.frameRate), compatibility, strategy))) { |
| 4909 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 4910 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 4911 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4912 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 4913 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 4914 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 4915 | } |
| 4916 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 4917 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 4918 | layer->setAutoRefresh(s.autoRefresh); |
| 4919 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 4920 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 4921 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 4922 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 4923 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 4924 | if (layer->setExtendedRangeBrightness(s.currentSdrHdrRatio, s.desiredSdrHdrRatio)) { |
| 4925 | flags |= eTraversalNeeded; |
| 4926 | } |
| 4927 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 4928 | if (what & layer_state_t::eCachingHintChanged) { |
| 4929 | if (layer->setCachingHint(s.cachingHint)) { |
| 4930 | flags |= eTraversalNeeded; |
| 4931 | } |
| 4932 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 4933 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 4934 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 4935 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 4936 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4937 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 4938 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 4939 | } |
| 4940 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 4941 | if (what & layer_state_t::eStretchChanged) { |
| 4942 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 4943 | flags |= eTraversalNeeded; |
| 4944 | } |
| 4945 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 4946 | if (what & layer_state_t::eBufferCropChanged) { |
| 4947 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 4948 | flags |= eTraversalNeeded; |
| 4949 | } |
| 4950 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4951 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 4952 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 4953 | flags |= eTraversalNeeded; |
| 4954 | } |
| 4955 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 4956 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4957 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 4958 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4959 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 4960 | } |
| 4961 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4962 | // This has to happen after we reparent children because when we reparent to null we remove |
| 4963 | // child layers from current state and remove its relative z. If the children are reparented in |
| 4964 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 4965 | // lose its relative z order. |
| 4966 | if (what & layer_state_t::eReparent) { |
| 4967 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 4968 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 4969 | ? s.parentSurfaceControlForChild->getHandle() |
| 4970 | : nullptr; |
| 4971 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4972 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 4973 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 4974 | mCurrentState.layersSortedByZ.remove(layer); |
| 4975 | } |
| 4976 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 4977 | } |
| 4978 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4979 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 4980 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 4981 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4982 | callbackHandles.emplace_back( |
| 4983 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4984 | } |
| 4985 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 4986 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 4987 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4988 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 4989 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 4990 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 4991 | flags |= eTraversalNeeded; |
| 4992 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4993 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4994 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 4995 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4996 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 4997 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 4998 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 4999 | } |
| 5000 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5001 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5002 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5003 | s.trustedPresentationListener)) { |
| 5004 | flags |= eTraversalNeeded; |
| 5005 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5006 | } |
| 5007 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5008 | if (what & layer_state_t::eFlushJankData) { |
| 5009 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5010 | } |
| 5011 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5012 | if (layer->setTransactionCompletedListeners(callbackHandles, |
| 5013 | layer->willPresentCurrentTransaction())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5014 | flags |= eTraversalNeeded; |
| 5015 | } |
| 5016 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5017 | // Do not put anything that updates layer state or modifies flags after |
| 5018 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5019 | |
| 5020 | // 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] | 5021 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5022 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5023 | flags |= eTransformHintUpdateNeeded; |
| 5024 | } |
| 5025 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5026 | return flags; |
| 5027 | } |
| 5028 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5029 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5030 | ResolvedComposerState& composerState, |
| 5031 | int64_t desiredPresentTime, |
| 5032 | bool isAutoTimestamp, int64_t postTime, |
| 5033 | uint32_t permissions, |
| 5034 | uint64_t transactionId) { |
| 5035 | layer_state_t& s = composerState.state; |
| 5036 | s.sanitize(permissions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5037 | |
| 5038 | std::vector<ListenerCallbacks> filteredListeners; |
| 5039 | for (auto& listener : s.listeners) { |
| 5040 | // Starts a registration but separates the callback ids according to callback type. This |
| 5041 | // allows the callback invoker to send on latch callbacks earlier. |
| 5042 | // note that startRegistration will not re-register if the listener has |
| 5043 | // already be registered for a prior surface control |
| 5044 | |
| 5045 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5046 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5047 | filteredListeners.push_back(onCommitCallbacks); |
| 5048 | } |
| 5049 | |
| 5050 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5051 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5052 | filteredListeners.push_back(onCompleteCallbacks); |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | const uint64_t what = s.what; |
| 5057 | uint32_t flags = 0; |
| 5058 | sp<Layer> layer = nullptr; |
| 5059 | if (s.surface) { |
| 5060 | layer = LayerHandle::getLayer(s.surface); |
| 5061 | } else { |
| 5062 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5063 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5064 | } |
| 5065 | if (layer == nullptr) { |
| 5066 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5067 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5068 | callbackIds, |
| 5069 | s.surface), |
| 5070 | std::vector<JankData>()); |
| 5071 | } |
| 5072 | return 0; |
| 5073 | } |
| 5074 | if (what & layer_state_t::eProducerDisconnect) { |
| 5075 | layer->onDisconnect(); |
| 5076 | } |
| 5077 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5078 | if (what & layer_state_t::eMetadataChanged) { |
| 5079 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5080 | } |
| 5081 | |
| 5082 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5083 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5084 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5085 | callbackHandles.emplace_back( |
| 5086 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5087 | } |
| 5088 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5089 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5090 | // requires to read drawing state from binder thread. So we need to fix that |
| 5091 | // before removing this. |
| 5092 | if (what & layer_state_t::eCropChanged) { |
| 5093 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5094 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5095 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5096 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5097 | } |
| 5098 | if (what & layer_state_t::eBufferChanged) { |
| 5099 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5100 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5101 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5102 | flags |= eTraversalNeeded; |
| 5103 | } |
| 5104 | mLayersWithQueuedFrames.emplace(layer); |
| 5105 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5106 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5107 | } |
| 5108 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5109 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5110 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5111 | } |
| 5112 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5113 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5114 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5115 | s.trustedPresentationListener)) { |
| 5116 | flags |= eTraversalNeeded; |
| 5117 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5120 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5121 | bool willPresentCurrentTransaction = |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5122 | requestedLayerState && requestedLayerState->hasReadyFrame(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5123 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5124 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5125 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5126 | return flags; |
| 5127 | } |
| 5128 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5129 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5130 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5131 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5132 | } |
| 5133 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5134 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5135 | const sp<IBinder>& mirrorFromHandle, |
| 5136 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5137 | if (!mirrorFromHandle) { |
| 5138 | return NAME_NOT_FOUND; |
| 5139 | } |
| 5140 | |
| 5141 | sp<Layer> mirrorLayer; |
| 5142 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5143 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5144 | { |
| 5145 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5146 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5147 | if (!mirrorFrom) { |
| 5148 | return NAME_NOT_FOUND; |
| 5149 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5150 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5151 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5152 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5153 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5154 | if (result != NO_ERROR) { |
| 5155 | return result; |
| 5156 | } |
| 5157 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 5158 | mirrorLayer->setClonedChild(mirrorFrom->createClone()); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5161 | outResult.layerId = mirrorLayer->sequence; |
| 5162 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5163 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5164 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5167 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5168 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5169 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5170 | const int uid = ipc->getCallingUid(); |
| 5171 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5172 | ALOGE("Permission denied when trying to mirror display"); |
| 5173 | return PERMISSION_DENIED; |
| 5174 | } |
| 5175 | |
| 5176 | ui::LayerStack layerStack; |
| 5177 | sp<Layer> rootMirrorLayer; |
| 5178 | status_t result = 0; |
| 5179 | |
| 5180 | { |
| 5181 | Mutex::Autolock lock(mStateLock); |
| 5182 | |
| 5183 | const auto display = getDisplayDeviceLocked(displayId); |
| 5184 | if (!display) { |
| 5185 | return NAME_NOT_FOUND; |
| 5186 | } |
| 5187 | |
| 5188 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5189 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5190 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5191 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5192 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5193 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5194 | outResult.layerId = rootMirrorLayer->sequence; |
| 5195 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5196 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5197 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | if (result != NO_ERROR) { |
| 5201 | return result; |
| 5202 | } |
| 5203 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 5204 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5205 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5206 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | setTransactionFlags(eTransactionFlushNeeded); |
| 5210 | return NO_ERROR; |
| 5211 | } |
| 5212 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5213 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5214 | status_t result = NO_ERROR; |
| 5215 | |
| 5216 | sp<Layer> layer; |
| 5217 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5218 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5219 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5220 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5221 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5222 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 5223 | FMT_FALLTHROUGH; |
| 5224 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5225 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5226 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5227 | if (pendingBufferCounter) { |
| 5228 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5229 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5230 | pendingBufferCounter); |
| 5231 | } |
| 5232 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5233 | default: |
| 5234 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5235 | break; |
| 5236 | } |
| 5237 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5238 | if (result != NO_ERROR) { |
| 5239 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5241 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5242 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5243 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5244 | // to the layer's handle inside this scope. |
| 5245 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5246 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5247 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5248 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5249 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5250 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5251 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5252 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5253 | if (result != NO_ERROR) { |
| 5254 | return result; |
| 5255 | } |
| 5256 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5257 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5258 | outResult.layerId = layer->sequence; |
| 5259 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5260 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5263 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5264 | sp<Layer>* outLayer) { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 5265 | args.textureName = getNewTexture(); |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5266 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5267 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5268 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5271 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5272 | sp<Layer>* outLayer) { |
| 5273 | *outLayer = getFactory().createEffectLayer(args); |
| 5274 | *handle = (*outLayer)->getHandle(); |
| 5275 | return NO_ERROR; |
| 5276 | } |
| 5277 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5278 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5279 | mLayersPendingRemoval.add(layer); |
| 5280 | mLayersRemoved = true; |
| 5281 | setTransactionFlags(eTransactionNeeded); |
| 5282 | } |
| 5283 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5284 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5285 | { |
| 5286 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 5287 | mDestroyedHandles.emplace_back(layerId); |
| 5288 | } |
| 5289 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5290 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5291 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5292 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5293 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5294 | |
| 5295 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5298 | void SurfaceFlinger::onInitializeDisplays() { |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5299 | const auto display = getDefaultDisplayDeviceLocked(); |
| 5300 | if (!display) return; |
| 5301 | |
| 5302 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 5303 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5304 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5305 | TransactionState state; |
| 5306 | state.inputWindowCommands = mInputWindowCommands; |
| 5307 | nsecs_t now = systemTime(); |
| 5308 | state.desiredPresentTime = now; |
| 5309 | state.postTime = now; |
| 5310 | state.permissions = layer_state_t::ACCESS_SURFACE_FLINGER; |
| 5311 | state.originPid = mPid; |
| 5312 | state.originUid = static_cast<int>(getuid()); |
| 5313 | uint64_t transactionId = (((uint64_t)mPid) << 32) | mUniqueTransactionId++; |
| 5314 | state.id = transactionId; |
| 5315 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5316 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5317 | Vector<DisplayState> displays; |
| 5318 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5319 | d.what = DisplayState::eDisplayProjectionChanged | |
| 5320 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5321 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 5322 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5323 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5324 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 5325 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5326 | d.width = 0; |
| 5327 | d.height = 0; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5328 | state.displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5329 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5330 | std::vector<TransactionState> transactions; |
| 5331 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5332 | |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5333 | // It should be on the main thread, apply it directly. |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5334 | if (mLegacyFrontEndEnabled) { |
| 5335 | applyTransactionsLocked(transactions, /*vsyncId=*/{0}); |
| 5336 | } else { |
| 5337 | applyAndCommitDisplayTransactionStates(transactions); |
| 5338 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5339 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5340 | setPowerModeInternal(display, hal::PowerMode::ON); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 8c00167 | 2018-05-30 16:52:06 -0700 | [diff] [blame] | 5344 | // Async since we may be called from the main thread. |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5345 | static_cast<void>(mScheduler->schedule( |
| 5346 | [this]() FTL_FAKE_GUARD(mStateLock) |
| 5347 | FTL_FAKE_GUARD(kMainThreadContext) { onInitializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5350 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5351 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5352 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5353 | return; |
| 5354 | } |
| 5355 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5356 | const auto displayId = display->getPhysicalId(); |
| 5357 | 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] | 5358 | |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5359 | const auto currentModeOpt = display->getPowerMode(); |
| 5360 | if (currentModeOpt == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5361 | return; |
| 5362 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5363 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5364 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5365 | .transform(&PhysicalDisplay::isInternal) |
| 5366 | .value_or(false); |
| 5367 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5368 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5369 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5370 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5371 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5372 | "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] | 5373 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5374 | display->setPowerMode(mode); |
| 5375 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 5376 | const auto refreshRate = display->refreshRateSelector().getActiveMode().modePtr->getFps(); |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5377 | if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5378 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5379 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5380 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5381 | // outer display of a foldable is powered on. This condition relies on the above |
| 5382 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5383 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5384 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5385 | // |
| 5386 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5387 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5388 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5389 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5390 | |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5391 | // Keep uclamp in a separate syscall and set it before changing to RT due to b/190237315. |
| 5392 | // We can merge the syscall later. |
| 5393 | if (SurfaceFlinger::setSchedAttr(true) != NO_ERROR) { |
| 5394 | ALOGW("Couldn't set uclamp.min on display on: %s\n", strerror(errno)); |
| 5395 | } |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 5396 | if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) { |
| 5397 | ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno)); |
| 5398 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5399 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5400 | if (displayId == mActiveDisplayId && mode != hal::PowerMode::DOZE_SUSPEND) { |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 5401 | setHWCVsyncEnabled(displayId, |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5402 | mScheduler->getVsyncSchedule(displayId) |
| 5403 | ->getPendingHardwareVsyncState()); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5404 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5405 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5406 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5408 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5409 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5410 | } else if (mode == hal::PowerMode::OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5411 | // Turn off the display |
Martin Liu | 4a32235 | 2020-03-24 21:30:38 +0800 | [diff] [blame] | 5412 | if (SurfaceFlinger::setSchedFifo(false) != NO_ERROR) { |
| 5413 | 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] | 5414 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5415 | if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { |
| 5416 | ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); |
| 5417 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5418 | if (displayId == mActiveDisplayId && *currentModeOpt != hal::PowerMode::DOZE_SUSPEND) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5419 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5420 | mScheduler->enableSyntheticVsync(); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5421 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5422 | |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 5423 | // Make sure HWVsync is disabled before turning off the display |
Leon Scroggins III | c275df4 | 2023-02-07 16:40:21 -0500 | [diff] [blame] | 5424 | setHWCVsyncEnabled(displayId, false); |
Leon Scroggins III | db16a2b | 2023-02-06 17:50:05 -0500 | [diff] [blame] | 5425 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5426 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5427 | mVisibleRegionsDirty = true; |
| 5428 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5429 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5430 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5431 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5432 | if (displayId == mActiveDisplayId && *currentModeOpt == hal::PowerMode::DOZE_SUSPEND) { |
Yifei Zhang | f0bd62e | 2021-06-16 15:27:05 -0700 | [diff] [blame] | 5433 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5434 | mVisibleRegionsDirty = true; |
| 5435 | scheduleRepaint(); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5436 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5437 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5438 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5439 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5440 | // Leave display going to doze |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5441 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5442 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5443 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5444 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5445 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5446 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 5447 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5448 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5449 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5450 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5451 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 5452 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5453 | mRefreshRateStats->setPowerMode(mode); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5454 | mScheduler->setDisplayPowerMode(displayId, mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5457 | 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] | 5458 | } |
| 5459 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5460 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5461 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 5462 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 5463 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5464 | if (!display) { |
| 5465 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 5466 | displayToken.get()); |
| 5467 | } else if (display->isVirtual()) { |
| 5468 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 5469 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5470 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5471 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5472 | }); |
| 5473 | |
| 5474 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5477 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5478 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 5479 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5480 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5481 | const int pid = ipc->getCallingPid(); |
| 5482 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 5483 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5484 | if ((uid != AID_SHELL) && |
| 5485 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5486 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 5487 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5488 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5489 | static const std::unordered_map<std::string, Dumper> dumpers = { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5490 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5491 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5492 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5493 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5494 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 5495 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 5496 | {"--hwclayers"s, dumper(&SurfaceFlinger::dumpHwcLayersMinidumpLocked)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5497 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 5498 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 5499 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5500 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5501 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5502 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5503 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5504 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 5505 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5506 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5507 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5508 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5509 | // Traversal of drawing state must happen on the main thread. |
| 5510 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 5511 | // traversals, which can result in use-after-frees. |
| 5512 | std::string compositionLayers; |
| 5513 | mScheduler |
| 5514 | ->schedule([&] { |
| 5515 | StringAppendF(&compositionLayers, "Composition layers\n"); |
| 5516 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 5517 | auto* compositionState = layer->getCompositionState(); |
| 5518 | if (!compositionState || !compositionState->isVisible) return; |
| 5519 | |
| 5520 | android::base::StringAppendF(&compositionLayers, "* Layer %p (%s)\n", layer, |
| 5521 | layer->getDebugName() ? layer->getDebugName() |
| 5522 | : "<unknown>"); |
| 5523 | compositionState->dump(compositionLayers); |
| 5524 | }); |
| 5525 | }) |
| 5526 | .get(); |
| 5527 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5528 | bool dumpLayers = true; |
| 5529 | { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5530 | TimedLock lock(mStateLock, s2ns(1), __func__); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5531 | if (!lock.locked()) { |
| 5532 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 5533 | strerror(-lock.status), lock.status); |
| 5534 | } |
| 5535 | |
| 5536 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 5537 | (it->second)(args, asProto, result); |
| 5538 | dumpLayers = false; |
| 5539 | } else if (!asProto) { |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5540 | dumpAllLocked(args, compositionLayers, result); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5541 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 5542 | } |
| 5543 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5544 | if (dumpLayers) { |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5545 | LayersTraceFileProto traceFileProto = mLayerTracing.createTraceFileProto(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5546 | LayersTraceProto* layersTrace = traceFileProto.add_entry(); |
| 5547 | LayersProto layersProto = dumpProtoFromMainThread(); |
| 5548 | layersTrace->mutable_layers()->Swap(&layersProto); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5549 | auto displayProtos = dumpDisplayProto(); |
| 5550 | layersTrace->mutable_displays()->Swap(&displayProtos); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5551 | |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5552 | if (asProto) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5553 | result.append(traceFileProto.SerializeAsString()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5554 | } else { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5555 | // Dump info that we need to access from the main thread |
chaviw | a2b9fab | 2021-09-08 14:46:30 -0500 | [diff] [blame] | 5556 | const auto layerTree = LayerProtoParser::generateLayerTree(layersTrace->layers()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5557 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
| 5558 | result.append("\n"); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5559 | dumpOffscreenLayers(result); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5560 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5561 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5563 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | return NO_ERROR; |
| 5565 | } |
| 5566 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5567 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5568 | return doDump(fd, DumpArgs(), asProto); |
| 5569 | } |
| 5570 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5571 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5572 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5573 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5576 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5577 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5578 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 5579 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5580 | const auto name = String8(args[1]); |
| 5581 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
| 5582 | if (layer->getName() == name.string()) { |
| 5583 | layer->dumpFrameStats(result); |
| 5584 | } |
| 5585 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5588 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5589 | const bool clearAll = args.size() < 2; |
| 5590 | const auto name = clearAll ? String8() : String8(args[1]); |
| 5591 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 5592 | mCurrentState.traverse([&](Layer* layer) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5593 | if (clearAll || layer->getName() == name.string()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 5594 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5595 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 5596 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5597 | } |
| 5598 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5599 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 5600 | mTimeStats->parseArgs(asProto, args, result); |
| 5601 | } |
| 5602 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 5603 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 5604 | mFrameTimeline->parseArgs(args, result); |
| 5605 | } |
| 5606 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5607 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5608 | static TimePoint sTimestamp = now; |
| 5609 | if (now - sTimestamp < 30min) return; |
| 5610 | sTimestamp = now; |
| 5611 | |
| 5612 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5613 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5616 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5617 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 5618 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5619 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 5620 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5621 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 5622 | getHwComposer().getMaxVirtualDisplayDimension()); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5623 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
| 5624 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
| 5625 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5626 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5629 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 5630 | utils::Dumper dumper{result}; |
| 5631 | |
| 5632 | mScheduler->dump(dumper); |
| 5633 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5634 | // TODO(b/241285876): Move to DisplayModeController. |
| 5635 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 5636 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5637 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5638 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5639 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5640 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 5641 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5642 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5643 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 5644 | " ns\n\n", |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5645 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5646 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5647 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5648 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5649 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 5653 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5654 | } |
| 5655 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5656 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 5657 | for (const auto& [token, display] : mDisplays) { |
| 5658 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 5659 | compositionDisplay->dumpPlannerInfo(args, result); |
| 5660 | } |
| 5661 | } |
| 5662 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5663 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 5664 | for (const auto& [token, display] : mDisplays) { |
| 5665 | display->getCompositionDisplay()->dump(result); |
| 5666 | result += '\n'; |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5671 | utils::Dumper dumper{result}; |
| 5672 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5673 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5674 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 5675 | |
| 5676 | display.snapshot().dump(dumper); |
| 5677 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5678 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5679 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5680 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5681 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5682 | |
| 5683 | for (const auto& [token, display] : mDisplays) { |
| 5684 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 5685 | const auto displayId = display->getId(); |
| 5686 | utils::Dumper::Section section(dumper, |
| 5687 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 5688 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5689 | } |
| 5690 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5693 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 5694 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5695 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5696 | if (!displayId) { |
| 5697 | continue; |
| 5698 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5699 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5700 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5701 | continue; |
| 5702 | } |
| 5703 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5704 | StringAppendF(&result, |
| 5705 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 5706 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5707 | uint8_t port; |
| 5708 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 5709 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5710 | result.append("no identification data\n"); |
| 5711 | continue; |
| 5712 | } |
| 5713 | |
| 5714 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5715 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5716 | continue; |
| 5717 | } |
| 5718 | |
| 5719 | const auto edid = parseEdid(data); |
| 5720 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5721 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5722 | continue; |
| 5723 | } |
| 5724 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5725 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5726 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 5727 | result.append("\"\n"); |
| 5728 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5731 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 5732 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 5733 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5734 | uint8_t port; |
| 5735 | DisplayIdentificationData data; |
| 5736 | |
| 5737 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 5738 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 5739 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 5740 | } |
| 5741 | } |
| 5742 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5743 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5744 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5745 | StringAppendF(&result, "Device uses color management: %d\n", useColorManagement); |
| 5746 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 5747 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5748 | |
| 5749 | // TODO: print out if wide-color mode is active or not |
| 5750 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5751 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 5752 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 5753 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5754 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5755 | } |
| 5756 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 5757 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 5758 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 5759 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 5760 | decodeColorMode(currentMode).c_str(), currentMode); |
| 5761 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5762 | } |
| 5763 | result.append("\n"); |
| 5764 | } |
| 5765 | |
Dominik Laskowski | 542c9dc | 2020-04-10 12:42:02 -0700 | [diff] [blame] | 5766 | LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 5767 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 5768 | |
| 5769 | // Determine if virtual layers display should be skipped |
| 5770 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 5771 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 5772 | if (display->isVirtual()) { |
| 5773 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 5774 | } |
| 5775 | } |
| 5776 | } |
| 5777 | |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 5778 | if (mLegacyFrontEndEnabled) { |
| 5779 | LayersProto layersProto; |
| 5780 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 5781 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 5782 | continue; |
| 5783 | } |
| 5784 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 5785 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 5786 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 5787 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5788 | |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 5789 | const frontend::LayerHierarchy& root = mLayerHierarchyBuilder.getHierarchy(); |
| 5790 | LayersProto layersProto; |
| 5791 | for (auto& [child, variant] : root.mChildren) { |
| 5792 | if (variant != frontend::LayerHierarchy::Variant::Attached || |
| 5793 | stackIdsToSkip.find(child->getLayer()->layerStack.id) != stackIdsToSkip.end()) { |
| 5794 | continue; |
| 5795 | } |
| 5796 | LayerProtoHelper::writeHierarchyToProto(layersProto, *child, mLayerSnapshotBuilder, |
| 5797 | mLegacyLayers, traceFlags); |
| 5798 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5799 | return layersProto; |
| 5800 | } |
| 5801 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5802 | google::protobuf::RepeatedPtrField<DisplayProto> SurfaceFlinger::dumpDisplayProto() const { |
| 5803 | google::protobuf::RepeatedPtrField<DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5804 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5805 | DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5806 | displayProto->set_id(display->getId().value); |
| 5807 | displayProto->set_name(display->getDisplayName()); |
| 5808 | displayProto->set_layer_stack(display->getLayerStack().id); |
| 5809 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 5810 | [&]() { return displayProto->mutable_size(); }); |
| 5811 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 5812 | return displayProto->mutable_layer_stack_space_rect(); |
| 5813 | }); |
| 5814 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 5815 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 5816 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5817 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 5818 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5819 | } |
| 5820 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 5821 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 5822 | getHwComposer().dump(result); |
| 5823 | } |
| 5824 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5825 | void SurfaceFlinger::dumpOffscreenLayersProto(LayersProto& layersProto, uint32_t traceFlags) const { |
| 5826 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 5827 | // it. |
| 5828 | LayerProto* rootProto = layersProto.add_layers(); |
| 5829 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 5830 | rootProto->set_id(offscreenRootLayerId); |
| 5831 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 5832 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5833 | |
| 5834 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5835 | // Add layer as child of the fake root |
| 5836 | rootProto->add_children(offscreenLayer->sequence); |
| 5837 | |
| 5838 | // Add layer |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 5839 | LayerProto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5840 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5841 | } |
| 5842 | } |
| 5843 | |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5844 | LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5845 | return mScheduler->schedule([=] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5848 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5849 | auto future = mScheduler->schedule([this] { |
| 5850 | std::string result; |
| 5851 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 5852 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 5853 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5854 | } |
| 5855 | return result; |
| 5856 | }); |
| 5857 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5858 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5859 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5862 | void SurfaceFlinger::dumpHwcLayersMinidumpLocked(std::string& result) const { |
| 5863 | for (const auto& [token, display] : mDisplays) { |
| 5864 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 5865 | if (!displayId) { |
| 5866 | continue; |
| 5867 | } |
| 5868 | |
| 5869 | 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] | 5870 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5871 | Layer::miniDumpHeader(result); |
| 5872 | |
| 5873 | const DisplayDevice& ref = *display; |
Leon Scroggins III | 140c6a4 | 2022-11-09 14:41:33 -0500 | [diff] [blame] | 5874 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDump(result, ref); }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 5875 | result.append("\n"); |
| 5876 | } |
| 5877 | } |
| 5878 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5879 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, const std::string& compositionLayers, |
| 5880 | std::string& result) const { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5881 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5882 | Colorizer colorizer(colorize); |
| 5883 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5884 | // figure out if we're stuck somewhere |
| 5885 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5886 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5887 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 5888 | |
| 5889 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5890 | * Dump library configuration. |
| 5891 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5892 | |
| 5893 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5894 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5895 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5896 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5897 | result.append("\n"); |
| 5898 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 5899 | result.append("\nDisplay identification data:\n"); |
| 5900 | dumpDisplayIdentificationData(result); |
| 5901 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 5902 | result.append("\nWide-Color information:\n"); |
| 5903 | dumpWideColorInfo(result); |
| 5904 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5905 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5906 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5907 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5908 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5909 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 5910 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5911 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5912 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 5913 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5914 | dumpScheduler(result); |
| 5915 | dumpEvents(result); |
| 5916 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 5917 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5918 | |
Alec Mouri | 40189b0 | 2019-03-05 15:07:54 -0800 | [diff] [blame] | 5919 | StringAppendF(&result, "Total missed frame count: %u\n", mFrameMissedCount.load()); |
| 5920 | StringAppendF(&result, "HWC missed frame count: %u\n", mHwcFrameMissedCount.load()); |
| 5921 | StringAppendF(&result, "GPU missed frame count: %u\n\n", mGpuFrameMissedCount.load()); |
Marissa Wall | cfcdaa5 | 2018-05-21 15:45:59 -0700 | [diff] [blame] | 5922 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5923 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5924 | * Dump the visible layer list |
| 5925 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5926 | colorizer.bold(result); |
chaviw | eadf0d4 | 2019-08-12 13:28:29 -0700 | [diff] [blame] | 5927 | StringAppendF(&result, "Visible layers (count = %zu)\n", mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5928 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 5929 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5930 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 5931 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5932 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5933 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5934 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5935 | dumpDisplays(result); |
| 5936 | dumpCompositionDisplays(result); |
| 5937 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 5938 | |
| 5939 | mCompositionEngine->dump(result); |
| 5940 | |
| 5941 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5942 | * Dump SurfaceFlinger global state |
| 5943 | */ |
| 5944 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5945 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 5946 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 5947 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5948 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 5949 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5950 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 5951 | result.append("ClientCache state:\n"); |
| 5952 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 5953 | DebugEGLImageTracker::getInstance()->dump(result); |
| 5954 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5955 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 5956 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 5957 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5958 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 5959 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 5960 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 5961 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5962 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 5963 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5964 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 5965 | if (const auto activeModePtr = |
| 5966 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 5967 | fps = to_string(activeModePtr->getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 5968 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 5969 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 5970 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 5971 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5972 | } else { |
| 5973 | fps = "unknown"; |
| 5974 | xDpi = "unknown"; |
| 5975 | yDpi = "unknown"; |
| 5976 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5977 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 5978 | " refresh-rate : %s\n" |
| 5979 | " x-dpi : %s\n" |
| 5980 | " y-dpi : %s\n", |
| 5981 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5982 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5983 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5984 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5985 | |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 5986 | /* |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5987 | * Tracing state |
| 5988 | */ |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 5989 | mLayerTracing.dump(result); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5990 | |
| 5991 | result.append("\nTransaction tracing: "); |
| 5992 | if (mTransactionTracing) { |
| 5993 | result.append("enabled\n"); |
| 5994 | mTransactionTracing->dump(result); |
| 5995 | } else { |
| 5996 | result.append("disabled\n"); |
| 5997 | } |
| 5998 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 5999 | |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6000 | dumpHwcLayersMinidumpLocked(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6001 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6002 | { |
| 6003 | DumpArgs plannerArgs; |
| 6004 | plannerArgs.add(); // first argument is ignored |
| 6005 | plannerArgs.add(String16("--layers")); |
| 6006 | dumpPlannerInfo(plannerArgs, result); |
| 6007 | } |
| 6008 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6009 | /* |
| 6010 | * Dump HWComposer state |
| 6011 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6012 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6013 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6014 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6015 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6016 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6017 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6018 | |
| 6019 | /* |
| 6020 | * Dump gralloc state |
| 6021 | */ |
| 6022 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6023 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6024 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6025 | /* |
| 6026 | * Dump flag/property manager state |
| 6027 | */ |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 6028 | mFlagManager.dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6029 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6030 | result.append(mTimeStats->miniDump()); |
| 6031 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6032 | } |
| 6033 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6034 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6035 | if (saturation == 1) { |
| 6036 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6037 | } |
| 6038 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6039 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6040 | luminance *= 1.0f - saturation; |
| 6041 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6042 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6043 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6044 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6045 | return saturationMatrix; |
| 6046 | } |
| 6047 | |
| 6048 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6049 | mat4 colorMatrix = |
| 6050 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6051 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6052 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6053 | mCurrentState.colorMatrix = colorMatrix; |
| 6054 | mCurrentState.colorMatrixChanged = true; |
| 6055 | setTransactionFlags(eTransactionNeeded); |
| 6056 | } |
| 6057 | } |
| 6058 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6059 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6060 | #pragma clang diagnostic push |
| 6061 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6062 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6063 | // These methods should at minimum make sure that the client requested |
| 6064 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6065 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6066 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6067 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6068 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6069 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6070 | // permission dynamically. Don't use the permission cache for this check. |
| 6071 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6072 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6073 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6074 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6075 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6076 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6078 | return OK; |
| 6079 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6080 | // The following calls are currently used by clients that do not |
| 6081 | // request necessary permissions. However, they do not expose any secret |
| 6082 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6083 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6084 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6085 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6086 | case GET_DISPLAY_MODES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6087 | // Calling setTransactionState is safe, because you need to have been |
| 6088 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6089 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6090 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6091 | return OK; |
| 6092 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6093 | case BOOT_FINISHED: |
| 6094 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6095 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6096 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6097 | case CREATE_DISPLAY: |
| 6098 | case DESTROY_DISPLAY: |
| 6099 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6100 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6101 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6102 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6103 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6104 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6105 | case GET_DISPLAY_STATE: |
| 6106 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6107 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6108 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6109 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6110 | case SET_ACTIVE_COLOR_MODE: |
| 6111 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6112 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6113 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6114 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6115 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6116 | case CAPTURE_LAYERS: |
| 6117 | case CAPTURE_DISPLAY: |
| 6118 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6119 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6120 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6121 | case OVERRIDE_HDR_TYPES: |
| 6122 | case ON_PULL_ATOM: |
| 6123 | case ENABLE_VSYNC_INJECTIONS: |
| 6124 | case INJECT_VSYNC: |
| 6125 | case GET_LAYER_DEBUG_INFO: |
| 6126 | case GET_COLOR_MANAGEMENT: |
| 6127 | case GET_COMPOSITION_PREFERENCE: |
| 6128 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6129 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6130 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6131 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6132 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6133 | case ADD_REGION_SAMPLING_LISTENER: |
| 6134 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6135 | case ADD_FPS_LISTENER: |
| 6136 | case REMOVE_FPS_LISTENER: |
| 6137 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6138 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6139 | case ADD_WINDOW_INFOS_LISTENER: |
| 6140 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6141 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6142 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6143 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6144 | case SET_DISPLAY_BRIGHTNESS: |
| 6145 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6146 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6147 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6148 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6149 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6150 | case SET_FRAME_RATE: |
| 6151 | case SET_OVERRIDE_FRAME_RATE: |
| 6152 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6153 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6154 | case GET_GPU_CONTEXT_PRIORITY: |
| 6155 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6156 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6157 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6159 | |
| 6160 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6161 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6162 | // We let them pass by default. |
| 6163 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6164 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6165 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6166 | return OK; |
| 6167 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6168 | // Numbers from 1000 to 1042 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6169 | // 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] | 6170 | if (code >= 1000 && code <= 1042) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6171 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6172 | return OK; |
| 6173 | } |
| 6174 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6175 | return PERMISSION_DENIED; |
| 6176 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6179 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6180 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6181 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6182 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6183 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6184 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6186 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6187 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6188 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6189 | const int uid = ipc->getCallingUid(); |
| 6190 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6191 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6192 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6193 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6194 | "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] | 6195 | return PERMISSION_DENIED; |
| 6196 | } |
| 6197 | int n; |
| 6198 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6199 | case 1000: // Unused. |
| 6200 | case 1001: |
| 6201 | return NAME_NOT_FOUND; |
| 6202 | case 1002: // Toggle flashing on surface damage. |
| 6203 | if (const int delay = data.readInt32(); delay > 0) { |
| 6204 | mDebugFlashDelay = delay; |
| 6205 | } else { |
| 6206 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 6207 | } |
| 6208 | scheduleRepaint(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6210 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6211 | case 1006: |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6212 | scheduleComposite(FrameHint::kActive); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6214 | case 1005: { // Force commit ahead of next VSYNC. |
| 6215 | Mutex::Autolock lock(mStateLock); |
| 6216 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | |
| 6217 | eTraversalNeeded); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6218 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6220 | case 1007: // Unused. |
| 6221 | return NAME_NOT_FOUND; |
| 6222 | case 1008: // Toggle forced GPU composition. |
| 6223 | mDebugDisableHWC = data.readInt32() != 0; |
| 6224 | scheduleRepaint(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6225 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6226 | case 1009: // Toggle use of transform hint. |
| 6227 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6228 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6229 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6230 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6231 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6232 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6233 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6234 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6235 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6236 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6237 | case 1013: // Unused. |
| 6238 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6239 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6240 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6241 | // daltonize |
| 6242 | n = data.readInt32(); |
| 6243 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6244 | case 1: |
| 6245 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6246 | break; |
| 6247 | case 2: |
| 6248 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6249 | break; |
| 6250 | case 3: |
| 6251 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6252 | break; |
| 6253 | default: |
| 6254 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6255 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6256 | } |
| 6257 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6258 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6259 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6260 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6261 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6262 | |
| 6263 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6264 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6266 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6267 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6268 | // apply a color matrix |
| 6269 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6270 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6271 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6272 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6273 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6274 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6275 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6276 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6277 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6278 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6279 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6280 | |
| 6281 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6282 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6283 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6284 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6285 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6286 | } |
| 6287 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6288 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6289 | return NO_ERROR; |
| 6290 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6291 | case 1016: { // Unused. |
| 6292 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6293 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6294 | case 1017: { |
| 6295 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6296 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6297 | return NO_ERROR; |
| 6298 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6299 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6300 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6301 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6302 | return NO_ERROR; |
| 6303 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6304 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6305 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6306 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6307 | return NO_ERROR; |
| 6308 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6309 | case 1020: { // Unused |
| 6310 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6311 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6312 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6313 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6314 | static_cast<void>( |
| 6315 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6316 | return NO_ERROR; |
| 6317 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6318 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6319 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6320 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6321 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6322 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6323 | return NO_ERROR; |
| 6324 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6325 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6326 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6327 | |
| 6328 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6329 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6330 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6331 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6332 | return NO_ERROR; |
| 6333 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6334 | // Deprecate, use 1030 to check whether the device is color managed. |
| 6335 | case 1024: { |
| 6336 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6337 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6338 | case 1025: { // Set layer tracing |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6339 | n = data.readInt32(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6340 | bool tracingEnabledChanged; |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6341 | if (n == 1) { |
| 6342 | int64_t fixedStartingTime = data.readInt64(); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6343 | ALOGD("LayerTracing enabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6344 | tracingEnabledChanged = mLayerTracing.enable(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6345 | if (tracingEnabledChanged) { |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 6346 | int64_t startingTime = |
| 6347 | (fixedStartingTime) ? fixedStartingTime : systemTime(); |
| 6348 | mScheduler |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 6349 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 6350 | kMainThreadContext) { |
| 6351 | addToLayerTracing(true /* visibleRegionDirty */, startingTime, |
| 6352 | mLastCommittedVsyncId.value); |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 6353 | }) |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6354 | .wait(); |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6355 | } |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6356 | } else if (n == 2) { |
| 6357 | std::string filename = std::string(data.readCString()); |
| 6358 | ALOGD("LayerTracing disabled. Trace wrote to %s", filename.c_str()); |
| 6359 | tracingEnabledChanged = mLayerTracing.disable(filename.c_str()); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6360 | } else { |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6361 | ALOGD("LayerTracing disabled"); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6362 | tracingEnabledChanged = mLayerTracing.disable(); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6363 | } |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 6364 | mTracingEnabledChanged = tracingEnabledChanged; |
| 6365 | reply->writeInt32(NO_ERROR); |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6366 | return NO_ERROR; |
| 6367 | } |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6368 | case 1026: { // Get layer tracing status |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6369 | reply->writeBool(mLayerTracing.isEnabled()); |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6370 | return NO_ERROR; |
| 6371 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6372 | // Is a DisplayColorSetting supported? |
| 6373 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6374 | const auto display = getDefaultDisplayDevice(); |
| 6375 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6376 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6377 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6378 | |
| 6379 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 6380 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6381 | case DisplayColorSetting::kManaged: |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6382 | reply->writeBool(useColorManagement); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6383 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6384 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6385 | reply->writeBool(true); |
| 6386 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6387 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6388 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6389 | break; |
| 6390 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6391 | reply->writeBool( |
| 6392 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6393 | break; |
| 6394 | } |
| 6395 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6396 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 6397 | case 1028: { // Unused. |
| 6398 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 6399 | } |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6400 | // Set buffer size for SF tracing (value in KB) |
| 6401 | case 1029: { |
| 6402 | n = data.readInt32(); |
| 6403 | if (n <= 0 || n > MAX_TRACING_MEMORY) { |
| 6404 | ALOGW("Invalid buffer size: %d KB", n); |
| 6405 | reply->writeInt32(BAD_VALUE); |
| 6406 | return BAD_VALUE; |
| 6407 | } |
| 6408 | |
| 6409 | ALOGD("Updating trace buffer to %d KB", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6410 | mLayerTracing.setBufferSize(n * 1024); |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6411 | reply->writeInt32(NO_ERROR); |
| 6412 | return NO_ERROR; |
| 6413 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6414 | // Is device color managed? |
| 6415 | case 1030: { |
| 6416 | reply->writeBool(useColorManagement); |
| 6417 | return NO_ERROR; |
| 6418 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6419 | // Override default composition data space |
| 6420 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 6421 | // && adb shell stop zygote && adb shell start zygote |
| 6422 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 6423 | // adb shell stop zygote && adb shell start zygote |
| 6424 | case 1031: { |
| 6425 | Mutex::Autolock _l(mStateLock); |
| 6426 | n = data.readInt32(); |
| 6427 | if (n) { |
| 6428 | n = data.readInt32(); |
| 6429 | if (n) { |
| 6430 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6431 | if (!validateCompositionDataspace(dataspace)) { |
| 6432 | return BAD_VALUE; |
| 6433 | } |
| 6434 | mDefaultCompositionDataspace = dataspace; |
| 6435 | } |
| 6436 | n = data.readInt32(); |
| 6437 | if (n) { |
| 6438 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6439 | if (!validateCompositionDataspace(dataspace)) { |
| 6440 | return BAD_VALUE; |
| 6441 | } |
| 6442 | mWideColorGamutCompositionDataspace = dataspace; |
| 6443 | } |
| 6444 | } else { |
| 6445 | // restore composition data space. |
| 6446 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 6447 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
| 6448 | } |
| 6449 | return NO_ERROR; |
| 6450 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6451 | // Set trace flags |
| 6452 | case 1033: { |
| 6453 | n = data.readUint32(); |
| 6454 | ALOGD("Updating trace flags to 0x%x", n); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 6455 | mLayerTracing.setTraceFlags(n); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6456 | reply->writeInt32(NO_ERROR); |
| 6457 | return NO_ERROR; |
| 6458 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6459 | case 1034: { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6460 | auto future = mScheduler->schedule( |
| 6461 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6462 | switch (n = data.readInt32()) { |
| 6463 | case 0: |
| 6464 | case 1: |
| 6465 | enableRefreshRateOverlay(static_cast<bool>(n)); |
| 6466 | break; |
| 6467 | default: |
| 6468 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 6469 | } |
| 6470 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6471 | |
| 6472 | future.wait(); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6473 | return NO_ERROR; |
| 6474 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6475 | case 1035: { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6476 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6477 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6478 | const auto display = [&]() -> sp<IBinder> { |
| 6479 | uint64_t value; |
| 6480 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6481 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6482 | } |
| 6483 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6484 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 6485 | return getPhysicalDisplayToken(*id); |
| 6486 | } |
| 6487 | |
| 6488 | ALOGE("Invalid physical display ID"); |
| 6489 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6490 | }(); |
| 6491 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 6492 | mDebugDisplayModeSetByBackdoor = false; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6493 | const status_t result = setActiveModeFromBackdoor(display, DisplayModeId{modeId}); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6494 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 6495 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6496 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6497 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 6498 | // manager frame rate policy a new policy which allows switching between all refresh |
| 6499 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6500 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6501 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6502 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6503 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6504 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6505 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6506 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6507 | // This is a little racy, but not in a way that hurts anything. As |
| 6508 | // we grab the defaultMode from the display manager policy, we could |
| 6509 | // be setting a new display manager policy, leaving us using a stale |
| 6510 | // defaultMode. The defaultMode doesn't matter for the override |
| 6511 | // policy though, since we set allowGroupSwitching to true, so it's |
| 6512 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6513 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 6514 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6515 | .getDisplayManagerPolicy() |
| 6516 | .defaultMode; |
| 6517 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6518 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6519 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6520 | .get(); |
| 6521 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6522 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6523 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6524 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6525 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6526 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6527 | display, |
| 6528 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6529 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6530 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6531 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6532 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6533 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 6534 | // reallocate the display state including framebuffers. |
| 6535 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6536 | const hal::HWDisplayId hwcId = |
| 6537 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 6538 | |
| 6539 | onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6540 | return NO_ERROR; |
| 6541 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 6542 | // Modify the max number of display frames stored within FrameTimeline |
| 6543 | case 1038: { |
| 6544 | n = data.readInt32(); |
| 6545 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 6546 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 6547 | return BAD_VALUE; |
| 6548 | } |
| 6549 | if (n == 0) { |
| 6550 | // restore to default |
| 6551 | mFrameTimeline->reset(); |
| 6552 | return NO_ERROR; |
| 6553 | } |
| 6554 | mFrameTimeline->setMaxDisplayFrames(n); |
| 6555 | return NO_ERROR; |
| 6556 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6557 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 6558 | PhysicalDisplayId displayId = [&]() { |
| 6559 | Mutex::Autolock lock(mStateLock); |
| 6560 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 6561 | }(); |
| 6562 | |
| 6563 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 6564 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 6565 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 6566 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6567 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 6568 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6569 | // Toggle caching feature |
| 6570 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 6571 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 6572 | // caching to a particular physical display |
| 6573 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6574 | auto future = mScheduler->schedule([&] { |
| 6575 | n = data.readInt32(); |
| 6576 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 6577 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 6578 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 6579 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 6580 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 6581 | return NAME_NOT_FOUND; |
| 6582 | } |
| 6583 | } |
| 6584 | { |
| 6585 | Mutex::Autolock lock(mStateLock); |
| 6586 | mLayerCachingEnabled = n != 0; |
| 6587 | for (const auto& [_, display] : mDisplays) { |
| 6588 | if (!inputId || *inputId == display->getPhysicalId()) { |
| 6589 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6590 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6591 | } |
| 6592 | } |
| 6593 | return OK; |
| 6594 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6595 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6596 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6597 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6598 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6599 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6600 | return NO_ERROR; |
| 6601 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6602 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6603 | if (mTransactionTracing) { |
| 6604 | if (data.readInt32()) { |
| 6605 | // Transaction tracing is always running but allow the user to temporarily |
| 6606 | // increase the buffer when actively debugging. |
| 6607 | mTransactionTracing->setBufferSize( |
| 6608 | TransactionTracing::ACTIVE_TRACING_BUFFER_SIZE); |
| 6609 | } else { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 6610 | mTransactionTracing->writeToFile(); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6611 | mTransactionTracing->setBufferSize( |
| 6612 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6613 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6614 | } |
| 6615 | reply->writeInt32(NO_ERROR); |
| 6616 | return NO_ERROR; |
| 6617 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 6618 | case 1042: { // Write layers trace or transaction trace to file |
| 6619 | if (mTransactionTracing) { |
| 6620 | mTransactionTracing->writeToFile(); |
| 6621 | } |
| 6622 | if (mLayerTracingEnabled) { |
| 6623 | mLayerTracing.writeToFile(); |
| 6624 | } |
| 6625 | reply->writeInt32(NO_ERROR); |
| 6626 | return NO_ERROR; |
| 6627 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | } |
| 6629 | } |
| 6630 | return err; |
| 6631 | } |
| 6632 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6633 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 6634 | static bool updateOverlay = |
| 6635 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 6636 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6637 | |
| 6638 | // Update the overlay on the main thread to avoid race conditions with |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6639 | // RefreshRateSelector::getActiveMode |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6640 | static_cast<void>(mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6641 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6642 | if (!display) { |
| 6643 | ALOGW("%s: default display is null", __func__); |
| 6644 | return; |
| 6645 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 6646 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6647 | |
| 6648 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 6649 | const std::optional<DisplayModeId> desiredModeId = desiredActiveMode |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6650 | ? std::make_optional(desiredActiveMode->modeOpt->modePtr->getId()) |
| 6651 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 6652 | : std::nullopt; |
| 6653 | |
| 6654 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 6655 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 6656 | if (display->onKernelTimerChanged(desiredModeId, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6657 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 6658 | } |
| 6659 | })); |
| 6660 | } |
| 6661 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6662 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 6663 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 6664 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 6665 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 6666 | const auto timeout = getIdleTimerTimeout(displayId); |
| 6667 | if (isKernelIdleTimerHwcSupported) { |
| 6668 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 6669 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 6670 | // In order to decide if we can use the HWC api for idle timer |
| 6671 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 6672 | // without relying on hasDisplayCapability. |
| 6673 | // hasDisplayCapability relies on DisplayCapabilities |
| 6674 | // which are updated after we set the PowerMode::ON. |
| 6675 | // DISPLAY_IDLE_TIMER is a display driver property |
| 6676 | // and is available before the PowerMode::ON |
| 6677 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 6678 | } |
| 6679 | return {std::nullopt, timeout}; |
| 6680 | } |
| 6681 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 6682 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 6683 | } |
| 6684 | |
| 6685 | return {std::nullopt, timeout}; |
| 6686 | } |
| 6687 | |
| 6688 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 6689 | KernelIdleTimerController controller, |
| 6690 | PhysicalDisplayId displayId) { |
| 6691 | switch (controller) { |
| 6692 | case KernelIdleTimerController::HwcApi: { |
| 6693 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 6694 | break; |
| 6695 | } |
| 6696 | case KernelIdleTimerController::Sysprop: { |
| 6697 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 6698 | break; |
| 6699 | } |
| 6700 | } |
| 6701 | } |
| 6702 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6703 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6704 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6705 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 6706 | const auto display = getDefaultDisplayDeviceLocked(); |
| 6707 | if (!display) { |
| 6708 | ALOGW("%s: default display is null", __func__); |
| 6709 | return; |
| 6710 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6711 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6712 | // If the support for kernel idle timer is disabled for the active display, |
| 6713 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6714 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6715 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6716 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 6717 | return; |
| 6718 | } |
| 6719 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6720 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6721 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6722 | switch (action) { |
| 6723 | case KernelIdleTimerAction::TurnOff: |
| 6724 | if (mKernelIdleTimerEnabled) { |
| 6725 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6726 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 6727 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 6728 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6729 | mKernelIdleTimerEnabled = false; |
| 6730 | } |
| 6731 | break; |
| 6732 | case KernelIdleTimerAction::TurnOn: |
| 6733 | if (!mKernelIdleTimerEnabled) { |
| 6734 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6735 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6736 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 6737 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 6738 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6739 | mKernelIdleTimerEnabled = true; |
| 6740 | } |
| 6741 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 6742 | } |
| 6743 | } |
| 6744 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6745 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 6746 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6747 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6748 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 6749 | ~WindowDisconnector() { |
| 6750 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6751 | } |
| 6752 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 6753 | private: |
| 6754 | ANativeWindow* mWindow; |
| 6755 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 6756 | }; |
| 6757 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6758 | static bool hasCaptureBlackoutContentPermission() { |
| 6759 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6760 | const int pid = ipc->getCallingPid(); |
| 6761 | const int uid = ipc->getCallingUid(); |
| 6762 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 6763 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 6764 | } |
| 6765 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6766 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 6767 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6768 | const int pid = ipc->getCallingPid(); |
| 6769 | const int uid = ipc->getCallingUid(); |
| 6770 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 6771 | return OK; |
| 6772 | } |
| 6773 | |
| 6774 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 6775 | // itself, we allow it to continue. |
| 6776 | if (captureArgs.uid == uid) { |
| 6777 | return OK; |
| 6778 | } |
| 6779 | |
| 6780 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 6781 | return PERMISSION_DENIED; |
| 6782 | } |
| 6783 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6784 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 6785 | static constexpr int kFifoPriority = 2; |
| 6786 | static constexpr int kOtherPriority = 0; |
| 6787 | |
| 6788 | struct sched_param param = {0}; |
| 6789 | int sched_policy; |
| 6790 | if (enabled) { |
| 6791 | sched_policy = SCHED_FIFO; |
| 6792 | param.sched_priority = kFifoPriority; |
| 6793 | } else { |
| 6794 | sched_policy = SCHED_OTHER; |
| 6795 | param.sched_priority = kOtherPriority; |
| 6796 | } |
| 6797 | |
| 6798 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 6799 | return -errno; |
| 6800 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6801 | |
| 6802 | return NO_ERROR; |
| 6803 | } |
| 6804 | |
| 6805 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 6806 | static const unsigned int kUclampMin = |
| 6807 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 6808 | |
| 6809 | if (!kUclampMin) { |
| 6810 | // uclamp.min set to 0 (default), skip setting |
| 6811 | return NO_ERROR; |
| 6812 | } |
| 6813 | |
| 6814 | // Currently, there is no wrapper in bionic: b/183240349. |
| 6815 | struct sched_attr { |
| 6816 | uint32_t size; |
| 6817 | uint32_t sched_policy; |
| 6818 | uint64_t sched_flags; |
| 6819 | int32_t sched_nice; |
| 6820 | uint32_t sched_priority; |
| 6821 | uint64_t sched_runtime; |
| 6822 | uint64_t sched_deadline; |
| 6823 | uint64_t sched_period; |
| 6824 | uint32_t sched_util_min; |
| 6825 | uint32_t sched_util_max; |
| 6826 | }; |
| 6827 | |
| 6828 | sched_attr attr = {}; |
| 6829 | attr.size = sizeof(attr); |
| 6830 | |
| 6831 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 6832 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 6833 | attr.sched_util_max = 1024; |
| 6834 | |
| 6835 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 6836 | return -errno; |
| 6837 | } |
| 6838 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 6839 | return NO_ERROR; |
| 6840 | } |
| 6841 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6842 | status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6843 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6844 | ATRACE_CALL(); |
| 6845 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6846 | status_t validate = validateScreenshotPermissions(args); |
| 6847 | if (validate != OK) { |
| 6848 | return validate; |
| 6849 | } |
| 6850 | |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6851 | if (!args.displayToken) return BAD_VALUE; |
| 6852 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6853 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6854 | ui::LayerStack layerStack; |
| 6855 | ui::Size reqSize(args.width, args.height); |
| 6856 | ui::Dataspace dataspace; |
| 6857 | { |
| 6858 | Mutex::Autolock lock(mStateLock); |
| 6859 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
| 6860 | if (!display) return NAME_NOT_FOUND; |
| 6861 | displayWeak = display; |
| 6862 | layerStack = display->getLayerStack(); |
| 6863 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6864 | // 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] | 6865 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6866 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6867 | } |
| 6868 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6869 | // Allow the caller to specify a dataspace regardless of the display's color mode, e.g. if |
| 6870 | // it wants sRGB regardless of the display's wide color mode. |
| 6871 | dataspace = args.dataspace == ui::Dataspace::UNKNOWN |
| 6872 | ? ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode) |
| 6873 | : args.dataspace; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6874 | } |
| 6875 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6876 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6877 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 6878 | args.useIdentityTransform, args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6879 | }); |
| 6880 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6881 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 6882 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 6883 | getLayerSnapshots = |
| 6884 | getLayerSnapshotsForScreenshots(layerStack, args.uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6885 | } else { |
| 6886 | auto traverseLayers = [this, args, layerStack](const LayerVector::Visitor& visitor) { |
| 6887 | traverseLayersInLayerStack(layerStack, args.uid, visitor); |
| 6888 | }; |
| 6889 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 6890 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 6891 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 6892 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6893 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 6894 | captureListener); |
| 6895 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6896 | } |
| 6897 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6898 | status_t SurfaceFlinger::captureDisplay(DisplayId displayId, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6899 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6900 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6901 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6902 | ui::Size size; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 6903 | ui::Dataspace dataspace; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6904 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6905 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 6906 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6907 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6908 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6909 | return NAME_NOT_FOUND; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6910 | } |
| 6911 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6912 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6913 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 6914 | size = display->getLayerStackSpaceRect().getSize(); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6915 | dataspace = ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 6918 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6919 | return DisplayRenderArea::create(displayWeak, Rect(), size, dataspace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 6920 | false /* useIdentityTransform */, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 6921 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6922 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6923 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6924 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 6925 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 6926 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 6927 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6928 | } else { |
| 6929 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
| 6930 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, visitor); |
| 6931 | }; |
| 6932 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 6933 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6934 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 6935 | if (captureListener == nullptr) { |
| 6936 | ALOGE("capture screen must provide a capture listener callback"); |
| 6937 | return BAD_VALUE; |
| 6938 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6939 | |
| 6940 | constexpr bool kAllowProtected = false; |
| 6941 | constexpr bool kGrayscale = false; |
| 6942 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 6943 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 6944 | ui::PixelFormat::RGBA_8888, kAllowProtected, kGrayscale, |
| 6945 | captureListener); |
| 6946 | return fenceStatus(future.get()); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 6947 | } |
| 6948 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6949 | status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
chaviw | 8ffc7b8 | 2020-08-18 11:25:37 -0700 | [diff] [blame] | 6950 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 6951 | ATRACE_CALL(); |
| 6952 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 6953 | status_t validate = validateScreenshotPermissions(args); |
| 6954 | if (validate != OK) { |
| 6955 | return validate; |
| 6956 | } |
| 6957 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 6958 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6959 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6960 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 6961 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6962 | ui::Dataspace dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6963 | |
| 6964 | // Call this before holding mStateLock to avoid any deadlocking. |
| 6965 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
| 6966 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6967 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6968 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 6969 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6970 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 6971 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6972 | ALOGE("captureLayers called with an invalid or removed parent"); |
| 6973 | return NAME_NOT_FOUND; |
| 6974 | } |
| 6975 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 6976 | if (!canCaptureBlackoutContent && |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 6977 | parent->getDrawingState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6978 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
| 6979 | return PERMISSION_DENIED; |
| 6980 | } |
| 6981 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 6982 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6983 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6984 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6985 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6986 | } |
| 6987 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 6988 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6989 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6990 | crop.bottom = parentSourceBounds.getHeight(); |
| 6991 | } |
| 6992 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6993 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 6994 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 6995 | // crop was not specified, or an invalid frame scale was provided. |
| 6996 | return BAD_VALUE; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6997 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6998 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 6999 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7000 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7001 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7002 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7003 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7004 | } else { |
| 7005 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
| 7006 | return NAME_NOT_FOUND; |
| 7007 | } |
| 7008 | } |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 7009 | |
arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 7010 | // The dataspace is depended on the color mode of display, that could use non-native mode |
| 7011 | // (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes, |
| 7012 | // and failed if display is not in native mode. This provide a way to force using native |
| 7013 | // colors when capture. |
Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 7014 | dataspace = args.dataspace; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7015 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7016 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7017 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7018 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7019 | ALOGW("Failed to captureLayes: crop or scale too small"); |
| 7020 | return BAD_VALUE; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7021 | } |
| 7022 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7023 | bool childrenOnly = args.childrenOnly; |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7024 | RenderAreaFuture renderAreaFuture = ftl::defer([=]() -> std::unique_ptr<RenderArea> { |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7025 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 7026 | childrenOnly, args.captureSecureLayers); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7027 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7028 | GetLayerSnapshotsFunction getLayerSnapshots; |
| 7029 | if (mLayerLifecycleManagerEnabled) { |
| 7030 | FloatRect parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7031 | : crop.toFloatRect(); |
| 7032 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 7033 | std::move(excludeLayerIds), |
| 7034 | args.childrenOnly, parentCrop); |
| 7035 | } else { |
| 7036 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 7037 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 7038 | if (!layer->isVisible()) { |
| 7039 | return; |
| 7040 | } else if (args.childrenOnly && layer == parent.get()) { |
| 7041 | return; |
| 7042 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7043 | return; |
| 7044 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7045 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7046 | auto p = sp<Layer>::fromExisting(layer); |
| 7047 | while (p != nullptr) { |
| 7048 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7049 | return; |
| 7050 | } |
| 7051 | p = p->getParent(); |
| 7052 | } |
| 7053 | |
| 7054 | visitor(layer); |
| 7055 | }); |
| 7056 | }; |
| 7057 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7058 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7059 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7060 | if (captureListener == nullptr) { |
| 7061 | ALOGE("capture screen must provide a capture listener callback"); |
| 7062 | return BAD_VALUE; |
| 7063 | } |
| 7064 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7065 | auto future = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7066 | args.pixelFormat, args.allowProtected, args.grayscale, |
| 7067 | captureListener); |
| 7068 | return fenceStatus(future.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7069 | } |
| 7070 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7071 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7072 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7073 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, bool allowProtected, bool grayscale, |
| 7074 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7075 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7076 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7077 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7078 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7079 | ") that exceeds render target size limit.", |
| 7080 | bufferSize.getWidth(), bufferSize.getHeight()); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7081 | return ftl::yield<FenceResult>(base::unexpected(BAD_VALUE)).share(); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7082 | } |
| 7083 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7084 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7085 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7086 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7087 | // application to avoid being screenshot or drawn via unsecure display. |
| 7088 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7089 | bool hasProtectedLayer = false; |
| 7090 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7091 | hasProtectedLayer = mScheduler |
| 7092 | ->schedule([=]() { |
| 7093 | bool protectedLayerFound = false; |
| 7094 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7095 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7096 | protectedLayerFound |= |
| 7097 | (layerFe->mSnapshot->isVisible && |
| 7098 | layerFe->mSnapshot->hasProtectedContent); |
| 7099 | } |
| 7100 | return protectedLayerFound; |
| 7101 | }) |
| 7102 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 7105 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7106 | GRALLOC_USAGE_HW_TEXTURE | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7107 | (hasProtectedLayer && allowProtected && supportsProtected |
| 7108 | ? GRALLOC_USAGE_PROTECTED |
| 7109 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7110 | sp<GraphicBuffer> buffer = |
| 7111 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7112 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7113 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7114 | |
| 7115 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7116 | if (bufferStatus != OK) { |
| 7117 | // Animations may end up being really janky, but don't crash here. |
| 7118 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7119 | // too much. |
| 7120 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
| 7121 | return ftl::yield<FenceResult>(base::unexpected(bufferStatus)).share(); |
| 7122 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7123 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7124 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7125 | renderengine::impl::ExternalTexture::Usage:: |
| 7126 | WRITEABLE); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7127 | return captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
Derek Sollenberger | 3425788 | 2021-04-06 18:32:34 +0000 | [diff] [blame] | 7128 | false /* regionSampling */, grayscale, captureListener); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7129 | } |
| 7130 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7131 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7132 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7133 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 7134 | bool grayscale, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7135 | ATRACE_CALL(); |
| 7136 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7137 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 7138 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7139 | auto future = mScheduler->schedule( |
| 7140 | [=, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
| 7141 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 7142 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 7143 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7144 | if (!renderArea) { |
| 7145 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 7146 | if (captureListener) { |
| 7147 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7148 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7149 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7150 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7151 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7152 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7153 | ftl::SharedFuture<FenceResult> renderFuture; |
| 7154 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7155 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7156 | canCaptureBlackoutContent, regionSampling, |
| 7157 | grayscale, captureResults); |
| 7158 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7159 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7160 | if (captureListener) { |
| 7161 | // Defer blocking on renderFuture back to the Binder thread. |
| 7162 | return ftl::Future(std::move(renderFuture)) |
| 7163 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 7164 | FenceResult fenceResult) mutable -> FenceResult { |
| 7165 | captureResults.fenceResult = std::move(fenceResult); |
| 7166 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7167 | return base::unexpected(NO_ERROR); |
| 7168 | }) |
| 7169 | .share(); |
| 7170 | } |
| 7171 | return renderFuture; |
| 7172 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7173 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7174 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7175 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 7176 | return future; |
| 7177 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7178 | |
| 7179 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7180 | } |
| 7181 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7182 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7183 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7184 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 7185 | bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, |
| 7186 | ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 7187 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7188 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7189 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7190 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7191 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 7192 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 7193 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 7194 | layerFE->mSnapshot->geomLayerTransform = |
| 7195 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 7196 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 7197 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7198 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7199 | |
| 7200 | // We allow the system server to take screenshots of secure layers for |
| 7201 | // use in situations like the Screen-rotation animation and place |
| 7202 | // the impetus on WindowManager to not persist them. |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7203 | if (captureResults.capturedSecureLayers && !canCaptureBlackoutContent) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7204 | ALOGW("FB is protected: PERMISSION_DENIED"); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7205 | return ftl::yield<FenceResult>(base::unexpected(PERMISSION_DENIED)).share(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7206 | } |
| 7207 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7208 | captureResults.buffer = buffer->getBuffer(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7209 | auto dataspace = renderArea->getReqDataSpace(); |
| 7210 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7211 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7212 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 7213 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 7214 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7215 | if (dataspace == ui::Dataspace::UNKNOWN && parent) { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7216 | Mutex::Autolock lock(mStateLock); |
| 7217 | auto display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 7218 | return display.getLayerStack() == layerStack; |
| 7219 | }); |
| 7220 | if (!display) { |
| 7221 | // If the layer is not on a display, use the dataspace for the default display. |
| 7222 | display = getDefaultDisplayDeviceLocked(); |
| 7223 | } |
| 7224 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7225 | dataspace = ui::pickDataspaceFor(display->getCompositionDisplay()->getState().colorMode); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7226 | renderIntent = display->getCompositionDisplay()->getState().renderIntent; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7227 | sdrWhitePointNits = display->getCompositionDisplay()->getState().sdrWhitePointNits; |
| 7228 | displayBrightnessNits = display->getCompositionDisplay()->getState().displayBrightnessNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7229 | } |
| 7230 | captureResults.capturedDataspace = dataspace; |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7231 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7232 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 7233 | if (!layers.empty()) { |
| 7234 | const sp<LayerFE>& layerFE = layers.back().second; |
| 7235 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 7236 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 7237 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7238 | auto copyLayerFEs = [&layers]() { |
| 7239 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 7240 | layerFEs.reserve(layers.size()); |
| 7241 | for (const auto& [_, layerFE] : layers) { |
| 7242 | layerFEs.push_back(layerFE); |
| 7243 | } |
| 7244 | return layerFEs; |
| 7245 | }; |
| 7246 | |
| 7247 | auto present = [this, buffer = std::move(buffer), dataspace, sdrWhitePointNits, |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 7248 | displayBrightnessNits, grayscale, layerFEs = copyLayerFEs(), layerStack, |
| 7249 | regionSampling, renderArea = std::move(renderArea), |
| 7250 | renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7251 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
| 7252 | mFactory.createCompositionEngine(); |
| 7253 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 7254 | |
| 7255 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 7256 | .renderIntent = renderIntent}; |
| 7257 | |
| 7258 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 7259 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 7260 | .colorProfile = colorProfile, |
| 7261 | .renderArea = *renderArea, |
| 7262 | .layerStack = layerStack, |
| 7263 | .buffer = std::move(buffer), |
| 7264 | .sdrWhitePointNits = sdrWhitePointNits, |
| 7265 | .displayBrightnessNits = displayBrightnessNits, |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7266 | .regionSampling = regionSampling}); |
| 7267 | |
| 7268 | const float colorSaturation = grayscale ? 0 : 1; |
| 7269 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 7270 | .outputs = {output}, |
| 7271 | .layers = std::move(layerFEs), |
| 7272 | .updatingOutputGeometryThisFrame = true, |
| 7273 | .updatingGeometryThisFrame = true, |
| 7274 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 7275 | }; |
| 7276 | compositionEngine->present(refreshArgs); |
| 7277 | |
| 7278 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 7279 | }; |
| 7280 | |
| 7281 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 7282 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 7283 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 7284 | // immediately. |
| 7285 | // |
| 7286 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 7287 | // to CompositionEngine::present. |
| 7288 | const bool renderEngineIsThreaded = [&]() { |
| 7289 | using Type = renderengine::RenderEngine::RenderEngineType; |
| 7290 | const auto type = mRenderEngine->getRenderEngineType(); |
| 7291 | return type == Type::THREADED || type == Type::SKIA_GL_THREADED; |
| 7292 | }(); |
| 7293 | auto presentFuture = renderEngineIsThreaded ? ftl::defer(std::move(present)).share() |
| 7294 | : ftl::yield(present()).share(); |
| 7295 | |
| 7296 | for (auto& [layer, layerFE] : layers) { |
| 7297 | layer->onLayerDisplayed( |
| 7298 | ftl::Future(presentFuture) |
| 7299 | .then([layerFE = std::move(layerFE)](FenceResult) { |
| 7300 | return layerFE->stealCompositionResult().releaseFences.back().get(); |
| 7301 | }) |
| 7302 | .share()); |
| 7303 | } |
| 7304 | |
| 7305 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 7306 | } |
| 7307 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7308 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
| 7309 | if (mLayerLifecycleManagerEnabled) { |
| 7310 | for (auto& layer : mLegacyLayers) { |
| 7311 | visitor(layer.second.get()); |
| 7312 | } |
| 7313 | } else { |
| 7314 | mDrawingState.traverse(visitor); |
| 7315 | } |
| 7316 | } |
| 7317 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7318 | // --------------------------------------------------------------------------- |
| 7319 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 7320 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 7321 | layersSortedByZ.traverse(visitor); |
| 7322 | } |
| 7323 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7324 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 7325 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7328 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 7329 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7330 | } |
| 7331 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7332 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7333 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7334 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 7335 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7336 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7337 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7338 | continue; |
| 7339 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 7340 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7341 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7342 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 7343 | return; |
| 7344 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7345 | if (!layer->isVisible()) { |
| 7346 | return; |
| 7347 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7348 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 7349 | return; |
| 7350 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7351 | visitor(layer); |
| 7352 | }); |
| 7353 | } |
| 7354 | } |
| 7355 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7356 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7357 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 7358 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7359 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7360 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7361 | } |
| 7362 | |
| 7363 | return mPhysicalDisplays.get(displayId) |
| 7364 | .transform(&PhysicalDisplay::snapshotRef) |
| 7365 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 7366 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 7367 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7368 | .transform([](const DisplayModePtr& modePtr) { |
| 7369 | return scheduler::FrameRateMode{modePtr->getFps(), ftl::as_non_null(modePtr)}; |
| 7370 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7371 | } |
| 7372 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7373 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7374 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7375 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7376 | const auto displayId = display->getPhysicalId(); |
| 7377 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7378 | Mutex::Autolock lock(mStateLock); |
| 7379 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7380 | if (mDebugDisplayModeSetByBackdoor) { |
| 7381 | // ignore this request as mode is overridden by backdoor |
| 7382 | return NO_ERROR; |
| 7383 | } |
| 7384 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7385 | auto& selector = display->refreshRateSelector(); |
| 7386 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7387 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7388 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7389 | case SetPolicyResult::Invalid: |
| 7390 | return BAD_VALUE; |
| 7391 | case SetPolicyResult::Unchanged: |
| 7392 | return NO_ERROR; |
| 7393 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7394 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7395 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7396 | |
| 7397 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 7398 | .transform(&PhysicalDisplay::isInternal) |
| 7399 | .value_or(false); |
| 7400 | |
| 7401 | if (isInternalDisplay && displayId != mActiveDisplayId) { |
| 7402 | // The policy will be be applied when the display becomes active. |
| 7403 | ALOGV("%s(%s): Inactive display", __func__, to_string(displayId).c_str()); |
| 7404 | return NO_ERROR; |
| 7405 | } |
| 7406 | |
| 7407 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7408 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7409 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 7410 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7411 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7412 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7413 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 7414 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7415 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 7416 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7417 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
| 7418 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7419 | toggleKernelIdleTimer(); |
| 7420 | } else { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7421 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7422 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 7423 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7424 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7425 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7426 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 7427 | return NAME_NOT_FOUND; |
| 7428 | } |
| 7429 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7430 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7431 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 7432 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7433 | ALOGV("Switching to Scheduler preferred mode %d (%s)", preferredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7434 | to_string(preferredMode.fps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7435 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7436 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7437 | ALOGE("%s: Preferred mode %d is disallowed", __func__, preferredModeId.value()); |
| 7438 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 7439 | } |
| 7440 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7441 | setDesiredActiveMode({std::move(preferredMode), .emitEvent = true}, force); |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 7442 | return NO_ERROR; |
| 7443 | } |
| 7444 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7445 | namespace { |
| 7446 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 7447 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 7448 | } |
| 7449 | |
| 7450 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 7451 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 7452 | } |
| 7453 | |
| 7454 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 7455 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 7456 | aidlRange.min = range.min.getValue(); |
| 7457 | aidlRange.max = range.max.getValue(); |
| 7458 | return aidlRange; |
| 7459 | } |
| 7460 | |
| 7461 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 7462 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 7463 | aidlRanges.physical = translate(ranges.physical); |
| 7464 | aidlRanges.render = translate(ranges.render); |
| 7465 | return aidlRanges; |
| 7466 | } |
| 7467 | |
| 7468 | } // namespace |
| 7469 | |
| 7470 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 7471 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7472 | ATRACE_CALL(); |
| 7473 | |
| 7474 | if (!displayToken) { |
| 7475 | return BAD_VALUE; |
| 7476 | } |
| 7477 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7478 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7479 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7480 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7481 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7482 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7483 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7484 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7485 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7486 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7487 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7488 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7489 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 7490 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7491 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7492 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 7493 | } |
| 7494 | }); |
| 7495 | |
| 7496 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7497 | } |
| 7498 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 7499 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7500 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7501 | ATRACE_CALL(); |
| 7502 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7503 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7504 | return BAD_VALUE; |
| 7505 | } |
| 7506 | |
| 7507 | Mutex::Autolock lock(mStateLock); |
| 7508 | const auto display = getDisplayDeviceLocked(displayToken); |
| 7509 | if (!display) { |
| 7510 | return NAME_NOT_FOUND; |
| 7511 | } |
| 7512 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7513 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7514 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 7515 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7516 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7517 | scheduler::RefreshRateSelector::Policy policy = |
| 7518 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 7519 | outSpecs->defaultMode = policy.defaultMode.value(); |
| 7520 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 7521 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 7522 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7523 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 7524 | } |
| 7525 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 7526 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7527 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 7528 | if (!layer->isRemovedFromCurrentState()) { |
| 7529 | mScheduler->registerLayer(layer); |
| 7530 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 7534 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7535 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 7536 | if (!layer->isRemovedFromCurrentState()) { |
| 7537 | mScheduler->deregisterLayer(layer); |
| 7538 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7539 | if (mTransactionTracing) { |
| 7540 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 7541 | } |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7542 | } |
| 7543 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7544 | void SurfaceFlinger::onLayerUpdate() { |
| 7545 | scheduleCommit(FrameHint::kActive); |
| 7546 | } |
| 7547 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7548 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 7549 | // Here we add children in the current state to offscreen layers and remove the |
| 7550 | // layer itself from the offscreen layer list. Since |
| 7551 | // this is the dtor, it is safe to access the current state. This keeps us |
| 7552 | // from dangling children layers such that they are not reachable from the |
| 7553 | // Drawing state nor the offscreen layer list |
| 7554 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7555 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 7556 | for (auto& child : layer->getCurrentChildren()) { |
| 7557 | mOffscreenLayers.emplace(child.get()); |
| 7558 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 7559 | mOffscreenLayers.erase(layer); |
| 7560 | } |
| 7561 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 7562 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 7563 | mOffscreenLayers.erase(layer); |
| 7564 | } |
| 7565 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 7566 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 7567 | float lightPosY, float lightPosZ, |
| 7568 | float lightRadius) { |
| 7569 | Mutex::Autolock _l(mStateLock); |
| 7570 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 7571 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 7572 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 7573 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 7574 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 7575 | |
| 7576 | // these values are overridden when calculating the shadow settings for a layer. |
| 7577 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 7578 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 7579 | return NO_ERROR; |
| 7580 | } |
| 7581 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7582 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 7583 | const { |
| 7584 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 7585 | // on the work to remove the table in that bug rather than adding more to |
| 7586 | // it. |
| 7587 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7588 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 7589 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 7590 | }; |
| 7591 | return genericLayerMetadataKeyMap; |
| 7592 | } |
| 7593 | |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 7594 | status_t SurfaceFlinger::setOverrideFrameRate(uid_t uid, float frameRate) { |
| 7595 | PhysicalDisplayId displayId = [&]() { |
| 7596 | Mutex::Autolock lock(mStateLock); |
| 7597 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7598 | }(); |
| 7599 | |
| 7600 | mScheduler->setGameModeRefreshRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 7601 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 7602 | return NO_ERROR; |
| 7603 | } |
| 7604 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7605 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7606 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7607 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 7608 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7609 | if (setByHwc) { |
| 7610 | const auto status = |
| 7611 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 7612 | if (status != NO_ERROR) { |
| 7613 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 7614 | return; |
| 7615 | } |
| 7616 | } |
| 7617 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7618 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 7619 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
Yifei Zhang | cfb7bb3 | 2023-01-12 16:17:14 -0800 | [diff] [blame] | 7620 | mRefreshRateOverlayRenderRate, |
| 7621 | mRefreshRateOverlayShowInMiddle); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 7622 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7623 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 7624 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7625 | } |
| 7626 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7627 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 7628 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 7629 | } |
| 7630 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7631 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
| 7632 | std::chrono::nanoseconds presentLatency) { |
| 7633 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 7634 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7635 | pipelineDepth++; |
| 7636 | } |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7637 | return std::max(1ll, pipelineDepth - 1); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7640 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7641 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7642 | |
| 7643 | if (!getHwComposer().isHeadless()) { |
| 7644 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7645 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7646 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7647 | } |
| 7648 | |
| 7649 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7650 | return NO_ERROR; |
| 7651 | } |
| 7652 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 7653 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 7654 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7655 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7656 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 7657 | refreshRate = *frameRateOverride; |
| 7658 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7659 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7660 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7661 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7662 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7663 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 7664 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 7665 | } |
| 7666 | |
| 7667 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 7668 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 7669 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 7670 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 7671 | } |
| 7672 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7673 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7674 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7675 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7676 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 7677 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7681 | bool addToRoot = state.addToRoot; |
| 7682 | if (state.initialParent != nullptr) { |
| 7683 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7684 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7685 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 7686 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7687 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7688 | } |
| 7689 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 7690 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 7691 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7692 | mCurrentState.layersSortedByZ.add(layer); |
| 7693 | } else if (parent == nullptr) { |
| 7694 | layer->onRemovedFromCurrentState(); |
| 7695 | } else if (parent->isRemovedFromCurrentState()) { |
| 7696 | parent->addChild(layer); |
| 7697 | layer->onRemovedFromCurrentState(); |
| 7698 | } else { |
| 7699 | parent->addChild(layer); |
| 7700 | } |
| 7701 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 7702 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 7703 | sp<const DisplayDevice> hintDisplay; |
| 7704 | // Find the display that includes the layer. |
| 7705 | for (const auto& [token, display] : mDisplays) { |
| 7706 | if (display->getLayerStack() == layerStack) { |
| 7707 | hintDisplay = display; |
| 7708 | break; |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | if (hintDisplay) { |
| 7713 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 7714 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 7715 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7716 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7717 | void SurfaceFlinger::sample() { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7718 | if (!mLumaSampling || !mRegionSamplingThread) { |
| 7719 | return; |
| 7720 | } |
| 7721 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7722 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 7723 | } |
| 7724 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7725 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 7726 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 7727 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7728 | } |
| 7729 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7730 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 7731 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7732 | ATRACE_CALL(); |
| 7733 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7734 | if (inactiveDisplayPtr) { |
| 7735 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 7736 | } |
| 7737 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7738 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 7739 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 7740 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7741 | updateActiveDisplayVsyncLocked(activeDisplay); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7742 | mScheduler->setModeChangePending(false); |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 7743 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 7744 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7745 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7746 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 7747 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 7748 | // The policy of the new active/pacesetter display may have changed while it was inactive. In |
| 7749 | // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In |
| 7750 | // either case, the Scheduler's cachedModeChangedParams must be initialized to the newly active |
| 7751 | // mode, and the kernel idle timer of the newly active display must be toggled. |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7752 | constexpr bool kForce = true; |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 7753 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), kForce); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7754 | } |
| 7755 | |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7756 | status_t SurfaceFlinger::addWindowInfosListener( |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 7757 | const sp<IWindowInfosListener>& windowInfosListener) { |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7758 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 7759 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 7760 | return NO_ERROR; |
| 7761 | } |
| 7762 | |
| 7763 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 7764 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 7765 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 7766 | return NO_ERROR; |
| 7767 | } |
| 7768 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7769 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7770 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 7771 | if (bufferData.buffer && |
| 7772 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 7773 | std::string errorMessage = |
| 7774 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 7775 | "layer %s that exceeds render target size limit of %u.", |
| 7776 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 7777 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 7778 | ALOGD("%s", errorMessage.c_str()); |
| 7779 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 7780 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 7781 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 7782 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7783 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7784 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7785 | |
| 7786 | bool cachedBufferChanged = |
| 7787 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 7788 | if (cachedBufferChanged && bufferData.buffer) { |
| 7789 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 7790 | if (result.ok()) { |
| 7791 | return result.value(); |
| 7792 | } |
| 7793 | |
| 7794 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 7795 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 7796 | |
| 7797 | if (bufferData.releaseBufferListener) { |
| 7798 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 7799 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 7800 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 7801 | } |
| 7802 | |
| 7803 | return nullptr; |
| 7804 | } |
| 7805 | |
| 7806 | if (cachedBufferChanged) { |
| 7807 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 7808 | } |
| 7809 | |
| 7810 | if (bufferData.buffer) { |
| 7811 | return std::make_shared< |
| 7812 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 7813 | renderengine::impl::ExternalTexture::Usage:: |
| 7814 | READABLE); |
| 7815 | } |
| 7816 | |
| 7817 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7818 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7819 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 7820 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7821 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 7822 | { |
| 7823 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 7824 | mirrorDisplays = std::move(mMirrorDisplays); |
| 7825 | mMirrorDisplays.clear(); |
| 7826 | if (mirrorDisplays.size() == 0) { |
| 7827 | return false; |
| 7828 | } |
| 7829 | } |
| 7830 | |
| 7831 | sp<IBinder> unused; |
| 7832 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 7833 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 7834 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7835 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7836 | rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 7837 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 7838 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 7839 | layer->isInternalDisplayOverlay()) { |
| 7840 | continue; |
| 7841 | } |
| 7842 | |
| 7843 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 7844 | ISurfaceComposerClient::eNoColorFill, |
| 7845 | gui::LayerMetadata()); |
| 7846 | sp<Layer> childMirror; |
| 7847 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
| 7848 | childMirror->setClonedChild(layer->createClone()); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 7849 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 7850 | } |
| 7851 | } |
| 7852 | return true; |
| 7853 | } |
| 7854 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7855 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 7856 | std::vector<LayerCreatedState>& createdLayers) { |
| 7857 | if (createdLayers.size() == 0) { |
| 7858 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | Mutex::Autolock _l(mStateLock); |
| 7862 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 7863 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7864 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7865 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7866 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 7867 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7868 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 7869 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 7870 | LayerMetadata parentMetadata; |
| 7871 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 7872 | layer->updateMetadataSnapshot(parentMetadata); |
| 7873 | } |
| 7874 | |
| 7875 | std::unordered_set<Layer*> visited; |
| 7876 | mDrawingState.traverse([&visited](Layer* layer) { |
| 7877 | if (visited.find(layer) != visited.end()) { |
| 7878 | return; |
| 7879 | } |
| 7880 | |
| 7881 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 7882 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 7883 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 7884 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 7885 | if (layer->getDrawingState().isRelativeOf) { |
| 7886 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 7887 | return; |
| 7888 | } |
| 7889 | |
| 7890 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 7891 | }); |
| 7892 | } |
| 7893 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7894 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 7895 | compositionengine::CompositionRefreshArgs& refreshArgs, |
| 7896 | std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
| 7897 | if (mLayerLifecycleManagerEnabled) { |
| 7898 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 7899 | mLayerSnapshotBuilder.getSnapshots(); |
| 7900 | for (auto [_, layerFE] : layers) { |
| 7901 | auto i = layerFE->mSnapshot->globalZ; |
| 7902 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 7903 | } |
| 7904 | } |
| 7905 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
| 7906 | for (auto [layer, layerFE] : layers) { |
| 7907 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 7908 | } |
| 7909 | } |
| 7910 | } |
| 7911 | |
| 7912 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
| 7913 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly, int64_t vsyncId) { |
| 7914 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
| 7915 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 7916 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7917 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 7918 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 7919 | if (cursorOnly && |
| 7920 | snapshot->compositionType != |
| 7921 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 7922 | return; |
| 7923 | } |
| 7924 | |
| 7925 | if (!snapshot->hasSomethingToDraw()) { |
| 7926 | return; |
| 7927 | } |
| 7928 | |
| 7929 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 7930 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 7931 | "Couldnt find layer object for %s", |
| 7932 | snapshot->getDebugString().c_str()); |
| 7933 | auto& legacyLayer = it->second; |
| 7934 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 7935 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7936 | layerFE->mSnapshot = std::move(snapshot); |
| 7937 | refreshArgs.layers.push_back(layerFE); |
| 7938 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 7939 | }); |
| 7940 | } |
| 7941 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
| 7942 | mDrawingState.traverseInZOrder([&refreshArgs, cursorOnly, &layers](Layer* layer) { |
| 7943 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 7944 | if (cursorOnly && |
| 7945 | layer->getLayerSnapshot()->compositionType != |
| 7946 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 7947 | return; |
| 7948 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 7949 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 7950 | refreshArgs.layers.push_back(layerFE); |
| 7951 | layers.emplace_back(layer, layerFE.get()); |
| 7952 | } |
| 7953 | }); |
| 7954 | } |
| 7955 | |
| 7956 | return layers; |
| 7957 | } |
| 7958 | |
| 7959 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7960 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 7961 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 7962 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 7963 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7964 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7965 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7966 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7967 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 7968 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7969 | if (stopTraversal) { |
| 7970 | return; |
| 7971 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7972 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 7973 | return; |
| 7974 | } |
| 7975 | if (uid != CaptureArgs::UNSET_UID && snapshot->inputInfo.ownerUid != uid) { |
| 7976 | return; |
| 7977 | } |
| 7978 | if (!snapshot->hasSomethingToDraw()) { |
| 7979 | return; |
| 7980 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7981 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 7982 | return; |
| 7983 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7984 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7985 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 7986 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 7987 | "Couldnt find layer object for %s", |
| 7988 | snapshot->getDebugString().c_str()); |
| 7989 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 7990 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 7991 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 7992 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 7993 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7994 | |
| 7995 | return layers; |
| 7996 | }; |
| 7997 | } |
| 7998 | |
| 7999 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
| 8000 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 8001 | std::unordered_set<uint32_t> excludeLayerIds, |
| 8002 | bool childrenOnly, const FloatRect& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8003 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8004 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8005 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8006 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8007 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8008 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8009 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8010 | .displays = mFrontEndDisplayInfos, |
| 8011 | .displayChanges = true, |
| 8012 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
| 8013 | .supportsBlur = mSupportsBlur, |
| 8014 | .forceFullDamage = mForceFullDamage, |
| 8015 | .parentCrop = {parentCrop}, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8016 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8017 | .supportedLayerGenericMetadata = |
| 8018 | getHwComposer().getSupportedLayerGenericMetadata(), |
| 8019 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8020 | mLayerSnapshotBuilder.update(args); |
| 8021 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8022 | auto getLayerSnapshotsFn = |
| 8023 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8024 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8025 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 8026 | args.parentCrop.reset(); |
| 8027 | args.excludeLayerIds.clear(); |
| 8028 | mLayerSnapshotBuilder.update(args); |
| 8029 | return layers; |
| 8030 | }; |
| 8031 | } |
| 8032 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 8033 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 8034 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8035 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 8036 | // Locking: |
| 8037 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 8038 | // we must keep a copy of the transactions (specifically the composer |
| 8039 | // states) around outside the scope of the lock. |
| 8040 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 8041 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 8042 | // before committing the created layers. |
| 8043 | update.transactions = mTransactionHandler.flushTransactions(); |
| 8044 | { |
| 8045 | // TODO(b/238781169) lockless queue this and keep order. |
| 8046 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 8047 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 8048 | mCreatedLayers.clear(); |
| 8049 | update.newLayers = std::move(mNewLayers); |
| 8050 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 8051 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 8052 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8053 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 8054 | mDestroyedHandles.clear(); |
| 8055 | } |
| 8056 | return update; |
| 8057 | } |
| 8058 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 8059 | void SurfaceFlinger::addToLayerTracing(bool visibleRegionDirty, int64_t time, int64_t vsyncId) { |
| 8060 | const uint32_t tracingFlags = mLayerTracing.getFlags(); |
| 8061 | LayersProto layers(dumpDrawingStateProto(tracingFlags)); |
| 8062 | if (tracingFlags & LayerTracing::TRACE_EXTRA) { |
| 8063 | dumpOffscreenLayersProto(layers); |
| 8064 | } |
| 8065 | std::string hwcDump; |
| 8066 | if (tracingFlags & LayerTracing::TRACE_HWC) { |
| 8067 | dumpHwc(hwcDump); |
| 8068 | } |
| 8069 | auto displays = dumpDisplayProto(); |
| 8070 | mLayerTracing.notify(visibleRegionDirty, time, vsyncId, &layers, std::move(hwcDump), &displays); |
| 8071 | } |
| 8072 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8073 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8074 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8075 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 8076 | status_t status = checkAccessPermission(); |
| 8077 | if (status != OK) { |
| 8078 | return binderStatusFromStatusT(status); |
| 8079 | } |
| 8080 | mFlinger->bootFinished(); |
| 8081 | return binder::Status::ok(); |
| 8082 | } |
| 8083 | |
| 8084 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 8085 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8086 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8087 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8088 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8089 | if (conn == nullptr) { |
| 8090 | *outConnection = nullptr; |
| 8091 | return binderStatusFromStatusT(BAD_VALUE); |
| 8092 | } else { |
| 8093 | *outConnection = conn; |
| 8094 | return binder::Status::ok(); |
| 8095 | } |
| 8096 | } |
| 8097 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8098 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 8099 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8100 | if (client->initCheck() == NO_ERROR) { |
| 8101 | *outClient = client; |
| 8102 | return binder::Status::ok(); |
| 8103 | } else { |
| 8104 | *outClient = nullptr; |
| 8105 | return binderStatusFromStatusT(BAD_VALUE); |
| 8106 | } |
| 8107 | } |
| 8108 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8109 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8110 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8111 | sp<IBinder>* outDisplay) { |
| 8112 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8113 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8114 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8115 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8116 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8117 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8118 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8119 | } |
| 8120 | |
| 8121 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 8122 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8123 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8124 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8125 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8126 | mFlinger->destroyDisplay(display); |
| 8127 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 8131 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 8132 | std::vector<int64_t> displayIds; |
| 8133 | displayIds.reserve(physicalDisplayIds.size()); |
| 8134 | for (auto item : physicalDisplayIds) { |
| 8135 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 8136 | } |
| 8137 | *outDisplayIds = displayIds; |
| 8138 | return binder::Status::ok(); |
| 8139 | } |
| 8140 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8141 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 8142 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8143 | status_t status = checkAccessPermission(); |
| 8144 | if (status != OK) { |
| 8145 | return binderStatusFromStatusT(status); |
| 8146 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8147 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 8148 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 8149 | return binder::Status::ok(); |
| 8150 | } |
| 8151 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8152 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 8153 | status_t status = checkAccessPermission(); |
| 8154 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8155 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8156 | } |
| 8157 | mFlinger->setPowerMode(display, mode); |
| 8158 | return binder::Status::ok(); |
| 8159 | } |
| 8160 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8161 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 8162 | std::vector<FrameEvent>* outSupported) { |
| 8163 | status_t status; |
| 8164 | if (!outSupported) { |
| 8165 | status = UNEXPECTED_NULL; |
| 8166 | } else { |
| 8167 | outSupported->clear(); |
| 8168 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 8169 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8170 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8171 | } |
| 8172 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8173 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 8174 | gui::DisplayStatInfo* outStatInfo) { |
| 8175 | DisplayStatInfo statInfo; |
| 8176 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 8177 | if (status == NO_ERROR) { |
| 8178 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 8179 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 8180 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8181 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 8185 | gui::DisplayState* outState) { |
| 8186 | ui::DisplayState state; |
| 8187 | status_t status = mFlinger->getDisplayState(display, &state); |
| 8188 | if (status == NO_ERROR) { |
| 8189 | outState->layerStack = state.layerStack.id; |
| 8190 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 8191 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 8192 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 8193 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8194 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8195 | } |
| 8196 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8197 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8198 | gui::StaticDisplayInfo* outInfo) { |
| 8199 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 8200 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8201 | |
| 8202 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8203 | if (status == NO_ERROR) { |
| 8204 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 8205 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 8206 | outInfo->density = info.density; |
| 8207 | outInfo->secure = info.secure; |
| 8208 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 8209 | |
| 8210 | gui::DeviceProductInfo dinfo; |
| 8211 | std::optional<DeviceProductInfo> dpi = info.deviceProductInfo; |
| 8212 | dinfo.name = std::move(dpi->name); |
| 8213 | dinfo.manufacturerPnpId = |
| 8214 | std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), dpi->manufacturerPnpId.end()); |
| 8215 | dinfo.productId = dpi->productId; |
Kriti Dang | 1de958d | 2022-05-30 15:26:58 +0200 | [diff] [blame] | 8216 | dinfo.relativeAddress = |
| 8217 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8218 | if (const auto* model = |
| 8219 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 8220 | gui::DeviceProductInfo::ModelYear modelYear; |
| 8221 | modelYear.year = model->year; |
| 8222 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 8223 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 8224 | &dpi->manufactureOrModelDate)) { |
| 8225 | gui::DeviceProductInfo::ManufactureYear date; |
| 8226 | date.modelYear.year = manufacture->year; |
| 8227 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 8228 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 8229 | &dpi->manufactureOrModelDate)) { |
| 8230 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 8231 | date.manufactureYear.modelYear.year = manufacture->year; |
| 8232 | date.week = manufacture->week; |
| 8233 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 8234 | } |
| 8235 | |
| 8236 | outInfo->deviceProductInfo = dinfo; |
| 8237 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8238 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8239 | } |
| 8240 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8241 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 8242 | gui::DynamicDisplayInfo*& outInfo) { |
| 8243 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 8244 | outInfo->supportedDisplayModes.clear(); |
| 8245 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 8246 | for (const auto& mode : info.supportedDisplayModes) { |
| 8247 | gui::DisplayMode outMode; |
| 8248 | outMode.id = mode.id; |
| 8249 | outMode.resolution.width = mode.resolution.width; |
| 8250 | outMode.resolution.height = mode.resolution.height; |
| 8251 | outMode.xDpi = mode.xDpi; |
| 8252 | outMode.yDpi = mode.yDpi; |
| 8253 | outMode.refreshRate = mode.refreshRate; |
| 8254 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 8255 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 8256 | outMode.presentationDeadline = mode.presentationDeadline; |
| 8257 | outMode.group = mode.group; |
| 8258 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 8259 | std::back_inserter(outMode.supportedHdrTypes), |
| 8260 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 8261 | outInfo->supportedDisplayModes.push_back(outMode); |
| 8262 | } |
| 8263 | |
| 8264 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 8265 | outInfo->renderFrameRate = info.renderFrameRate; |
| 8266 | |
| 8267 | outInfo->supportedColorModes.clear(); |
| 8268 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 8269 | for (const auto& cmode : info.supportedColorModes) { |
| 8270 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 8271 | } |
| 8272 | |
| 8273 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 8274 | |
| 8275 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 8276 | hdrCapabilities.supportedHdrTypes.clear(); |
| 8277 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 8278 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 8279 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 8280 | } |
| 8281 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 8282 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 8283 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 8284 | |
| 8285 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 8286 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 8287 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 8288 | } |
| 8289 | |
| 8290 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 8291 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8292 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8293 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8294 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8295 | getDynamicDisplayInfoInternal(info, outInfo); |
| 8296 | } |
| 8297 | return binderStatusFromStatusT(status); |
| 8298 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 8299 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8300 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 8301 | gui::DynamicDisplayInfo* outInfo) { |
| 8302 | ui::DynamicDisplayInfo info; |
| 8303 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 8304 | if (status == NO_ERROR) { |
| 8305 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8306 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8307 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 8308 | } |
| 8309 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8310 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 8311 | gui::DisplayPrimaries* outPrimaries) { |
| 8312 | ui::DisplayPrimaries primaries; |
| 8313 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 8314 | if (status == NO_ERROR) { |
| 8315 | outPrimaries->red.X = primaries.red.X; |
| 8316 | outPrimaries->red.Y = primaries.red.Y; |
| 8317 | outPrimaries->red.Z = primaries.red.Z; |
| 8318 | |
| 8319 | outPrimaries->green.X = primaries.green.X; |
| 8320 | outPrimaries->green.Y = primaries.green.Y; |
| 8321 | outPrimaries->green.Z = primaries.green.Z; |
| 8322 | |
| 8323 | outPrimaries->blue.X = primaries.blue.X; |
| 8324 | outPrimaries->blue.Y = primaries.blue.Y; |
| 8325 | outPrimaries->blue.Z = primaries.blue.Z; |
| 8326 | |
| 8327 | outPrimaries->white.X = primaries.white.X; |
| 8328 | outPrimaries->white.Y = primaries.white.Y; |
| 8329 | outPrimaries->white.Z = primaries.white.Z; |
| 8330 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8331 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 8335 | status_t status = checkAccessPermission(); |
| 8336 | if (status == OK) { |
| 8337 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 8338 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8339 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 8343 | int displayModeId) { |
| 8344 | status_t status = checkAccessPermission(); |
| 8345 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8346 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8347 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8348 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 8349 | } |
| 8350 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8351 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 8352 | status_t status = checkAccessPermission(); |
| 8353 | if (status == OK) { |
| 8354 | status = mFlinger->clearBootDisplayMode(display); |
| 8355 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8356 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8357 | } |
| 8358 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 8359 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 8360 | status_t status = checkAccessPermission(); |
| 8361 | if (status == OK) { |
| 8362 | status = mFlinger->getOverlaySupport(outProperties); |
| 8363 | } |
| 8364 | return binderStatusFromStatusT(status); |
| 8365 | } |
| 8366 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8367 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 8368 | status_t status = checkAccessPermission(); |
| 8369 | if (status == OK) { |
| 8370 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 8371 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8372 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8373 | } |
| 8374 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8375 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 8376 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 8377 | status_t status = checkAccessPermission(); |
| 8378 | if (status == OK) { |
| 8379 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 8380 | } |
| 8381 | return binderStatusFromStatusT(status); |
| 8382 | } |
| 8383 | |
| 8384 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8385 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 8386 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8387 | status_t status = checkAccessPermission(); |
| 8388 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 8389 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 8390 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 8391 | } |
| 8392 | return binderStatusFromStatusT(status); |
| 8393 | } |
| 8394 | |
| 8395 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 8396 | status_t status = checkAccessPermission(); |
| 8397 | if (status == OK) { |
| 8398 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 8399 | } |
| 8400 | return binderStatusFromStatusT(status); |
| 8401 | } |
| 8402 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8403 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 8404 | status_t status = checkAccessPermission(); |
| 8405 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8406 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8407 | } |
| 8408 | mFlinger->setAutoLowLatencyMode(display, on); |
| 8409 | return binder::Status::ok(); |
| 8410 | } |
| 8411 | |
| 8412 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 8413 | status_t status = checkAccessPermission(); |
| 8414 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8415 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8416 | } |
| 8417 | mFlinger->setGameContentType(display, on); |
| 8418 | return binder::Status::ok(); |
| 8419 | } |
| 8420 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8421 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 8422 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 8423 | status_t status = mFlinger->captureDisplay(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8424 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8425 | } |
| 8426 | |
| 8427 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
| 8428 | int64_t displayId, const sp<IScreenCaptureListener>& captureListener) { |
| 8429 | status_t status; |
| 8430 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8431 | const int uid = ipc->getCallingUid(); |
| 8432 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 8433 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
| 8434 | status = mFlinger->captureDisplay(*id, captureListener); |
| 8435 | } else { |
| 8436 | status = PERMISSION_DENIED; |
| 8437 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8438 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8439 | } |
| 8440 | |
| 8441 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 8442 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
| 8443 | status_t status = mFlinger->captureLayers(args, captureListener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8444 | return binderStatusFromStatusT(status); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8445 | } |
| 8446 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8447 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 8448 | const std::vector<int32_t>& hdrTypes) { |
| 8449 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 8450 | // permission dynamically. Don't use the permission cache for this check. |
| 8451 | status_t status = checkAccessPermission(false); |
| 8452 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8453 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8454 | } |
| 8455 | |
| 8456 | std::vector<ui::Hdr> hdrTypesVector; |
| 8457 | for (int32_t i : hdrTypes) { |
| 8458 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 8459 | } |
| 8460 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8461 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 8465 | status_t status; |
| 8466 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 8467 | if (uid != AID_SYSTEM) { |
| 8468 | status = PERMISSION_DENIED; |
| 8469 | } else { |
| 8470 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 8471 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8472 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8473 | } |
| 8474 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8475 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 8476 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8477 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8481 | const int pid = ipc->getCallingPid(); |
| 8482 | const int uid = ipc->getCallingUid(); |
| 8483 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 8484 | 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] | 8485 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8486 | } |
| 8487 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8488 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8489 | } |
| 8490 | |
| 8491 | binder::Status SurfaceComposerAIDL::getColorManagement(bool* outGetColorManagement) { |
| 8492 | status_t status = mFlinger->getColorManagement(outGetColorManagement); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8493 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8494 | } |
| 8495 | |
| 8496 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 8497 | ui::Dataspace dataspace; |
| 8498 | ui::PixelFormat pixelFormat; |
| 8499 | ui::Dataspace wideColorGamutDataspace; |
| 8500 | ui::PixelFormat wideColorGamutPixelFormat; |
| 8501 | status_t status = |
| 8502 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 8503 | &wideColorGamutPixelFormat); |
| 8504 | if (status == NO_ERROR) { |
| 8505 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 8506 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 8507 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 8508 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 8509 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8510 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 8514 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 8515 | status_t status = checkAccessPermission(); |
| 8516 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8517 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | ui::PixelFormat format; |
| 8521 | ui::Dataspace dataspace; |
| 8522 | uint8_t componentMask; |
| 8523 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 8524 | &componentMask); |
| 8525 | if (status == NO_ERROR) { |
| 8526 | outAttrs->format = static_cast<int32_t>(format); |
| 8527 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 8528 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 8529 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8530 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 8534 | bool enable, |
| 8535 | int8_t componentMask, |
| 8536 | int64_t maxFrames) { |
| 8537 | status_t status = checkAccessPermission(); |
| 8538 | if (status == OK) { |
| 8539 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 8540 | static_cast<uint8_t>(componentMask), |
| 8541 | static_cast<uint64_t>(maxFrames)); |
| 8542 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8543 | return binderStatusFromStatusT(status); |
| 8544 | } |
| 8545 | |
| 8546 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 8547 | int64_t maxFrames, int64_t timestamp, |
| 8548 | gui::DisplayedFrameStats* outStats) { |
| 8549 | if (!outStats) { |
| 8550 | return binderStatusFromStatusT(BAD_VALUE); |
| 8551 | } |
| 8552 | |
| 8553 | status_t status = checkAccessPermission(); |
| 8554 | if (status != OK) { |
| 8555 | return binderStatusFromStatusT(status); |
| 8556 | } |
| 8557 | |
| 8558 | DisplayedFrameStats stats; |
| 8559 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 8560 | static_cast<uint64_t>(timestamp), &stats); |
| 8561 | if (status == NO_ERROR) { |
| 8562 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 8563 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 8564 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 8565 | for (const auto& s : stats.component_0_sample) { |
| 8566 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 8567 | } |
| 8568 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 8569 | for (const auto& s : stats.component_1_sample) { |
| 8570 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 8571 | } |
| 8572 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 8573 | for (const auto& s : stats.component_2_sample) { |
| 8574 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 8575 | } |
| 8576 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 8577 | for (const auto& s : stats.component_3_sample) { |
| 8578 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 8579 | } |
| 8580 | } |
| 8581 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8582 | } |
| 8583 | |
| 8584 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 8585 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8586 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 8587 | } |
| 8588 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8589 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 8590 | bool* outIsWideColorDisplay) { |
| 8591 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8592 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8593 | } |
| 8594 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8595 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 8596 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 8597 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8598 | status_t status = checkReadFrameBufferPermission(); |
| 8599 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8600 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8601 | } |
| 8602 | android::Rect rect; |
| 8603 | rect.left = samplingArea.left; |
| 8604 | rect.top = samplingArea.top; |
| 8605 | rect.right = samplingArea.right; |
| 8606 | rect.bottom = samplingArea.bottom; |
| 8607 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8608 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8609 | } |
| 8610 | |
| 8611 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 8612 | const sp<gui::IRegionSamplingListener>& listener) { |
| 8613 | status_t status = checkReadFrameBufferPermission(); |
| 8614 | if (status == OK) { |
| 8615 | status = mFlinger->removeRegionSamplingListener(listener); |
| 8616 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8617 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8618 | } |
| 8619 | |
| 8620 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 8621 | const sp<gui::IFpsListener>& listener) { |
| 8622 | status_t status = checkReadFrameBufferPermission(); |
| 8623 | if (status == OK) { |
| 8624 | status = mFlinger->addFpsListener(taskId, listener); |
| 8625 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8626 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 8630 | status_t status = checkReadFrameBufferPermission(); |
| 8631 | if (status == OK) { |
| 8632 | status = mFlinger->removeFpsListener(listener); |
| 8633 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8634 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8635 | } |
| 8636 | |
| 8637 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 8638 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8639 | status_t status = checkAccessPermission(); |
| 8640 | if (status == OK) { |
| 8641 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 8642 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8643 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8644 | } |
| 8645 | |
| 8646 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 8647 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 8648 | status_t status = checkAccessPermission(); |
| 8649 | if (status == OK) { |
| 8650 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 8651 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8652 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8653 | } |
| 8654 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8655 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8656 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8657 | status_t status = checkAccessPermission(); |
| 8658 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8659 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8660 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8661 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8662 | } |
| 8663 | |
| 8664 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8665 | gui::DisplayModeSpecs* outSpecs) { |
| 8666 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8667 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8668 | } |
| 8669 | |
| 8670 | status_t status = checkAccessPermission(); |
| 8671 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8672 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8673 | } |
| 8674 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8675 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8676 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8677 | } |
| 8678 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8679 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 8680 | bool* outSupport) { |
| 8681 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8682 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8683 | } |
| 8684 | |
| 8685 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 8686 | const gui::DisplayBrightness& brightness) { |
| 8687 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8688 | if (status == OK) { |
| 8689 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 8690 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8691 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8692 | } |
| 8693 | |
| 8694 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 8695 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 8696 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8697 | if (status == OK) { |
| 8698 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 8699 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8700 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8701 | } |
| 8702 | |
| 8703 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 8704 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 8705 | status_t status = checkControlDisplayBrightnessPermission(); |
| 8706 | if (status == OK) { |
| 8707 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 8708 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8709 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8710 | } |
| 8711 | |
| 8712 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 8713 | status_t status = checkAccessPermission(); |
| 8714 | if (status == OK) { |
| 8715 | status = mFlinger->notifyPowerBoost(boostId); |
| 8716 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8717 | return binderStatusFromStatusT(status); |
| 8718 | } |
| 8719 | |
| 8720 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 8721 | const gui::Color& spotColor, |
| 8722 | float lightPosY, float lightPosZ, |
| 8723 | float lightRadius) { |
| 8724 | status_t status = checkAccessPermission(); |
| 8725 | if (status != OK) { |
| 8726 | return binderStatusFromStatusT(status); |
| 8727 | } |
| 8728 | |
| 8729 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 8730 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 8731 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 8732 | lightPosZ, lightRadius); |
| 8733 | return binderStatusFromStatusT(status); |
| 8734 | } |
| 8735 | |
| 8736 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 8737 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 8738 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 8739 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 8740 | if (status != NO_ERROR) { |
| 8741 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 8742 | return binderStatusFromStatusT(status); |
| 8743 | } |
| 8744 | |
| 8745 | if (!support || !support.has_value()) { |
| 8746 | outSupport->reset(); |
| 8747 | } else { |
| 8748 | outSupport->emplace(); |
| 8749 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 8750 | outSupport->value().alphaInterpretation = |
| 8751 | static_cast<int32_t>(support->alphaInterpretation); |
| 8752 | } |
| 8753 | |
| 8754 | return binder::Status::ok(); |
| 8755 | } |
| 8756 | |
| 8757 | binder::Status SurfaceComposerAIDL::setOverrideFrameRate(int32_t uid, float frameRate) { |
| 8758 | status_t status; |
| 8759 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 8760 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 8761 | status = mFlinger->setOverrideFrameRate(uid, frameRate); |
| 8762 | } else { |
| 8763 | ALOGE("setOverrideFrameRate() permission denied for uid: %d", c_uid); |
| 8764 | status = PERMISSION_DENIED; |
| 8765 | } |
| 8766 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8767 | } |
| 8768 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8769 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 8770 | *outPriority = mFlinger->getGpuContextPriority(); |
| 8771 | return binder::Status::ok(); |
| 8772 | } |
| 8773 | |
| 8774 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 8775 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8776 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8777 | } |
| 8778 | |
| 8779 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
| 8780 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 8781 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8782 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8783 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8784 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 8785 | // WindowInfosListeners |
| 8786 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 8787 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8788 | status = mFlinger->addWindowInfosListener(windowInfosListener); |
| 8789 | } else { |
| 8790 | status = PERMISSION_DENIED; |
| 8791 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8792 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8793 | } |
| 8794 | |
| 8795 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 8796 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 8797 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8798 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8799 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 8800 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 8801 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8802 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 8803 | } else { |
| 8804 | status = PERMISSION_DENIED; |
| 8805 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8806 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8807 | } |
| 8808 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8809 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 8810 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 8811 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8812 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 8813 | ipc->getCallingUid()); |
| 8814 | return PERMISSION_DENIED; |
| 8815 | } |
| 8816 | return OK; |
| 8817 | } |
| 8818 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8819 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 8820 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8821 | const int pid = ipc->getCallingPid(); |
| 8822 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 8823 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8824 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 8825 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 8826 | return PERMISSION_DENIED; |
| 8827 | } |
| 8828 | return OK; |
| 8829 | } |
| 8830 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8831 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 8832 | IPCThreadState* ipc = IPCThreadState::self(); |
| 8833 | const int pid = ipc->getCallingPid(); |
| 8834 | const int uid = ipc->getCallingUid(); |
| 8835 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 8836 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 8837 | return PERMISSION_DENIED; |
| 8838 | } |
| 8839 | return OK; |
| 8840 | } |
| 8841 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 8842 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 8843 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 8844 | } |
| 8845 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 8846 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 8847 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 8848 | #if defined(__gl_h_) |
| 8849 | #error "don't include gl/gl.h in this file" |
| 8850 | #endif |
| 8851 | |
| 8852 | #if defined(__gl2_h_) |
| 8853 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 8854 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 8855 | |
| 8856 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 8857 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |