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 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 27 | #include <aidl/android/hardware/power/Boost.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 28 | #include <android-base/parseint.h> |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
| 31 | #include <android-base/strings.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 32 | #include <android/configuration.h> |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 33 | #include <android/gui/IDisplayEventConnection.h> |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 34 | #include <android/gui/StaticDisplayInfo.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 35 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 36 | #include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h> |
| 37 | #include <android/hardware/configstore/1.1/types.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> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 71 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 72 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 73 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 74 | #include <layerproto/LayerProtoParser.h> |
| 75 | #include <log/log.h> |
| 76 | #include <private/android_filesystem_config.h> |
| 77 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 78 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 79 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 80 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 81 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 82 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 83 | #include <ui/ColorSpace.h> |
| 84 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 85 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 87 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 88 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 89 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 90 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 91 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 92 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 93 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 94 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 95 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 97 | #include <utils/String16.h> |
| 98 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 99 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 100 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 101 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 102 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 103 | #include <cinttypes> |
| 104 | #include <cmath> |
| 105 | #include <cstdint> |
| 106 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 107 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 108 | #include <mutex> |
| 109 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 110 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 111 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 112 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 113 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 115 | #include <gui/LayerStatePermissions.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 116 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 117 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 118 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 119 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 120 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 121 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 122 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 123 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 124 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 125 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 126 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 127 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 128 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 129 | #include "Effects/Daltonizer.h" |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 130 | #include "FlagManager.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 131 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 132 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 133 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 134 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 135 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 136 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 137 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 138 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 139 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 140 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 141 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 142 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 143 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 144 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 145 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 146 | #include "RegionSamplingThread.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 147 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 148 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 149 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 150 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 151 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 152 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 153 | #include "StartPropertySetThread.h" |
| 154 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 155 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 156 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 157 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 158 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 159 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 160 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 161 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 162 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 163 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 164 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 165 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 166 | _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] | 167 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 168 | // To enable layer borders in the system, change the below flag to true. |
| 169 | #undef DOES_CONTAIN_BORDER |
| 170 | #define DOES_CONTAIN_BORDER false |
| 171 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | namespace android { |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 173 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 174 | using namespace std::chrono_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 175 | using namespace std::string_literals; |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 176 | using namespace std::string_view_literals; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 177 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 178 | using namespace hardware::configstore; |
| 179 | using namespace hardware::configstore::V1_0; |
| 180 | using namespace sysprop; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 181 | using ftl::Flags; |
| 182 | using namespace ftl::flag_operators; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 183 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 184 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
| 185 | using aidl::android::hardware::graphics::composer3::Capability; |
| 186 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 187 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 188 | OutputCompositionState::CompositionStrategyPredictionState; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 189 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 190 | using base::StringAppendF; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 191 | using display::PhysicalDisplay; |
| 192 | using display::PhysicalDisplays; |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 193 | using frontend::TransactionHandler; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 194 | using gui::DisplayInfo; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 195 | using gui::GameMode; |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 196 | using gui::IDisplayEventConnection; |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 197 | using gui::IWindowInfosListener; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 198 | using gui::LayerMetadata; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 199 | using gui::WindowInfo; |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 200 | using gui::aidl_utils::binderStatusFromStatusT; |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 201 | using scheduler::VsyncModulator; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 202 | using ui::Dataspace; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 203 | using ui::DisplayPrimaries; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 204 | using ui::RenderIntent; |
Jiyong Park | 4b20c2e | 2017-01-14 19:45:11 +0900 | [diff] [blame] | 205 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 206 | using KernelIdleTimerController = scheduler::RefreshRateSelector::KernelIdleTimerController; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 207 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 208 | namespace hal = android::hardware::graphics::composer::hal; |
| 209 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 210 | namespace { |
Peiyong Lin | fca547f | 2018-07-09 13:03:33 -0700 | [diff] [blame] | 211 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 212 | static constexpr int FOUR_K_WIDTH = 3840; |
| 213 | static constexpr int FOUR_K_HEIGHT = 2160; |
| 214 | |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 215 | // TODO(b/141333600): Consolidate with DisplayMode::Builder::getDefaultDensity. |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 216 | constexpr float FALLBACK_DENSITY = ACONFIGURATION_DENSITY_TV; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 217 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 218 | float getDensityFromProperty(const char* property, bool required) { |
| 219 | char value[PROPERTY_VALUE_MAX]; |
| 220 | const float density = property_get(property, value, nullptr) > 0 ? std::atof(value) : 0.f; |
| 221 | if (!density && required) { |
| 222 | ALOGE("%s must be defined as a build property", property); |
| 223 | return FALLBACK_DENSITY; |
| 224 | } |
| 225 | return density; |
| 226 | } |
| 227 | |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 228 | // Currently we only support V0_SRGB and DISPLAY_P3 as composition preference. |
| 229 | bool validateCompositionDataspace(Dataspace dataspace) { |
| 230 | return dataspace == Dataspace::V0_SRGB || dataspace == Dataspace::DISPLAY_P3; |
| 231 | } |
| 232 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 233 | std::chrono::milliseconds getIdleTimerTimeout(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 234 | const auto displayIdleTimerMsKey = [displayId] { |
| 235 | std::stringstream ss; |
| 236 | ss << "debug.sf.set_idle_timer_ms_" << displayId.value; |
| 237 | return ss.str(); |
| 238 | }(); |
| 239 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 240 | const int32_t displayIdleTimerMs = base::GetIntProperty(displayIdleTimerMsKey, 0); |
| 241 | if (displayIdleTimerMs > 0) { |
| 242 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 243 | } |
| 244 | |
| 245 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms", 0); |
| 246 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 247 | return std::chrono::milliseconds(millis); |
| 248 | } |
| 249 | |
| 250 | bool getKernelIdleTimerSyspropConfig(DisplayId displayId) { |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 251 | const auto displaySupportKernelIdleTimerKey = [displayId] { |
| 252 | std::stringstream ss; |
| 253 | ss << "debug.sf.support_kernel_idle_timer_" << displayId.value; |
| 254 | return ss.str(); |
| 255 | }(); |
| 256 | |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 257 | const auto displaySupportKernelIdleTimer = |
| 258 | base::GetBoolProperty(displaySupportKernelIdleTimerKey, false); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 259 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 262 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 263 | using fps_approx_ops::operator>; |
| 264 | Fps refreshRate = Fps::fromValue(outMode.refreshRate); |
| 265 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 266 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 267 | } |
| 268 | |
| 269 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 270 | ui::DisplayMode& outMode) { |
| 271 | if (isAbove4k30(outMode) && |
| 272 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 273 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 274 | for (ui::Hdr type : displayHdrTypes) { |
| 275 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 276 | outMode.supportedHdrTypes.push_back(type); |
| 277 | } |
| 278 | } |
| 279 | } else { |
| 280 | for (ui::Hdr type : displayHdrTypes) { |
| 281 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 282 | outMode.supportedHdrTypes.push_back(type); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 289 | std::vector<ui::Hdr> hdrTypes; |
| 290 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 291 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 292 | hdrTypes.push_back(type); |
| 293 | } |
| 294 | } |
| 295 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 296 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 297 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 298 | } |
| 299 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 300 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 301 | if (!surfaceControl) { |
| 302 | return UNASSIGNED_LAYER_ID; |
| 303 | } |
| 304 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 305 | } |
| 306 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 307 | } // namespace anonymous |
| 308 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | // --------------------------------------------------------------------------- |
| 310 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 311 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 312 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 313 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 314 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 315 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 316 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 317 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 318 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 319 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 320 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 321 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 322 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 323 | static const int MAX_TRACING_MEMORY = 1024 * 1024 * 1024; // 1GB |
| 324 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 325 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 326 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 327 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 328 | bool SurfaceFlinger::hasSyncFramework; |
| 329 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 330 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 331 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 332 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 333 | bool SurfaceFlinger::useContextPriority; |
| 334 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 335 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 336 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 337 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 338 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 339 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 340 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 341 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 342 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 343 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 344 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 345 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 346 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 347 | return std::string("Enhanced"); |
| 348 | default: |
| 349 | return std::string("Unknown ") + |
| 350 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 351 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 354 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 355 | IPCThreadState* ipc = IPCThreadState::self(); |
| 356 | const int pid = ipc->getCallingPid(); |
| 357 | const int uid = ipc->getCallingUid(); |
| 358 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 359 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 362 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 363 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 364 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 365 | : mFactory(factory), |
| 366 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 367 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 368 | mFrameTracer(mFactory.createFrameTracer()), |
| 369 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 370 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 371 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 372 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 373 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 374 | mInternalDisplayDensity( |
| 375 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 376 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 377 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 378 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 379 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 380 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 381 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 382 | ATRACE_CALL(); |
| 383 | ALOGI("SurfaceFlinger is starting"); |
| 384 | |
| 385 | hasSyncFramework = running_without_sync_framework(true); |
| 386 | |
| 387 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 388 | |
| 389 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 390 | |
| 391 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 392 | minAcquiredBuffers = |
| 393 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 394 | |
| 395 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 396 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 397 | |
| 398 | mSupportsWideColor = has_wide_color_display(false); |
| 399 | mDefaultCompositionDataspace = |
| 400 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 401 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 402 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 403 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 404 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 405 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 406 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 407 | wideColorGamutCompositionPixelFormat = |
| 408 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 409 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 410 | mLayerCachingEnabled = [] { |
| 411 | const bool enable = |
| 412 | android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false); |
| 413 | return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable); |
| 414 | }(); |
| 415 | |
| 416 | useContextPriority = use_context_priority(true); |
| 417 | |
| 418 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 419 | |
| 420 | // debugging stuff... |
| 421 | char value[PROPERTY_VALUE_MAX]; |
| 422 | |
| 423 | property_get("ro.build.type", value, "user"); |
| 424 | mIsUserBuild = strcmp(value, "user") == 0; |
| 425 | |
| 426 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 427 | |
| 428 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 429 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 430 | |
| 431 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 432 | bool supportsBlurs = atoi(value); |
| 433 | mSupportsBlur = supportsBlurs; |
| 434 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 435 | |
| 436 | const size_t defaultListSize = MAX_LAYERS; |
| 437 | auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize)); |
| 438 | mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize; |
| 439 | mGraphicBufferProducerListSizeLogThreshold = |
| 440 | std::max(static_cast<int>(0.95 * |
| 441 | static_cast<double>(mMaxGraphicBufferProducerListSize)), |
| 442 | 1); |
| 443 | |
| 444 | property_get("debug.sf.luma_sampling", value, "1"); |
| 445 | mLumaSampling = atoi(value); |
| 446 | |
| 447 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 448 | mDisableClientCompositionCache = atoi(value); |
| 449 | |
| 450 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 451 | mPredictCompositionStrategy = atoi(value); |
| 452 | |
| 453 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 454 | mTreat170mAsSrgb = atoi(value); |
| 455 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 456 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 457 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 458 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 459 | mIgnoreHwcPhysicalDisplayOrientation = |
| 460 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 461 | |
| 462 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 463 | // but since /data may be encrypted, we need to wait until after vold |
| 464 | // comes online to attempt to read the property. The property is |
| 465 | // instead read after the boot animation |
| 466 | |
| 467 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 468 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 469 | // services that are not listed in the manifests. Considered |
| 470 | // deriving the setting from the set service name, but it |
| 471 | // would be brittle if the name that's not 'default' is used |
| 472 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 473 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 474 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 475 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 476 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 477 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 478 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 479 | mRefreshRateOverlayRenderRate = |
| 480 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 481 | mRefreshRateOverlayShowInMiddle = |
| 482 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 483 | |
| 484 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 485 | mTransactionTracing.emplace(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 486 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 487 | |
| 488 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 489 | |
| 490 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 491 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 492 | mLegacyFrontEndEnabled = !mLayerLifecycleManagerEnabled || |
| 493 | base::GetBoolProperty("persist.debug.sf.enable_legacy_frontend"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 497 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 498 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 499 | } |
| 500 | |
| 501 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 504 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 505 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 506 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 507 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 508 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 509 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 510 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 511 | // Sever the link to inputflinger since it's gone as well. |
| 512 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 513 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 514 | initializeDisplays(); |
| 515 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 516 | |
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 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 651 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 652 | return mCompositionEngine->getHwComposer(); |
| 653 | } |
| 654 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 655 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 656 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 659 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 660 | return *mCompositionEngine.get(); |
| 661 | } |
| 662 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 663 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 664 | if (mBootFinished == true) { |
| 665 | ALOGE("Extra call to bootFinished"); |
| 666 | return; |
| 667 | } |
| 668 | mBootFinished = true; |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 669 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 670 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 671 | } |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 672 | |
| 673 | if (mRenderEnginePrimeCacheFuture.valid()) { |
| 674 | mRenderEnginePrimeCacheFuture.get(); |
| 675 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | const nsecs_t now = systemTime(); |
| 677 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 678 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 679 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 680 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 681 | mFrameTimeline->onBootFinished(); |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 682 | getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 683 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 684 | // wait patiently for the window manager death |
| 685 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 686 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 687 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 688 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 692 | // formerly we would just kill the process, but we now ask it to exit so it |
| 693 | // can choose where to stop the animation. |
| 694 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 695 | |
| 696 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 697 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 698 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 699 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 700 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 701 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 702 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 703 | if (input == nullptr) { |
| 704 | ALOGE("Failed to link to input service"); |
| 705 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 706 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 707 | } |
| 708 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 709 | readPersistentProperties(); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 710 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 711 | const bool hintSessionEnabled = mFlagManager.use_adpf_cpu_hint(); |
| 712 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 713 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 714 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 715 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 716 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 717 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 718 | std::vector<int32_t> tidList; |
| 719 | tidList.emplace_back(gettid()); |
| 720 | if (renderEngineTid.has_value()) { |
| 721 | tidList.emplace_back(*renderEngineTid); |
| 722 | } |
| 723 | if (!mPowerAdvisor->startPowerHintSession(tidList)) { |
| 724 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 725 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 728 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 729 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 730 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 731 | ftl::FakeGuard guard(mStateLock); |
| 732 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 733 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 734 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 737 | static std::optional<renderengine::RenderEngine::RenderEngineType> |
| 738 | chooseRenderEngineTypeViaSysProp() { |
| 739 | char prop[PROPERTY_VALUE_MAX]; |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 740 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "skiaglthreaded"); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 741 | |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 742 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 743 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 744 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
| 745 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 746 | } else if (strcmp(prop, "skiavk") == 0) { |
| 747 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 748 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
| 749 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK_THREADED; |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 750 | } else { |
| 751 | ALOGE("Unrecognized RenderEngineType %s; ignoring!", prop); |
| 752 | return {}; |
| 753 | } |
| 754 | } |
| 755 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 756 | // Do not call property_set on main thread which will be blocked by init |
| 757 | // Use StartPropertySetThread instead. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 758 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 759 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 760 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 761 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 762 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 763 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 764 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 765 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 766 | // 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] | 767 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 768 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 769 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 770 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 771 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 772 | .setPrecacheToneMapperShaderOnly(false) |
| 773 | .setSupportsBackgroundBlur(mSupportsBlur) |
| 774 | .setContextPriority( |
| 775 | useContextPriority |
| 776 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 777 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 778 | if (auto type = chooseRenderEngineTypeViaSysProp()) { |
| 779 | builder.setRenderEngineType(type.value()); |
| 780 | } |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 781 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 782 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 783 | mMaxRenderTargetSize = |
| 784 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 785 | |
| 786 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 787 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 788 | ALOGW("Failed to set main task profile"); |
| 789 | } |
| 790 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 791 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 792 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 793 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 794 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 795 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 796 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 797 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 798 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 799 | enableHalVirtualDisplays(true); |
| 800 | } |
| 801 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 802 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 803 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 804 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 805 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 806 | // Commit primary display. |
| 807 | sp<const DisplayDevice> display; |
| 808 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 809 | const auto& displays = mCurrentState.displays; |
| 810 | |
| 811 | const auto& token = displays.keyAt(*indexOpt); |
| 812 | const auto& state = displays.valueAt(*indexOpt); |
| 813 | |
| 814 | processDisplayAdded(token, state); |
| 815 | mDrawingState.displays.add(token, state); |
| 816 | |
| 817 | display = getDefaultDisplayDeviceLocked(); |
| 818 | } |
| 819 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 820 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 821 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 822 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 823 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 824 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 825 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 826 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 827 | initScheduler(display); |
| 828 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true); |
| 829 | |
| 830 | // Commit secondary display(s). |
| 831 | processDisplayChangesLocked(); |
| 832 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 833 | // initialize our drawing state |
| 834 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 835 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 836 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 837 | |
| 838 | static_cast<void>(mScheduler->schedule( |
| 839 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 840 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 841 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 842 | |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 843 | char primeShaderCache[PROPERTY_VALUE_MAX]; |
| 844 | property_get("service.sf.prime_shader_cache", primeShaderCache, "1"); |
| 845 | if (atoi(primeShaderCache)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 846 | if (setSchedFifo(false) != NO_ERROR) { |
| 847 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 848 | } |
| 849 | |
| 850 | mRenderEnginePrimeCacheFuture = getRenderEngine().primeCache(); |
| 851 | |
| 852 | if (setSchedFifo(true) != NO_ERROR) { |
| 853 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 854 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 855 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 856 | |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 857 | // Inform native graphics APIs whether the present timestamp is supported: |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 858 | |
| 859 | const bool presentFenceReliable = |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 860 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 861 | mStartPropertySetThread = getFactory().createStartPropertySetThread(presentFenceReliable); |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 862 | |
| 863 | if (mStartPropertySetThread->Start() != NO_ERROR) { |
| 864 | ALOGE("Run StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 865 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 867 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 868 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 871 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 872 | if (!mTransactionTracing) { |
| 873 | return; |
| 874 | } |
| 875 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 876 | [&](const std::string& filename, bool overwrite) { |
| 877 | auto writeFn = [&]() { |
| 878 | if (!overwrite && access(filename.c_str(), F_OK) == 0) { |
| 879 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 880 | return; |
| 881 | } |
| 882 | mTransactionTracing->flush(); |
| 883 | mTransactionTracing->writeToFile(filename); |
| 884 | }; |
| 885 | if (std::this_thread::get_id() == mMainThreadId) { |
| 886 | writeFn(); |
| 887 | } else { |
| 888 | mScheduler->schedule(writeFn).get(); |
| 889 | } |
| 890 | }); |
| 891 | } |
| 892 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 893 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 894 | Mutex::Autolock _l(mStateLock); |
| 895 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 896 | char value[PROPERTY_VALUE_MAX]; |
| 897 | |
| 898 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 899 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 900 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 901 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 902 | |
| 903 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 904 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 905 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 906 | mForceColorMode = |
| 907 | 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] | 908 | } |
| 909 | |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 910 | void SurfaceFlinger::startBootAnim() { |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 911 | // Start boot animation service by setting a property mailbox |
| 912 | // 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] | 913 | mStartPropertySetThread->Start(); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 914 | // Wait until property was set |
Wei Wang | f9b05ee | 2017-07-19 20:59:39 -0700 | [diff] [blame] | 915 | if (mStartPropertySetThread->join() != NO_ERROR) { |
| 916 | ALOGE("Join StartPropertySetThread failed!"); |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame] | 917 | } |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 918 | } |
| 919 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 921 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 922 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 923 | std::vector<FrameEvent>* outSupported) const { |
| 924 | *outSupported = { |
| 925 | FrameEvent::REQUESTED_PRESENT, |
| 926 | FrameEvent::ACQUIRE, |
| 927 | FrameEvent::LATCH, |
| 928 | FrameEvent::FIRST_REFRESH_START, |
| 929 | FrameEvent::LAST_REFRESH_START, |
| 930 | FrameEvent::GPU_COMPOSITION_DONE, |
| 931 | FrameEvent::DEQUEUE_READY, |
| 932 | FrameEvent::RELEASE, |
| 933 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 934 | |
| 935 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 936 | |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 937 | if (!getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 938 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 939 | } |
| 940 | return NO_ERROR; |
| 941 | } |
| 942 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 943 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 944 | if (!displayToken || !state) { |
| 945 | return BAD_VALUE; |
| 946 | } |
| 947 | |
| 948 | Mutex::Autolock lock(mStateLock); |
| 949 | |
| 950 | const auto display = getDisplayDeviceLocked(displayToken); |
| 951 | if (!display) { |
| 952 | return NAME_NOT_FOUND; |
| 953 | } |
| 954 | |
| 955 | state->layerStack = display->getLayerStack(); |
| 956 | state->orientation = display->getOrientation(); |
| 957 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 958 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 959 | state->layerStackSpaceRect = |
| 960 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 961 | |
| 962 | return NO_ERROR; |
| 963 | } |
| 964 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 965 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 966 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 967 | return BAD_VALUE; |
| 968 | } |
| 969 | |
| 970 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 971 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 972 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 973 | |
| 974 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 975 | return NAME_NOT_FOUND; |
| 976 | } |
| 977 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 978 | const auto& [display, snapshotRef] = *displayOpt; |
| 979 | const auto& snapshot = snapshotRef.get(); |
| 980 | |
| 981 | info->connectionType = snapshot.connectionType(); |
| 982 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 983 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 984 | if (mEmulatedDisplayDensity) { |
| 985 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 986 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 987 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 988 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 989 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 990 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 991 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 992 | |
| 993 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 994 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 995 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 996 | return NO_ERROR; |
| 997 | } |
| 998 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 999 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1000 | const sp<DisplayDevice>& display, |
| 1001 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1002 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1003 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1004 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1005 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1006 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1007 | ui::DisplayMode outMode; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1008 | outMode.id = static_cast<int32_t>(id.value()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1009 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1010 | auto [width, height] = mode->getResolution(); |
| 1011 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1012 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1013 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1014 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1015 | std::swap(width, height); |
| 1016 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1019 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1020 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1021 | outMode.xDpi = xDpi; |
| 1022 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1023 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1024 | const nsecs_t period = mode->getVsyncPeriod(); |
| 1025 | outMode.refreshRate = Fps::fromPeriodNsecs(period).getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1026 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 1027 | const auto vsyncConfigSet = |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1028 | mVsyncConfiguration->getConfigsForRefreshRate(Fps::fromValue(outMode.refreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1029 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1030 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1031 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1032 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1033 | // This is how far in advance a buffer must be queued for |
| 1034 | // presentation at a given time. If you want a buffer to appear |
| 1035 | // on the screen at time N, you must submit the buffer before |
| 1036 | // (N - presentationDeadline). |
| 1037 | // |
| 1038 | // Normally it's one full refresh period (to give SF a chance to |
| 1039 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1040 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1041 | // composer or panel must be accounted for here. |
| 1042 | // |
| 1043 | // We add an additional 1ms to allow for processing time and |
| 1044 | // differences between the ideal and actual refresh rate. |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1045 | outMode.presentationDeadline = period - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1046 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1047 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1048 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1051 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1052 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1053 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1054 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1055 | const auto mode = display->refreshRateSelector().getActiveMode(); |
| 1056 | info->activeDisplayModeId = mode.modePtr->getId().value(); |
| 1057 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1058 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1059 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1060 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1061 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1062 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1063 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1064 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1065 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1066 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1067 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1068 | |
| 1069 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1070 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1071 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1072 | info->preferredBootDisplayMode = modeId->value(); |
| 1073 | } |
| 1074 | } |
| 1075 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1076 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1077 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1078 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1079 | ui::DynamicDisplayInfo* info) { |
| 1080 | if (!info) { |
| 1081 | return BAD_VALUE; |
| 1082 | } |
| 1083 | |
| 1084 | Mutex::Autolock lock(mStateLock); |
| 1085 | |
| 1086 | const auto id_ = |
| 1087 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1088 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1089 | |
| 1090 | if (!displayOpt) { |
| 1091 | return NAME_NOT_FOUND; |
| 1092 | } |
| 1093 | |
| 1094 | const auto& [display, snapshotRef] = *displayOpt; |
| 1095 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1096 | return NO_ERROR; |
| 1097 | } |
| 1098 | |
| 1099 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1100 | ui::DynamicDisplayInfo* info) { |
| 1101 | if (!displayToken || !info) { |
| 1102 | return BAD_VALUE; |
| 1103 | } |
| 1104 | |
| 1105 | Mutex::Autolock lock(mStateLock); |
| 1106 | |
| 1107 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1108 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1109 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1110 | |
| 1111 | if (!displayOpt) { |
| 1112 | return NAME_NOT_FOUND; |
| 1113 | } |
| 1114 | |
| 1115 | const auto& [display, snapshotRef] = *displayOpt; |
| 1116 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1117 | return NO_ERROR; |
| 1118 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1119 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1120 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1121 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1122 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1123 | return BAD_VALUE; |
| 1124 | } |
| 1125 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1126 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1127 | { |
| 1128 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1129 | if (displayToken) { |
| 1130 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1131 | if (!displayIdOpt) { |
| 1132 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1133 | return NAME_NOT_FOUND; |
| 1134 | } |
| 1135 | } else { |
| 1136 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1137 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1138 | // case). |
| 1139 | displayIdOpt = mActiveDisplayId; |
| 1140 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1141 | } |
| 1142 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1143 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1144 | if (!schedule) { |
| 1145 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1146 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1147 | return NAME_NOT_FOUND; |
| 1148 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1149 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1150 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1151 | return NO_ERROR; |
| 1152 | } |
| 1153 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1154 | void SurfaceFlinger::setDesiredActiveMode(display::DisplayModeRequest&& request, bool force) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1155 | const auto displayId = request.mode.modePtr->getPhysicalDisplayId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1156 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1157 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1158 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1159 | if (!display) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1160 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1161 | return; |
| 1162 | } |
| 1163 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1164 | const auto mode = request.mode; |
| 1165 | const bool emitEvent = request.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1166 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 1167 | switch (display->setDesiredActiveMode(DisplayDevice::ActiveModeInfo(std::move(request)), |
| 1168 | force)) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1169 | case DisplayDevice::DesiredActiveModeAction::InitiateDisplayModeSwitch: |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1170 | // Set the render rate as setDesiredActiveMode updated it. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1171 | mScheduler->setRenderRate(displayId, |
| 1172 | display->refreshRateSelector().getActiveMode().fps); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1173 | |
| 1174 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1175 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1176 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1177 | // Start receiving vsync samples now, so that we can detect a period |
| 1178 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1179 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
| 1180 | mode.modePtr->getFps()); |
| 1181 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1182 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1183 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1184 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1185 | |
| 1186 | if (displayId == mActiveDisplayId) { |
| 1187 | updatePhaseConfiguration(mode.fps); |
| 1188 | } |
| 1189 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1190 | mScheduler->setModeChangePending(true); |
| 1191 | break; |
| 1192 | case DisplayDevice::DesiredActiveModeAction::InitiateRenderRateSwitch: |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1193 | mScheduler->setRenderRate(displayId, mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1194 | |
| 1195 | if (displayId == mActiveDisplayId) { |
| 1196 | updatePhaseConfiguration(mode.fps); |
| 1197 | mRefreshRateStats->setRefreshRate(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1198 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1199 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1200 | if (emitEvent) { |
| 1201 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1202 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1203 | break; |
| 1204 | case DisplayDevice::DesiredActiveModeAction::None: |
| 1205 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1206 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1209 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
| 1210 | DisplayModeId modeId) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1211 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1212 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1213 | if (!displayToken) { |
| 1214 | return BAD_VALUE; |
| 1215 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1216 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1217 | const char* const whence = __func__; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1218 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1219 | const auto displayOpt = |
| 1220 | FTL_FAKE_GUARD(mStateLock, |
| 1221 | ftl::find_if(mPhysicalDisplays, |
| 1222 | PhysicalDisplay::hasToken(displayToken)) |
| 1223 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1224 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1225 | if (!displayOpt) { |
| 1226 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1227 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1230 | const auto& [display, snapshotRef] = *displayOpt; |
| 1231 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1232 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1233 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
| 1234 | [](const DisplayModePtr& mode) { return mode->getFps(); }); |
| 1235 | |
| 1236 | if (!fpsOpt) { |
| 1237 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1238 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1239 | return BAD_VALUE; |
| 1240 | } |
| 1241 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1242 | const Fps fps = *fpsOpt; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1243 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1244 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1245 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1246 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1247 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1248 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1249 | {fps, fps}, |
| 1250 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1251 | |
| 1252 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1253 | }); |
| 1254 | |
| 1255 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1258 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1259 | const auto displayId = display.getPhysicalId(); |
| 1260 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1261 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1262 | const auto upcomingModeInfo = display.getUpcomingActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1263 | if (!upcomingModeInfo.modeOpt) { |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1264 | // There is no pending mode change. This can happen if the active |
| 1265 | // display changed and the mode change happened on a different display. |
| 1266 | return; |
| 1267 | } |
| 1268 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1269 | if (display.getActiveMode().modePtr->getResolution() != |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1270 | upcomingModeInfo.modeOpt->modePtr->getResolution()) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1271 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1272 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1273 | // way the framebuffer). |
| 1274 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1275 | state.physical->activeMode = upcomingModeInfo.modeOpt->modePtr.get(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1276 | processDisplayChangesLocked(); |
| 1277 | |
| 1278 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1279 | return; |
| 1280 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1281 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1282 | const auto& activeMode = *upcomingModeInfo.modeOpt; |
| 1283 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getFps(), |
| 1284 | activeMode.fps); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1285 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1286 | if (displayId == mActiveDisplayId) { |
| 1287 | mRefreshRateStats->setRefreshRate(activeMode.fps); |
| 1288 | updatePhaseConfiguration(activeMode.fps); |
| 1289 | } |
Dominik Laskowski | 22488f6 | 2019-03-28 09:53:04 -0700 | [diff] [blame] | 1290 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1291 | if (upcomingModeInfo.event != scheduler::DisplayModeEvent::None) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1292 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
Ady Abraham | 447052e | 2019-02-13 16:07:27 -0800 | [diff] [blame] | 1293 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1296 | void SurfaceFlinger::clearDesiredActiveModeState(const sp<DisplayDevice>& display) { |
| 1297 | display->clearDesiredActiveModeState(); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1298 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1299 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1300 | mScheduler->setModeChangePending(false); |
| 1301 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1304 | void SurfaceFlinger::desiredActiveModeChangeDone(const sp<DisplayDevice>& display) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1305 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1306 | const auto& modeOpt = desiredActiveMode->modeOpt; |
| 1307 | const auto displayId = modeOpt->modePtr->getPhysicalDisplayId(); |
| 1308 | const auto displayFps = modeOpt->modePtr->getFps(); |
| 1309 | const auto renderFps = modeOpt->fps; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1310 | clearDesiredActiveModeState(display); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1311 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, displayFps); |
| 1312 | mScheduler->setRenderRate(displayId, renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1313 | |
| 1314 | if (displayId == mActiveDisplayId) { |
| 1315 | updatePhaseConfiguration(renderFps); |
| 1316 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1319 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1320 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1321 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1322 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1323 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1324 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1325 | const auto display = getDisplayDeviceLocked(id); |
| 1326 | if (!display) continue; |
| 1327 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1328 | // Store the local variable to release the lock. |
| 1329 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 1330 | if (!desiredActiveMode) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 1331 | // No desired active mode pending to be applied. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1332 | continue; |
| 1333 | } |
| 1334 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1335 | if (!display->isPoweredOn()) { |
| 1336 | // Display is no longer powered on, so abort the mode change. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1337 | clearDesiredActiveModeState(display); |
| 1338 | continue; |
| 1339 | } |
| 1340 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1341 | const auto desiredModeId = desiredActiveMode->modeOpt->modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1342 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1343 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1344 | if (!displayModePtrOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1345 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1346 | desiredModeId.value()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1347 | clearDesiredActiveModeState(display); |
| 1348 | continue; |
| 1349 | } |
| 1350 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1351 | 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] | 1352 | to_string(displayModePtrOpt->get()->getFps()).c_str(), |
| 1353 | to_string(display->getId()).c_str()); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1354 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1355 | if (display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | 85b2bdf | 2021-11-03 14:31:21 +0100 | [diff] [blame] | 1356 | // 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] | 1357 | desiredActiveModeChangeDone(display); |
| 1358 | continue; |
| 1359 | } |
| 1360 | |
| 1361 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1362 | // allowed modes might have changed by the time we process the refresh. |
| 1363 | // Make sure the desired mode is still allowed |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1364 | const auto displayModeAllowed = |
| 1365 | display->refreshRateSelector().isModeAllowed(*desiredActiveMode->modeOpt); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1366 | if (!displayModeAllowed) { |
Marin Shalamanov | dd00c00 | 2021-11-04 16:54:38 +0100 | [diff] [blame] | 1367 | clearDesiredActiveModeState(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1368 | continue; |
| 1369 | } |
| 1370 | |
| 1371 | // TODO(b/142753666) use constrains |
| 1372 | hal::VsyncPeriodChangeConstraints constraints; |
| 1373 | constraints.desiredTimeNanos = systemTime(); |
| 1374 | constraints.seamlessRequired = false; |
| 1375 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1376 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 1377 | const auto status = |
| 1378 | display->initiateModeChange(*desiredActiveMode, constraints, &outTimeline); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1379 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1380 | if (status != NO_ERROR) { |
| 1381 | // initiateModeChange may fail if a hotplug event is just about |
| 1382 | // to be sent. We just log the error in this case. |
| 1383 | ALOGW("initiateModeChange failed: %d", status); |
| 1384 | continue; |
| 1385 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1386 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1387 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1388 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1389 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1390 | if (outTimeline.refreshRequired) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 1391 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1392 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1393 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1394 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1395 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1396 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1401 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1402 | finalizeDisplayModeChange(*display); |
| 1403 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1404 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1405 | if (desiredActiveMode && display->getActiveMode() == desiredActiveMode->modeOpt) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1406 | desiredActiveModeChangeDone(display); |
| 1407 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1408 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1409 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1410 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1411 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1412 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1413 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1414 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1415 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1416 | for (const auto& [_, display] : mDisplays) { |
| 1417 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1418 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1419 | } |
| 1420 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1421 | }); |
| 1422 | |
| 1423 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1426 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1427 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1428 | if (!displayToken) { |
| 1429 | return BAD_VALUE; |
| 1430 | } |
| 1431 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1432 | Mutex::Autolock lock(mStateLock); |
| 1433 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1434 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1435 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1436 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1437 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1440 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1441 | return INVALID_OPERATION; |
| 1442 | } |
| 1443 | |
| 1444 | // TODO(b/229846990): For now, assume that all internal displays have the same primaries. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1445 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1446 | return NO_ERROR; |
| 1447 | } |
| 1448 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1449 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1450 | if (!displayToken) { |
| 1451 | return BAD_VALUE; |
| 1452 | } |
| 1453 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1454 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1455 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1456 | const auto displayOpt = |
| 1457 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1458 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1459 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1460 | |
| 1461 | if (!displayOpt) { |
| 1462 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1463 | return NAME_NOT_FOUND; |
| 1464 | } |
| 1465 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1466 | const auto& [display, snapshotRef] = *displayOpt; |
| 1467 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1468 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1469 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1470 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1471 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1472 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1473 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1474 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1475 | return BAD_VALUE; |
| 1476 | } |
| 1477 | |
| 1478 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1479 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1480 | |
| 1481 | return NO_ERROR; |
| 1482 | }); |
| 1483 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1484 | // TODO(b/195698395): Propagate error. |
| 1485 | future.wait(); |
| 1486 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1487 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1488 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1489 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1490 | auto future = mScheduler->schedule( |
| 1491 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1492 | |
| 1493 | *outSupport = future.get(); |
| 1494 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1497 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1498 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1499 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1500 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1501 | for (const auto& combination : aidlProperties.combinations) { |
| 1502 | std::vector<int32_t> pixelFormats; |
| 1503 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1504 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1505 | std::back_inserter(pixelFormats), |
| 1506 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1507 | std::vector<int32_t> standards; |
| 1508 | standards.reserve(combination.standards.size()); |
| 1509 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1510 | std::back_inserter(standards), |
| 1511 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1512 | std::vector<int32_t> transfers; |
| 1513 | transfers.reserve(combination.transfers.size()); |
| 1514 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1515 | std::back_inserter(transfers), |
| 1516 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1517 | std::vector<int32_t> ranges; |
| 1518 | ranges.reserve(combination.ranges.size()); |
| 1519 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1520 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1521 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1522 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1523 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1524 | outCombination.standards = std::move(standards); |
| 1525 | outCombination.transfers = std::move(transfers); |
| 1526 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1527 | outProperties->combinations.emplace_back(outCombination); |
| 1528 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1529 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1530 | return NO_ERROR; |
| 1531 | } |
| 1532 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1533 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1534 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1535 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1536 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1537 | const auto snapshotOpt = |
| 1538 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1539 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1540 | .transform(&PhysicalDisplay::snapshotRef); |
| 1541 | |
| 1542 | if (!snapshotOpt) { |
| 1543 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1544 | return NAME_NOT_FOUND; |
| 1545 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1546 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1547 | const auto& snapshot = snapshotOpt->get(); |
| 1548 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1549 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1550 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1551 | if (!hwcIdOpt) { |
| 1552 | ALOGE("%s: Invalid mode %d for display %s", whence, modeId.value(), |
| 1553 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1554 | return BAD_VALUE; |
| 1555 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1556 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1557 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1558 | }); |
| 1559 | return future.get(); |
| 1560 | } |
| 1561 | |
| 1562 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1563 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1564 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1565 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1566 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1567 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1568 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1569 | return BAD_VALUE; |
| 1570 | } |
| 1571 | }); |
| 1572 | return future.get(); |
| 1573 | } |
| 1574 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1575 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1576 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1577 | bool hdrOutputConversionSupport; |
| 1578 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1579 | if (hdrOutputConversionSupport == false) { |
| 1580 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1581 | return INVALID_OPERATION; |
| 1582 | } |
| 1583 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1584 | for (auto capability : aidlConversionCapability) { |
| 1585 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1586 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1587 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1588 | tempCapability.addsLatency = capability.addsLatency; |
| 1589 | hdrConversionCapabilities->push_back(tempCapability); |
| 1590 | } |
| 1591 | return NO_ERROR; |
| 1592 | } |
| 1593 | |
| 1594 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1595 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1596 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1597 | bool hdrOutputConversionSupport; |
| 1598 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1599 | if (hdrOutputConversionSupport == false) { |
| 1600 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1601 | return INVALID_OPERATION; |
| 1602 | } |
| 1603 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
| 1604 | using AidlHdrConversionStrategy = |
| 1605 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1606 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1607 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1608 | status_t status; |
| 1609 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1610 | switch (hdrConversionStrategy.getTag()) { |
| 1611 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1612 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1613 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1614 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1615 | &aidlPreferredHdrOutputType); |
| 1616 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1617 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1618 | } |
| 1619 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1620 | auto autoHdrTypes = |
| 1621 | hdrConversionStrategy |
| 1622 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1623 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1624 | for (auto type : autoHdrTypes) { |
| 1625 | aidlAutoHdrTypes.push_back( |
| 1626 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1627 | } |
| 1628 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1629 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1630 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1631 | &aidlPreferredHdrOutputType); |
| 1632 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1633 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1634 | } |
| 1635 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1636 | auto forceHdrConversion = |
| 1637 | hdrConversionStrategy |
| 1638 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1639 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1640 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1641 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1642 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1643 | &aidlPreferredHdrOutputType); |
| 1644 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1645 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | }); |
| 1649 | return future.get(); |
| 1650 | } |
| 1651 | |
| 1652 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1653 | auto future = mScheduler->schedule([this] { |
| 1654 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1655 | }); |
| 1656 | |
| 1657 | *outSupport = future.get(); |
| 1658 | return NO_ERROR; |
| 1659 | } |
| 1660 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1661 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1662 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1663 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1664 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1665 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1666 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1667 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1668 | } |
| 1669 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1672 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1673 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1674 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1675 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1676 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1677 | getHwComposer().setContentType(*displayId, type); |
| 1678 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1679 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1680 | } |
| 1681 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1684 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1685 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1686 | Mutex::Autolock lock(mStateLock); |
| 1687 | |
| 1688 | auto display = getDisplayDeviceLocked(displayToken); |
| 1689 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1690 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1691 | return NAME_NOT_FOUND; |
| 1692 | } |
| 1693 | |
| 1694 | display->overrideHdrTypes(hdrTypes); |
| 1695 | dispatchDisplayHotplugEvent(display->getPhysicalId(), true /* connected */); |
| 1696 | return NO_ERROR; |
| 1697 | } |
| 1698 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1699 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1700 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1701 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1702 | return NO_ERROR; |
| 1703 | } |
| 1704 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1705 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1706 | ui::PixelFormat* outFormat, |
| 1707 | ui::Dataspace* outDataspace, |
| 1708 | uint8_t* outComponentMask) const { |
| 1709 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1710 | return BAD_VALUE; |
| 1711 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1712 | |
| 1713 | Mutex::Autolock lock(mStateLock); |
| 1714 | |
| 1715 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1716 | if (!displayId) { |
| 1717 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1718 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1719 | |
| 1720 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1721 | outDataspace, outComponentMask); |
| 1722 | } |
| 1723 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1724 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1725 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1726 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1727 | const char* const whence = __func__; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1728 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1729 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1730 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1731 | componentMask, maxFrames); |
| 1732 | } else { |
| 1733 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1734 | return NAME_NOT_FOUND; |
| 1735 | } |
| 1736 | }); |
| 1737 | |
| 1738 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1741 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1742 | uint64_t maxFrames, uint64_t timestamp, |
| 1743 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1744 | Mutex::Autolock lock(mStateLock); |
| 1745 | |
| 1746 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1747 | if (!displayId) { |
| 1748 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1751 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1754 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1755 | if (!outSupported) { |
| 1756 | return BAD_VALUE; |
| 1757 | } |
| 1758 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1759 | return NO_ERROR; |
| 1760 | } |
| 1761 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1762 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1763 | bool* outIsWideColorDisplay) const { |
| 1764 | if (!displayToken || !outIsWideColorDisplay) { |
| 1765 | return BAD_VALUE; |
| 1766 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1767 | |
| 1768 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1769 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1770 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1771 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1772 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1773 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1774 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1775 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1776 | return NO_ERROR; |
| 1777 | } |
| 1778 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1779 | status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1780 | outLayers->clear(); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1781 | auto future = mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1782 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1783 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 1784 | outLayers->push_back(layer->getLayerDebugInfo(display.get())); |
| 1785 | }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1786 | }); |
| 1787 | |
| 1788 | future.wait(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1789 | return NO_ERROR; |
| 1790 | } |
| 1791 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1792 | status_t SurfaceFlinger::getCompositionPreference( |
| 1793 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1794 | Dataspace* outWideColorGamutDataspace, |
| 1795 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1796 | *outDataspace = mDefaultCompositionDataspace; |
| 1797 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1798 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1799 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1800 | return NO_ERROR; |
| 1801 | } |
| 1802 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1803 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1804 | const sp<IBinder>& stopLayerHandle, |
| 1805 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1806 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1807 | return BAD_VALUE; |
| 1808 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1809 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1810 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1811 | // 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] | 1812 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1813 | mRegionSamplingThread->addListener(samplingArea, |
| 1814 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1815 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1816 | return NO_ERROR; |
| 1817 | } |
| 1818 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1819 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1820 | if (!listener) { |
| 1821 | return BAD_VALUE; |
| 1822 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1823 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1824 | return NO_ERROR; |
| 1825 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1826 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1827 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1828 | if (!listener) { |
| 1829 | return BAD_VALUE; |
| 1830 | } |
| 1831 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1832 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1833 | return NO_ERROR; |
| 1834 | } |
| 1835 | |
| 1836 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1837 | if (!listener) { |
| 1838 | return BAD_VALUE; |
| 1839 | } |
| 1840 | mFpsReporter->removeListener(listener); |
| 1841 | return NO_ERROR; |
| 1842 | } |
| 1843 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1844 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1845 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1846 | if (!listener) { |
| 1847 | return BAD_VALUE; |
| 1848 | } |
| 1849 | |
| 1850 | mTunnelModeEnabledReporter->addListener(listener); |
| 1851 | return NO_ERROR; |
| 1852 | } |
| 1853 | |
| 1854 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1855 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1856 | if (!listener) { |
| 1857 | return BAD_VALUE; |
| 1858 | } |
| 1859 | |
| 1860 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1861 | return NO_ERROR; |
| 1862 | } |
| 1863 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1864 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1865 | bool* outSupport) const { |
| 1866 | if (!displayToken || !outSupport) { |
| 1867 | return BAD_VALUE; |
| 1868 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1869 | |
| 1870 | Mutex::Autolock lock(mStateLock); |
| 1871 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1872 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1873 | if (!displayId) { |
| 1874 | return NAME_NOT_FOUND; |
| 1875 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1876 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1877 | return NO_ERROR; |
| 1878 | } |
| 1879 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1880 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1881 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1882 | if (!displayToken) { |
| 1883 | return BAD_VALUE; |
| 1884 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1885 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1886 | const char* const whence = __func__; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1887 | return ftl::Future(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1888 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1889 | const bool supportsDisplayBrightnessCommand = |
| 1890 | getHwComposer().getComposer()->isSupported( |
| 1891 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1892 | // If we support applying display brightness as a command, then we also support |
| 1893 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1894 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1895 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1896 | float currentDimmingRatio = |
| 1897 | compositionDisplay->editState().sdrWhitePointNits / |
| 1898 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1899 | static constexpr float kDimmingThreshold = 0.02f; |
| 1900 | if (brightness.sdrWhitePointNits == 0.f || |
| 1901 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1902 | brightness.sdrWhitePointNits >= |
| 1903 | kDimmingThreshold) { |
| 1904 | // to optimize, skip brightness setter if the brightness difference ratio |
| 1905 | // is lower than threshold |
| 1906 | compositionDisplay |
| 1907 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1908 | brightness.displayBrightnessNits); |
| 1909 | } else { |
| 1910 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 1911 | brightness.sdrWhitePointNits); |
| 1912 | } |
| 1913 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1914 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1915 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 1916 | float currentHdrSdrRatio = |
| 1917 | compositionDisplay->editState().displayBrightnessNits / |
| 1918 | compositionDisplay->editState().sdrWhitePointNits; |
| 1919 | FTL_FAKE_GUARD(kMainThreadContext, |
| 1920 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1921 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1922 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 1923 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1924 | scheduleComposite(FrameHint::kNone); |
| 1925 | } else { |
| 1926 | scheduleCommit(FrameHint::kNone); |
| 1927 | } |
| 1928 | return ftl::yield<status_t>(OK); |
| 1929 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1930 | return getHwComposer() |
| 1931 | .setDisplayBrightness(display->getPhysicalId(), |
| 1932 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 1933 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1934 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 1935 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1936 | } |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1937 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1938 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1939 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 1940 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1941 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 1942 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 1943 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1944 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1947 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 1948 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1949 | if (!displayToken) { |
| 1950 | return BAD_VALUE; |
| 1951 | } |
| 1952 | |
| 1953 | Mutex::Autolock lock(mStateLock); |
| 1954 | |
| 1955 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1956 | if (!display) { |
| 1957 | return NAME_NOT_FOUND; |
| 1958 | } |
| 1959 | const auto displayId = display->getId(); |
| 1960 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1961 | if (!hdrInfoReporter) { |
| 1962 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 1963 | } |
| 1964 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 1965 | |
| 1966 | |
| 1967 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 1968 | return OK; |
| 1969 | } |
| 1970 | |
| 1971 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 1972 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 1973 | if (!displayToken) { |
| 1974 | return BAD_VALUE; |
| 1975 | } |
| 1976 | |
| 1977 | Mutex::Autolock lock(mStateLock); |
| 1978 | |
| 1979 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1980 | if (!display) { |
| 1981 | return NAME_NOT_FOUND; |
| 1982 | } |
| 1983 | const auto displayId = display->getId(); |
| 1984 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 1985 | if (hdrInfoReporter) { |
| 1986 | hdrInfoReporter->removeListener(listener); |
| 1987 | } |
| 1988 | return OK; |
| 1989 | } |
| 1990 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1991 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 1992 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1993 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1994 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1995 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1996 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | return NO_ERROR; |
| 2000 | } |
| 2001 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2002 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2003 | const sp<IBinder>& displayToken, |
| 2004 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2005 | if (!displayToken || !outSupport) { |
| 2006 | return BAD_VALUE; |
| 2007 | } |
| 2008 | |
| 2009 | Mutex::Autolock lock(mStateLock); |
| 2010 | |
| 2011 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2012 | if (!displayId) { |
| 2013 | return NAME_NOT_FOUND; |
| 2014 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2015 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2016 | return NO_ERROR; |
| 2017 | } |
| 2018 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2019 | // ---------------------------------------------------------------------------- |
| 2020 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2021 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2022 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2023 | const sp<IBinder>& layerHandle) { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 2024 | const auto& handle = |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 2025 | vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2026 | ? mSfConnectionHandle |
| 2027 | : mAppConnectionHandle; |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2028 | |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2029 | return mScheduler->createDisplayEventConnection(handle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2032 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2033 | if (hint == FrameHint::kActive) { |
| 2034 | mScheduler->resetIdleTimer(); |
| 2035 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2036 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2037 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2038 | } |
| 2039 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2040 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2041 | mMustComposite = true; |
| 2042 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void SurfaceFlinger::scheduleRepaint() { |
| 2046 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2047 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2050 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2051 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2052 | } |
| 2053 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2054 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2055 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2056 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2059 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2062 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2063 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2064 | ATRACE_NAME(vsyncPeriod |
| 2065 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2066 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2067 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2068 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2069 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2070 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2071 | // period flushed |
| 2072 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2073 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2074 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2077 | void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, |
| 2078 | hal::Connection connection) { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2079 | { |
| 2080 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2081 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2082 | } |
| 2083 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2084 | if (mScheduler) { |
| 2085 | mScheduler->scheduleConfigure(); |
| 2086 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2089 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2090 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2091 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2092 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2093 | |
| 2094 | if (timeline.refreshRequired) { |
| 2095 | scheduleComposite(FrameHint::kNone); |
| 2096 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2099 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2100 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2101 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2102 | } |
| 2103 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2104 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2105 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2106 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2109 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2110 | ATRACE_CALL(); |
| 2111 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2112 | } |
| 2113 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2114 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2115 | ATRACE_CALL(); |
| 2116 | if (const auto displayId = getHwComposer().toPhysicalDisplayId(data.display); displayId) { |
| 2117 | const Fps fps = Fps::fromPeriodNsecs(data.vsyncPeriodNanos); |
| 2118 | ATRACE_FORMAT("%s Fps %d", __func__, fps.getIntValue()); |
| 2119 | static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) { |
| 2120 | { |
| 2121 | { |
| 2122 | const auto display = getDisplayDeviceLocked(*displayId); |
| 2123 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2124 | display->updateRefreshRateOverlayRate(fps, |
| 2125 | display->getActiveMode() |
| 2126 | .fps, |
| 2127 | /* setByHwc */ true)); |
| 2128 | } |
| 2129 | } |
| 2130 | })); |
| 2131 | } |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2134 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2135 | Mutex::Autolock lock(mStateLock); |
| 2136 | if (configureLocked()) { |
| 2137 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2138 | } |
| 2139 | } |
| 2140 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2141 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2142 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2143 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2144 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2145 | frontend::Update update; |
| 2146 | if (flushTransactions) { |
| 2147 | update = flushLifecycleUpdates(); |
| 2148 | if (mTransactionTracing) { |
| 2149 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2150 | update, mFrontEndDisplayInfos, |
| 2151 | mFrontEndDisplayInfosChanged); |
| 2152 | } |
| 2153 | } |
| 2154 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2155 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2156 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2157 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2158 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2159 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2160 | } |
| 2161 | outTransactionsAreEmpty = !needsTraversal; |
| 2162 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2163 | if (shouldCommit) { |
| 2164 | commitTransactions(); |
| 2165 | } |
| 2166 | |
| 2167 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2168 | updateLayerGeometry(); |
| 2169 | return mustComposite; |
| 2170 | } |
| 2171 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2172 | void SurfaceFlinger::updateLayerHistory(const frontend::LayerSnapshot& snapshot) { |
| 2173 | using Changes = frontend::RequestedLayerState::Changes; |
| 2174 | if (snapshot.path.isClone() || |
| 2175 | !snapshot.changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation)) { |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | const auto layerProps = scheduler::LayerProps{ |
| 2180 | .visible = snapshot.isVisible, |
| 2181 | .bounds = snapshot.geomLayerBounds, |
| 2182 | .transform = snapshot.geomLayerTransform, |
| 2183 | .setFrameRateVote = snapshot.frameRate, |
| 2184 | .frameRateSelectionPriority = snapshot.frameRateSelectionPriority, |
| 2185 | }; |
| 2186 | |
| 2187 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 2188 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 2189 | snapshot.getDebugString().c_str()); |
| 2190 | |
| 2191 | if (snapshot.changes.test(Changes::Animation)) { |
| 2192 | it->second->recordLayerHistoryAnimationTx(layerProps); |
| 2193 | } |
| 2194 | |
| 2195 | if (snapshot.changes.test(Changes::FrameRate)) { |
| 2196 | it->second->setFrameRateForLayerTree(snapshot.frameRate, layerProps); |
| 2197 | } |
| 2198 | |
| 2199 | if (snapshot.changes.test(Changes::Buffer)) { |
| 2200 | it->second->recordLayerHistoryBufferUpdate(layerProps); |
| 2201 | } |
| 2202 | } |
| 2203 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2204 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2205 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2206 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2207 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2208 | frontend::Update update; |
| 2209 | if (flushTransactions) { |
| 2210 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2211 | // Locking: |
| 2212 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2213 | // we must keep a copy of the transactions (specifically the composer |
| 2214 | // states) around outside the scope of the lock. |
| 2215 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2216 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2217 | // before committing the created layers. |
| 2218 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2219 | // created one |
| 2220 | mTransactionHandler.collectTransactions(); |
| 2221 | { |
| 2222 | // TODO(b/238781169) lockless queue this and keep order. |
| 2223 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2224 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2225 | mCreatedLayers.clear(); |
| 2226 | update.newLayers = std::move(mNewLayers); |
| 2227 | mNewLayers.clear(); |
| 2228 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2229 | mNewLayerArgs.clear(); |
| 2230 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2231 | mDestroyedHandles.clear(); |
| 2232 | } |
| 2233 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2234 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2235 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2236 | if (mTransactionTracing) { |
| 2237 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2238 | update, mFrontEndDisplayInfos, |
| 2239 | mFrontEndDisplayInfosChanged); |
| 2240 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2241 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2242 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2243 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2244 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2245 | if (layer) { |
| 2246 | mLegacyLayers[layer->sequence] = layer; |
| 2247 | } |
| 2248 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2249 | if (mLayerLifecycleManager.getGlobalChanges().test(Changes::Hierarchy)) { |
| 2250 | ATRACE_NAME("LayerHierarchyBuilder:update"); |
| 2251 | mLayerHierarchyBuilder.update(mLayerLifecycleManager.getLayers(), |
| 2252 | mLayerLifecycleManager.getDestroyedLayers()); |
| 2253 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2256 | bool mustComposite = false; |
| 2257 | mustComposite |= applyAndCommitDisplayTransactionStates(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2258 | |
| 2259 | { |
| 2260 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2261 | frontend::LayerSnapshotBuilder::Args |
| 2262 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2263 | .layerLifecycleManager = mLayerLifecycleManager, |
| 2264 | .displays = mFrontEndDisplayInfos, |
| 2265 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2266 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2267 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2268 | .forceFullDamage = mForceFullDamage, |
| 2269 | .supportedLayerGenericMetadata = |
| 2270 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2271 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2272 | .skipRoundCornersWhenProtected = |
| 2273 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2274 | mLayerSnapshotBuilder.update(args); |
| 2275 | } |
| 2276 | |
| 2277 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2278 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2279 | mUpdateInputInfo = true; |
| 2280 | } |
| 2281 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2282 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2283 | mVisibleRegionsDirty = true; |
| 2284 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2285 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2286 | // The frame rate of attached choreographers can only change as a result of a |
| 2287 | // FrameRate change (including when Hierarchy changes). |
| 2288 | mUpdateAttachedChoreographer = true; |
| 2289 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2290 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2291 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2292 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2293 | bool newDataLatched = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2294 | if (!mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2295 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
Vishnu Nair | d2a38f9 | 2023-08-23 18:43:01 -0700 | [diff] [blame] | 2296 | mustComposite |= applyTransactions(update.transactions, vsyncId); |
Vishnu Nair | c1d19d7 | 2023-08-10 12:35:11 -0700 | [diff] [blame] | 2297 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2298 | const nsecs_t latchTime = systemTime(); |
| 2299 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2300 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2301 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2302 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2303 | layer->bgColorLayer) { |
| 2304 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2305 | LayerCreationArgs(this, nullptr, layer->name, |
| 2306 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
Vishnu Nair | e4af095 | 2023-05-01 09:11:33 -0700 | [diff] [blame] | 2307 | std::make_optional(layer->id), true)); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2308 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2309 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2310 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2311 | |
| 2312 | auto it = mLegacyLayers.find(layer->id); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2313 | 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] | 2314 | layer->getDebugString().c_str()); |
Vishnu Nair | f32ff9b | 2023-08-23 14:32:30 -0700 | [diff] [blame] | 2315 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2316 | if (!it->second->hasBuffer()) { |
| 2317 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2318 | // instead of a missed frame. This is used to identify scenarios where we |
| 2319 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2320 | // We only update the latch time for buffer less layers here, the latch time |
| 2321 | // is updated for buffer layers when the buffer is latched. |
| 2322 | it->second->updateLastLatchTime(latchTime); |
| 2323 | } |
| 2324 | continue; |
| 2325 | } |
| 2326 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2327 | const bool bgColorOnly = |
| 2328 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2329 | if (willReleaseBufferOnLatch) { |
| 2330 | mLayersWithBuffersRemoved.emplace(it->second); |
| 2331 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2332 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2333 | newDataLatched = true; |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2334 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2335 | mLayersWithQueuedFrames.emplace(it->second); |
| 2336 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2339 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 2340 | updateLayerHistory(snapshot); |
| 2341 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == |
| 2342 | mLayersIdsWithQueuedFrames.end()) |
| 2343 | return; |
| 2344 | Region visibleReg; |
| 2345 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2346 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2347 | }); |
| 2348 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2349 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2350 | mLegacyLayers.erase(destroyedLayer->id); |
| 2351 | } |
| 2352 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2353 | { |
| 2354 | ATRACE_NAME("LLM:commitChanges"); |
| 2355 | mLayerLifecycleManager.commitChanges(); |
| 2356 | } |
| 2357 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 2358 | commitTransactions(); |
| 2359 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2360 | // enter boot animation on first buffer latch |
| 2361 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2362 | ALOGI("Enter boot animation"); |
| 2363 | mBootStage = BootStage::BOOTANIMATION; |
| 2364 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2365 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2366 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2367 | return mustComposite; |
| 2368 | } |
| 2369 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2370 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2371 | const scheduler::FrameTargets& frameTargets) { |
| 2372 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2373 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2374 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2375 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2376 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2377 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2378 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 2381 | if (mTracingEnabledChanged) { |
| 2382 | mLayerTracingEnabled = mLayerTracing.isEnabled(); |
| 2383 | mTracingEnabledChanged = false; |
| 2384 | } |
| 2385 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2386 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2387 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2388 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2389 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2390 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2391 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2392 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2393 | return display->isModeSetPending(); |
| 2394 | } |
| 2395 | |
| 2396 | return false; |
| 2397 | })) { |
| 2398 | mScheduler->scheduleFrame(); |
| 2399 | return false; |
| 2400 | } |
| 2401 | |
| 2402 | { |
| 2403 | Mutex::Autolock lock(mStateLock); |
| 2404 | |
| 2405 | for (const auto [id, target] : frameTargets) { |
| 2406 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2407 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2408 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2409 | // the removed display. |
| 2410 | const auto display = getDisplayDeviceLocked(id); |
| 2411 | |
| 2412 | if (display && display->isModeSetPending()) { |
| 2413 | finalizeDisplayModeChange(*display); |
| 2414 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2415 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2418 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2419 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2420 | scheduleCommit(FrameHint::kNone); |
| 2421 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2425 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2426 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2427 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2428 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2429 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2430 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2431 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2432 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2433 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2434 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2435 | |
| 2436 | // 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] | 2437 | const Duration idealSfWorkDuration = |
| 2438 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2439 | const Duration frameDelay = |
| 2440 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2441 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2442 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2443 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2444 | |
| 2445 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2446 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2447 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2450 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2451 | Mutex::Autolock lock(mStateLock); |
| 2452 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2453 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2457 | // Composite if transactions were committed, or if requested by HWC. |
| 2458 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2459 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2460 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2461 | pacesetterFrameTarget.frameBeginTime().ns(), |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2462 | Fps::fromPeriodNsecs(vsyncPeriod.ns())); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2463 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2464 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2465 | bool transactionsAreEmpty; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2466 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2467 | mustComposite |= |
| 2468 | updateLayerSnapshotsLegacy(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2469 | flushTransactions, transactionsAreEmpty); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2470 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2471 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2472 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2473 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2474 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | if (transactionFlushNeeded()) { |
| 2478 | setTransactionFlags(eTransactionFlushNeeded); |
| 2479 | } |
| 2480 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2481 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2482 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2483 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2484 | // Invoke empty transaction callbacks early. |
| 2485 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2486 | } else { |
| 2487 | // Invoke OnCommit callbacks. |
| 2488 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2489 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | // Layers need to get updated (in the previous line) before we can use them for |
| 2493 | // choosing the refresh rate. |
| 2494 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2495 | // and may eventually call to ~Layer() if it holds the last reference |
| 2496 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2497 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2498 | mUpdateAttachedChoreographer = false; |
| 2499 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2500 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2501 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2502 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2503 | : nullptr, |
| 2504 | updateAttachedChoreographer); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2505 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2508 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2509 | if (!mustComposite) { |
| 2510 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2511 | } |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2512 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 2513 | if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
| 2514 | // This will block and tracing should only be enabled for debugging. |
| 2515 | addToLayerTracing(mVisibleRegionsDirty, pacesetterFrameTarget.frameBeginTime(), vsyncId); |
| 2516 | } |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2517 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2518 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2519 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2520 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2521 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2524 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2525 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2526 | const scheduler::FrameTarget& pacesetterTarget = |
| 2527 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2528 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2529 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2530 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2531 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2532 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2533 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2534 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2535 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2536 | |
| 2537 | // Add outputs for physical displays. |
| 2538 | for (const auto& [id, targeter] : frameTargeters) { |
| 2539 | ftl::FakeGuard guard(mStateLock); |
| 2540 | |
| 2541 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2542 | refreshArgs.outputs.push_back(display); |
| 2543 | } |
| 2544 | } |
| 2545 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2546 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2547 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2548 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2549 | display->tracePowerMode(); |
| 2550 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2551 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2552 | if (display->isVirtual()) { |
| 2553 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2554 | |
| 2555 | if (!refreshRate.isValid() || |
| 2556 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2557 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2558 | } |
| 2559 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2560 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2561 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2562 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2563 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2564 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2565 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2566 | updateLayerMetadataSnapshot(); |
| 2567 | mLayerMetadataSnapshotNeeded = false; |
| 2568 | } |
| 2569 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2570 | if (DOES_CONTAIN_BORDER) { |
| 2571 | refreshArgs.borderInfoList.clear(); |
| 2572 | mDrawingState.traverse([&refreshArgs](Layer* layer) { |
| 2573 | if (layer->isBorderEnabled()) { |
| 2574 | compositionengine::BorderRenderInfo info; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2575 | info.width = layer->getBorderWidth(); |
| 2576 | info.color = layer->getBorderColor(); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2577 | layer->traverse(LayerVector::StateSet::Drawing, [&info](Layer* ilayer) { |
| 2578 | info.layerIds.push_back(ilayer->getSequence()); |
| 2579 | }); |
| 2580 | refreshArgs.borderInfoList.emplace_back(std::move(info)); |
| 2581 | } |
| 2582 | }); |
| 2583 | } |
| 2584 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2585 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2586 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2587 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
Alec Mouri | 5c9c960 | 2020-09-01 15:10:40 -0700 | [diff] [blame] | 2588 | for (auto layer : mLayersWithQueuedFrames) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2589 | if (auto layerFE = layer->getCompositionEngineLayerFE()) |
| 2590 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2593 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2594 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2595 | |
| 2596 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2597 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2598 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2599 | |
| 2600 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2601 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2602 | mDrawingState.colorMatrixChanged = false; |
| 2603 | } |
| 2604 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2605 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2606 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2607 | if (mDebugFlashDelay != 0) { |
| 2608 | refreshArgs.devOptForceClientComposition = true; |
| 2609 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2610 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2611 | |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2612 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2613 | |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2614 | if (!getHwComposer().getComposer()->isSupported( |
| 2615 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime) && |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2616 | pacesetterTarget.wouldPresentEarly(vsyncPeriod)) { |
Dominik Laskowski | 42ccc93 | 2023-04-20 10:08:04 -0400 | [diff] [blame] | 2617 | const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2618 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2619 | // TODO(b/255601557): Calculate and pass per-display values for each FrameTarget. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2620 | refreshArgs.earliestPresentTime = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2621 | pacesetterTarget.previousFrameVsyncTime(vsyncPeriod) - hwcMinWorkDuration; |
Ady Abraham | f1db803 | 2023-03-24 17:52:34 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2624 | refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2625 | refreshArgs.expectedPresentTime = pacesetterTarget.expectedPresentTime().ns(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2626 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3645e64 | 2021-04-20 18:39:00 -0700 | [diff] [blame] | 2627 | |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2628 | // Store the present time just before calling to the composition engine so we could notify |
| 2629 | // the scheduler. |
| 2630 | const auto presentTime = systemTime(); |
| 2631 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2632 | constexpr bool kCursorOnly = false; |
| 2633 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2634 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2635 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2636 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2637 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2638 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2639 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2640 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2641 | // This is unexpected but instead of crashing, capture traces to disk |
| 2642 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2643 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2644 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2645 | outputLayer->getLayerFE().getDebugName(), |
| 2646 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2647 | |
| 2648 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2649 | mVisibleRegionsDirty = true; |
| 2650 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2651 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2652 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | } |
| 2656 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2657 | mCompositionEngine->present(refreshArgs); |
| 2658 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2659 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2660 | for (auto [layer, layerFE] : layers) { |
| 2661 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2662 | layer->onPreComposition(compositionResult.refreshStartTime); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2663 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
Vishnu Nair | 332e6ba | 2023-01-25 17:16:19 -0800 | [diff] [blame] | 2664 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2665 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2666 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2667 | } |
| 2668 | if (compositionResult.lastClientCompositionFence) { |
| 2669 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2670 | } |
| 2671 | } |
| 2672 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2673 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2674 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2675 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2676 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2677 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2678 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2679 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2680 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2681 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2682 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2683 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2684 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2687 | if (mScheduler->onPostComposition(presentTime)) { |
| 2688 | scheduleComposite(FrameHint::kNone); |
| 2689 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2690 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2691 | postComposition(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2692 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2693 | const bool hadGpuComposited = |
| 2694 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2695 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2696 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2697 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2698 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2699 | for (const auto& [_, display] : displays) { |
| 2700 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2701 | CompositionCoverageFlags& flags = |
| 2702 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2703 | |
| 2704 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2705 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2709 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2710 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2711 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2712 | } |
| 2713 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2714 | clientCompositionRecord.predicted |= |
| 2715 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2716 | clientCompositionRecord.predictionSucceeded |= |
| 2717 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2720 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2721 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2722 | |
| 2723 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2724 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2725 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2726 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2727 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2728 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2729 | using namespace ftl::flag_operators; |
| 2730 | |
| 2731 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2732 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2733 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2734 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2735 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2736 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2737 | mLayersIdsWithQueuedFrames.clear(); |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 2738 | if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { |
| 2739 | // This will block and should only be used for debugging. |
| 2740 | addToLayerTracing(mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), vsyncId); |
| 2741 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2742 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2743 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2744 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2745 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2746 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2747 | |
| 2748 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2749 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2750 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2751 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2752 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2753 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2754 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2755 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2756 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2757 | |
| 2758 | // Filter out virtual displays. |
| 2759 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2760 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2761 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2766 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2767 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2768 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2769 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2770 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2771 | if (mVisibleRegionsDirty) { |
| 2772 | computeLayerBounds(); |
| 2773 | } |
| 2774 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2775 | for (auto& layer : mLayersPendingRefresh) { |
| 2776 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2777 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2778 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2779 | } |
| 2780 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2783 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2784 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2785 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2786 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2787 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2788 | if (snapshot.externalTexture && |
| 2789 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2790 | return false; |
| 2791 | } |
| 2792 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 2793 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 2794 | // via a desired hdr/sdr ratio |
| 2795 | auto pixelFormat = snapshot.buffer |
| 2796 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 2797 | : std::nullopt; |
| 2798 | |
| 2799 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 2800 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2801 | return true; |
| 2802 | } |
| 2803 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 2804 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 2805 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 2806 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2807 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2808 | return true; |
| 2809 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2810 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2811 | } |
| 2812 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2813 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 2814 | bool isPrimary) const { |
| 2815 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 2816 | if (!id) { |
| 2817 | return ui::ROTATION_0; |
| 2818 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2819 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 2820 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 2821 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 2822 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 2823 | case Hwc2::AidlTransform::ROT_90: |
| 2824 | return ui::ROTATION_90; |
| 2825 | case Hwc2::AidlTransform::ROT_180: |
| 2826 | return ui::ROTATION_180; |
| 2827 | case Hwc2::AidlTransform::ROT_270: |
| 2828 | return ui::ROTATION_270; |
| 2829 | default: |
| 2830 | return ui::ROTATION_0; |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | if (isPrimary) { |
| 2835 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 2836 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 2837 | case Values::ORIENTATION_90: |
| 2838 | return ui::ROTATION_90; |
| 2839 | case Values::ORIENTATION_180: |
| 2840 | return ui::ROTATION_180; |
| 2841 | case Values::ORIENTATION_270: |
| 2842 | return ui::ROTATION_270; |
| 2843 | default: |
| 2844 | break; |
| 2845 | } |
| 2846 | } |
| 2847 | return ui::ROTATION_0; |
| 2848 | } |
| 2849 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2850 | void SurfaceFlinger::postComposition(PhysicalDisplayId pacesetterId, |
| 2851 | const scheduler::FrameTargeters& frameTargeters, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2852 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2853 | ATRACE_CALL(); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2854 | ALOGV(__func__); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2855 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2856 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 2857 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2858 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2859 | for (const auto& [id, targeter] : frameTargeters) { |
| 2860 | auto presentFence = getHwComposer().getPresentFence(id); |
| 2861 | |
| 2862 | if (id == pacesetterId) { |
| 2863 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 2864 | } |
| 2865 | |
| 2866 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 2867 | fenceTime->isValid()) { |
| 2868 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 2869 | } |
| 2870 | |
| 2871 | ftl::FakeGuard guard(mStateLock); |
| 2872 | if (const auto display = getCompositionDisplayLocked(id); |
| 2873 | display && display->getState().usesClientComposition) { |
| 2874 | gpuCompositionDoneFences |
| 2875 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 2876 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2877 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 2878 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2879 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2880 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2881 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 2882 | presentFences.get(pacesetterId) |
| 2883 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 2884 | .value_or(FenceTime::NO_FENCE); |
| 2885 | |
| 2886 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 2887 | gpuCompositionDoneFences.get(pacesetterId) |
| 2888 | .transform([](sp<Fence> fence) { |
| 2889 | return std::make_shared<FenceTime>(std::move(fence)); |
| 2890 | }) |
| 2891 | .value_or(FenceTime::NO_FENCE); |
| 2892 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2893 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 2894 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2895 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 2896 | // information from previous' frame classification is already available when sending jank info |
| 2897 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2898 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 2899 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 2900 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2901 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 2902 | // 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] | 2903 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2904 | const TimePoint compositeTime = |
| 2905 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
| 2906 | const Duration presentLatency = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2907 | getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE) |
| 2908 | ? Duration::zero() |
| 2909 | : mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2910 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2911 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 2912 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 2913 | const Period vsyncPeriod = schedule->period(); |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2914 | const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 2915 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 2916 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 2917 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2918 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 2919 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2920 | { |
| 2921 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 2922 | Mutex::Autolock lock(mStateLock); |
| 2923 | for (const auto& [token, display] : mDisplays) { |
| 2924 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 2930 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 2931 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 2932 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 2933 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 2934 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 2935 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 2936 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
| 2937 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 2938 | ui::INVALID_LAYER_STACK); |
| 2939 | } |
| 2940 | } |
| 2941 | layer->releasePendingBuffer(presentTime.ns()); |
| 2942 | } |
| 2943 | mLayersWithBuffersRemoved.clear(); |
| 2944 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2945 | for (const auto& layer: mLayersWithQueuedFrames) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2946 | layer->onPostComposition(pacesetterDisplay.get(), pacesetterGpuCompositionDoneFenceTime, |
| 2947 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 2948 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 2949 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 2950 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2951 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 2952 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2953 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 2954 | { |
| 2955 | Mutex::Autolock lock(mStateLock); |
| 2956 | if (mFpsReporter) { |
| 2957 | mFpsReporter->dispatchLayerFps(); |
| 2958 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 2959 | |
| 2960 | if (mTunnelModeEnabledReporter) { |
| 2961 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 2962 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2963 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 2964 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 2965 | if (reporter && reporter->hasListeners()) { |
| 2966 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 2967 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2971 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 2972 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2973 | } |
| 2974 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2975 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2976 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 2977 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 2978 | int32_t maxArea = 0; |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 2979 | auto updateInfoFn = |
| 2980 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 2981 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 2982 | if (snapshot.isVisible && |
| 2983 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 2984 | if (isHdrLayer(snapshot)) { |
| 2985 | const auto* outputLayer = |
| 2986 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 2987 | if (outputLayer) { |
| 2988 | const float desiredHdrSdrRatio = |
| 2989 | snapshot.desiredHdrSdrRatio <= 1.f |
| 2990 | ? std::numeric_limits<float>::infinity() |
| 2991 | : snapshot.desiredHdrSdrRatio; |
| 2992 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 2993 | info.numberOfHdrLayers++; |
| 2994 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 2995 | const int32_t area = |
| 2996 | displayFrame.width() * displayFrame.height(); |
| 2997 | if (area > maxArea) { |
| 2998 | maxArea = area; |
| 2999 | info.maxW = displayFrame.width(); |
| 3000 | info.maxH = displayFrame.height(); |
| 3001 | } |
| 3002 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3003 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3004 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3005 | }; |
| 3006 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3007 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3008 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3009 | [&, compositionDisplay = compositionDisplay]( |
| 3010 | std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 3011 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 3012 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 3013 | "Couldnt find layer object for %s", |
| 3014 | snapshot->getDebugString().c_str()); |
| 3015 | auto& legacyLayer = it->second; |
| 3016 | sp<LayerFE> layerFe = |
| 3017 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3018 | |
| 3019 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3020 | }); |
| 3021 | } else { |
| 3022 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3023 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3024 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3025 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3026 | }); |
| 3027 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3028 | listener->dispatchHdrLayerInfo(info); |
| 3029 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3030 | } |
| 3031 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3032 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3033 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3034 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3035 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3036 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3037 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3038 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3039 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3040 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3041 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3042 | const bool isInternalDisplay = |
| 3043 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3044 | |
| 3045 | if (isInternalDisplay) { |
| 3046 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3047 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3050 | const bool hasPacesetterDisplay = |
| 3051 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3052 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3053 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3054 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3055 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3059 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3060 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3061 | return; |
| 3062 | } |
| 3063 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3064 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3065 | getRenderEngine().cleanupPostRender(); |
| 3066 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3067 | if (mNumTrustedPresentationListeners > 0) { |
| 3068 | // 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] | 3069 | traverseLegacyLayers([&](Layer* layer) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3070 | if (!layer->hasTrustedPresentationListener()) { |
| 3071 | return; |
| 3072 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3073 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3074 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3075 | : layer->getLayerSnapshot(); |
| 3076 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3077 | if (snapshot) { |
| 3078 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3079 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3080 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3081 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3082 | nanoseconds_to_milliseconds(presentStartTime), |
| 3083 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3084 | }); |
| 3085 | } |
| 3086 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3087 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3088 | // side-effect of getTotalSize(), so we check that again here |
| 3089 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3090 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3091 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3092 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3093 | |
| 3094 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3097 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3098 | const ui::Size maxSize = [this] { |
| 3099 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3100 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3101 | // The LayerTraceGenerator tool runs without displays. |
| 3102 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3103 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3104 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3105 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3106 | const auto& display = pair.second; |
| 3107 | return {std::max(size.getWidth(), display->getWidth()), |
| 3108 | std::max(size.getHeight(), display->getHeight())}; |
| 3109 | }); |
| 3110 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3111 | |
| 3112 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3113 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3114 | const float xMax = maxSize.getWidth() * 10.f; |
| 3115 | const float yMax = maxSize.getHeight() * 10.f; |
| 3116 | |
| 3117 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3121 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3122 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3123 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3127 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3128 | ATRACE_CALL(); |
| 3129 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3130 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3131 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3132 | // effects of the State assignment don't happen with mStateLock held, |
| 3133 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3134 | State drawingState(mDrawingState); |
| 3135 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3136 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3137 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3139 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3140 | // so we can call commitTransactionsLocked unconditionally. |
| 3141 | // We clear the flags with mStateLock held to guarantee that |
| 3142 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3143 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3144 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3145 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3146 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3149 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3150 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3151 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
| 3152 | std::optional<hal::HWDisplayId> activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3153 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3154 | int attempt = 0; |
| 3155 | constexpr int kMaxAttempts = 3; |
| 3156 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3157 | hwcModes = getHwComposer().getModes(displayId, |
| 3158 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3159 | .getPeriodNsecs()); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3160 | activeModeHwcId = getHwComposer().getActiveMode(displayId); |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3161 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3162 | const auto isActiveMode = [activeModeHwcId](const HWComposer::HWCDisplayMode& mode) { |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3163 | return mode.hwcId == activeModeHwcId; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3164 | }; |
| 3165 | |
| 3166 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3167 | break; |
| 3168 | } |
| 3169 | } while (++attempt < kMaxAttempts); |
| 3170 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3171 | if (attempt == kMaxAttempts) { |
| 3172 | const std::string activeMode = |
| 3173 | activeModeHwcId ? std::to_string(*activeModeHwcId) : "unknown"s; |
| 3174 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3175 | "hwcModes={%s}", |
| 3176 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3177 | return {}; |
| 3178 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3179 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3180 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3181 | .transform([](const PhysicalDisplay& display) { |
| 3182 | return display.snapshot().displayModes(); |
| 3183 | }) |
| 3184 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3185 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3186 | ui::DisplayModeId nextModeId = 1 + |
| 3187 | std::accumulate(oldModes.begin(), oldModes.end(), static_cast<ui::DisplayModeId>(-1), |
| 3188 | [](ui::DisplayModeId max, const auto& pair) { |
| 3189 | return std::max(max, pair.first.value()); |
| 3190 | }); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3191 | |
| 3192 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3193 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3194 | const DisplayModeId id{nextModeId++}; |
| 3195 | newModes.try_emplace(id, |
| 3196 | DisplayMode::Builder(hwcMode.hwcId) |
| 3197 | .setId(id) |
| 3198 | .setPhysicalDisplayId(displayId) |
| 3199 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3200 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
| 3201 | .setDpiX(hwcMode.dpiX) |
| 3202 | .setDpiY(hwcMode.dpiY) |
| 3203 | .setGroup(hwcMode.configGroup) |
| 3204 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3205 | } |
| 3206 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3207 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3208 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3209 | [](const auto& lhs, const auto& rhs) { |
| 3210 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3211 | }); |
| 3212 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3213 | // Keep IDs if modes have not changed. |
| 3214 | const auto& modes = sameModes ? oldModes : newModes; |
| 3215 | const DisplayModePtr activeMode = |
| 3216 | std::find_if(modes.begin(), modes.end(), [activeModeHwcId](const auto& pair) { |
| 3217 | return pair.second->getHwcId() == activeModeHwcId; |
| 3218 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3219 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3220 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3221 | } |
| 3222 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3223 | bool SurfaceFlinger::configureLocked() { |
| 3224 | std::vector<HotplugEvent> events; |
| 3225 | { |
| 3226 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3227 | events = std::move(mPendingHotplugEvents); |
| 3228 | } |
| 3229 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3230 | for (const auto [hwcDisplayId, connection] : events) { |
| 3231 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3232 | const auto displayId = info->id; |
| 3233 | const bool connected = connection == hal::Connection::CONNECTED; |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3234 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3235 | if (const char* const log = |
| 3236 | processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) { |
| 3237 | ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(), |
| 3238 | hwcDisplayId); |
| 3239 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3240 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3241 | } |
| 3242 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3243 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3244 | } |
| 3245 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3246 | const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId, |
| 3247 | hal::HWDisplayId hwcDisplayId, bool connected, |
| 3248 | DisplayIdentificationInfo&& info) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3249 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3250 | if (!connected) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3251 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3252 | const auto& display = displayOpt->get(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3253 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3254 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3255 | mCurrentState.displays.removeItemsAt(index); |
| 3256 | } |
| 3257 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3258 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3259 | return "Disconnecting"; |
| 3260 | } |
| 3261 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3262 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3263 | if (!activeMode) { |
| 3264 | // TODO(b/241286153): Report hotplug failure to the framework. |
| 3265 | ALOGE("Failed to hotplug display %s", to_string(displayId).c_str()); |
| 3266 | getHwComposer().disconnectDisplay(displayId); |
| 3267 | return nullptr; |
| 3268 | } |
| 3269 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3270 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3271 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3272 | if (displayOpt) { |
| 3273 | const auto& display = displayOpt->get(); |
| 3274 | const auto& snapshot = display.snapshot(); |
| 3275 | |
| 3276 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3277 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3278 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3279 | } else { |
| 3280 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3281 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3282 | |
| 3283 | const auto it = |
| 3284 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3285 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3286 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3287 | |
| 3288 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3289 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3290 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3291 | return "Reconnecting"; |
| 3292 | } |
| 3293 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3294 | const sp<IBinder> token = sp<BBinder>::make(); |
| 3295 | |
| 3296 | mPhysicalDisplays.try_emplace(displayId, token, displayId, |
| 3297 | getHwComposer().getDisplayConnectionType(displayId), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3298 | std::move(displayModes), std::move(colorModes), |
| 3299 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3300 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3301 | DisplayDeviceState state; |
| 3302 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3303 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3304 | .activeMode = std::move(activeMode)}; |
| 3305 | state.isSecure = true; // All physical displays are currently considered secure. |
| 3306 | state.displayName = std::move(info.name); |
| 3307 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3308 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3309 | return "Connecting"; |
| 3310 | } |
| 3311 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3312 | void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) { |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 3313 | mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected); |
| 3314 | mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 3315 | } |
| 3316 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3317 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3318 | const scheduler::FrameRateMode& mode) { |
| 3319 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3320 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3321 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3322 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3323 | |
| 3324 | ((*mScheduler).*onDisplayModeChanged)(mAppConnectionHandle, mode); |
| 3325 | } |
| 3326 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3327 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3328 | const wp<IBinder>& displayToken, |
| 3329 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3330 | const DisplayDeviceState& state, |
| 3331 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3332 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3333 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3334 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3335 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3336 | creationArgs.isSecure = state.isSecure; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3337 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3338 | creationArgs.hasWideColorGamut = false; |
| 3339 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3340 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3341 | if (const auto& physical = state.physical) { |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3342 | creationArgs.activeModeId = physical->activeMode->getId(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3343 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3344 | getKernelIdleTimerProperties(compositionDisplay->getId()); |
| 3345 | |
Ady Abraham | 0c8b723 | 2023-01-27 21:12:16 -0800 | [diff] [blame] | 3346 | using Config = scheduler::RefreshRateSelector::Config; |
| 3347 | const auto enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3348 | ? Config::FrameRateOverride::Enabled |
| 3349 | : Config::FrameRateOverride::Disabled; |
Ady Abraham | 0d4b41c | 2023-02-14 23:28:40 +0000 | [diff] [blame] | 3350 | Config config = |
Ady Abraham | 8ca643a | 2022-10-18 18:26:47 -0700 | [diff] [blame] | 3351 | {.enableFrameRateOverride = enableFrameRateOverride, |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 3352 | .frameRateMultipleThreshold = |
Ady Abraham | 9a2ea34 | 2021-09-03 17:32:34 -0700 | [diff] [blame] | 3353 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold", 0), |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3354 | .idleTimerTimeout = idleTimerTimeoutMs, |
| 3355 | .kernelIdleTimerController = kernelIdleTimerController}; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3356 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3357 | creationArgs.refreshRateSelector = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3358 | mPhysicalDisplays.get(physical->id) |
| 3359 | .transform(&PhysicalDisplay::snapshotRef) |
| 3360 | .transform([&](const display::DisplaySnapshot& snapshot) { |
| 3361 | return std::make_shared< |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3362 | scheduler::RefreshRateSelector>(snapshot.displayModes(), |
| 3363 | creationArgs.activeModeId, |
| 3364 | config); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3365 | }) |
| 3366 | .value_or(nullptr); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3367 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3368 | creationArgs.isPrimary = physical->id == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3369 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3370 | mPhysicalDisplays.get(physical->id) |
| 3371 | .transform(&PhysicalDisplay::snapshotRef) |
| 3372 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3373 | for (const auto mode : snapshot.colorModes()) { |
| 3374 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3375 | creationArgs.hwcColorModes |
| 3376 | .emplace(mode, |
| 3377 | getHwComposer().getRenderIntents(physical->id, mode)); |
| 3378 | } |
| 3379 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3380 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3381 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3382 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3383 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3384 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3385 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3386 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3387 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3388 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3389 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3390 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3391 | // Make sure that composition can never be stalled by a virtual display |
| 3392 | // 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] | 3393 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3394 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3395 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3396 | } |
| 3397 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3398 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3399 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3400 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3401 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3402 | // virtual displays are always considered enabled |
linpeter | 1c69cd3 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 3403 | creationArgs.initialPowerMode = |
| 3404 | state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3405 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3406 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3407 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3408 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3409 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3410 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3411 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3412 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3413 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3414 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3415 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3416 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3417 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3418 | display->getCompositionDisplay()->setColorProfile( |
| 3419 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3420 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3421 | |
| 3422 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3423 | const auto& mode = *physical->activeMode; |
| 3424 | display->setActiveMode(mode.getId(), mode.getFps(), mode.getFps()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3425 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3426 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3427 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3428 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3429 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3430 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3431 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3432 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3433 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3434 | } |
| 3435 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3436 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3437 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3438 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3439 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3440 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3441 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3442 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3443 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3444 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3445 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3446 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3447 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3448 | int format; |
| 3449 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3450 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3451 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3452 | } else { |
| 3453 | // Virtual displays without a surface are dormant: |
| 3454 | // they have external state (layer stack, projection, |
| 3455 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3456 | return; |
| 3457 | } |
| 3458 | |
| 3459 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3460 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3461 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3462 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3463 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3464 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3465 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3466 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3467 | builder.setIsSecure(state.isSecure); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3468 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3469 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3470 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3471 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3472 | |
| 3473 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3474 | sp<IGraphicBufferProducer> producer; |
| 3475 | sp<IGraphicBufferProducer> bqProducer; |
| 3476 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3477 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3478 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3479 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3480 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3481 | LOG_FATAL_IF(!displayId); |
| 3482 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3483 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3484 | displaySurface = surface; |
| 3485 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3486 | } else { |
| 3487 | ALOGE_IF(state.surface != nullptr, |
| 3488 | "adding a supported display, but rendering " |
| 3489 | "surface is provided (%p), ignoring it", |
| 3490 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3491 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3492 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3493 | displaySurface = |
| 3494 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3495 | state.physical->activeMode->getResolution(), |
| 3496 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3497 | producer = bqProducer; |
| 3498 | } |
| 3499 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3500 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3501 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3502 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3503 | |
| 3504 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3505 | const auto displayId = display->getPhysicalId(); |
| 3506 | { |
Dominik Laskowski | 59db956 | 2022-10-27 16:18:53 -0400 | [diff] [blame] | 3507 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3508 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3509 | |
| 3510 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3511 | mScheduler->registerDisplay(displayId, display->holdRefreshRateSelector()); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3512 | } |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 3513 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3514 | dispatchDisplayHotplugEvent(displayId, true); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3515 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3516 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3517 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3518 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3521 | mDisplays.try_emplace(displayToken, std::move(display)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3525 | auto display = getDisplayDeviceLocked(displayToken); |
| 3526 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3527 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3528 | |
| 3529 | if (display->isVirtual()) { |
| 3530 | releaseVirtualDisplay(display->getVirtualId()); |
| 3531 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3532 | dispatchDisplayHotplugEvent(display->getPhysicalId(), false); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3533 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | |
| 3537 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3538 | |
| 3539 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3540 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3541 | // Destroy the display without holding the mStateLock. |
| 3542 | // This is a temporary solution until we can manage transaction queues without |
| 3543 | // holding the mStateLock. |
| 3544 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3545 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3546 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3547 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3548 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3549 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3550 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3551 | // not be accessible. |
| 3552 | })); |
| 3553 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3557 | const DisplayDeviceState& currentState, |
| 3558 | const DisplayDeviceState& drawingState) { |
| 3559 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3560 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3561 | |
| 3562 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3563 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3564 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3565 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3566 | if (display->isVirtual()) { |
| 3567 | releaseVirtualDisplay(display->getVirtualId()); |
| 3568 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3569 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3570 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3571 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3572 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3573 | if (const auto& physical = currentState.physical) { |
| 3574 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3575 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3576 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3577 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3578 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3579 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3580 | const auto display = getDisplayDeviceLocked(displayToken); |
| 3581 | setPowerModeInternal(display, hal::PowerMode::ON); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3582 | |
| 3583 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3584 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3585 | resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3586 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3587 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3588 | return; |
| 3589 | } |
| 3590 | |
| 3591 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3592 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3593 | display->setLayerFilter( |
| 3594 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3595 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3596 | if (currentState.flags != drawingState.flags) { |
| 3597 | display->setFlags(currentState.flags); |
| 3598 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3599 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3600 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3601 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3602 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3603 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3604 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3605 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3606 | sActiveDisplayRotationFlags = |
| 3607 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3608 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3609 | } |
| 3610 | if (currentState.width != drawingState.width || |
| 3611 | currentState.height != drawingState.height) { |
| 3612 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3613 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3614 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3615 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3620 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 3621 | void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) { |
| 3622 | // Cancel the pending refresh rate change, if any, before updating the phase configuration. |
| 3623 | mScheduler->vsyncModulator().cancelRefreshRateChange(); |
| 3624 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3625 | mVsyncConfiguration->reset(); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3626 | updatePhaseConfiguration(refreshRate); |
| 3627 | mRefreshRateStats->setRefreshRate(refreshRate); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 3628 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3629 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3630 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3631 | // here we take advantage of Vector's copy-on-write semantics to |
| 3632 | // improve performance by skipping the transaction entirely when |
| 3633 | // know that the lists are identical |
| 3634 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3635 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3636 | if (!curr.isIdenticalTo(draw)) { |
| 3637 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3638 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3639 | |
| 3640 | // find the displays that were removed |
| 3641 | // (ie: in drawing state but not in current state) |
| 3642 | // also handle displays that changed |
| 3643 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3644 | for (size_t i = 0; i < draw.size(); i++) { |
| 3645 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3646 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3647 | if (j < 0) { |
| 3648 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3649 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3650 | } else { |
| 3651 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3652 | const DisplayDeviceState& currentState = curr[j]; |
| 3653 | const DisplayDeviceState& drawingState = draw[i]; |
| 3654 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3655 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | // find displays that were added |
| 3659 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3660 | for (size_t i = 0; i < curr.size(); i++) { |
| 3661 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3662 | if (draw.indexOfKey(displayToken) < 0) { |
| 3663 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3667 | |
| 3668 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3669 | } |
| 3670 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3671 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 3672 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3673 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3674 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3675 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3676 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3677 | mFrontEndDisplayInfos.clear(); |
| 3678 | for (const auto& [_, display] : mDisplays) { |
| 3679 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 3680 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 3681 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 3682 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3684 | if (mSomeChildrenChanged) { |
| 3685 | mVisibleRegionsDirty = true; |
| 3686 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3687 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3690 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 3691 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3692 | // 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] | 3693 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 3694 | // 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] | 3695 | // the hint is set before we acquire a buffer from the surface texture. |
| 3696 | // |
| 3697 | // NOTE: layer transactions have taken place already, so we use their |
| 3698 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 3699 | // happened yet, so we must use the current state layer list |
| 3700 | // (soon to become the drawing state list). |
| 3701 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3702 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3703 | ui::LayerStack layerStack; |
| 3704 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3705 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3706 | // NOTE: we rely on the fact that layers are sorted by |
| 3707 | // layerStack first (so we don't have to traverse the list |
| 3708 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3709 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 3710 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3711 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3712 | |
| 3713 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 3714 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3715 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 3716 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3717 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3718 | |
| 3719 | // Pick the primary display if another display mirrors the layer. |
| 3720 | if (hintDisplay) { |
| 3721 | hintDisplay = nullptr; |
| 3722 | break; |
| 3723 | } |
| 3724 | |
| 3725 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3726 | } |
| 3727 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 3728 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3729 | if (!hintDisplay) { |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3730 | // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to |
| 3731 | // redraw after transform hint changes. See bug 8508397. |
Lloyd Pique | d432a7c | 2018-03-23 16:05:31 -0700 | [diff] [blame] | 3732 | // could be null when this layer is using a layerStack |
| 3733 | // that is not visible on any display. Also can occur at |
| 3734 | // screen off/on times. |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3735 | // U Update: Don't provide stale hints to the clients. For |
| 3736 | // special cases where we want the app to draw its |
| 3737 | // first frame before the display is available, we rely |
| 3738 | // on WMS and DMS to provide the right information |
| 3739 | // so the client can calculate the hint. |
| 3740 | ALOGV("Skipping reporting transform hint update for %s", layer->getDebugName()); |
| 3741 | layer->skipReportingTransformHint(); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3742 | } else { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3743 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 3744 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3745 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 3746 | } |
| 3747 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3748 | if (mLayersAdded) { |
| 3749 | mLayersAdded = false; |
| 3750 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3751 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3752 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | // some layers might have been removed, so |
| 3756 | // we need to update the regions they're exposing. |
| 3757 | if (mLayersRemoved) { |
| 3758 | mLayersRemoved = false; |
| 3759 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3760 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3761 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3762 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 3763 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3764 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3765 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3766 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 3767 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 3768 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | } |
| 3770 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 3771 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 3772 | mUpdateInputInfo = true; |
| 3773 | } |
| 3774 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3775 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3778 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3779 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 3780 | return; |
| 3781 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3782 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3783 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3784 | std::vector<WindowInfo> windowInfos; |
| 3785 | std::vector<DisplayInfo> displayInfos; |
| 3786 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3787 | if (mUpdateInputInfo) { |
| 3788 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3789 | updateWindowInfo = true; |
| 3790 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3791 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3792 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3793 | std::unordered_set<int32_t> visibleWindowIds; |
| 3794 | for (WindowInfo& windowInfo : windowInfos) { |
| 3795 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 3796 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3797 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3798 | } |
| 3799 | bool visibleWindowsChanged = false; |
| 3800 | if (visibleWindowIds != mVisibleWindowIds) { |
| 3801 | visibleWindowsChanged = true; |
| 3802 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3803 | } |
| 3804 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3805 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 3806 | windowInfos = std::move(windowInfos), |
| 3807 | displayInfos = std::move(displayInfos), |
| 3808 | inputWindowCommands = |
| 3809 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3810 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3811 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3812 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 3813 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3814 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3815 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 3816 | std::move(displayInfos), |
| 3817 | ftl::to_underlying(vsyncId), |
| 3818 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 3819 | std::move( |
| 3820 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 3821 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 3822 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 3823 | } else { |
| 3824 | // If there are listeners but no changes to input windows, call the listeners |
| 3825 | // immediately. |
| 3826 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 3827 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 3828 | listener->onWindowInfosReported(); |
| 3829 | } |
| 3830 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3831 | } |
| 3832 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 3833 | inputFlinger->setFocusedWindow(focusRequest); |
| 3834 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 3835 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 3836 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 3837 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3840 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 3841 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 3842 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 3843 | if (!supportsDisplayBrightnessCommand) { |
| 3844 | return; |
| 3845 | } |
| 3846 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3847 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3848 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 3849 | if (!needsComposite) { |
| 3850 | const status_t error = |
| 3851 | getHwComposer() |
| 3852 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 3853 | display->getCompositionDisplay() |
| 3854 | ->getState() |
| 3855 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3856 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 3857 | .applyImmediately = true}) |
| 3858 | .get(); |
| 3859 | |
| 3860 | ALOGE_IF(error != NO_ERROR, |
| 3861 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 3862 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 3863 | } |
| 3864 | display->persistBrightness(needsComposite); |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 3869 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 3870 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3871 | static size_t sNumWindowInfos = 0; |
| 3872 | outWindowInfos.reserve(sNumWindowInfos); |
| 3873 | sNumWindowInfos = 0; |
| 3874 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3875 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3876 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 3877 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 3878 | outWindowInfos.push_back(snapshot.inputInfo); |
| 3879 | }); |
| 3880 | } else { |
| 3881 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) { |
| 3882 | if (!layer->needsInputInfo()) return; |
| 3883 | const auto opt = |
| 3884 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 3885 | .transform([](const frontend::DisplayInfo& info) { |
| 3886 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 3887 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3888 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3889 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 3890 | }); |
| 3891 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3892 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3893 | sNumWindowInfos = outWindowInfos.size(); |
| 3894 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 3895 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 3896 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 3897 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 3898 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3901 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3902 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3903 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3904 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3905 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 3906 | } |
| 3907 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 3908 | |
| 3909 | constexpr bool kCursorOnly = true; |
| 3910 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 3911 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3912 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 3915 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 3916 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 3917 | } |
| 3918 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3919 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3920 | if (mBootStage != BootStage::FINISHED) { |
| 3921 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 3922 | return; |
| 3923 | } |
| 3924 | |
| 3925 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3926 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3927 | // If this is called from the main thread mStateLock must be locked before |
| 3928 | // 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] | 3929 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 3930 | |
| 3931 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 3932 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3933 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3934 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3935 | |
| 3936 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 3937 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3938 | |
| 3939 | if (!display) continue; |
| 3940 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3941 | if (!display->isPoweredOn()) { |
| 3942 | ALOGV("%s(%s): Display is powered off", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 3943 | continue; |
| 3944 | } |
| 3945 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3946 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3947 | setDesiredActiveMode(std::move(request)); |
| 3948 | } else { |
| 3949 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, modePtr->getId().value(), |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3950 | to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 3951 | } |
| 3952 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 3955 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 3956 | PhysicalDisplayId displayId = [&]() { |
| 3957 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 3958 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 3959 | }(); |
| 3960 | |
| 3961 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 3962 | } |
| 3963 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 3964 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 3965 | mPowerAdvisor->notifyCpuLoadUp(); |
| 3966 | } |
| 3967 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 3968 | void SurfaceFlinger::onChoreographerAttached() { |
| 3969 | ATRACE_CALL(); |
| 3970 | if (mLayerLifecycleManagerEnabled) { |
| 3971 | mUpdateAttachedChoreographer = true; |
| 3972 | scheduleCommit(FrameHint::kNone); |
| 3973 | } |
| 3974 | } |
| 3975 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3976 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3977 | using namespace scheduler; |
| 3978 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3979 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 3980 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3981 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 3982 | const Fps activeRefreshRate = activeMode.fps; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3983 | mRefreshRateStats = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3984 | std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 3985 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 3986 | mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate); |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 3987 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 3988 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 3989 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3990 | if (sysprop::use_content_detection_for_refresh_rate(false)) { |
| 3991 | features |= Feature::kContentDetection; |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 3992 | if (base::GetBoolProperty("debug.sf.enable_small_dirty_detection"s, false)) { |
| 3993 | features |= Feature::kSmallDirtyContentDetection; |
| 3994 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 3995 | } |
| 3996 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 3997 | features |= Feature::kTracePredictedVsync; |
| 3998 | } |
| 3999 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Ady Abraham | de549d4 | 2022-01-26 19:19:17 -0800 | [diff] [blame] | 4000 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4001 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4002 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4003 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4004 | features |= Feature::kKernelIdleTimer; |
| 4005 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4006 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4007 | features |= Feature::kBackpressureGpuComposition; |
| 4008 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4009 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4010 | auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs()); |
| 4011 | |
| 4012 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4013 | static_cast<ISchedulerCallback&>(*this), features, |
| 4014 | std::move(modulatorPtr)); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4015 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4016 | mScheduler->startTimers(); |
| 4017 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 4018 | const auto configs = mVsyncConfiguration->getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4019 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4020 | mAppConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4021 | mScheduler->createEventThread(Scheduler::Cycle::Render, |
| 4022 | mFrameTimeline->getTokenManager(), |
| 4023 | /* workDuration */ configs.late.appWorkDuration, |
| 4024 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4025 | mSfConnectionHandle = |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4026 | mScheduler->createEventThread(Scheduler::Cycle::LastComposite, |
| 4027 | mFrameTimeline->getTokenManager(), |
| 4028 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4029 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4030 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4031 | mScheduler->initVsync(mScheduler->getVsyncSchedule()->getDispatch(), |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 4032 | *mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4033 | |
| 4034 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4035 | sp<RegionSamplingThread>::make(*this, |
| 4036 | RegionSamplingThread::EnvironmentTimingTunables()); |
| 4037 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4038 | } |
| 4039 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4040 | void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 4041 | mVsyncConfiguration->setRefreshRateFps(refreshRate); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4042 | mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(), |
| 4043 | refreshRate.getPeriod()); |
Dominik Laskowski | 08d05c2 | 2020-07-22 00:05:08 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4046 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4047 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4048 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4049 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4050 | // Notify removed layers now that they can't be drawn from |
| 4051 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4052 | // Ensure any buffers set to display on any children are released. |
| 4053 | if (l->isRemovedFromCurrentState()) { |
| 4054 | l->latchAndReleaseBuffer(); |
| 4055 | } |
| 4056 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4057 | // If a layer has a parent, we allow it to out-live it's handle |
| 4058 | // with the idea that the parent holds a reference and will eventually |
| 4059 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4060 | // here. |
| 4061 | if (l->isAtRoot()) { |
| 4062 | l->setIsAtRoot(false); |
| 4063 | mCurrentState.layersSortedByZ.remove(l); |
| 4064 | } |
| 4065 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4066 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4067 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4068 | // ensure we can copy its current to drawing state. |
| 4069 | if (!l->getParent()) { |
| 4070 | mOffscreenLayers.emplace(l.get()); |
| 4071 | } |
| 4072 | } |
| 4073 | mLayersPendingRemoval.clear(); |
| 4074 | } |
| 4075 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4076 | mDrawingState = mCurrentState; |
| 4077 | // clear the "changed" flags in current state |
| 4078 | mCurrentState.colorMatrixChanged = false; |
| 4079 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4080 | if (mVisibleRegionsDirty) { |
| 4081 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4082 | rootLayer->commitChildList(); |
| 4083 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4084 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4085 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4086 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4087 | if (mLayerMirrorRoots.size() > 0) { |
| 4088 | std::deque<Layer*> pendingUpdates; |
| 4089 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4090 | mLayerMirrorRoots.end()); |
| 4091 | std::vector<Layer*> needsUpdating; |
| 4092 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4093 | pendingUpdates.pop_front(); |
| 4094 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4095 | continue; |
| 4096 | } |
| 4097 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4098 | } else { |
| 4099 | needsUpdating.push_back(cloneRoot); |
| 4100 | } |
| 4101 | } |
| 4102 | for (Layer* cloneRoot : needsUpdating) { |
| 4103 | cloneRoot->updateMirrorInfo({}); |
| 4104 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4105 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4108 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4109 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4110 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4111 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4112 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4113 | layer->commitChildList(); |
| 4114 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4115 | }); |
| 4116 | } |
| 4117 | } |
| 4118 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4119 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4120 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4121 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4122 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4123 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4124 | } |
| 4125 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4128 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4129 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4130 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4131 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4133 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4134 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4135 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4136 | |
| 4137 | // Store the set of layers that need updates. This set must not change as |
| 4138 | // buffers are being latched, as this could result in a deadlock. |
| 4139 | // Example: Two producers share the same command stream and: |
| 4140 | // 1.) Layer 0 is latched |
| 4141 | // 2.) Layer 0 gets a new frame |
| 4142 | // 2.) Layer 1 gets a new frame |
| 4143 | // 3.) Layer 1 is latched. |
| 4144 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4145 | // 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] | 4146 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4147 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4148 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4149 | if (flags & Layer::eVisibleRegion) { |
| 4150 | mVisibleRegionsDirty = true; |
| 4151 | } |
| 4152 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4153 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4154 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4155 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4156 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4157 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4158 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4159 | if (!layer->hasBuffer()) { |
| 4160 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4161 | // instead of a missed frame. This is used to identify scenarios where we |
| 4162 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4163 | // We only update the latch time for buffer less layers here, the latch time |
| 4164 | // is updated for buffer layers when the buffer is latched. |
| 4165 | layer->updateLastLatchTime(latchTime); |
| 4166 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4167 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4168 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4169 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4170 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4171 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4172 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4173 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4174 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4175 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4176 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4177 | } |
| 4178 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4179 | if (!mLayersWithQueuedFrames.empty()) { |
| 4180 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4181 | // writes to Layer current state. See also b/119481871 |
| 4182 | Mutex::Autolock lock(mStateLock); |
| 4183 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4184 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4185 | if (layer->willReleaseBufferOnLatch()) { |
| 4186 | mLayersWithBuffersRemoved.emplace(layer); |
| 4187 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4188 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4189 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4190 | newDataLatched = true; |
| 4191 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4192 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4193 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4194 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4195 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4196 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4197 | |
| 4198 | // If we will need to wake up at some time in the future to deal with a |
| 4199 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4200 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4201 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4202 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4203 | } |
| 4204 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4205 | // enter boot animation on first buffer latch |
| 4206 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4207 | ALOGI("Enter boot animation"); |
| 4208 | mBootStage = BootStage::BOOTANIMATION; |
| 4209 | } |
| 4210 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4211 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4212 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4213 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4214 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4215 | // 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] | 4216 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | } |
| 4218 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4219 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4220 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4221 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4222 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4223 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4224 | MAX_LAYERS); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4225 | static_cast<void>(mScheduler->schedule([=] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4226 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4227 | bool leakingParentLayerFound = false; |
| 4228 | mDrawingState.traverse([&](Layer* layer) { |
| 4229 | if (leakingParentLayerFound) { |
| 4230 | return; |
| 4231 | } |
| 4232 | if (layer->getChildrenCount() > 20) { |
| 4233 | leakingParentLayerFound = true; |
| 4234 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4235 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4236 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4237 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4238 | parent = parent->getParent(); |
| 4239 | } |
| 4240 | // Sample up to 100 layers |
| 4241 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4242 | layer->getChildrenCount()); |
| 4243 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4244 | layer->traverseChildren([&](Layer* layer) { |
| 4245 | if (rand() % sampleSize == 0) { |
| 4246 | ALOGE("Child Layer: %s", layer->getName().c_str()); |
| 4247 | } |
| 4248 | }); |
| 4249 | } |
| 4250 | }); |
| 4251 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4252 | int numLayers = 0; |
| 4253 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4254 | |
| 4255 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4256 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4257 | // Aim to dump about 200 layers to avoid totally trashing |
| 4258 | // logcat. On the other hand, if there really are 4096 layers |
| 4259 | // something has gone totally wrong its probably the most |
| 4260 | // useful information in logcat. |
| 4261 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4262 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4263 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4264 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4265 | } |
| 4266 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4267 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4268 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4269 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4270 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4271 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4272 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4273 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4274 | } |
| 4275 | } |
| 4276 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4277 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4278 | } |
| 4279 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4280 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4281 | if (outTransformHint) { |
| 4282 | *outTransformHint = mActiveDisplayTransformHint; |
| 4283 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4284 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4285 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4286 | { |
| 4287 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4288 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4289 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4290 | args.mirrorLayerHandle.clear(); |
| 4291 | args.parentHandle.clear(); |
| 4292 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4293 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4294 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4295 | setTransactionFlags(eTransactionNeeded); |
| 4296 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4299 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4300 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4303 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4304 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4305 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4306 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | } |
| 4308 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4309 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4310 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4311 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4312 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4313 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4314 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4315 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4316 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4317 | } else if (frameHint == FrameHint::kActive) { |
| 4318 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4319 | // as a new activity just happened. |
| 4320 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4321 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | } |
| 4323 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4324 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4325 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4326 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4327 | |
| 4328 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4329 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4330 | |
| 4331 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4332 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4333 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4334 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4335 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4336 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4337 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4338 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4339 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4340 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4341 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4342 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4343 | if (!mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
| 4344 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4345 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4346 | return TransactionReadiness::NotReady; |
| 4347 | } |
| 4348 | |
| 4349 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4350 | // expected present time of this transaction. |
| 4351 | if (transaction.isAutoTimestamp && |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4352 | frameIsEarly(expectedPresentTime, VsyncId{transaction.frameTimelineInfo.vsyncId})) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4353 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4354 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4355 | return TransactionReadiness::NotReady; |
| 4356 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4357 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4358 | return TransactionReadiness::Ready; |
| 4359 | } |
| 4360 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4361 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4362 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4363 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4364 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4365 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4366 | resolvedState) -> bool { |
| 4367 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4368 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4369 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4370 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4371 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4372 | if (s.bufferData->hasBarrier) { |
| 4373 | // The current producerId is already a newer producer than the buffer that has a |
| 4374 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4375 | // don't wait on the barrier since we know that's stale information. |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4376 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4377 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4378 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4379 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4380 | s.bufferData->acquireFence); |
| 4381 | // Delete the entire state at this point and not just release the buffer because |
| 4382 | // everything associated with the Layer in this Transaction is now out of date. |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4383 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4384 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4385 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4386 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4387 | } |
| 4388 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4389 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4390 | const bool willApplyBarrierFrame = |
| 4391 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4392 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4393 | s.bufferData->barrierFrameNumber)); |
| 4394 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4395 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4396 | layer->getDebugName(), |
| 4397 | layer->getDrawingState().barrierFrameNumber, |
| 4398 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4399 | ready = TransactionReadiness::NotReadyBarrier; |
| 4400 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4401 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4406 | // the transaction in the queue. |
| 4407 | const bool hasPendingBuffer = |
| 4408 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4409 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4410 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4411 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4412 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4413 | } |
| 4414 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4415 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4416 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4417 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4418 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4419 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4420 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4421 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4422 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4423 | flushState.firstTransaction) && |
| 4424 | layer->isSimpleBufferUpdate(s); |
| 4425 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4426 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4427 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4428 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4429 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4430 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4431 | ready = TransactionReadiness::NotReady; |
| 4432 | auto& listener = s.bufferData->releaseBufferListener; |
| 4433 | if (listener && |
| 4434 | (flushState.queueProcessTime - transaction.postTime) > |
| 4435 | std::chrono::nanoseconds(4s).count()) { |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4436 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4437 | .onTransactionQueueStalled(transaction.id, |
| 4438 | {.pid = layer->getOwnerPid(), |
| 4439 | .layerId = static_cast<uint32_t>( |
| 4440 | layer->getSequence()), |
| 4441 | .layerName = layer->getDebugName(), |
| 4442 | .bufferId = s.bufferData->getId(), |
| 4443 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4444 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4445 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4446 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4447 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4448 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4449 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4450 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4451 | return ready; |
| 4452 | } |
| 4453 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4454 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4455 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4456 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4457 | auto ready = TransactionReadiness::Ready; |
| 4458 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4459 | resolvedState) -> bool { |
| 4460 | const frontend::RequestedLayerState* layer = |
| 4461 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4462 | const auto& transaction = *flushState.transaction; |
| 4463 | const auto& s = resolvedState.state; |
| 4464 | // check for barrier frames |
| 4465 | if (s.bufferData->hasBarrier) { |
| 4466 | // The current producerId is already a newer producer than the buffer that has a |
| 4467 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4468 | // don't wait on the barrier since we know that's stale information. |
| 4469 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4470 | if (s.bufferData->releaseBufferListener) { |
| 4471 | uint32_t currentMaxAcquiredBufferCount = |
| 4472 | getMaxAcquiredBufferCountForCurrentRefreshRate(layer->ownerUid.val()); |
| 4473 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4474 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4475 | s.bufferData->releaseBufferListener |
| 4476 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer()->getId(), |
| 4477 | s.bufferData->frameNumber}, |
| 4478 | s.bufferData->acquireFence |
| 4479 | ? s.bufferData->acquireFence |
| 4480 | : Fence::NO_FENCE, |
| 4481 | currentMaxAcquiredBufferCount); |
| 4482 | } |
| 4483 | |
| 4484 | // Delete the entire state at this point and not just release the buffer because |
| 4485 | // everything associated with the Layer in this Transaction is now out of date. |
| 4486 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", layer->name.c_str(), |
| 4487 | layer->barrierProducerId, s.bufferData->producerId); |
| 4488 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4489 | } |
| 4490 | |
| 4491 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4492 | const bool willApplyBarrierFrame = |
| 4493 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4494 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4495 | s.bufferData->barrierFrameNumber)); |
| 4496 | if (!willApplyBarrierFrame) { |
| 4497 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4498 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4499 | s.bufferData->barrierFrameNumber); |
| 4500 | ready = TransactionReadiness::NotReadyBarrier; |
| 4501 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4502 | } |
| 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4507 | // the transaction in the queue. |
| 4508 | const bool hasPendingBuffer = |
| 4509 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4510 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
| 4511 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4512 | ready = TransactionReadiness::NotReady; |
| 4513 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4514 | } |
| 4515 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4516 | const bool acquireFenceAvailable = s.bufferData && |
| 4517 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4518 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4519 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4520 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4521 | if (!fenceSignaled) { |
| 4522 | // check fence status |
| 4523 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4524 | flushState.firstTransaction) && |
| 4525 | layer->isSimpleBufferUpdate(s); |
| 4526 | if (allowLatchUnsignaled) { |
| 4527 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", layer->name.c_str()); |
| 4528 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4529 | } else { |
| 4530 | ready = TransactionReadiness::NotReady; |
| 4531 | auto& listener = s.bufferData->releaseBufferListener; |
| 4532 | if (listener && |
| 4533 | (flushState.queueProcessTime - transaction.postTime) > |
| 4534 | std::chrono::nanoseconds(4s).count()) { |
| 4535 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4536 | .onTransactionQueueStalled(transaction.id, |
| 4537 | {.pid = layer->ownerPid.val(), |
| 4538 | .layerId = layer->id, |
| 4539 | .layerName = layer->name, |
| 4540 | .bufferId = s.bufferData->getId(), |
| 4541 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4542 | } |
| 4543 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 4544 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4545 | } |
| 4546 | } |
| 4547 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 4548 | }); |
| 4549 | return ready; |
| 4550 | } |
| 4551 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4552 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 4553 | mTransactionHandler.addTransactionReadyFilter( |
| 4554 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4555 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4556 | mTransactionHandler.addTransactionReadyFilter( |
| 4557 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 4558 | std::placeholders::_1)); |
| 4559 | } else { |
| 4560 | mTransactionHandler.addTransactionReadyFilter( |
| 4561 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 4562 | std::placeholders::_1)); |
| 4563 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4564 | } |
| 4565 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4566 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4567 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4568 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4569 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4570 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4573 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4574 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4575 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 4576 | return applyTransactionsLocked(transactions, vsyncId); |
| 4577 | } |
| 4578 | |
| 4579 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 4580 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4581 | bool needsTraversal = false; |
| 4582 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 4583 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4584 | needsTraversal |= |
| 4585 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 4586 | transaction.displays, transaction.flags, |
| 4587 | transaction.inputWindowCommands, |
| 4588 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4589 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4590 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4591 | transaction.listenerCallbacks, transaction.originPid, |
| 4592 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 4593 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4594 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4598 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4601 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 4602 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4603 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4604 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4605 | return false; |
| 4606 | } |
| 4607 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4608 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 4609 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 4610 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 4611 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4612 | return false; |
| 4613 | } |
| 4614 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4615 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->period() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4616 | |
| 4617 | return predictedPresentTime >= expectedPresentTime && |
| 4618 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4619 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 4620 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4621 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 4622 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4623 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4624 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4625 | return false; |
| 4626 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 4627 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4628 | // We only want to latch unsignaled when a single layer is updated in this |
| 4629 | // transaction (i.e. not a blast sync transaction). |
| 4630 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4631 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4632 | return false; |
| 4633 | } |
| 4634 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4635 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4636 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4637 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 4638 | "transaction)", |
| 4639 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4640 | return false; |
| 4641 | } |
| 4642 | |
| 4643 | // We don't want to latch unsignaled if are in early / client composition |
| 4644 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 4645 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 4646 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 4647 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 4648 | "isVsyncConfigEarly)", |
| 4649 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 4650 | return false; |
| 4651 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4652 | } |
| 4653 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4654 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 4655 | } |
| 4656 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 4657 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4658 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 4659 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4660 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 4661 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4662 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 4663 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 4664 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 4665 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4666 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4667 | const int originPid = ipc->getCallingPid(); |
| 4668 | const int originUid = ipc->getCallingUid(); |
| 4669 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
| 4670 | for (auto composerState : states) { |
| 4671 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4672 | } |
| 4673 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4674 | for (DisplayState display : displays) { |
| 4675 | display.sanitize(permissions); |
| 4676 | } |
| 4677 | |
| 4678 | if (!inputWindowCommands.empty() && |
| 4679 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 4680 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 4681 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 4684 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 4685 | const bool hasPermission = |
| 4686 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 4687 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 4688 | if (!hasPermission) { |
| 4689 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 4690 | "eEarlyWakeup[Start|End] flags"); |
| 4691 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 4692 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 4693 | } |
| 4694 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 4695 | const int64_t postTime = systemTime(); |
| 4696 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4697 | std::vector<uint64_t> uncacheBufferIds; |
| 4698 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 4699 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 4700 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 4701 | if (buffer != nullptr) { |
| 4702 | uncacheBufferIds.push_back(buffer->getId()); |
| 4703 | } |
| 4704 | } |
| 4705 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4706 | std::vector<ResolvedComposerState> resolvedStates; |
| 4707 | resolvedStates.reserve(states.size()); |
| 4708 | for (auto& state : states) { |
| 4709 | resolvedStates.emplace_back(std::move(state)); |
| 4710 | auto& resolvedState = resolvedStates.back(); |
| 4711 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 4712 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4713 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4714 | std::string layerName = (layer) ? |
| 4715 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4716 | resolvedState.externalTexture = |
| 4717 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 4718 | layerName.c_str(), transactionId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4719 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 4720 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4721 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 4722 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 4723 | resolvedState.parentId = |
| 4724 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 4725 | } |
| 4726 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 4727 | resolvedState.relativeParentId = |
| 4728 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 4729 | } |
| 4730 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 4731 | wp<IBinder>& touchableRegionCropHandle = |
| 4732 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 4733 | resolvedState.touchCropId = |
| 4734 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 4735 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4738 | TransactionState state{frameTimelineInfo, |
| 4739 | resolvedStates, |
| 4740 | displays, |
| 4741 | flags, |
| 4742 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4743 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4744 | desiredPresentTime, |
| 4745 | isAutoTimestamp, |
| 4746 | std::move(uncacheBufferIds), |
| 4747 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4748 | hasListenerCallbacks, |
| 4749 | listenerCallbacks, |
| 4750 | originPid, |
| 4751 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 4752 | transactionId, |
| 4753 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 4754 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 4755 | if (mTransactionTracing) { |
| 4756 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 4757 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4758 | |
| 4759 | const auto schedule = [](uint32_t flags) { |
| 4760 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 4761 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 4762 | return TransactionSchedule::Late; |
| 4763 | }(state.flags); |
| 4764 | |
| 4765 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4766 | mTransactionHandler.queueTransaction(std::move(state)); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4767 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4768 | return NO_ERROR; |
| 4769 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4770 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4771 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4772 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 4773 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4774 | const InputWindowCommands& inputWindowCommands, |
| 4775 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4776 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4777 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4778 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 4779 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 4780 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4781 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4782 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4783 | transactionFlags |= setDisplayStateLocked(display); |
| 4784 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4787 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 4788 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 4789 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4790 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 4791 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4794 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4795 | for (auto& resolvedState : states) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4796 | if (mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4797 | clientStateFlags |= |
| 4798 | setClientStateLocked(frameTimelineInfo, resolvedState, desiredPresentTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4799 | isAutoTimestamp, postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4800 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4801 | } else /*mLayerLifecycleManagerEnabled*/ { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4802 | clientStateFlags |= updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, |
| 4803 | desiredPresentTime, isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4804 | postTime, transactionId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4805 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4806 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 4807 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 4808 | const auto layerProps = scheduler::LayerProps{ |
| 4809 | .visible = layer->isVisible(), |
| 4810 | .bounds = layer->getBounds(), |
| 4811 | .transform = layer->getTransform(), |
| 4812 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 4813 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 4814 | }; |
| 4815 | layer->recordLayerHistoryAnimationTx(layerProps); |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 4816 | } |
| 4817 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 4820 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4821 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 4822 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 4823 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 4824 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 4827 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 4828 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 4829 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 4830 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 4831 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 4832 | transactionFlags = eTransactionNeeded; |
| 4833 | } |
| 4834 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4835 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 4836 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4837 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4838 | // 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] | 4839 | if (transactionFlags & eTraversalNeeded) { |
| 4840 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4841 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4842 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 4843 | if (transactionFlags) { |
| 4844 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 4845 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4847 | |
| 4848 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | } |
| 4850 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4851 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStates( |
| 4852 | std::vector<TransactionState>& transactions) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 4853 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4854 | bool needsTraversal = false; |
| 4855 | uint32_t transactionFlags = 0; |
| 4856 | for (auto& transaction : transactions) { |
| 4857 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4858 | transactionFlags |= setDisplayStateLocked(display); |
| 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | if (transactionFlags) { |
| 4863 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 4864 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 4865 | if (transactionFlags & eTraversalNeeded) { |
| 4866 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 4867 | needsTraversal = true; |
| 4868 | } |
| 4869 | if (transactionFlags) { |
| 4870 | setTransactionFlags(transactionFlags); |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4875 | if (mFrontEndDisplayInfosChanged && !mLegacyFrontEndEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4876 | processDisplayChangesLocked(); |
| 4877 | mFrontEndDisplayInfos.clear(); |
| 4878 | for (const auto& [_, display] : mDisplays) { |
| 4879 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4880 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 4881 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | return needsTraversal; |
| 4885 | } |
| 4886 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4887 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 4888 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 4889 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 4890 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4891 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4892 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 4893 | |
| 4894 | const uint32_t what = s.what; |
| 4895 | if (what & DisplayState::eSurfaceChanged) { |
| 4896 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 4897 | state.surface = s.surface; |
| 4898 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 4899 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4900 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4901 | if (what & DisplayState::eLayerStackChanged) { |
| 4902 | if (state.layerStack != s.layerStack) { |
| 4903 | state.layerStack = s.layerStack; |
| 4904 | flags |= eDisplayTransactionNeeded; |
| 4905 | } |
| 4906 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 4907 | if (what & DisplayState::eFlagsChanged) { |
| 4908 | if (state.flags != s.flags) { |
| 4909 | state.flags = s.flags; |
| 4910 | flags |= eDisplayTransactionNeeded; |
| 4911 | } |
| 4912 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4913 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 4914 | if (state.orientation != s.orientation) { |
| 4915 | state.orientation = s.orientation; |
| 4916 | flags |= eDisplayTransactionNeeded; |
| 4917 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4918 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 4919 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4920 | flags |= eDisplayTransactionNeeded; |
| 4921 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 4922 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 4923 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 4924 | flags |= eDisplayTransactionNeeded; |
| 4925 | } |
| 4926 | } |
| 4927 | if (what & DisplayState::eDisplaySizeChanged) { |
| 4928 | if (state.width != s.width) { |
| 4929 | state.width = s.width; |
| 4930 | flags |= eDisplayTransactionNeeded; |
| 4931 | } |
| 4932 | if (state.height != s.height) { |
| 4933 | state.height = s.height; |
| 4934 | flags |= eDisplayTransactionNeeded; |
| 4935 | } |
| 4936 | } |
| 4937 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 4938 | return flags; |
| 4939 | } |
| 4940 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4941 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4942 | IPCThreadState* ipc = IPCThreadState::self(); |
| 4943 | const int pid = ipc->getCallingPid(); |
| 4944 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4945 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 4946 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 4947 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 4948 | return false; |
| 4949 | } |
| 4950 | return true; |
| 4951 | } |
| 4952 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4953 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 4954 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 4955 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 4956 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 4957 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4958 | |
| 4959 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4960 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4961 | // Starts a registration but separates the callback ids according to callback type. This |
| 4962 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4963 | // note that startRegistration will not re-register if the listener has |
| 4964 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4965 | |
| 4966 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 4967 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4968 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 4972 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4973 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 4974 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4977 | const uint64_t what = s.what; |
| 4978 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4979 | sp<Layer> layer = nullptr; |
| 4980 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 4981 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 4982 | } else { |
| 4983 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 4984 | ALOGW("Attempt to set client state with a null layer handle"); |
| 4985 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4986 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 4987 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 4988 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 4989 | callbackIds, |
| 4990 | s.surface), |
| 4991 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 4992 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4993 | return 0; |
| 4994 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 4995 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 4996 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 4997 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 4998 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 4999 | // Only set by BLAST adapter layers |
| 5000 | if (what & layer_state_t::eProducerDisconnect) { |
| 5001 | layer->onDisconnect(); |
| 5002 | } |
| 5003 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5004 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5005 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5006 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5007 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5008 | } |
| 5009 | if (what & layer_state_t::eLayerChanged) { |
| 5010 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5011 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5012 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5013 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5014 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5015 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5016 | mCurrentState.layersSortedByZ.add(layer); |
| 5017 | // we need traversal (state changed) |
| 5018 | // AND transaction (list changed) |
| 5019 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5020 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5021 | } else { |
| 5022 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5023 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5024 | } |
| 5025 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5026 | } |
| 5027 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5028 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5029 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5030 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5031 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5032 | if (p == nullptr) { |
| 5033 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5034 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5035 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5036 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5037 | mCurrentState.layersSortedByZ.add(layer); |
| 5038 | // we need traversal (state changed) |
| 5039 | // AND transaction (list changed) |
| 5040 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5041 | } |
| 5042 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5043 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5044 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5045 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5046 | } |
| 5047 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5048 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5049 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5050 | } |
| 5051 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5052 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5053 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5054 | if (what & layer_state_t::eColorTransformChanged) { |
| 5055 | if (layer->setColorTransform(s.colorTransform)) { |
| 5056 | flags |= eTraversalNeeded; |
| 5057 | } |
| 5058 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5059 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5060 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5061 | flags |= eTraversalNeeded; |
| 5062 | } |
| 5063 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5064 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5065 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5066 | } |
| 5067 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5068 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5069 | flags |= eTraversalNeeded; |
| 5070 | } |
| 5071 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5072 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5073 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5074 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5075 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5076 | flags |= eTraversalNeeded; |
| 5077 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5078 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5079 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5080 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5081 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5082 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5083 | } |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5084 | if (what & layer_state_t::eRenderBorderChanged) { |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 5085 | if (layer->enableBorder(s.borderEnabled, s.borderWidth, s.borderColor)) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 5086 | flags |= eTraversalNeeded; |
| 5087 | } |
| 5088 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5089 | if (what & layer_state_t::eLayerStackChanged) { |
| 5090 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5091 | // We only allow setting layer stacks for top level layers, |
| 5092 | // everything else inherits layer stack from its parent. |
| 5093 | if (layer->hasParent()) { |
| 5094 | 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] | 5095 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5096 | } else if (idx < 0) { |
| 5097 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5098 | "that also does not appear in the top level layer list. Something" |
| 5099 | " has gone wrong.", |
| 5100 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5101 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5102 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5103 | mCurrentState.layersSortedByZ.add(layer); |
| 5104 | // we need traversal (state changed) |
| 5105 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5106 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5107 | } |
| 5108 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5109 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5110 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5111 | } |
| 5112 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5113 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5114 | flags |= eTraversalNeeded; |
| 5115 | } |
| 5116 | if (what & layer_state_t::eCropChanged) { |
| 5117 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5118 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5119 | if (what & layer_state_t::eDataspaceChanged) { |
| 5120 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5121 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5122 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5123 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5124 | } |
| 5125 | if (what & layer_state_t::eApiChanged) { |
| 5126 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5127 | } |
| 5128 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5129 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5130 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5131 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5132 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5133 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5134 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5135 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5136 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5137 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5138 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5139 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5140 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5141 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5142 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5143 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5144 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5145 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5146 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5147 | if (layer->setMetadata(s.metadata)) { |
| 5148 | flags |= eTraversalNeeded; |
| 5149 | mLayerMetadataSnapshotNeeded = true; |
| 5150 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5151 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5152 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5153 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5154 | flags |= eTraversalNeeded; |
| 5155 | } |
| 5156 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5157 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5158 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5159 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5160 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5161 | const auto compatibility = |
| 5162 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5163 | |
| 5164 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5165 | flags |= eTraversalNeeded; |
| 5166 | } |
| 5167 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5168 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5169 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5170 | flags |= eTraversalNeeded; |
| 5171 | } |
| 5172 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5173 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5174 | const auto compatibility = |
| 5175 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5176 | const auto strategy = |
| 5177 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5178 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5179 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5180 | compatibility, strategy))) { |
| 5181 | flags |= eTraversalNeeded; |
| 5182 | } |
| 5183 | } |
| 5184 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5185 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
| 5186 | if (layer->setFrameRateCategory(category)) { |
| 5187 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5188 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5189 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5190 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5191 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5192 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5193 | } |
| 5194 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5195 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5196 | layer->setAutoRefresh(s.autoRefresh); |
| 5197 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5198 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5199 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5200 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5201 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5202 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5203 | flags |= eTraversalNeeded; |
| 5204 | } |
| 5205 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5206 | if (what & layer_state_t::eCachingHintChanged) { |
| 5207 | if (layer->setCachingHint(s.cachingHint)) { |
| 5208 | flags |= eTraversalNeeded; |
| 5209 | } |
| 5210 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5211 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5212 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5213 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5214 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5215 | if (layer->setTrustedOverlay(s.isTrustedOverlay)) { |
| 5216 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5217 | } |
| 5218 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5219 | if (what & layer_state_t::eStretchChanged) { |
| 5220 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5221 | flags |= eTraversalNeeded; |
| 5222 | } |
| 5223 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5224 | if (what & layer_state_t::eBufferCropChanged) { |
| 5225 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5226 | flags |= eTraversalNeeded; |
| 5227 | } |
| 5228 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5229 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5230 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5231 | flags |= eTraversalNeeded; |
| 5232 | } |
| 5233 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5234 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5235 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5236 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5237 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5238 | } |
| 5239 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5240 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5241 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5242 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5243 | // lose its relative z order. |
| 5244 | if (what & layer_state_t::eReparent) { |
| 5245 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5246 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5247 | ? s.parentSurfaceControlForChild->getHandle() |
| 5248 | : nullptr; |
| 5249 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5250 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5251 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5252 | mCurrentState.layersSortedByZ.remove(layer); |
| 5253 | } |
| 5254 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5255 | } |
| 5256 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5257 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5258 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5259 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5260 | callbackHandles.emplace_back( |
| 5261 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5262 | } |
| 5263 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5264 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5265 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5266 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5267 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5268 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5269 | flags |= eTraversalNeeded; |
| 5270 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5271 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5272 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5273 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5274 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5275 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5276 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5277 | } |
| 5278 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5279 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5280 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5281 | s.trustedPresentationListener)) { |
| 5282 | flags |= eTraversalNeeded; |
| 5283 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5286 | if (what & layer_state_t::eFlushJankData) { |
| 5287 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5288 | } |
| 5289 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5290 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5291 | layer->willPresentCurrentTransaction() || |
| 5292 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5293 | flags |= eTraversalNeeded; |
| 5294 | } |
| 5295 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5296 | // Do not put anything that updates layer state or modifies flags after |
| 5297 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5298 | |
| 5299 | // 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] | 5300 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5301 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5302 | flags |= eTransformHintUpdateNeeded; |
| 5303 | } |
| 5304 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5305 | return flags; |
| 5306 | } |
| 5307 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5308 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5309 | ResolvedComposerState& composerState, |
| 5310 | int64_t desiredPresentTime, |
| 5311 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5312 | uint64_t transactionId) { |
| 5313 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5314 | |
| 5315 | std::vector<ListenerCallbacks> filteredListeners; |
| 5316 | for (auto& listener : s.listeners) { |
| 5317 | // Starts a registration but separates the callback ids according to callback type. This |
| 5318 | // allows the callback invoker to send on latch callbacks earlier. |
| 5319 | // note that startRegistration will not re-register if the listener has |
| 5320 | // already be registered for a prior surface control |
| 5321 | |
| 5322 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5323 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5324 | filteredListeners.push_back(onCommitCallbacks); |
| 5325 | } |
| 5326 | |
| 5327 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5328 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5329 | filteredListeners.push_back(onCompleteCallbacks); |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | const uint64_t what = s.what; |
| 5334 | uint32_t flags = 0; |
| 5335 | sp<Layer> layer = nullptr; |
| 5336 | if (s.surface) { |
| 5337 | layer = LayerHandle::getLayer(s.surface); |
| 5338 | } else { |
| 5339 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5340 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5341 | } |
| 5342 | if (layer == nullptr) { |
| 5343 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5344 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5345 | callbackIds, |
| 5346 | s.surface), |
| 5347 | std::vector<JankData>()); |
| 5348 | } |
| 5349 | return 0; |
| 5350 | } |
| 5351 | if (what & layer_state_t::eProducerDisconnect) { |
| 5352 | layer->onDisconnect(); |
| 5353 | } |
| 5354 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5355 | if (what & layer_state_t::eMetadataChanged) { |
| 5356 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5357 | } |
| 5358 | |
| 5359 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5360 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5361 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5362 | callbackHandles.emplace_back( |
| 5363 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5364 | } |
| 5365 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5366 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5367 | // requires to read drawing state from binder thread. So we need to fix that |
| 5368 | // before removing this. |
| 5369 | if (what & layer_state_t::eCropChanged) { |
| 5370 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5371 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5372 | if (what & layer_state_t::eSidebandStreamChanged) { |
| 5373 | if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded; |
| 5374 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5375 | if (what & layer_state_t::eDataspaceChanged) { |
| 5376 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5377 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5378 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5379 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5380 | flags |= eTraversalNeeded; |
| 5381 | } |
| 5382 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5383 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5384 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5385 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5386 | if (snapshot) { |
| 5387 | transformHint = snapshot->transformHint; |
| 5388 | } |
| 5389 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5390 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5391 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5392 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5393 | flags |= eTraversalNeeded; |
| 5394 | } |
| 5395 | mLayersWithQueuedFrames.emplace(layer); |
| 5396 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5397 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5398 | } |
| 5399 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5400 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5401 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5402 | } |
| 5403 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5404 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5405 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5406 | s.trustedPresentationListener)) { |
| 5407 | flags |= eTraversalNeeded; |
| 5408 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5409 | } |
| 5410 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5411 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5412 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5413 | (requestedLayerState->hasReadyFrame() || |
| 5414 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5415 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5416 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5417 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5418 | return flags; |
| 5419 | } |
| 5420 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5421 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5422 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5423 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5424 | } |
| 5425 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5426 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5427 | const sp<IBinder>& mirrorFromHandle, |
| 5428 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5429 | if (!mirrorFromHandle) { |
| 5430 | return NAME_NOT_FOUND; |
| 5431 | } |
| 5432 | |
| 5433 | sp<Layer> mirrorLayer; |
| 5434 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5435 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5436 | { |
| 5437 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5438 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5439 | if (!mirrorFrom) { |
| 5440 | return NAME_NOT_FOUND; |
| 5441 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5442 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5443 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5444 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5445 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5446 | if (result != NO_ERROR) { |
| 5447 | return result; |
| 5448 | } |
| 5449 | |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 5450 | mirrorLayer->setClonedChild(mirrorFrom->createClone(mirrorLayer->getSequence())); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5453 | outResult.layerId = mirrorLayer->sequence; |
| 5454 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5455 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5456 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5459 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5460 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5461 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5462 | const int uid = ipc->getCallingUid(); |
| 5463 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5464 | ALOGE("Permission denied when trying to mirror display"); |
| 5465 | return PERMISSION_DENIED; |
| 5466 | } |
| 5467 | |
| 5468 | ui::LayerStack layerStack; |
| 5469 | sp<Layer> rootMirrorLayer; |
| 5470 | status_t result = 0; |
| 5471 | |
| 5472 | { |
| 5473 | Mutex::Autolock lock(mStateLock); |
| 5474 | |
| 5475 | const auto display = getDisplayDeviceLocked(displayId); |
| 5476 | if (!display) { |
| 5477 | return NAME_NOT_FOUND; |
| 5478 | } |
| 5479 | |
| 5480 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5481 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5482 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5483 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5484 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5485 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5486 | outResult.layerId = rootMirrorLayer->sequence; |
| 5487 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5488 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5489 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | if (result != NO_ERROR) { |
| 5493 | return result; |
| 5494 | } |
| 5495 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5496 | if (mLegacyFrontEndEnabled) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5497 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5498 | mMirrorDisplays.emplace_back(layerStack, outResult.handle, args.client); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | setTransactionFlags(eTransactionFlushNeeded); |
| 5502 | return NO_ERROR; |
| 5503 | } |
| 5504 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5505 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5506 | status_t result = NO_ERROR; |
| 5507 | |
| 5508 | sp<Layer> layer; |
| 5509 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5510 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5511 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 5512 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 5513 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 5514 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
| 5515 | FMT_FALLTHROUGH; |
| 5516 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5517 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5518 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 5519 | if (pendingBufferCounter) { |
| 5520 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5521 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 5522 | pendingBufferCounter); |
| 5523 | } |
| 5524 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5525 | default: |
| 5526 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5527 | break; |
| 5528 | } |
| 5529 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5530 | if (result != NO_ERROR) { |
| 5531 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5532 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5533 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5534 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5535 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 5536 | // to the layer's handle inside this scope. |
| 5537 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5538 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5539 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5540 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 5541 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 5542 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5543 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5544 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 5545 | if (result != NO_ERROR) { |
| 5546 | return result; |
| 5547 | } |
| 5548 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5549 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 5550 | outResult.layerId = layer->sequence; |
| 5551 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5552 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5553 | } |
| 5554 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5555 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5556 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5557 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5558 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 5559 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 5560 | } |
| 5561 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5562 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 5563 | sp<Layer>* outLayer) { |
| 5564 | *outLayer = getFactory().createEffectLayer(args); |
| 5565 | *handle = (*outLayer)->getHandle(); |
| 5566 | return NO_ERROR; |
| 5567 | } |
| 5568 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5569 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5570 | mLayersPendingRemoval.add(layer); |
| 5571 | mLayersRemoved = true; |
| 5572 | setTransactionFlags(eTransactionNeeded); |
| 5573 | } |
| 5574 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5575 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 5576 | { |
| 5577 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 5578 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5579 | } |
| 5580 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 5581 | mTransactionHandler.onLayerDestroyed(layerId); |
| 5582 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 5583 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5584 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 5585 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 5586 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 5587 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5588 | |
| 5589 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 5590 | } |
| 5591 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 5592 | void SurfaceFlinger::initializeDisplays() { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5593 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5594 | if (!display) return; |
| 5595 | |
| 5596 | const sp<IBinder> token = display->getDisplayToken().promote(); |
| 5597 | LOG_ALWAYS_FATAL_IF(token == nullptr); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 5598 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5599 | TransactionState state; |
| 5600 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5601 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5602 | state.desiredPresentTime = now; |
| 5603 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5604 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5605 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5606 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5607 | state.id = transactionId; |
| 5608 | |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5609 | // reset screen orientation and use primary layer stack |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5610 | Vector<DisplayState> displays; |
| 5611 | DisplayState d; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 5612 | d.what = DisplayState::eDisplayProjectionChanged | |
| 5613 | DisplayState::eLayerStackChanged; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 5614 | d.token = token; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 5615 | d.layerStack = ui::DEFAULT_LAYER_STACK; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 5616 | d.orientation = ui::ROTATION_0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5617 | d.orientedDisplaySpaceRect.makeInvalid(); |
| 5618 | d.layerStackSpaceRect.makeInvalid(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5619 | d.width = 0; |
| 5620 | d.height = 0; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5621 | state.displays.add(d); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5622 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5623 | std::vector<TransactionState> transactions; |
| 5624 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5625 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5626 | if (mLegacyFrontEndEnabled) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5627 | applyTransactions(transactions, VsyncId{0}); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 5628 | } else { |
| 5629 | applyAndCommitDisplayTransactionStates(transactions); |
| 5630 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5631 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5632 | { |
| 5633 | ftl::FakeGuard guard(mStateLock); |
| 5634 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 5635 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 5636 | } |
| 5637 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5638 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 5639 | if (display->isVirtual()) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 5640 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5641 | return; |
| 5642 | } |
| 5643 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5644 | const auto displayId = display->getPhysicalId(); |
| 5645 | 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] | 5646 | |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5647 | const auto currentModeOpt = display->getPowerMode(); |
| 5648 | if (currentModeOpt == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5649 | return; |
| 5650 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5651 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 5652 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 5653 | .transform(&PhysicalDisplay::isInternal) |
| 5654 | .value_or(false); |
| 5655 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 5656 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5657 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5658 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 5659 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 5660 | "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] | 5661 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5662 | display->setPowerMode(mode); |
| 5663 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 5664 | const auto refreshRate = display->refreshRateSelector().getActiveMode().modePtr->getFps(); |
Dominik Laskowski | b4ff7d9 | 2022-11-22 13:59:53 -0500 | [diff] [blame] | 5665 | if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 5666 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5667 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5668 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 5669 | // outer display of a foldable is powered on. This condition relies on the above |
| 5670 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 5671 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 5672 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5673 | // |
| 5674 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 5675 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 5676 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 5677 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 5678 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5679 | if (displayId == mActiveDisplayId) { |
| 5680 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 5681 | // set it before SCHED_FIFO due to b/190237315. |
| 5682 | if (setSchedAttr(true) != NO_ERROR) { |
| 5683 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 5684 | strerror(errno)); |
| 5685 | } |
| 5686 | if (setSchedFifo(true) != NO_ERROR) { |
| 5687 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 5688 | strerror(errno)); |
| 5689 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 5690 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5691 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5692 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5693 | if (displayId == mActiveDisplayId && mode != hal::PowerMode::DOZE_SUSPEND) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5694 | const bool enable = |
| 5695 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 5696 | requestHardwareVsync(displayId, enable); |
| 5697 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5698 | mScheduler->enableSyntheticVsync(false); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5699 | |
| 5700 | constexpr bool kAllowToEnable = true; |
| 5701 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, refreshRate); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5702 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5704 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 5705 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5706 | } else if (mode == hal::PowerMode::OFF) { |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 5707 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5708 | |
| 5709 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5710 | if (const auto display = getActivatableDisplay()) { |
| 5711 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 5712 | } else { |
| 5713 | if (setSchedFifo(false) != NO_ERROR) { |
| 5714 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 5715 | strerror(errno)); |
| 5716 | } |
| 5717 | if (setSchedAttr(false) != NO_ERROR) { |
| 5718 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 5719 | strerror(errno)); |
| 5720 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5721 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 5722 | if (*currentModeOpt != hal::PowerMode::DOZE_SUSPEND) { |
| 5723 | mScheduler->disableHardwareVsync(displayId, true); |
| 5724 | mScheduler->enableSyntheticVsync(); |
| 5725 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 5726 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 5727 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5728 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5729 | // Disable VSYNC before turning off the display. |
| 5730 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5731 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5732 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5733 | mVisibleRegionsDirty = true; |
| 5734 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5735 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5736 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5737 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5738 | if (displayId == mActiveDisplayId && *currentModeOpt == hal::PowerMode::DOZE_SUSPEND) { |
Yifei Zhang | f0bd62e | 2021-06-16 15:27:05 -0700 | [diff] [blame] | 5739 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 5740 | mVisibleRegionsDirty = true; |
| 5741 | scheduleRepaint(); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5742 | mScheduler->enableSyntheticVsync(false); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5743 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, refreshRate); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5744 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5745 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5746 | // Leave display going to doze |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5747 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 5748 | mScheduler->disableHardwareVsync(displayId, true); |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5749 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 5750 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5751 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 5752 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 5753 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5754 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5755 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5756 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 5757 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 5758 | mTimeStats->setPowerMode(mode); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5759 | mRefreshRateStats->setPowerMode(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 5762 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 5763 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 5764 | 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] | 5765 | } |
| 5766 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5767 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 5768 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 5769 | kMainThreadContext) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 5770 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 5771 | if (!display) { |
| 5772 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 5773 | displayToken.get()); |
| 5774 | } else if (display->isVirtual()) { |
| 5775 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 5776 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 5777 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 5778 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 5779 | }); |
| 5780 | |
| 5781 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5784 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5785 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 5786 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5787 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5788 | const int pid = ipc->getCallingPid(); |
| 5789 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 5790 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 5791 | if ((uid != AID_SHELL) && |
| 5792 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5793 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 5794 | pid, uid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | } else { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5796 | static const std::unordered_map<std::string, Dumper> dumpers = { |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5797 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5798 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 5799 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 5800 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5801 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 5802 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 5803 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5804 | {"--hwclayers"s, dumper(&SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5805 | {"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)}, |
| 5806 | {"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)}, |
| 5807 | {"--list"s, dumper(&SurfaceFlinger::listLayersLocked)}, |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5808 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5809 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5810 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5811 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5812 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 5813 | }; |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5814 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5815 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5816 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5817 | // Traversal of drawing state must happen on the main thread. |
| 5818 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 5819 | // traversals, which can result in use-after-frees. |
| 5820 | std::string compositionLayers; |
| 5821 | mScheduler |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5822 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 5823 | if (!mLayerLifecycleManagerEnabled) { |
| 5824 | StringAppendF(&compositionLayers, "Composition layers\n"); |
| 5825 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 5826 | auto* compositionState = layer->getCompositionState(); |
| 5827 | if (!compositionState || !compositionState->isVisible) return; |
| 5828 | android::base::StringAppendF(&compositionLayers, "* Layer %p (%s)\n", |
| 5829 | layer, |
| 5830 | layer->getDebugName() |
| 5831 | ? layer->getDebugName() |
| 5832 | : "<unknown>"); |
| 5833 | compositionState->dump(compositionLayers); |
| 5834 | }); |
| 5835 | } else { |
| 5836 | std::ostringstream out; |
| 5837 | out << "\nComposition list\n"; |
| 5838 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5839 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 5840 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 5841 | if (snapshot->hasSomethingToDraw()) { |
| 5842 | if (lastPrintedLayerStackHeader != |
| 5843 | snapshot->outputFilter.layerStack) { |
| 5844 | lastPrintedLayerStackHeader = |
| 5845 | snapshot->outputFilter.layerStack; |
| 5846 | out << "LayerStack=" << lastPrintedLayerStackHeader.id |
| 5847 | << "\n"; |
| 5848 | } |
| 5849 | out << " " << *snapshot << "\n"; |
| 5850 | } |
| 5851 | }); |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5852 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 5853 | out << "\nInput list\n"; |
| 5854 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 5855 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 5856 | [&](const frontend::LayerSnapshot& snapshot) { |
| 5857 | if (lastPrintedLayerStackHeader != |
| 5858 | snapshot.outputFilter.layerStack) { |
| 5859 | lastPrintedLayerStackHeader = |
| 5860 | snapshot.outputFilter.layerStack; |
| 5861 | out << "LayerStack=" << lastPrintedLayerStackHeader.id |
| 5862 | << "\n"; |
| 5863 | } |
| 5864 | out << " " << snapshot << "\n"; |
| 5865 | }); |
| 5866 | |
| 5867 | out << "\nLayer Hierarchy\n" |
| 5868 | << mLayerHierarchyBuilder.getHierarchy() << "\n\n"; |
| 5869 | compositionLayers = out.str(); |
| 5870 | dumpHwcLayersMinidump(compositionLayers); |
| 5871 | } |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5872 | }) |
| 5873 | .get(); |
| 5874 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5875 | bool dumpLayers = true; |
| 5876 | { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 5877 | TimedLock lock(mStateLock, s2ns(1), __func__); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5878 | if (!lock.locked()) { |
| 5879 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 5880 | strerror(-lock.status), lock.status); |
| 5881 | } |
| 5882 | |
| 5883 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 5884 | (it->second)(args, asProto, result); |
| 5885 | dumpLayers = false; |
| 5886 | } else if (!asProto) { |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 5887 | dumpAllLocked(args, compositionLayers, result); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5888 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 5889 | } |
| 5890 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 5891 | if (dumpLayers) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 5892 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 5893 | mLayerTracing.createTraceFileProto(); |
| 5894 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 5895 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5896 | layersTrace->mutable_layers()->Swap(&layersProto); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5897 | auto displayProtos = dumpDisplayProto(); |
| 5898 | layersTrace->mutable_displays()->Swap(&displayProtos); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5899 | |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5900 | if (asProto) { |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 5901 | result.append(traceFileProto.SerializeAsString()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5902 | } else { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5903 | // Dump info that we need to access from the main thread |
chaviw | a2b9fab | 2021-09-08 14:46:30 -0500 | [diff] [blame] | 5904 | const auto layerTree = LayerProtoParser::generateLayerTree(layersTrace->layers()); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5905 | result.append(LayerProtoParser::layerTreeToString(layerTree)); |
| 5906 | result.append("\n"); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 5907 | dumpOffscreenLayers(result); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 5908 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 5909 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5911 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5912 | return NO_ERROR; |
| 5913 | } |
| 5914 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5915 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 5916 | return doDump(fd, DumpArgs(), asProto); |
| 5917 | } |
| 5918 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5919 | void SurfaceFlinger::listLayersLocked(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5920 | mCurrentState.traverseInZOrder( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5921 | [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5922 | } |
| 5923 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5924 | void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 5925 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5926 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 5927 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5928 | const auto name = String8(args[1]); |
| 5929 | mCurrentState.traverseInZOrder([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5930 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5931 | layer->dumpFrameStats(result); |
| 5932 | } |
| 5933 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5936 | void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5937 | const bool clearAll = args.size() < 2; |
| 5938 | const auto name = clearAll ? String8() : String8(args[1]); |
| 5939 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 5940 | mCurrentState.traverse([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 5941 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 5942 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5943 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 5944 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 5947 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 5948 | mTimeStats->parseArgs(asProto, args, result); |
| 5949 | } |
| 5950 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 5951 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 5952 | mFrameTimeline->parseArgs(args, result); |
| 5953 | } |
| 5954 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5955 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 5956 | static TimePoint sTimestamp = now; |
| 5957 | if (now - sTimestamp < 30min) return; |
| 5958 | sTimestamp = now; |
| 5959 | |
| 5960 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 5961 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 5962 | } |
| 5963 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5964 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5965 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 5966 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5967 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 5968 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 5969 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 5970 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5971 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 5972 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5973 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 5974 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 5975 | } |
| 5976 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5977 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 5978 | utils::Dumper dumper{result}; |
| 5979 | |
| 5980 | mScheduler->dump(dumper); |
| 5981 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5982 | // TODO(b/241285876): Move to DisplayModeController. |
| 5983 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 5984 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5985 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 5986 | mRefreshRateStats->dump(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5987 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 5988 | |
Ady Abraham | 8287e85 | 2020-08-12 14:44:58 -0700 | [diff] [blame] | 5989 | mVsyncConfiguration->dump(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5990 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5991 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 5992 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5993 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5994 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 5995 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5996 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Ana Krulec | c287042 | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 5997 | mScheduler->dump(mAppConnectionHandle, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6001 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6002 | } |
| 6003 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6004 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6005 | for (const auto& [token, display] : mDisplays) { |
| 6006 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6007 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6008 | } |
| 6009 | } |
| 6010 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6011 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6012 | for (const auto& [token, display] : mDisplays) { |
| 6013 | display->getCompositionDisplay()->dump(result); |
| 6014 | result += '\n'; |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6019 | utils::Dumper dumper{result}; |
| 6020 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6021 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6022 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6023 | |
| 6024 | display.snapshot().dump(dumper); |
| 6025 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6026 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6027 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6028 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6029 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6030 | |
| 6031 | for (const auto& [token, display] : mDisplays) { |
| 6032 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6033 | const auto displayId = display->getId(); |
| 6034 | utils::Dumper::Section section(dumper, |
| 6035 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6036 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6037 | } |
| 6038 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6041 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6042 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6043 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6044 | if (!displayId) { |
| 6045 | continue; |
| 6046 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6047 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6048 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6049 | continue; |
| 6050 | } |
| 6051 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6052 | StringAppendF(&result, |
| 6053 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6054 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6055 | uint8_t port; |
| 6056 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6057 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6058 | result.append("no identification data\n"); |
| 6059 | continue; |
| 6060 | } |
| 6061 | |
| 6062 | if (!isEdid(data)) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6063 | result.append("unknown identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6064 | continue; |
| 6065 | } |
| 6066 | |
| 6067 | const auto edid = parseEdid(data); |
| 6068 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6069 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6070 | continue; |
| 6071 | } |
| 6072 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6073 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6074 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6075 | result.append("\"\n"); |
| 6076 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6077 | } |
| 6078 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6079 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6080 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6081 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6082 | uint8_t port; |
| 6083 | DisplayIdentificationData data; |
| 6084 | |
| 6085 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6086 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6087 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6088 | } |
| 6089 | } |
| 6090 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6091 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6092 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6093 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6094 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6095 | |
| 6096 | // TODO: print out if wide-color mode is active or not |
| 6097 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6098 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6099 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6100 | for (const auto mode : display.snapshot().colorModes()) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6101 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6102 | } |
| 6103 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6104 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6105 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6106 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
| 6107 | decodeColorMode(currentMode).c_str(), currentMode); |
| 6108 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6109 | } |
| 6110 | result.append("\n"); |
| 6111 | } |
| 6112 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6113 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6114 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6115 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6116 | listener->dump(result); |
| 6117 | result.append("\n"); |
| 6118 | } |
| 6119 | } |
| 6120 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6121 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6122 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6123 | |
| 6124 | // Determine if virtual layers display should be skipped |
| 6125 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6126 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6127 | if (display->isVirtual()) { |
| 6128 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6129 | } |
| 6130 | } |
| 6131 | } |
| 6132 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6133 | if (mLegacyFrontEndEnabled) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6134 | perfetto::protos::LayersProto layersProto; |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6135 | for (const sp<Layer>& layer : mDrawingState.layersSortedByZ) { |
| 6136 | if (stackIdsToSkip.find(layer->getLayerStack().id) != stackIdsToSkip.end()) { |
| 6137 | continue; |
| 6138 | } |
| 6139 | layer->writeToProto(layersProto, traceFlags); |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6140 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 6141 | return layersProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 6142 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6143 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6144 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6145 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6146 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6147 | } |
| 6148 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6149 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6150 | SurfaceFlinger::dumpDisplayProto() const { |
| 6151 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6152 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6153 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6154 | displayProto->set_id(display->getId().value); |
| 6155 | displayProto->set_name(display->getDisplayName()); |
| 6156 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6157 | |
| 6158 | if (!display->isVirtual()) { |
| 6159 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6160 | displayProto->set_dpi_x(dpi.x); |
| 6161 | displayProto->set_dpi_y(dpi.y); |
| 6162 | } |
| 6163 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6164 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6165 | [&]() { return displayProto->mutable_size(); }); |
| 6166 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6167 | return displayProto->mutable_layer_stack_space_rect(); |
| 6168 | }); |
| 6169 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6170 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6171 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6172 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6173 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6174 | } |
| 6175 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6176 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6177 | getHwComposer().dump(result); |
| 6178 | } |
| 6179 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6180 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6181 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6182 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6183 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6184 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6185 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6186 | rootProto->set_id(offscreenRootLayerId); |
| 6187 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6188 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6189 | |
| 6190 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6191 | // Add layer as child of the fake root |
| 6192 | rootProto->add_children(offscreenLayer->sequence); |
| 6193 | |
| 6194 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6195 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6196 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6197 | } |
| 6198 | } |
| 6199 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 6200 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6201 | return mScheduler->schedule([=] { return dumpDrawingStateProto(traceFlags); }).get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6202 | } |
| 6203 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6204 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6205 | auto future = mScheduler->schedule([this] { |
| 6206 | std::string result; |
| 6207 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6208 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6209 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6210 | } |
| 6211 | return result; |
| 6212 | }); |
| 6213 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6214 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6215 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6216 | } |
| 6217 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6218 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6219 | for (const auto& [token, display] : mDisplays) { |
| 6220 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6221 | if (!displayId) { |
| 6222 | continue; |
| 6223 | } |
| 6224 | |
| 6225 | 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] | 6226 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6227 | Layer::miniDumpHeader(result); |
| 6228 | |
| 6229 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6230 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6231 | result.append("\n"); |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
| 6236 | for (const auto& [token, display] : mDisplays) { |
| 6237 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6238 | if (!displayId) { |
| 6239 | continue; |
| 6240 | } |
| 6241 | |
| 6242 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6243 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6244 | Layer::miniDumpHeader(result); |
| 6245 | |
| 6246 | const DisplayDevice& ref = *display; |
| 6247 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6248 | if (!snapshot.hasSomethingToDraw() || |
| 6249 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6250 | return; |
| 6251 | } |
| 6252 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 6253 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), "Couldnt find layer object for %s", |
| 6254 | snapshot.getDebugString().c_str()); |
| 6255 | it->second->miniDump(result, snapshot, ref); |
| 6256 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6257 | result.append("\n"); |
| 6258 | } |
| 6259 | } |
| 6260 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6261 | void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, const std::string& compositionLayers, |
| 6262 | std::string& result) const { |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6263 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6264 | Colorizer colorizer(colorize); |
| 6265 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6266 | // figure out if we're stuck somewhere |
| 6267 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6268 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6269 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6270 | |
| 6271 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6272 | * Dump library configuration. |
| 6273 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6274 | |
| 6275 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6276 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6277 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6278 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6279 | result.append("\n"); |
| 6280 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6281 | result.append("\nDisplay identification data:\n"); |
| 6282 | dumpDisplayIdentificationData(result); |
| 6283 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6284 | result.append("\nWide-Color information:\n"); |
| 6285 | dumpWideColorInfo(result); |
| 6286 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6287 | dumpHdrInfo(result); |
| 6288 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6289 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6290 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6291 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6292 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6293 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6294 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6295 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6296 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6297 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6298 | dumpScheduler(result); |
| 6299 | dumpEvents(result); |
| 6300 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6301 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6302 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6303 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6304 | * Dump the visible layer list |
| 6305 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6306 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6307 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6308 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6309 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6310 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6311 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6312 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6313 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6314 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6315 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6316 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6317 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6318 | dumpDisplays(result); |
| 6319 | dumpCompositionDisplays(result); |
| 6320 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6321 | |
| 6322 | mCompositionEngine->dump(result); |
| 6323 | |
| 6324 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6325 | * Dump SurfaceFlinger global state |
| 6326 | */ |
| 6327 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6328 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6329 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6330 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6331 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6332 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6333 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6334 | result.append("ClientCache state:\n"); |
| 6335 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6336 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6337 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6338 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6339 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6340 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6341 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6342 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6343 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6344 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6345 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6346 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6347 | std::string fps, xDpi, yDpi; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 6348 | if (const auto activeModePtr = |
| 6349 | display->refreshRateSelector().getActiveMode().modePtr.get()) { |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6350 | fps = to_string(activeModePtr->getFps()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6351 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6352 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6353 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6354 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6355 | } else { |
| 6356 | fps = "unknown"; |
| 6357 | xDpi = "unknown"; |
| 6358 | yDpi = "unknown"; |
| 6359 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6360 | StringAppendF(&result, |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6361 | " refresh-rate : %s\n" |
| 6362 | " x-dpi : %s\n" |
| 6363 | " y-dpi : %s\n", |
| 6364 | fps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6365 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6366 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6367 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6368 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6369 | /* |
| 6370 | * Tracing state |
| 6371 | */ |
| 6372 | mLayerTracing.dump(result); |
| 6373 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6374 | result.append("\nTransaction tracing: "); |
| 6375 | if (mTransactionTracing) { |
| 6376 | result.append("enabled\n"); |
| 6377 | mTransactionTracing->dump(result); |
| 6378 | } else { |
| 6379 | result.append("disabled\n"); |
| 6380 | } |
| 6381 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6382 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6383 | if (mLegacyFrontEndEnabled) { |
| 6384 | dumpHwcLayersMinidumpLockedLegacy(result); |
| 6385 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6386 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6387 | { |
| 6388 | DumpArgs plannerArgs; |
| 6389 | plannerArgs.add(); // first argument is ignored |
| 6390 | plannerArgs.add(String16("--layers")); |
| 6391 | dumpPlannerInfo(plannerArgs, result); |
| 6392 | } |
| 6393 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6394 | /* |
| 6395 | * Dump HWComposer state |
| 6396 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6397 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6398 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6399 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6400 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6401 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6402 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6403 | |
| 6404 | /* |
| 6405 | * Dump gralloc state |
| 6406 | */ |
| 6407 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6408 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6409 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6410 | /* |
| 6411 | * Dump flag/property manager state |
| 6412 | */ |
Robert Carr | 9b623c3 | 2022-03-21 15:55:22 -0700 | [diff] [blame] | 6413 | mFlagManager.dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6414 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6415 | result.append(mTimeStats->miniDump()); |
| 6416 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6417 | |
| 6418 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6419 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6420 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6421 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6422 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6423 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6424 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6425 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6426 | } |
| 6427 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6428 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6429 | if (saturation == 1) { |
| 6430 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6431 | } |
| 6432 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6433 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6434 | luminance *= 1.0f - saturation; |
| 6435 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6436 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6437 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6438 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6439 | return saturationMatrix; |
| 6440 | } |
| 6441 | |
| 6442 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6443 | mat4 colorMatrix = |
| 6444 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6445 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6446 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6447 | mCurrentState.colorMatrix = colorMatrix; |
| 6448 | mCurrentState.colorMatrixChanged = true; |
| 6449 | setTransactionFlags(eTransactionNeeded); |
| 6450 | } |
| 6451 | } |
| 6452 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6453 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6454 | #pragma clang diagnostic push |
| 6455 | #pragma clang diagnostic error "-Wswitch-enum" |
| 6456 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 6457 | // These methods should at minimum make sure that the client requested |
| 6458 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6459 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6460 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 6461 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6462 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6463 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 6464 | // permission dynamically. Don't use the permission cache for this check. |
| 6465 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 6466 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 6467 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6468 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 6469 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6470 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6471 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 6472 | return OK; |
| 6473 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6474 | // The following calls are currently used by clients that do not |
| 6475 | // request necessary permissions. However, they do not expose any secret |
| 6476 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 6477 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6478 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6479 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 6480 | case GET_DISPLAY_MODES: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6481 | // Calling setTransactionState is safe, because you need to have been |
| 6482 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6483 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 6484 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6485 | return OK; |
| 6486 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 6487 | case BOOT_FINISHED: |
| 6488 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 6489 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 6490 | case CREATE_CONNECTION: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6491 | case CREATE_DISPLAY: |
| 6492 | case DESTROY_DISPLAY: |
| 6493 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 6494 | case GET_PHYSICAL_DISPLAY_IDS: |
| 6495 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6496 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6497 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 6498 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6499 | case GET_DISPLAY_STATE: |
| 6500 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 6501 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 6502 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 6503 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 6504 | case SET_ACTIVE_COLOR_MODE: |
| 6505 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6506 | case CLEAR_BOOT_DISPLAY_MODE: |
| 6507 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 6508 | case SET_AUTO_LOW_LATENCY_MODE: |
| 6509 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6510 | case CAPTURE_LAYERS: |
| 6511 | case CAPTURE_DISPLAY: |
| 6512 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 6513 | case CLEAR_ANIMATION_FRAME_STATS: |
| 6514 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6515 | case OVERRIDE_HDR_TYPES: |
| 6516 | case ON_PULL_ATOM: |
| 6517 | case ENABLE_VSYNC_INJECTIONS: |
| 6518 | case INJECT_VSYNC: |
| 6519 | case GET_LAYER_DEBUG_INFO: |
| 6520 | case GET_COLOR_MANAGEMENT: |
| 6521 | case GET_COMPOSITION_PREFERENCE: |
| 6522 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 6523 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6524 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 6525 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6526 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6527 | case ADD_REGION_SAMPLING_LISTENER: |
| 6528 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 6529 | case ADD_FPS_LISTENER: |
| 6530 | case REMOVE_FPS_LISTENER: |
| 6531 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 6532 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 6533 | case ADD_WINDOW_INFOS_LISTENER: |
| 6534 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 6535 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 6536 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 6537 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 6538 | case SET_DISPLAY_BRIGHTNESS: |
| 6539 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 6540 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 6541 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 6542 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 6543 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 6544 | case SET_FRAME_RATE: |
| 6545 | case SET_OVERRIDE_FRAME_RATE: |
| 6546 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 6547 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 6548 | case GET_GPU_CONTEXT_PRIORITY: |
| 6549 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 6550 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 6551 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6553 | |
| 6554 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 6555 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 6556 | // We let them pass by default. |
| 6557 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 6558 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 6559 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 6560 | return OK; |
| 6561 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 6562 | // Numbers from 1000 to 1044 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6563 | // in onTransact verifies that the user is root, and has access to use SF. |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 6564 | if (code >= 1000 && code <= 1044) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6565 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 6566 | return OK; |
| 6567 | } |
| 6568 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 6569 | return PERMISSION_DENIED; |
| 6570 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6571 | } |
| 6572 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6573 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 6574 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6575 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 6576 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6577 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 6578 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 6580 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 6581 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 6582 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6583 | const int uid = ipc->getCallingUid(); |
| 6584 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 6585 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6586 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 6587 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 6588 | "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] | 6589 | return PERMISSION_DENIED; |
| 6590 | } |
| 6591 | int n; |
| 6592 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6593 | case 1000: // Unused. |
| 6594 | case 1001: |
| 6595 | return NAME_NOT_FOUND; |
| 6596 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6597 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6599 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 6600 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6601 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6603 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6604 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 6605 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6606 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6607 | case 1007: // Unused. |
| 6608 | return NAME_NOT_FOUND; |
| 6609 | case 1008: // Toggle forced GPU composition. |
| 6610 | mDebugDisableHWC = data.readInt32() != 0; |
| 6611 | scheduleRepaint(); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 6612 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6613 | case 1009: // Toggle use of transform hint. |
| 6614 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 6615 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 6616 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6617 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 6618 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6620 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 6621 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 6622 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6623 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6624 | case 1013: // Unused. |
| 6625 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6626 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6627 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6628 | // daltonize |
| 6629 | n = data.readInt32(); |
| 6630 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6631 | case 1: |
| 6632 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 6633 | break; |
| 6634 | case 2: |
| 6635 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 6636 | break; |
| 6637 | case 3: |
| 6638 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 6639 | break; |
| 6640 | default: |
| 6641 | mDaltonizer.setType(ColorBlindnessType::None); |
| 6642 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6643 | } |
| 6644 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6645 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6646 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6647 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 6648 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6649 | |
| 6650 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6651 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6653 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6654 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6655 | // apply a color matrix |
| 6656 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6657 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6658 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 6659 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6660 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6661 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 6662 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6663 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6664 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6665 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6666 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6667 | |
| 6668 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 6669 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6670 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 6671 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 6672 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 6673 | } |
| 6674 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6675 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 6676 | return NO_ERROR; |
| 6677 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 6678 | case 1016: { // Unused. |
| 6679 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 6680 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6681 | case 1017: { |
| 6682 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 6683 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 6684 | return NO_ERROR; |
| 6685 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6686 | case 1018: { // Modify Choreographer's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6687 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6688 | mScheduler->setDuration(mAppConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6689 | return NO_ERROR; |
| 6690 | } |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6691 | case 1019: { // Modify SurfaceFlinger's duration |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6692 | n = data.readInt32(); |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 6693 | mScheduler->setDuration(mSfConnectionHandle, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 6694 | return NO_ERROR; |
| 6695 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 6696 | case 1020: { // Unused |
| 6697 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 6698 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6699 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6700 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6701 | static_cast<void>( |
| 6702 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 6703 | return NO_ERROR; |
| 6704 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6705 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6706 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6707 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6708 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6709 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 6710 | return NO_ERROR; |
| 6711 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6712 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6713 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6714 | |
| 6715 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 6716 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 6717 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6718 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6719 | return NO_ERROR; |
| 6720 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 6721 | // Deprecate, use 1030 to check whether the device is color managed. |
| 6722 | case 1024: { |
| 6723 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 6724 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6725 | case 1025: { // Set layer tracing |
| 6726 | n = data.readInt32(); |
| 6727 | bool tracingEnabledChanged; |
| 6728 | if (n == 1) { |
| 6729 | int64_t fixedStartingTime = data.readInt64(); |
| 6730 | ALOGD("LayerTracing enabled"); |
| 6731 | tracingEnabledChanged = mLayerTracing.enable(); |
| 6732 | if (tracingEnabledChanged) { |
| 6733 | const TimePoint startingTime = fixedStartingTime |
| 6734 | ? TimePoint::fromNs(fixedStartingTime) |
| 6735 | : TimePoint::now(); |
| 6736 | |
| 6737 | mScheduler |
| 6738 | ->schedule([this, startingTime]() FTL_FAKE_GUARD( |
| 6739 | mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6740 | constexpr bool kVisibleRegionDirty = true; |
| 6741 | addToLayerTracing(kVisibleRegionDirty, startingTime, |
| 6742 | mLastCommittedVsyncId); |
| 6743 | }) |
| 6744 | .wait(); |
| 6745 | } |
| 6746 | } else if (n == 2) { |
| 6747 | std::string filename = std::string(data.readCString()); |
| 6748 | ALOGD("LayerTracing disabled. Trace wrote to %s", filename.c_str()); |
| 6749 | tracingEnabledChanged = mLayerTracing.disable(filename.c_str()); |
| 6750 | } else { |
| 6751 | ALOGD("LayerTracing disabled"); |
| 6752 | tracingEnabledChanged = mLayerTracing.disable(); |
| 6753 | } |
| 6754 | mTracingEnabledChanged = tracingEnabledChanged; |
| 6755 | reply->writeInt32(NO_ERROR); |
| 6756 | return NO_ERROR; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 6757 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6758 | case 1026: { // Get layer tracing status |
| 6759 | reply->writeBool(mLayerTracing.isEnabled()); |
| 6760 | return NO_ERROR; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 6761 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6762 | // Is a DisplayColorSetting supported? |
| 6763 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6764 | const auto display = getDefaultDisplayDevice(); |
| 6765 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6766 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6767 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6768 | |
| 6769 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 6770 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6771 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6772 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6773 | reply->writeBool(true); |
| 6774 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 6775 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6776 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6777 | break; |
| 6778 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6779 | reply->writeBool( |
| 6780 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 6781 | break; |
| 6782 | } |
| 6783 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 6784 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 6785 | case 1028: { // Unused. |
| 6786 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 6787 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6788 | // Set buffer size for SF tracing (value in KB) |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6789 | case 1029: { |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6790 | n = data.readInt32(); |
| 6791 | if (n <= 0 || n > MAX_TRACING_MEMORY) { |
| 6792 | ALOGW("Invalid buffer size: %d KB", n); |
| 6793 | reply->writeInt32(BAD_VALUE); |
| 6794 | return BAD_VALUE; |
| 6795 | } |
| 6796 | |
| 6797 | ALOGD("Updating trace buffer to %d KB", n); |
| 6798 | mLayerTracing.setBufferSize(n * 1024); |
| 6799 | reply->writeInt32(NO_ERROR); |
| 6800 | return NO_ERROR; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 6801 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6802 | // Is device color managed? |
| 6803 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 6804 | // ColorDisplayManager stil calls this |
| 6805 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 6806 | return NO_ERROR; |
| 6807 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6808 | // Override default composition data space |
| 6809 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 6810 | // && adb shell stop zygote && adb shell start zygote |
| 6811 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 6812 | // adb shell stop zygote && adb shell start zygote |
| 6813 | case 1031: { |
| 6814 | Mutex::Autolock _l(mStateLock); |
| 6815 | n = data.readInt32(); |
| 6816 | if (n) { |
| 6817 | n = data.readInt32(); |
| 6818 | if (n) { |
| 6819 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6820 | if (!validateCompositionDataspace(dataspace)) { |
| 6821 | return BAD_VALUE; |
| 6822 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6823 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6824 | } |
| 6825 | n = data.readInt32(); |
| 6826 | if (n) { |
| 6827 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 6828 | if (!validateCompositionDataspace(dataspace)) { |
| 6829 | return BAD_VALUE; |
| 6830 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6831 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6832 | } |
| 6833 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6834 | // restore composition data space. |
| 6835 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 6836 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 6837 | } |
| 6838 | return NO_ERROR; |
| 6839 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6840 | // Set trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6841 | case 1033: { |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 6842 | n = data.readUint32(); |
| 6843 | ALOGD("Updating trace flags to 0x%x", n); |
| 6844 | mLayerTracing.setTraceFlags(n); |
| 6845 | reply->writeInt32(NO_ERROR); |
| 6846 | return NO_ERROR; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 6847 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6848 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 6849 | n = data.readInt32(); |
| 6850 | if (n == 0 || n == 1) { |
| 6851 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 6852 | } else { |
| 6853 | Mutex::Autolock lock(mStateLock); |
| 6854 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 6855 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 6856 | return NO_ERROR; |
| 6857 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6858 | case 1035: { |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6859 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 6860 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6861 | const auto display = [&]() -> sp<IBinder> { |
| 6862 | uint64_t value; |
| 6863 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6864 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6865 | } |
| 6866 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6867 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 6868 | return getPhysicalDisplayToken(*id); |
| 6869 | } |
| 6870 | |
| 6871 | ALOGE("Invalid physical display ID"); |
| 6872 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 6873 | }(); |
| 6874 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 6875 | mDebugDisplayModeSetByBackdoor = false; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6876 | const status_t result = setActiveModeFromBackdoor(display, DisplayModeId{modeId}); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 6877 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 6878 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 6879 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6880 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 6881 | // manager frame rate policy a new policy which allows switching between all refresh |
| 6882 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6883 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6884 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6885 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6886 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6887 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6888 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6889 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6890 | // This is a little racy, but not in a way that hurts anything. As |
| 6891 | // we grab the defaultMode from the display manager policy, we could |
| 6892 | // be setting a new display manager policy, leaving us using a stale |
| 6893 | // defaultMode. The defaultMode doesn't matter for the override |
| 6894 | // policy though, since we set allowGroupSwitching to true, so it's |
| 6895 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6896 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 6897 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6898 | .getDisplayManagerPolicy() |
| 6899 | .defaultMode; |
| 6900 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6901 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6902 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6903 | .get(); |
| 6904 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6905 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6906 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6907 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6908 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 6909 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 6910 | display, |
| 6911 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6912 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 6913 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6914 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 6915 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6916 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 6917 | // reallocate the display state including framebuffers. |
| 6918 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 6919 | const hal::HWDisplayId hwcId = |
| 6920 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 6921 | |
| 6922 | onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 6923 | return NO_ERROR; |
| 6924 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 6925 | // Modify the max number of display frames stored within FrameTimeline |
| 6926 | case 1038: { |
| 6927 | n = data.readInt32(); |
| 6928 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 6929 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 6930 | return BAD_VALUE; |
| 6931 | } |
| 6932 | if (n == 0) { |
| 6933 | // restore to default |
| 6934 | mFrameTimeline->reset(); |
| 6935 | return NO_ERROR; |
| 6936 | } |
| 6937 | mFrameTimeline->setMaxDisplayFrames(n); |
| 6938 | return NO_ERROR; |
| 6939 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6940 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 6941 | PhysicalDisplayId displayId = [&]() { |
| 6942 | Mutex::Autolock lock(mStateLock); |
| 6943 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 6944 | }(); |
| 6945 | |
| 6946 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 6947 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 6948 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
| 6949 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 6950 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 6951 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6952 | // Toggle caching feature |
| 6953 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 6954 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 6955 | // caching to a particular physical display |
| 6956 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6957 | auto future = mScheduler->schedule([&] { |
| 6958 | n = data.readInt32(); |
| 6959 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 6960 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 6961 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 6962 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 6963 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 6964 | return NAME_NOT_FOUND; |
| 6965 | } |
| 6966 | } |
| 6967 | { |
| 6968 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6969 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6970 | for (const auto& [_, display] : mDisplays) { |
| 6971 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6972 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6973 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | return OK; |
| 6977 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6978 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6979 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 6980 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6981 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6982 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 6983 | return NO_ERROR; |
| 6984 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6985 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6986 | if (mTransactionTracing) { |
| 6987 | if (data.readInt32()) { |
| 6988 | // Transaction tracing is always running but allow the user to temporarily |
| 6989 | // increase the buffer when actively debugging. |
| 6990 | mTransactionTracing->setBufferSize( |
Diwas Sharma | a002117 | 2023-09-01 00:43:31 +0000 | [diff] [blame] | 6991 | TransactionTracing::ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6992 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 6993 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6994 | mTransactionTracing->setBufferSize( |
| 6995 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6996 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6997 | } |
| 6998 | reply->writeInt32(NO_ERROR); |
| 6999 | return NO_ERROR; |
| 7000 | } |
Diwas Sharma | a002117 | 2023-09-01 00:43:31 +0000 | [diff] [blame] | 7001 | case 1042: { // Write layers trace or transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7002 | if (mTransactionTracing) { |
| 7003 | mTransactionTracing->writeToFile(); |
| 7004 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 7005 | if (mLayerTracingEnabled) { |
| 7006 | mLayerTracing.writeToFile(); |
| 7007 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7008 | reply->writeInt32(NO_ERROR); |
| 7009 | return NO_ERROR; |
| 7010 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7011 | // hdr sdr ratio overlay |
| 7012 | case 1043: { |
| 7013 | auto future = mScheduler->schedule( |
| 7014 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7015 | n = data.readInt32(); |
| 7016 | mHdrSdrRatioOverlay = n != 0; |
| 7017 | switch (n) { |
| 7018 | case 0: |
| 7019 | case 1: |
| 7020 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7021 | break; |
| 7022 | default: |
| 7023 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
| 7024 | } |
| 7025 | }); |
| 7026 | future.wait(); |
| 7027 | return NO_ERROR; |
| 7028 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7029 | |
| 7030 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7031 | /* |
| 7032 | * Mirror one display onto another. |
| 7033 | * Ensure the source and destination displays are on. |
| 7034 | * Commands: |
| 7035 | * 0: Mirror one display to another |
| 7036 | * 1: Disable mirroring to a previously mirrored display |
| 7037 | * 2: Disable mirroring on previously mirrored displays |
| 7038 | * |
| 7039 | * Ex: |
| 7040 | * Get the display ids: |
| 7041 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7042 | * Mirror first display to the second: |
| 7043 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7044 | * 4619827677550801153 |
| 7045 | * Stop mirroring: |
| 7046 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7047 | */ |
| 7048 | |
| 7049 | int64_t arg0 = data.readInt64(); |
| 7050 | |
| 7051 | switch (arg0) { |
| 7052 | case 0: { |
| 7053 | // Mirror arg1 to arg2 |
| 7054 | int64_t arg1 = data.readInt64(); |
| 7055 | int64_t arg2 = data.readInt64(); |
| 7056 | // Enable mirroring for one display |
| 7057 | const auto display1id = DisplayId::fromValue(arg1); |
| 7058 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7059 | display1id.value()); |
| 7060 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7061 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7062 | ui::LayerStack layerStack; |
| 7063 | { |
| 7064 | Mutex::Autolock lock(mStateLock); |
| 7065 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7066 | layerStack = display->getLayerStack(); |
| 7067 | } |
| 7068 | SurfaceComposerClient::Transaction t; |
| 7069 | t.setDisplayLayerStack(token2, layerStack); |
| 7070 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7071 | t.setLayerStack(mirrorRoot, layerStack); |
| 7072 | t.apply(); |
| 7073 | |
| 7074 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7075 | break; |
| 7076 | } |
| 7077 | |
| 7078 | case 1: { |
| 7079 | // Disable mirroring for arg1 |
| 7080 | int64_t arg1 = data.readInt64(); |
| 7081 | mMirrorMapForDebug.erase(arg1); |
| 7082 | break; |
| 7083 | } |
| 7084 | |
| 7085 | case 2: { |
| 7086 | // Disable mirroring for all displays |
| 7087 | mMirrorMapForDebug.clear(); |
| 7088 | break; |
| 7089 | } |
| 7090 | |
| 7091 | default: |
| 7092 | return BAD_VALUE; |
| 7093 | } |
| 7094 | return NO_ERROR; |
| 7095 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7096 | } |
| 7097 | } |
| 7098 | return err; |
| 7099 | } |
| 7100 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7101 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7102 | static bool updateOverlay = |
| 7103 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7104 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7105 | |
| 7106 | // Update the overlay on the main thread to avoid race conditions with |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7107 | // RefreshRateSelector::getActiveMode |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7108 | static_cast<void>(mScheduler->schedule([=] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7109 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7110 | if (!display) { |
| 7111 | ALOGW("%s: default display is null", __func__); |
| 7112 | return; |
| 7113 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7114 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7115 | |
| 7116 | const auto desiredActiveMode = display->getDesiredActiveMode(); |
| 7117 | const std::optional<DisplayModeId> desiredModeId = desiredActiveMode |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7118 | ? std::make_optional(desiredActiveMode->modeOpt->modePtr->getId()) |
| 7119 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7120 | : std::nullopt; |
| 7121 | |
| 7122 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7123 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 7124 | if (display->onKernelTimerChanged(desiredModeId, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7125 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7126 | } |
| 7127 | })); |
| 7128 | } |
| 7129 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7130 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
| 7131 | SurfaceFlinger::getKernelIdleTimerProperties(DisplayId displayId) { |
| 7132 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7133 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7134 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7135 | if (isKernelIdleTimerHwcSupported) { |
| 7136 | if (const auto id = PhysicalDisplayId::tryCast(displayId); |
| 7137 | getHwComposer().hasDisplayIdleTimerCapability(*id)) { |
| 7138 | // In order to decide if we can use the HWC api for idle timer |
| 7139 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7140 | // without relying on hasDisplayCapability. |
| 7141 | // hasDisplayCapability relies on DisplayCapabilities |
| 7142 | // which are updated after we set the PowerMode::ON. |
| 7143 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7144 | // and is available before the PowerMode::ON |
| 7145 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7146 | } |
| 7147 | return {std::nullopt, timeout}; |
| 7148 | } |
| 7149 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7150 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7151 | } |
| 7152 | |
| 7153 | return {std::nullopt, timeout}; |
| 7154 | } |
| 7155 | |
| 7156 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7157 | KernelIdleTimerController controller, |
| 7158 | PhysicalDisplayId displayId) { |
| 7159 | switch (controller) { |
| 7160 | case KernelIdleTimerController::HwcApi: { |
| 7161 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7162 | break; |
| 7163 | } |
| 7164 | case KernelIdleTimerController::Sysprop: { |
| 7165 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7166 | break; |
| 7167 | } |
| 7168 | } |
| 7169 | } |
| 7170 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7171 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7172 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7173 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7174 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7175 | if (!display) { |
| 7176 | ALOGW("%s: default display is null", __func__); |
| 7177 | return; |
| 7178 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7179 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7180 | // If the support for kernel idle timer is disabled for the active display, |
| 7181 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7182 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7183 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7184 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7185 | return; |
| 7186 | } |
| 7187 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7188 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7189 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7190 | switch (action) { |
| 7191 | case KernelIdleTimerAction::TurnOff: |
| 7192 | if (mKernelIdleTimerEnabled) { |
| 7193 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7194 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7195 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7196 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7197 | mKernelIdleTimerEnabled = false; |
| 7198 | } |
| 7199 | break; |
| 7200 | case KernelIdleTimerAction::TurnOn: |
| 7201 | if (!mKernelIdleTimerEnabled) { |
| 7202 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7203 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7204 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7205 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7206 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7207 | mKernelIdleTimerEnabled = true; |
| 7208 | } |
| 7209 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7210 | } |
| 7211 | } |
| 7212 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7213 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7214 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7215 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7216 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7217 | ~WindowDisconnector() { |
| 7218 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7219 | } |
| 7220 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7221 | private: |
| 7222 | ANativeWindow* mWindow; |
| 7223 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7224 | }; |
| 7225 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7226 | static bool hasCaptureBlackoutContentPermission() { |
| 7227 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7228 | const int pid = ipc->getCallingPid(); |
| 7229 | const int uid = ipc->getCallingUid(); |
| 7230 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7231 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7232 | } |
| 7233 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7234 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7235 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7236 | const int pid = ipc->getCallingPid(); |
| 7237 | const int uid = ipc->getCallingUid(); |
| 7238 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7239 | return OK; |
| 7240 | } |
| 7241 | |
| 7242 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7243 | // itself, we allow it to continue. |
| 7244 | if (captureArgs.uid == uid) { |
| 7245 | return OK; |
| 7246 | } |
| 7247 | |
| 7248 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7249 | return PERMISSION_DENIED; |
| 7250 | } |
| 7251 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7252 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7253 | static constexpr int kFifoPriority = 2; |
| 7254 | static constexpr int kOtherPriority = 0; |
| 7255 | |
| 7256 | struct sched_param param = {0}; |
| 7257 | int sched_policy; |
| 7258 | if (enabled) { |
| 7259 | sched_policy = SCHED_FIFO; |
| 7260 | param.sched_priority = kFifoPriority; |
| 7261 | } else { |
| 7262 | sched_policy = SCHED_OTHER; |
| 7263 | param.sched_priority = kOtherPriority; |
| 7264 | } |
| 7265 | |
| 7266 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7267 | return -errno; |
| 7268 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7269 | |
| 7270 | return NO_ERROR; |
| 7271 | } |
| 7272 | |
| 7273 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7274 | static const unsigned int kUclampMin = |
| 7275 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min", 0U); |
| 7276 | |
| 7277 | if (!kUclampMin) { |
| 7278 | // uclamp.min set to 0 (default), skip setting |
| 7279 | return NO_ERROR; |
| 7280 | } |
| 7281 | |
| 7282 | // Currently, there is no wrapper in bionic: b/183240349. |
| 7283 | struct sched_attr { |
| 7284 | uint32_t size; |
| 7285 | uint32_t sched_policy; |
| 7286 | uint64_t sched_flags; |
| 7287 | int32_t sched_nice; |
| 7288 | uint32_t sched_priority; |
| 7289 | uint64_t sched_runtime; |
| 7290 | uint64_t sched_deadline; |
| 7291 | uint64_t sched_period; |
| 7292 | uint32_t sched_util_min; |
| 7293 | uint32_t sched_util_max; |
| 7294 | }; |
| 7295 | |
| 7296 | sched_attr attr = {}; |
| 7297 | attr.size = sizeof(attr); |
| 7298 | |
| 7299 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7300 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7301 | attr.sched_util_max = 1024; |
| 7302 | |
| 7303 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7304 | return -errno; |
| 7305 | } |
| 7306 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7307 | return NO_ERROR; |
| 7308 | } |
| 7309 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7310 | namespace { |
| 7311 | |
| 7312 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, const DisplayDevice* display, |
| 7313 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
| 7314 | if (requestedDataspace != ui::Dataspace::UNKNOWN || display == nullptr) { |
| 7315 | return requestedDataspace; |
| 7316 | } |
| 7317 | |
| 7318 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7319 | |
| 7320 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7321 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7322 | // TODO: Enable once HDR screenshots are ready. |
| 7323 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7324 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7325 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7326 | // proof as PQ is, but is good enough. |
| 7327 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7328 | // to consistently supply metadata to image encoders. |
| 7329 | return ui::Dataspace::BT2020_HLG; |
| 7330 | } |
| 7331 | |
| 7332 | return dataspaceForColorMode; |
| 7333 | } |
| 7334 | |
| 7335 | } // namespace |
| 7336 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7337 | static void invokeScreenCaptureError(const status_t status, |
| 7338 | const sp<IScreenCaptureListener>& captureListener) { |
| 7339 | ScreenCaptureResults captureResults; |
| 7340 | captureResults.fenceResult = base::unexpected(status); |
| 7341 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7342 | } |
| 7343 | |
| 7344 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7345 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7346 | ATRACE_CALL(); |
| 7347 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7348 | status_t validate = validateScreenshotPermissions(args); |
| 7349 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7350 | invokeScreenCaptureError(validate, captureListener); |
| 7351 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7354 | if (!args.displayToken) { |
| 7355 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7356 | return; |
| 7357 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7358 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7359 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7360 | ui::LayerStack layerStack; |
| 7361 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7362 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7363 | { |
| 7364 | Mutex::Autolock lock(mStateLock); |
| 7365 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7366 | if (!display) { |
| 7367 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7368 | return; |
| 7369 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7370 | displayWeak = display; |
| 7371 | layerStack = display->getLayerStack(); |
| 7372 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7373 | // 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] | 7374 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7375 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7376 | } |
| 7377 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7378 | for (const auto& handle : args.excludeHandles) { |
| 7379 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7380 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7381 | excludeLayerIds.emplace(excludeLayer); |
| 7382 | } else { |
| 7383 | ALOGW("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7384 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7385 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7386 | } |
| 7387 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7390 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | c44a1ff | 2023-05-19 23:49:05 +0000 | [diff] [blame] | 7391 | return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, args.dataspace, |
| 7392 | args.useIdentityTransform, args.hintForSeamlessTransition, |
| 7393 | args.captureSecureLayers); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7394 | }); |
| 7395 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7396 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7397 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7398 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7399 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7400 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7401 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7402 | layerStack](const LayerVector::Visitor& visitor) { |
| 7403 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7404 | }; |
| 7405 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7406 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7407 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7408 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7409 | args.allowProtected, args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7410 | } |
| 7411 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7412 | void SurfaceFlinger::captureDisplay(DisplayId displayId, |
| 7413 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7414 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7415 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7416 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7417 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7418 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7419 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7420 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7421 | if (!display) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7422 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7423 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7424 | } |
| 7425 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7426 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7427 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7428 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7431 | RenderAreaFuture renderAreaFuture = ftl::defer([=] { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7432 | return DisplayRenderArea::create(displayWeak, Rect(), size, ui::Dataspace::UNKNOWN, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 7433 | false /* useIdentityTransform */, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7434 | false /* hintForSeamlessTransition */, |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7435 | false /* captureSecureLayers */); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7436 | }); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7437 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7438 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7439 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7440 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7441 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7442 | } else { |
| 7443 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7444 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7445 | }; |
| 7446 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7447 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7448 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7449 | if (captureListener == nullptr) { |
| 7450 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7451 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7452 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7453 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7454 | |
| 7455 | constexpr bool kAllowProtected = false; |
| 7456 | constexpr bool kGrayscale = false; |
| 7457 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7458 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, size, |
| 7459 | ui::PixelFormat::RGBA_8888, kAllowProtected, kGrayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7460 | } |
| 7461 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7462 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 7463 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7464 | ATRACE_CALL(); |
| 7465 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7466 | status_t validate = validateScreenshotPermissions(args); |
| 7467 | if (validate != OK) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7468 | invokeScreenCaptureError(validate, captureListener); |
| 7469 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7470 | } |
| 7471 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7472 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7473 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7474 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7475 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7476 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7477 | |
| 7478 | // Call this before holding mStateLock to avoid any deadlocking. |
| 7479 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
| 7480 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7481 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7482 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7483 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 7484 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7485 | if (parent == nullptr) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7486 | ALOGE("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7487 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7488 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7489 | } |
| 7490 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7491 | if (!canCaptureBlackoutContent && |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7492 | parent->getDrawingState().flags & layer_state_t::eLayerSecure) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7493 | ALOGW("Attempting to capture secure layer: PERMISSION_DENIED"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7494 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7495 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7496 | } |
| 7497 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 7498 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7499 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7500 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7501 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7502 | } |
| 7503 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7504 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7505 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7506 | crop.bottom = parentSourceBounds.getHeight(); |
| 7507 | } |
| 7508 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7509 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 7510 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 7511 | // crop was not specified, or an invalid frame scale was provided. |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7512 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7513 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7514 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 7515 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7516 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7517 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7518 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7519 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7520 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7521 | } else { |
| 7522 | ALOGW("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7523 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7524 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 7525 | } |
| 7526 | } |
| 7527 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 7528 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7529 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 7530 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
| 7531 | ALOGW("Failed to captureLayes: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7532 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7533 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 7534 | } |
| 7535 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7536 | bool childrenOnly = args.childrenOnly; |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 7537 | RenderAreaFuture renderAreaFuture = ftl::defer([=]() -> std::unique_ptr<RenderArea> { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7538 | ui::Transform layerTransform; |
| 7539 | Rect layerBufferSize; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7540 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7541 | frontend::LayerSnapshot* snapshot = |
| 7542 | mLayerSnapshotBuilder.getSnapshot(parent->getSequence()); |
| 7543 | if (!snapshot) { |
| 7544 | ALOGW("Couldn't find layer snapshot for %d", parent->getSequence()); |
| 7545 | } else { |
| 7546 | layerTransform = snapshot->localTransform; |
| 7547 | layerBufferSize = snapshot->bufferSize; |
| 7548 | } |
| 7549 | } else { |
| 7550 | layerTransform = parent->getTransform(); |
| 7551 | layerBufferSize = parent->getBufferSize(parent->getDrawingState()); |
| 7552 | } |
| 7553 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 7554 | return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7555 | childrenOnly, args.captureSecureLayers, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7556 | layerTransform, layerBufferSize, |
| 7557 | args.hintForSeamlessTransition); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7558 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7559 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7560 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 7561 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 7562 | if (args.childrenOnly) { |
| 7563 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 7564 | : crop.toFloatRect(); |
| 7565 | } |
| 7566 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7567 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 7568 | std::move(excludeLayerIds), |
| 7569 | args.childrenOnly, parentCrop); |
| 7570 | } else { |
| 7571 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 7572 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 7573 | if (!layer->isVisible()) { |
| 7574 | return; |
| 7575 | } else if (args.childrenOnly && layer == parent.get()) { |
| 7576 | return; |
| 7577 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7578 | return; |
| 7579 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 7580 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7581 | auto p = sp<Layer>::fromExisting(layer); |
| 7582 | while (p != nullptr) { |
| 7583 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7584 | return; |
| 7585 | } |
| 7586 | p = p->getParent(); |
| 7587 | } |
| 7588 | |
| 7589 | visitor(layer); |
| 7590 | }); |
| 7591 | }; |
| 7592 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7593 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 7594 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7595 | if (captureListener == nullptr) { |
| 7596 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7597 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7598 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7599 | } |
| 7600 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7601 | captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, reqSize, args.pixelFormat, |
| 7602 | args.allowProtected, args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7605 | void SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, |
| 7606 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 7607 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 7608 | bool allowProtected, bool grayscale, |
| 7609 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7610 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7611 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7612 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 7613 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 7614 | ") that exceeds render target size limit.", |
| 7615 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7616 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7617 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 7618 | } |
| 7619 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7620 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 7621 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 7622 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 7623 | // application to avoid being screenshot or drawn via unsecure display. |
| 7624 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 7625 | bool hasProtectedLayer = false; |
| 7626 | if (allowProtected && supportsProtected) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7627 | hasProtectedLayer = mScheduler |
| 7628 | ->schedule([=]() { |
| 7629 | bool protectedLayerFound = false; |
| 7630 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7631 | for (auto& [_, layerFe] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7632 | protectedLayerFound |= |
| 7633 | (layerFe->mSnapshot->isVisible && |
| 7634 | layerFe->mSnapshot->hasProtectedContent); |
| 7635 | } |
| 7636 | return protectedLayerFound; |
| 7637 | }) |
| 7638 | .get(); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7639 | } |
| 7640 | |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 7641 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 7642 | GRALLOC_USAGE_HW_TEXTURE | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7643 | (hasProtectedLayer && allowProtected && supportsProtected |
| 7644 | ? GRALLOC_USAGE_PROTECTED |
| 7645 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7646 | sp<GraphicBuffer> buffer = |
| 7647 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 7648 | static_cast<android_pixel_format>(reqPixelFormat), |
| 7649 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 7650 | |
| 7651 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7652 | if (bufferStatus != OK) { |
| 7653 | // Animations may end up being really janky, but don't crash here. |
| 7654 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 7655 | // too much. |
| 7656 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7657 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 7658 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 7659 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 7660 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 7661 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 7662 | renderengine::impl::ExternalTexture::Usage:: |
| 7663 | WRITEABLE); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7664 | auto fence = captureScreenCommon(std::move(renderAreaFuture), getLayerSnapshots, texture, |
| 7665 | false /* regionSampling */, grayscale, captureListener); |
| 7666 | fence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 7667 | } |
| 7668 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7669 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenCommon( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7670 | RenderAreaFuture renderAreaFuture, GetLayerSnapshotsFunction getLayerSnapshots, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 7671 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 7672 | bool grayscale, const sp<IScreenCaptureListener>& captureListener) { |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7673 | ATRACE_CALL(); |
| 7674 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7675 | bool canCaptureBlackoutContent = hasCaptureBlackoutContentPermission(); |
Robert Carr | 03480e2 | 2018-01-04 16:02:06 -0800 | [diff] [blame] | 7676 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7677 | auto future = mScheduler->schedule( |
| 7678 | [=, renderAreaFuture = std::move(renderAreaFuture)]() FTL_FAKE_GUARD( |
| 7679 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 7680 | ScreenCaptureResults captureResults; |
Patrick Williams | 3190813 | 2023-01-09 13:38:48 -0600 | [diff] [blame] | 7681 | std::shared_ptr<RenderArea> renderArea = renderAreaFuture.get(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7682 | if (!renderArea) { |
| 7683 | ALOGW("Skipping screen capture because of invalid render area."); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 7684 | if (captureListener) { |
| 7685 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 7686 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7687 | } |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7688 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 7689 | } |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7690 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7691 | ftl::SharedFuture<FenceResult> renderFuture; |
| 7692 | renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7693 | renderFuture = renderScreenImpl(renderArea, getLayerSnapshots, buffer, |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7694 | canCaptureBlackoutContent, regionSampling, |
| 7695 | grayscale, captureResults); |
| 7696 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7697 | |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 7698 | if (captureListener) { |
| 7699 | // Defer blocking on renderFuture back to the Binder thread. |
| 7700 | return ftl::Future(std::move(renderFuture)) |
| 7701 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 7702 | FenceResult fenceResult) mutable -> FenceResult { |
| 7703 | captureResults.fenceResult = std::move(fenceResult); |
| 7704 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7705 | return base::unexpected(NO_ERROR); |
| 7706 | }) |
| 7707 | .share(); |
| 7708 | } |
| 7709 | return renderFuture; |
| 7710 | }); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7711 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7712 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7713 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 7714 | return future; |
| 7715 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7716 | |
| 7717 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 7718 | } |
| 7719 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 7720 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7721 | std::shared_ptr<const RenderArea> renderArea, GetLayerSnapshotsFunction getLayerSnapshots, |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7722 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 7723 | bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, |
| 7724 | ScreenCaptureResults& captureResults) { |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 7725 | ATRACE_CALL(); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7726 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7727 | auto layers = getLayerSnapshots(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7728 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7729 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 7730 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 7731 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 7732 | layerFE->mSnapshot->geomLayerTransform = |
| 7733 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 7734 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 7735 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 7736 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7737 | |
| 7738 | // We allow the system server to take screenshots of secure layers for |
| 7739 | // use in situations like the Screen-rotation animation and place |
| 7740 | // the impetus on WindowManager to not persist them. |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7741 | if (captureResults.capturedSecureLayers && !canCaptureBlackoutContent) { |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7742 | ALOGW("FB is protected: PERMISSION_DENIED"); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 7743 | return ftl::yield<FenceResult>(base::unexpected(PERMISSION_DENIED)).share(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7744 | } |
| 7745 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7746 | auto capturedBuffer = buffer; |
| 7747 | |
| 7748 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7749 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 7750 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 7751 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 7752 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 7753 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7754 | captureResults.capturedDataspace = requestedDataspace; |
| 7755 | |
| 7756 | { |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7757 | Mutex::Autolock lock(mStateLock); |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7758 | const DisplayDevice* display = nullptr; |
| 7759 | if (parent) { |
| 7760 | display = findDisplay([layerStack = parent->getLayerStack()](const auto& display) { |
| 7761 | return display.getLayerStack() == layerStack; |
| 7762 | }).get(); |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7763 | } |
| 7764 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7765 | if (display == nullptr) { |
| 7766 | display = renderArea->getDisplayDevice().get(); |
| 7767 | } |
| 7768 | |
| 7769 | if (display == nullptr) { |
| 7770 | display = getDefaultDisplayDeviceLocked().get(); |
| 7771 | } |
| 7772 | |
| 7773 | if (display != nullptr) { |
| 7774 | const auto& state = display->getCompositionDisplay()->getState(); |
| 7775 | captureResults.capturedDataspace = |
| 7776 | pickBestDataspace(requestedDataspace, display, captureResults.capturedHdrLayers, |
| 7777 | renderArea->getHintForSeamlessTransition()); |
| 7778 | sdrWhitePointNits = state.sdrWhitePointNits; |
| 7779 | displayBrightnessNits = state.displayBrightnessNits; |
John Reck | 1dadaa6 | 2023-07-11 14:07:00 -0400 | [diff] [blame] | 7780 | // Only clamp the display brightness if this is not a seamless transition. Otherwise |
| 7781 | // for seamless transitions it's important to match the current display state as the |
| 7782 | // buffer will be shown under these same conditions, and we want to avoid any flickers |
| 7783 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
John Reck | 5b02fc4 | 2023-06-14 14:41:10 -0400 | [diff] [blame] | 7784 | // Restrict the amount of HDR "headroom" in the screenshot to avoid over-dimming |
| 7785 | // the SDR portion. 2.0 chosen by experimentation |
| 7786 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 7787 | displayBrightnessNits = |
| 7788 | std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, displayBrightnessNits); |
| 7789 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7790 | |
| 7791 | if (requestedDataspace == ui::Dataspace::UNKNOWN) { |
| 7792 | renderIntent = state.renderIntent; |
| 7793 | } |
| 7794 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 7795 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7796 | |
| 7797 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 7798 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7799 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 7800 | if (!layers.empty()) { |
| 7801 | const sp<LayerFE>& layerFE = layers.back().second; |
| 7802 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 7803 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 7804 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7805 | auto copyLayerFEs = [&layers]() { |
| 7806 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 7807 | layerFEs.reserve(layers.size()); |
| 7808 | for (const auto& [_, layerFE] : layers) { |
| 7809 | layerFEs.push_back(layerFE); |
| 7810 | } |
| 7811 | return layerFEs; |
| 7812 | }; |
| 7813 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7814 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
| 7815 | sdrWhitePointNits, displayBrightnessNits, grayscale, layerFEs = copyLayerFEs(), |
| 7816 | layerStack, regionSampling, renderArea = std::move(renderArea), |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 7817 | renderIntent]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7818 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7819 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7820 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 7821 | |
| 7822 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 7823 | .renderIntent = renderIntent}; |
| 7824 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7825 | float targetBrightness = 1.0f; |
| 7826 | if (dataspace == ui::Dataspace::BT2020_HLG) { |
| 7827 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 7828 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 7829 | // will appear way too bright. |
| 7830 | if (maxBrightnessNits < 1000.f) { |
| 7831 | targetBrightness = 1000.f / maxBrightnessNits; |
| 7832 | } |
| 7833 | } |
| 7834 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7835 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 7836 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 7837 | .colorProfile = colorProfile, |
| 7838 | .renderArea = *renderArea, |
| 7839 | .layerStack = layerStack, |
| 7840 | .buffer = std::move(buffer), |
| 7841 | .sdrWhitePointNits = sdrWhitePointNits, |
| 7842 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7843 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 7844 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 7845 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 7846 | .dimInGammaSpaceForEnhancedScreenshots = |
| 7847 | mDimInGammaSpaceForEnhancedScreenshots}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7848 | |
| 7849 | const float colorSaturation = grayscale ? 0 : 1; |
| 7850 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 7851 | .outputs = {output}, |
| 7852 | .layers = std::move(layerFEs), |
| 7853 | .updatingOutputGeometryThisFrame = true, |
| 7854 | .updatingGeometryThisFrame = true, |
| 7855 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 7856 | }; |
| 7857 | compositionEngine->present(refreshArgs); |
| 7858 | |
| 7859 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 7860 | }; |
| 7861 | |
| 7862 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 7863 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 7864 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 7865 | // immediately. |
| 7866 | // |
| 7867 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 7868 | // to CompositionEngine::present. |
| 7869 | const bool renderEngineIsThreaded = [&]() { |
| 7870 | using Type = renderengine::RenderEngine::RenderEngineType; |
| 7871 | const auto type = mRenderEngine->getRenderEngineType(); |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 7872 | return type == Type::SKIA_GL_THREADED; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7873 | }(); |
| 7874 | auto presentFuture = renderEngineIsThreaded ? ftl::defer(std::move(present)).share() |
| 7875 | : ftl::yield(present()).share(); |
| 7876 | |
| 7877 | for (auto& [layer, layerFE] : layers) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 7878 | layer->onLayerDisplayed(ftl::Future(presentFuture) |
| 7879 | .then([layerFE = std::move(layerFE)](FenceResult) { |
| 7880 | return layerFE->stealCompositionResult() |
| 7881 | .releaseFences.back() |
| 7882 | .first.get(); |
| 7883 | }) |
| 7884 | .share(), |
| 7885 | ui::INVALID_LAYER_STACK); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 7886 | } |
| 7887 | |
| 7888 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 7889 | } |
| 7890 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7891 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7892 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 7893 | for (auto& layer : mLegacyLayers) { |
| 7894 | visitor(layer.second.get()); |
| 7895 | } |
| 7896 | } else { |
| 7897 | mDrawingState.traverse(visitor); |
| 7898 | } |
| 7899 | } |
| 7900 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7901 | // --------------------------------------------------------------------------- |
| 7902 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 7903 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 7904 | layersSortedByZ.traverse(visitor); |
| 7905 | } |
| 7906 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7907 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 7908 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7909 | } |
| 7910 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 7911 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 7912 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 7913 | } |
| 7914 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7915 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7916 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7917 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7918 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 7919 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7920 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7921 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7922 | continue; |
| 7923 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 7924 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7925 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 7926 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 7927 | return; |
| 7928 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7929 | if (!layer->isVisible()) { |
| 7930 | return; |
| 7931 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7932 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 7933 | return; |
| 7934 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7935 | |
| 7936 | if (!excludeLayerIds.empty()) { |
| 7937 | auto p = sp<Layer>::fromExisting(layer); |
| 7938 | while (p != nullptr) { |
| 7939 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 7940 | return; |
| 7941 | } |
| 7942 | p = p->getParent(); |
| 7943 | } |
| 7944 | } |
| 7945 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7946 | visitor(layer); |
| 7947 | }); |
| 7948 | } |
| 7949 | } |
| 7950 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7951 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7952 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 7953 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7954 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7955 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7956 | } |
| 7957 | |
| 7958 | return mPhysicalDisplays.get(displayId) |
| 7959 | .transform(&PhysicalDisplay::snapshotRef) |
| 7960 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 7961 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 7962 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 7963 | .transform([](const DisplayModePtr& modePtr) { |
| 7964 | return scheduler::FrameRateMode{modePtr->getFps(), ftl::as_non_null(modePtr)}; |
| 7965 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 7966 | } |
| 7967 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7968 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7969 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7970 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7971 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 7972 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 7973 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 7974 | Mutex::Autolock lock(mStateLock); |
| 7975 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7976 | if (mDebugDisplayModeSetByBackdoor) { |
| 7977 | // ignore this request as mode is overridden by backdoor |
| 7978 | return NO_ERROR; |
| 7979 | } |
| 7980 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7981 | auto& selector = display->refreshRateSelector(); |
| 7982 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7983 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7984 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7985 | case SetPolicyResult::Invalid: |
| 7986 | return BAD_VALUE; |
| 7987 | case SetPolicyResult::Unchanged: |
| 7988 | return NO_ERROR; |
| 7989 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7990 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7991 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7992 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 7993 | // TODO(b/255635711): Apply the policy once the display is powered on, which is currently only |
| 7994 | // done for the internal display that becomes active on fold/unfold. For now, assume that DM |
| 7995 | // always powers on the secondary (internal or external) display before setting its policy. |
| 7996 | if (!display->isPoweredOn()) { |
| 7997 | ALOGV("%s(%s): Display is powered off", __func__, to_string(displayId).c_str()); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 7998 | return NO_ERROR; |
| 7999 | } |
| 8000 | |
| 8001 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8002 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8003 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8004 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8005 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector, bool force) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8006 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8007 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8008 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8009 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8010 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8011 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
| 8012 | mScheduler->onPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8013 | toggleKernelIdleTimer(); |
| 8014 | } else { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8015 | mScheduler->onNonPrimaryDisplayModeChanged(mAppConnectionHandle, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8016 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8017 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8018 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8019 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8020 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8021 | return NAME_NOT_FOUND; |
| 8022 | } |
| 8023 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8024 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8025 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8026 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8027 | ALOGV("Switching to Scheduler preferred mode %d (%s)", preferredModeId.value(), |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8028 | to_string(preferredMode.fps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8029 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8030 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8031 | ALOGE("%s: Preferred mode %d is disallowed", __func__, preferredModeId.value()); |
| 8032 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8033 | } |
| 8034 | |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8035 | setDesiredActiveMode({preferredMode, .emitEvent = true}, force); |
| 8036 | |
| 8037 | // Update the frameRateOverride list as the display render rate might have changed |
| 8038 | if (mScheduler->updateFrameRateOverrides(/*consideredSignals*/ {}, preferredMode.fps)) { |
| 8039 | triggerOnFrameRateOverridesChanged(); |
| 8040 | } |
| 8041 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8042 | return NO_ERROR; |
| 8043 | } |
| 8044 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8045 | namespace { |
| 8046 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8047 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8048 | } |
| 8049 | |
| 8050 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8051 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8052 | } |
| 8053 | |
| 8054 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8055 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8056 | aidlRange.min = range.min.getValue(); |
| 8057 | aidlRange.max = range.max.getValue(); |
| 8058 | return aidlRange; |
| 8059 | } |
| 8060 | |
| 8061 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8062 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8063 | aidlRanges.physical = translate(ranges.physical); |
| 8064 | aidlRanges.render = translate(ranges.render); |
| 8065 | return aidlRanges; |
| 8066 | } |
| 8067 | |
| 8068 | } // namespace |
| 8069 | |
| 8070 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8071 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8072 | ATRACE_CALL(); |
| 8073 | |
| 8074 | if (!displayToken) { |
| 8075 | return BAD_VALUE; |
| 8076 | } |
| 8077 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8078 | auto future = mScheduler->schedule([=]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8079 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8080 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8081 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8082 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8083 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8084 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8085 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8086 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8087 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8088 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8089 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
| 8090 | translate(specs.appRequestRanges), specs.allowGroupSwitching}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8091 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8092 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8093 | } |
| 8094 | }); |
| 8095 | |
| 8096 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8097 | } |
| 8098 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8099 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8100 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8101 | ATRACE_CALL(); |
| 8102 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8103 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8104 | return BAD_VALUE; |
| 8105 | } |
| 8106 | |
| 8107 | Mutex::Autolock lock(mStateLock); |
| 8108 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8109 | if (!display) { |
| 8110 | return NAME_NOT_FOUND; |
| 8111 | } |
| 8112 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8113 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8114 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8115 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8116 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8117 | scheduler::RefreshRateSelector::Policy policy = |
| 8118 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8119 | outSpecs->defaultMode = policy.defaultMode.value(); |
| 8120 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8121 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8122 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8123 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8126 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8127 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8128 | if (!layer->isRemovedFromCurrentState()) { |
| 8129 | mScheduler->registerLayer(layer); |
| 8130 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
| 8133 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8134 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8135 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8136 | if (!layer->isRemovedFromCurrentState()) { |
| 8137 | mScheduler->deregisterLayer(layer); |
| 8138 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8139 | if (mTransactionTracing) { |
| 8140 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8141 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8142 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8143 | } |
| 8144 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8145 | void SurfaceFlinger::onLayerUpdate() { |
| 8146 | scheduleCommit(FrameHint::kActive); |
| 8147 | } |
| 8148 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8149 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8150 | // Here we add children in the current state to offscreen layers and remove the |
| 8151 | // layer itself from the offscreen layer list. Since |
| 8152 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8153 | // from dangling children layers such that they are not reachable from the |
| 8154 | // Drawing state nor the offscreen layer list |
| 8155 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8156 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8157 | for (auto& child : layer->getCurrentChildren()) { |
| 8158 | mOffscreenLayers.emplace(child.get()); |
| 8159 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8160 | mOffscreenLayers.erase(layer); |
| 8161 | } |
| 8162 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8163 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8164 | mOffscreenLayers.erase(layer); |
| 8165 | } |
| 8166 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8167 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8168 | float lightPosY, float lightPosZ, |
| 8169 | float lightRadius) { |
| 8170 | Mutex::Autolock _l(mStateLock); |
| 8171 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8172 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8173 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8174 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8175 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8176 | |
| 8177 | // these values are overridden when calculating the shadow settings for a layer. |
| 8178 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8179 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8180 | return NO_ERROR; |
| 8181 | } |
| 8182 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8183 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8184 | const { |
| 8185 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8186 | // on the work to remove the table in that bug rather than adding more to |
| 8187 | // it. |
| 8188 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8189 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8190 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8191 | }; |
| 8192 | return genericLayerMetadataKeyMap; |
| 8193 | } |
| 8194 | |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8195 | status_t SurfaceFlinger::setOverrideFrameRate(uid_t uid, float frameRate) { |
| 8196 | PhysicalDisplayId displayId = [&]() { |
| 8197 | Mutex::Autolock lock(mStateLock); |
| 8198 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8199 | }(); |
| 8200 | |
| 8201 | mScheduler->setGameModeRefreshRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8202 | mScheduler->onFrameRateOverridesChanged(mAppConnectionHandle, displayId); |
| 8203 | return NO_ERROR; |
| 8204 | } |
| 8205 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8206 | status_t SurfaceFlinger::updateSmallAreaDetection( |
| 8207 | std::vector<std::pair<uid_t, float>>& uidThresholdMappings) { |
| 8208 | mScheduler->updateSmallAreaDetection(uidThresholdMappings); |
| 8209 | return NO_ERROR; |
| 8210 | } |
| 8211 | |
| 8212 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(uid_t uid, float threshold) { |
| 8213 | mScheduler->setSmallAreaDetectionThreshold(uid, threshold); |
| 8214 | return NO_ERROR; |
| 8215 | } |
| 8216 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8217 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8218 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8219 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8220 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8221 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8222 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8223 | kMainThreadContext) { |
| 8224 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8225 | mRefreshRateOverlayRenderRate, |
| 8226 | mRefreshRateOverlayShowInMiddle); |
| 8227 | }; |
| 8228 | enableOverlay(setByHwc); |
| 8229 | if (setByHwc) { |
| 8230 | const auto status = |
| 8231 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8232 | if (status != NO_ERROR) { |
| 8233 | ALOGE("Error updating the refresh rate changed callback debug enabled"); |
| 8234 | enableOverlay(/*setByHwc*/ false); |
| 8235 | } |
| 8236 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8237 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8238 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8239 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8240 | } |
| 8241 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8242 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8243 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8244 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8245 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8246 | device->enableHdrSdrRatioOverlay(enable); |
| 8247 | } |
| 8248 | } |
| 8249 | } |
| 8250 | } |
| 8251 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8252 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8253 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8254 | } |
| 8255 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8256 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8257 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8258 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8259 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8260 | pipelineDepth++; |
| 8261 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8262 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8263 | } |
| 8264 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8265 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8266 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8267 | |
| 8268 | if (!getHwComposer().isHeadless()) { |
| 8269 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8270 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8271 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8272 | } |
| 8273 | |
| 8274 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8275 | return NO_ERROR; |
| 8276 | } |
| 8277 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8278 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8279 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8280 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8281 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8282 | refreshRate = *frameRateOverride; |
| 8283 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8284 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8285 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8286 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8287 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8288 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8289 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8290 | } |
| 8291 | |
| 8292 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
| 8293 | const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late; |
| 8294 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8295 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8296 | } |
| 8297 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8298 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8299 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8300 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8301 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8302 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8303 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8304 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8305 | |
| 8306 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8307 | bool addToRoot = state.addToRoot; |
| 8308 | if (state.initialParent != nullptr) { |
| 8309 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8310 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8311 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8312 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8313 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8314 | } |
| 8315 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8316 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8317 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8318 | mCurrentState.layersSortedByZ.add(layer); |
| 8319 | } else if (parent == nullptr) { |
| 8320 | layer->onRemovedFromCurrentState(); |
| 8321 | } else if (parent->isRemovedFromCurrentState()) { |
| 8322 | parent->addChild(layer); |
| 8323 | layer->onRemovedFromCurrentState(); |
| 8324 | } else { |
| 8325 | parent->addChild(layer); |
| 8326 | } |
| 8327 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8328 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8329 | sp<const DisplayDevice> hintDisplay; |
| 8330 | // Find the display that includes the layer. |
| 8331 | for (const auto& [token, display] : mDisplays) { |
| 8332 | if (display->getLayerStack() == layerStack) { |
| 8333 | hintDisplay = display; |
| 8334 | break; |
| 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | if (hintDisplay) { |
| 8339 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8340 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8341 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8342 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8343 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8344 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8345 | return; |
| 8346 | } |
| 8347 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 8348 | mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime()); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8349 | } |
| 8350 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8351 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8352 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8353 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 8354 | |
| 8355 | // Notify layers to update small dirty flag. |
| 8356 | if (mScheduler->supportSmallDirtyDetection()) { |
| 8357 | mCurrentState.traverse([&](Layer* layer) { |
| 8358 | if (layer->getLayerStack() == activeDisplay.getLayerStack()) { |
| 8359 | layer->setIsSmallDirty(); |
| 8360 | } |
| 8361 | }); |
| 8362 | } |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8363 | } |
| 8364 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8365 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8366 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8367 | |
| 8368 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8369 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8370 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8371 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8372 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8373 | mPhysicalDisplays.get(*idOpt) |
| 8374 | .transform(&PhysicalDisplay::isInternal) |
| 8375 | .value_or(false); |
| 8376 | }); |
| 8377 | } |
| 8378 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8379 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8380 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8381 | ATRACE_CALL(); |
| 8382 | |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8383 | // For the first display activated during boot, there is no need to force setDesiredActiveMode, |
| 8384 | // because DM is about to send its policy via setDesiredDisplayModeSpecs. |
| 8385 | bool forceApplyPolicy = false; |
| 8386 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8387 | if (inactiveDisplayPtr) { |
| 8388 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8389 | forceApplyPolicy = true; |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8390 | } |
| 8391 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8392 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 8393 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8394 | |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 8395 | resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
| 8396 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8397 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8398 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8399 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8400 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 8401 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8402 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8403 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 8404 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 8405 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 8406 | // The policy of the new active/pacesetter display may have changed while it was inactive. In |
| 8407 | // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In |
| 8408 | // either case, the Scheduler's cachedModeChangedParams must be initialized to the newly active |
| 8409 | // mode, and the kernel idle timer of the newly active display must be toggled. |
Dominik Laskowski | 360ae78 | 2023-02-22 13:30:37 -0500 | [diff] [blame] | 8410 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), |
| 8411 | forceApplyPolicy); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8412 | } |
| 8413 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 8414 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 8415 | gui::WindowInfosListenerInfo* outInfo) { |
| 8416 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 8417 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 8418 | return NO_ERROR; |
| 8419 | } |
| 8420 | |
| 8421 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 8422 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 8423 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 8424 | return NO_ERROR; |
| 8425 | } |
| 8426 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 8427 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 8428 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
| 8429 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 8430 | return NO_ERROR; |
| 8431 | } |
| 8432 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8433 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8434 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 8435 | if (bufferData.buffer && |
| 8436 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8437 | std::string errorMessage = |
| 8438 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 8439 | "layer %s that exceeds render target size limit of %u.", |
| 8440 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 8441 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 8442 | ALOGD("%s", errorMessage.c_str()); |
| 8443 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8444 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 8445 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 8446 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8447 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8448 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8449 | |
| 8450 | bool cachedBufferChanged = |
| 8451 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 8452 | if (cachedBufferChanged && bufferData.buffer) { |
| 8453 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 8454 | if (result.ok()) { |
| 8455 | return result.value(); |
| 8456 | } |
| 8457 | |
| 8458 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8459 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 8460 | |
| 8461 | if (bufferData.releaseBufferListener) { |
| 8462 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 8463 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 8464 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 8465 | } |
| 8466 | |
| 8467 | return nullptr; |
| 8468 | } |
| 8469 | |
| 8470 | if (cachedBufferChanged) { |
| 8471 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 8472 | } |
| 8473 | |
| 8474 | if (bufferData.buffer) { |
| 8475 | return std::make_shared< |
| 8476 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 8477 | renderengine::impl::ExternalTexture::Usage:: |
| 8478 | READABLE); |
| 8479 | } |
| 8480 | |
| 8481 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8482 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8483 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8484 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8485 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 8486 | { |
| 8487 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 8488 | mirrorDisplays = std::move(mMirrorDisplays); |
| 8489 | mMirrorDisplays.clear(); |
| 8490 | if (mirrorDisplays.size() == 0) { |
| 8491 | return false; |
| 8492 | } |
| 8493 | } |
| 8494 | |
| 8495 | sp<IBinder> unused; |
| 8496 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 8497 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 8498 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 8499 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 8500 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 8501 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 8502 | if (idx >= 0 && ret) { |
| 8503 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 8504 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 8505 | } |
| 8506 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8507 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8508 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 8509 | layer->isInternalDisplayOverlay()) { |
| 8510 | continue; |
| 8511 | } |
| 8512 | |
| 8513 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 8514 | ISurfaceComposerClient::eNoColorFill, |
| 8515 | gui::LayerMetadata()); |
| 8516 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8517 | { |
| 8518 | Mutex::Autolock lock(mStateLock); |
| 8519 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8520 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Vishnu Nair | de17725 | 2023-04-21 12:44:10 -0700 | [diff] [blame] | 8521 | childMirror->setClonedChild(layer->createClone(childMirror->getSequence())); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 8522 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 8523 | } |
| 8524 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 8525 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 8526 | } |
| 8527 | } |
| 8528 | return true; |
| 8529 | } |
| 8530 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8531 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 8532 | std::vector<LayerCreatedState>& createdLayers) { |
| 8533 | if (createdLayers.size() == 0) { |
| 8534 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8535 | } |
| 8536 | |
| 8537 | Mutex::Autolock _l(mStateLock); |
| 8538 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 8539 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8540 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8541 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8542 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8543 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8544 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 8545 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 8546 | LayerMetadata parentMetadata; |
| 8547 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 8548 | layer->updateMetadataSnapshot(parentMetadata); |
| 8549 | } |
| 8550 | |
| 8551 | std::unordered_set<Layer*> visited; |
| 8552 | mDrawingState.traverse([&visited](Layer* layer) { |
| 8553 | if (visited.find(layer) != visited.end()) { |
| 8554 | return; |
| 8555 | } |
| 8556 | |
| 8557 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 8558 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 8559 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 8560 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 8561 | if (layer->getDrawingState().isRelativeOf) { |
| 8562 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 8563 | return; |
| 8564 | } |
| 8565 | |
| 8566 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 8567 | }); |
| 8568 | } |
| 8569 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8570 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 8571 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8572 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8573 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8574 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 8575 | mLayerSnapshotBuilder.getSnapshots(); |
| 8576 | for (auto [_, layerFE] : layers) { |
| 8577 | auto i = layerFE->mSnapshot->globalZ; |
| 8578 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 8579 | } |
| 8580 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8581 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8582 | for (auto [layer, layerFE] : layers) { |
| 8583 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 8584 | } |
| 8585 | } |
| 8586 | } |
| 8587 | |
| 8588 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 8589 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8590 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8591 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8592 | nsecs_t currentTime = systemTime(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8593 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8594 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 8595 | if (cursorOnly && |
| 8596 | snapshot->compositionType != |
| 8597 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 8598 | return; |
| 8599 | } |
| 8600 | |
| 8601 | if (!snapshot->hasSomethingToDraw()) { |
| 8602 | return; |
| 8603 | } |
| 8604 | |
| 8605 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8606 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8607 | "Couldnt find layer object for %s", |
| 8608 | snapshot->getDebugString().c_str()); |
| 8609 | auto& legacyLayer = it->second; |
| 8610 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8611 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8612 | layerFE->mSnapshot = std::move(snapshot); |
| 8613 | refreshArgs.layers.push_back(layerFE); |
| 8614 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 8615 | }); |
| 8616 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8617 | if (mLegacyFrontEndEnabled && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8618 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8619 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 8620 | if (cursorOnly && |
| 8621 | layer->getLayerSnapshot()->compositionType != |
| 8622 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 8623 | return; |
| 8624 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 8625 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 8626 | refreshArgs.layers.push_back(layerFE); |
| 8627 | layers.emplace_back(layer, layerFE.get()); |
| 8628 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 8629 | }; |
| 8630 | |
| 8631 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 8632 | // for hot path avoid traversals by walking though the previous composition list |
| 8633 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 8634 | moveSnapshots(layer.get()); |
| 8635 | } |
| 8636 | } else { |
| 8637 | mPreviouslyComposedLayers.clear(); |
| 8638 | mDrawingState.traverseInZOrder( |
| 8639 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 8640 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 8641 | for (auto [layer, _] : layers) { |
| 8642 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 8643 | } |
| 8644 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8645 | } |
| 8646 | |
| 8647 | return layers; |
| 8648 | } |
| 8649 | |
| 8650 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8651 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 8652 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 8653 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 8654 | snapshotFilterFn) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8655 | return [&, layerStack, uid]() { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8656 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8657 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8658 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 8659 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8660 | if (stopTraversal) { |
| 8661 | return; |
| 8662 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8663 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 8664 | return; |
| 8665 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 8666 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8667 | return; |
| 8668 | } |
| 8669 | if (!snapshot->hasSomethingToDraw()) { |
| 8670 | return; |
| 8671 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8672 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 8673 | return; |
| 8674 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8675 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8676 | auto it = mLegacyLayers.find(snapshot->sequence); |
| 8677 | LOG_ALWAYS_FATAL_IF(it == mLegacyLayers.end(), |
| 8678 | "Couldnt find layer object for %s", |
| 8679 | snapshot->getDebugString().c_str()); |
| 8680 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
| 8681 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name); |
| 8682 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 8683 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 8684 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8685 | |
| 8686 | return layers; |
| 8687 | }; |
| 8688 | } |
| 8689 | |
| 8690 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8691 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 8692 | uint32_t uid, |
| 8693 | std::unordered_set<uint32_t> excludeLayerIds) { |
| 8694 | return [&, layerStack, uid, excludeLayerIds = std::move(excludeLayerIds)]() { |
| 8695 | if (excludeLayerIds.empty()) { |
| 8696 | auto getLayerSnapshotsFn = |
| 8697 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8698 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8699 | return layers; |
| 8700 | } |
| 8701 | |
| 8702 | frontend::LayerSnapshotBuilder::Args |
| 8703 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 8704 | .layerLifecycleManager = mLayerLifecycleManager, |
| 8705 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 8706 | .displays = mFrontEndDisplayInfos, |
| 8707 | .displayChanges = true, |
| 8708 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8709 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8710 | .forceFullDamage = mForceFullDamage, |
| 8711 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8712 | .supportedLayerGenericMetadata = |
| 8713 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8714 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8715 | .skipRoundCornersWhenProtected = |
| 8716 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8717 | mLayerSnapshotBuilder.update(args); |
| 8718 | |
| 8719 | auto getLayerSnapshotsFn = |
| 8720 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 8721 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8722 | |
| 8723 | args.excludeLayerIds.clear(); |
| 8724 | mLayerSnapshotBuilder.update(args); |
| 8725 | |
| 8726 | return layers; |
| 8727 | }; |
| 8728 | } |
| 8729 | |
| 8730 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8731 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 8732 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8733 | bool childrenOnly, |
| 8734 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8735 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8736 | parentCrop]() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8737 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8738 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8739 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8740 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8741 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8742 | .displays = mFrontEndDisplayInfos, |
| 8743 | .displayChanges = true, |
| 8744 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8745 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8746 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8747 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 8748 | .excludeLayerIds = std::move(excludeLayerIds), |
| 8749 | .supportedLayerGenericMetadata = |
| 8750 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 8751 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 8752 | .skipRoundCornersWhenProtected = |
| 8753 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8754 | mLayerSnapshotBuilder.update(args); |
| 8755 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 8756 | auto getLayerSnapshotsFn = |
| 8757 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8758 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 8759 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 8760 | args.parentCrop.reset(); |
| 8761 | args.excludeLayerIds.clear(); |
| 8762 | mLayerSnapshotBuilder.update(args); |
| 8763 | return layers; |
| 8764 | }; |
| 8765 | } |
| 8766 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8767 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 8768 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8769 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 8770 | // Locking: |
| 8771 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 8772 | // we must keep a copy of the transactions (specifically the composer |
| 8773 | // states) around outside the scope of the lock. |
| 8774 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 8775 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 8776 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 8777 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8778 | update.transactions = mTransactionHandler.flushTransactions(); |
| 8779 | { |
| 8780 | // TODO(b/238781169) lockless queue this and keep order. |
| 8781 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 8782 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 8783 | mCreatedLayers.clear(); |
| 8784 | update.newLayers = std::move(mNewLayers); |
| 8785 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8786 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 8787 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8788 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 8789 | mDestroyedHandles.clear(); |
| 8790 | } |
| 8791 | return update; |
| 8792 | } |
| 8793 | |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 8794 | void SurfaceFlinger::addToLayerTracing(bool visibleRegionDirty, TimePoint time, VsyncId vsyncId) { |
| 8795 | const uint32_t tracingFlags = mLayerTracing.getFlags(); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame^] | 8796 | perfetto::protos::LayersProto layers(dumpDrawingStateProto(tracingFlags)); |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 8797 | if (tracingFlags & LayerTracing::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8798 | dumpOffscreenLayersProto(layers); |
| 8799 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 8800 | std::string hwcDump; |
| 8801 | if (tracingFlags & LayerTracing::TRACE_HWC) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8802 | dumpHwc(hwcDump); |
| 8803 | } |
Diwas Sharma | 6975834 | 2023-09-01 00:40:19 +0000 | [diff] [blame] | 8804 | auto displays = dumpDisplayProto(); |
| 8805 | mLayerTracing.notify(visibleRegionDirty, time.ns(), ftl::to_underlying(vsyncId), &layers, |
| 8806 | std::move(hwcDump), &displays); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 8807 | } |
| 8808 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 8809 | // sfdo functions |
| 8810 | |
| 8811 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 8812 | auto future = mScheduler->schedule( |
| 8813 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 8814 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 8815 | future.wait(); |
| 8816 | } |
| 8817 | |
| 8818 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 8819 | if (delay > 0) { |
| 8820 | mDebugFlashDelay = delay; |
| 8821 | } else { |
| 8822 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 8823 | } |
| 8824 | scheduleRepaint(); |
| 8825 | } |
| 8826 | |
| 8827 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 8828 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 8829 | } |
| 8830 | |
| 8831 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 8832 | Mutex::Autolock lock(mStateLock); |
| 8833 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 8834 | } |
| 8835 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 8836 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8837 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8838 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 8839 | status_t status = checkAccessPermission(); |
| 8840 | if (status != OK) { |
| 8841 | return binderStatusFromStatusT(status); |
| 8842 | } |
| 8843 | mFlinger->bootFinished(); |
| 8844 | return binder::Status::ok(); |
| 8845 | } |
| 8846 | |
| 8847 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 8848 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8849 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8850 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 8851 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 8852 | if (conn == nullptr) { |
| 8853 | *outConnection = nullptr; |
| 8854 | return binderStatusFromStatusT(BAD_VALUE); |
| 8855 | } else { |
| 8856 | *outConnection = conn; |
| 8857 | return binder::Status::ok(); |
| 8858 | } |
| 8859 | } |
| 8860 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8861 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 8862 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8863 | if (client->initCheck() == NO_ERROR) { |
| 8864 | *outClient = client; |
| 8865 | return binder::Status::ok(); |
| 8866 | } else { |
| 8867 | *outClient = nullptr; |
| 8868 | return binderStatusFromStatusT(BAD_VALUE); |
| 8869 | } |
| 8870 | } |
| 8871 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8872 | binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8873 | float requestedRefreshRate, |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8874 | sp<IBinder>* outDisplay) { |
| 8875 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8876 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8877 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8878 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8879 | String8 displayName8 = String8::format("%s", displayName.c_str()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 8880 | *outDisplay = mFlinger->createDisplay(displayName8, secure, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8881 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8882 | } |
| 8883 | |
| 8884 | binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { |
| 8885 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8886 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8887 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8888 | } |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8889 | mFlinger->destroyDisplay(display); |
| 8890 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8891 | } |
| 8892 | |
| 8893 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 8894 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 8895 | std::vector<int64_t> displayIds; |
| 8896 | displayIds.reserve(physicalDisplayIds.size()); |
| 8897 | for (auto item : physicalDisplayIds) { |
| 8898 | displayIds.push_back(static_cast<int64_t>(item.value)); |
| 8899 | } |
| 8900 | *outDisplayIds = displayIds; |
| 8901 | return binder::Status::ok(); |
| 8902 | } |
| 8903 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8904 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 8905 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8906 | status_t status = checkAccessPermission(); |
| 8907 | if (status != OK) { |
| 8908 | return binderStatusFromStatusT(status); |
| 8909 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 8910 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 8911 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 8912 | return binder::Status::ok(); |
| 8913 | } |
| 8914 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8915 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 8916 | status_t status = checkAccessPermission(); |
| 8917 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8918 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8919 | } |
| 8920 | mFlinger->setPowerMode(display, mode); |
| 8921 | return binder::Status::ok(); |
| 8922 | } |
| 8923 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8924 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 8925 | std::vector<FrameEvent>* outSupported) { |
| 8926 | status_t status; |
| 8927 | if (!outSupported) { |
| 8928 | status = UNEXPECTED_NULL; |
| 8929 | } else { |
| 8930 | outSupported->clear(); |
| 8931 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 8932 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8933 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 8934 | } |
| 8935 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8936 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 8937 | gui::DisplayStatInfo* outStatInfo) { |
| 8938 | DisplayStatInfo statInfo; |
| 8939 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 8940 | if (status == NO_ERROR) { |
| 8941 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 8942 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 8943 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8944 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8945 | } |
| 8946 | |
| 8947 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 8948 | gui::DisplayState* outState) { |
| 8949 | ui::DisplayState state; |
| 8950 | status_t status = mFlinger->getDisplayState(display, &state); |
| 8951 | if (status == NO_ERROR) { |
| 8952 | outState->layerStack = state.layerStack.id; |
| 8953 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 8954 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 8955 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 8956 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 8957 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 8958 | } |
| 8959 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8960 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8961 | gui::StaticDisplayInfo* outInfo) { |
| 8962 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 8963 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 8964 | |
| 8965 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8966 | if (status == NO_ERROR) { |
| 8967 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 8968 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 8969 | outInfo->density = info.density; |
| 8970 | outInfo->secure = info.secure; |
| 8971 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 8972 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 8973 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 8974 | gui::DeviceProductInfo dinfo; |
| 8975 | dinfo.name = std::move(dpi->name); |
| 8976 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 8977 | dpi->manufacturerPnpId.end()); |
| 8978 | dinfo.productId = dpi->productId; |
| 8979 | dinfo.relativeAddress = |
| 8980 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 8981 | if (const auto* model = |
| 8982 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 8983 | gui::DeviceProductInfo::ModelYear modelYear; |
| 8984 | modelYear.year = model->year; |
| 8985 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 8986 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 8987 | &dpi->manufactureOrModelDate)) { |
| 8988 | gui::DeviceProductInfo::ManufactureYear date; |
| 8989 | date.modelYear.year = manufacture->year; |
| 8990 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 8991 | } else if (const auto* manufacture = |
| 8992 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 8993 | &dpi->manufactureOrModelDate)) { |
| 8994 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 8995 | date.manufactureYear.modelYear.year = manufacture->year; |
| 8996 | date.week = manufacture->week; |
| 8997 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 8998 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 8999 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9000 | outInfo->deviceProductInfo = dinfo; |
| 9001 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9002 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9003 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9004 | } |
| 9005 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9006 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9007 | gui::DynamicDisplayInfo*& outInfo) { |
| 9008 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9009 | outInfo->supportedDisplayModes.clear(); |
| 9010 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9011 | for (const auto& mode : info.supportedDisplayModes) { |
| 9012 | gui::DisplayMode outMode; |
| 9013 | outMode.id = mode.id; |
| 9014 | outMode.resolution.width = mode.resolution.width; |
| 9015 | outMode.resolution.height = mode.resolution.height; |
| 9016 | outMode.xDpi = mode.xDpi; |
| 9017 | outMode.yDpi = mode.yDpi; |
| 9018 | outMode.refreshRate = mode.refreshRate; |
| 9019 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9020 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9021 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9022 | outMode.group = mode.group; |
| 9023 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9024 | std::back_inserter(outMode.supportedHdrTypes), |
| 9025 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9026 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9027 | } |
| 9028 | |
| 9029 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9030 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9031 | |
| 9032 | outInfo->supportedColorModes.clear(); |
| 9033 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9034 | for (const auto& cmode : info.supportedColorModes) { |
| 9035 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9036 | } |
| 9037 | |
| 9038 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9039 | |
| 9040 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9041 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9042 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9043 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9044 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9045 | } |
| 9046 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9047 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9048 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9049 | |
| 9050 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9051 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9052 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9053 | } |
| 9054 | |
| 9055 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9056 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9057 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9058 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9059 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9060 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9061 | } |
| 9062 | return binderStatusFromStatusT(status); |
| 9063 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9064 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9065 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9066 | gui::DynamicDisplayInfo* outInfo) { |
| 9067 | ui::DynamicDisplayInfo info; |
| 9068 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9069 | if (status == NO_ERROR) { |
| 9070 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9071 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9072 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9073 | } |
| 9074 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9075 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9076 | gui::DisplayPrimaries* outPrimaries) { |
| 9077 | ui::DisplayPrimaries primaries; |
| 9078 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9079 | if (status == NO_ERROR) { |
| 9080 | outPrimaries->red.X = primaries.red.X; |
| 9081 | outPrimaries->red.Y = primaries.red.Y; |
| 9082 | outPrimaries->red.Z = primaries.red.Z; |
| 9083 | |
| 9084 | outPrimaries->green.X = primaries.green.X; |
| 9085 | outPrimaries->green.Y = primaries.green.Y; |
| 9086 | outPrimaries->green.Z = primaries.green.Z; |
| 9087 | |
| 9088 | outPrimaries->blue.X = primaries.blue.X; |
| 9089 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9090 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9091 | |
| 9092 | outPrimaries->white.X = primaries.white.X; |
| 9093 | outPrimaries->white.Y = primaries.white.Y; |
| 9094 | outPrimaries->white.Z = primaries.white.Z; |
| 9095 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9096 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9097 | } |
| 9098 | |
| 9099 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9100 | status_t status = checkAccessPermission(); |
| 9101 | if (status == OK) { |
| 9102 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9103 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9104 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9105 | } |
| 9106 | |
| 9107 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9108 | int displayModeId) { |
| 9109 | status_t status = checkAccessPermission(); |
| 9110 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9111 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9112 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9113 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9114 | } |
| 9115 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9116 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9117 | status_t status = checkAccessPermission(); |
| 9118 | if (status == OK) { |
| 9119 | status = mFlinger->clearBootDisplayMode(display); |
| 9120 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9121 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9122 | } |
| 9123 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9124 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9125 | status_t status = checkAccessPermission(); |
| 9126 | if (status == OK) { |
| 9127 | status = mFlinger->getOverlaySupport(outProperties); |
| 9128 | } |
| 9129 | return binderStatusFromStatusT(status); |
| 9130 | } |
| 9131 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9132 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9133 | status_t status = checkAccessPermission(); |
| 9134 | if (status == OK) { |
| 9135 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9136 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9137 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9138 | } |
| 9139 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9140 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9141 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9142 | status_t status = checkAccessPermission(); |
| 9143 | if (status == OK) { |
| 9144 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9145 | } |
| 9146 | return binderStatusFromStatusT(status); |
| 9147 | } |
| 9148 | |
| 9149 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9150 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9151 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9152 | status_t status = checkAccessPermission(); |
| 9153 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9154 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9155 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9156 | } |
| 9157 | return binderStatusFromStatusT(status); |
| 9158 | } |
| 9159 | |
| 9160 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9161 | status_t status = checkAccessPermission(); |
| 9162 | if (status == OK) { |
| 9163 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9164 | } |
| 9165 | return binderStatusFromStatusT(status); |
| 9166 | } |
| 9167 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9168 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9169 | status_t status = checkAccessPermission(); |
| 9170 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9171 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9172 | } |
| 9173 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9174 | return binder::Status::ok(); |
| 9175 | } |
| 9176 | |
| 9177 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9178 | status_t status = checkAccessPermission(); |
| 9179 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9180 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9181 | } |
| 9182 | mFlinger->setGameContentType(display, on); |
| 9183 | return binder::Status::ok(); |
| 9184 | } |
| 9185 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9186 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9187 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9188 | mFlinger->captureDisplay(args, captureListener); |
| 9189 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9190 | } |
| 9191 | |
| 9192 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
| 9193 | int64_t displayId, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9194 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9195 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9196 | const int uid = ipc->getCallingUid(); |
| 9197 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9198 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9199 | mFlinger->captureDisplay(*id, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9200 | } else { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9201 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9202 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9203 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9204 | } |
| 9205 | |
| 9206 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9207 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9208 | mFlinger->captureLayers(args, captureListener); |
| 9209 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9210 | } |
| 9211 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9212 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9213 | const std::vector<int32_t>& hdrTypes) { |
| 9214 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9215 | // permission dynamically. Don't use the permission cache for this check. |
| 9216 | status_t status = checkAccessPermission(false); |
| 9217 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9218 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9219 | } |
| 9220 | |
| 9221 | std::vector<ui::Hdr> hdrTypesVector; |
| 9222 | for (int32_t i : hdrTypes) { |
| 9223 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9224 | } |
| 9225 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9226 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9227 | } |
| 9228 | |
| 9229 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9230 | status_t status; |
| 9231 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9232 | if (uid != AID_SYSTEM) { |
| 9233 | status = PERMISSION_DENIED; |
| 9234 | } else { |
| 9235 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9236 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9237 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9238 | } |
| 9239 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9240 | binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) { |
| 9241 | if (!outLayers) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9242 | return binderStatusFromStatusT(UNEXPECTED_NULL); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9243 | } |
| 9244 | |
| 9245 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9246 | const int pid = ipc->getCallingPid(); |
| 9247 | const int uid = ipc->getCallingUid(); |
| 9248 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 9249 | 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] | 9250 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9251 | } |
| 9252 | status_t status = mFlinger->getLayerDebugInfo(outLayers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9253 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9254 | } |
| 9255 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9256 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9257 | ui::Dataspace dataspace; |
| 9258 | ui::PixelFormat pixelFormat; |
| 9259 | ui::Dataspace wideColorGamutDataspace; |
| 9260 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9261 | status_t status = |
| 9262 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9263 | &wideColorGamutPixelFormat); |
| 9264 | if (status == NO_ERROR) { |
| 9265 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9266 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9267 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9268 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9269 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9270 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9271 | } |
| 9272 | |
| 9273 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9274 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9275 | status_t status = checkAccessPermission(); |
| 9276 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9277 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9278 | } |
| 9279 | |
| 9280 | ui::PixelFormat format; |
| 9281 | ui::Dataspace dataspace; |
| 9282 | uint8_t componentMask; |
| 9283 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9284 | &componentMask); |
| 9285 | if (status == NO_ERROR) { |
| 9286 | outAttrs->format = static_cast<int32_t>(format); |
| 9287 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9288 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9289 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9290 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9291 | } |
| 9292 | |
| 9293 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9294 | bool enable, |
| 9295 | int8_t componentMask, |
| 9296 | int64_t maxFrames) { |
| 9297 | status_t status = checkAccessPermission(); |
| 9298 | if (status == OK) { |
| 9299 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9300 | static_cast<uint8_t>(componentMask), |
| 9301 | static_cast<uint64_t>(maxFrames)); |
| 9302 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9303 | return binderStatusFromStatusT(status); |
| 9304 | } |
| 9305 | |
| 9306 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9307 | int64_t maxFrames, int64_t timestamp, |
| 9308 | gui::DisplayedFrameStats* outStats) { |
| 9309 | if (!outStats) { |
| 9310 | return binderStatusFromStatusT(BAD_VALUE); |
| 9311 | } |
| 9312 | |
| 9313 | status_t status = checkAccessPermission(); |
| 9314 | if (status != OK) { |
| 9315 | return binderStatusFromStatusT(status); |
| 9316 | } |
| 9317 | |
| 9318 | DisplayedFrameStats stats; |
| 9319 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 9320 | static_cast<uint64_t>(timestamp), &stats); |
| 9321 | if (status == NO_ERROR) { |
| 9322 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 9323 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 9324 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 9325 | for (const auto& s : stats.component_0_sample) { |
| 9326 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 9327 | } |
| 9328 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 9329 | for (const auto& s : stats.component_1_sample) { |
| 9330 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 9331 | } |
| 9332 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 9333 | for (const auto& s : stats.component_2_sample) { |
| 9334 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 9335 | } |
| 9336 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 9337 | for (const auto& s : stats.component_3_sample) { |
| 9338 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 9339 | } |
| 9340 | } |
| 9341 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9342 | } |
| 9343 | |
| 9344 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 9345 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9346 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9347 | } |
| 9348 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9349 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 9350 | bool* outIsWideColorDisplay) { |
| 9351 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9352 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9353 | } |
| 9354 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9355 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 9356 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 9357 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9358 | status_t status = checkReadFrameBufferPermission(); |
| 9359 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9360 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9361 | } |
| 9362 | android::Rect rect; |
| 9363 | rect.left = samplingArea.left; |
| 9364 | rect.top = samplingArea.top; |
| 9365 | rect.right = samplingArea.right; |
| 9366 | rect.bottom = samplingArea.bottom; |
| 9367 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9368 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9369 | } |
| 9370 | |
| 9371 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 9372 | const sp<gui::IRegionSamplingListener>& listener) { |
| 9373 | status_t status = checkReadFrameBufferPermission(); |
| 9374 | if (status == OK) { |
| 9375 | status = mFlinger->removeRegionSamplingListener(listener); |
| 9376 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9377 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9378 | } |
| 9379 | |
| 9380 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 9381 | const sp<gui::IFpsListener>& listener) { |
| 9382 | status_t status = checkReadFrameBufferPermission(); |
| 9383 | if (status == OK) { |
| 9384 | status = mFlinger->addFpsListener(taskId, listener); |
| 9385 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9386 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9387 | } |
| 9388 | |
| 9389 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 9390 | status_t status = checkReadFrameBufferPermission(); |
| 9391 | if (status == OK) { |
| 9392 | status = mFlinger->removeFpsListener(listener); |
| 9393 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9394 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9395 | } |
| 9396 | |
| 9397 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 9398 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9399 | status_t status = checkAccessPermission(); |
| 9400 | if (status == OK) { |
| 9401 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 9402 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9403 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9404 | } |
| 9405 | |
| 9406 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 9407 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 9408 | status_t status = checkAccessPermission(); |
| 9409 | if (status == OK) { |
| 9410 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 9411 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9412 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9413 | } |
| 9414 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9415 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9416 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9417 | status_t status = checkAccessPermission(); |
| 9418 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9419 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9420 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9421 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 9425 | gui::DisplayModeSpecs* outSpecs) { |
| 9426 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9427 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9428 | } |
| 9429 | |
| 9430 | status_t status = checkAccessPermission(); |
| 9431 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9432 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9433 | } |
| 9434 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 9435 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9436 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9437 | } |
| 9438 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9439 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 9440 | bool* outSupport) { |
| 9441 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9442 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9443 | } |
| 9444 | |
| 9445 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 9446 | const gui::DisplayBrightness& brightness) { |
| 9447 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9448 | if (status == OK) { |
| 9449 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 9450 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9451 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9452 | } |
| 9453 | |
| 9454 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 9455 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9456 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9457 | if (status == OK) { |
| 9458 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 9459 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9460 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9461 | } |
| 9462 | |
| 9463 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 9464 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 9465 | status_t status = checkControlDisplayBrightnessPermission(); |
| 9466 | if (status == OK) { |
| 9467 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 9468 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9469 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9470 | } |
| 9471 | |
| 9472 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 9473 | status_t status = checkAccessPermission(); |
| 9474 | if (status == OK) { |
| 9475 | status = mFlinger->notifyPowerBoost(boostId); |
| 9476 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9477 | return binderStatusFromStatusT(status); |
| 9478 | } |
| 9479 | |
| 9480 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 9481 | const gui::Color& spotColor, |
| 9482 | float lightPosY, float lightPosZ, |
| 9483 | float lightRadius) { |
| 9484 | status_t status = checkAccessPermission(); |
| 9485 | if (status != OK) { |
| 9486 | return binderStatusFromStatusT(status); |
| 9487 | } |
| 9488 | |
| 9489 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 9490 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 9491 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 9492 | lightPosZ, lightRadius); |
| 9493 | return binderStatusFromStatusT(status); |
| 9494 | } |
| 9495 | |
| 9496 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 9497 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 9498 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 9499 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 9500 | if (status != NO_ERROR) { |
| 9501 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 9502 | return binderStatusFromStatusT(status); |
| 9503 | } |
| 9504 | |
| 9505 | if (!support || !support.has_value()) { |
| 9506 | outSupport->reset(); |
| 9507 | } else { |
| 9508 | outSupport->emplace(); |
| 9509 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 9510 | outSupport->value().alphaInterpretation = |
| 9511 | static_cast<int32_t>(support->alphaInterpretation); |
| 9512 | } |
| 9513 | |
| 9514 | return binder::Status::ok(); |
| 9515 | } |
| 9516 | |
| 9517 | binder::Status SurfaceComposerAIDL::setOverrideFrameRate(int32_t uid, float frameRate) { |
| 9518 | status_t status; |
| 9519 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9520 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9521 | status = mFlinger->setOverrideFrameRate(uid, frameRate); |
| 9522 | } else { |
| 9523 | ALOGE("setOverrideFrameRate() permission denied for uid: %d", c_uid); |
| 9524 | status = PERMISSION_DENIED; |
| 9525 | } |
| 9526 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9527 | } |
| 9528 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9529 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 9530 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 9531 | return binder::Status::ok(); |
| 9532 | } |
| 9533 | |
| 9534 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 9535 | mFlinger->sfdo_setDebugFlash(delay); |
| 9536 | return binder::Status::ok(); |
| 9537 | } |
| 9538 | |
| 9539 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 9540 | mFlinger->sfdo_scheduleComposite(); |
| 9541 | return binder::Status::ok(); |
| 9542 | } |
| 9543 | |
| 9544 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 9545 | mFlinger->sfdo_scheduleCommit(); |
| 9546 | return binder::Status::ok(); |
| 9547 | } |
| 9548 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 9549 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& uids, |
| 9550 | const std::vector<float>& thresholds) { |
| 9551 | status_t status; |
| 9552 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9553 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9554 | if (uids.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
| 9555 | |
| 9556 | std::vector<std::pair<uid_t, float>> mappings; |
| 9557 | const size_t size = uids.size(); |
| 9558 | mappings.reserve(size); |
| 9559 | for (int i = 0; i < size; i++) { |
| 9560 | auto row = std::make_pair(static_cast<uid_t>(uids[i]), thresholds[i]); |
| 9561 | mappings.push_back(row); |
| 9562 | } |
| 9563 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 9564 | } else { |
| 9565 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 9566 | status = PERMISSION_DENIED; |
| 9567 | } |
| 9568 | return binderStatusFromStatusT(status); |
| 9569 | } |
| 9570 | |
| 9571 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t uid, float threshold) { |
| 9572 | status_t status; |
| 9573 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 9574 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 9575 | status = mFlinger->setSmallAreaDetectionThreshold(uid, threshold); |
| 9576 | } else { |
| 9577 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 9578 | status = PERMISSION_DENIED; |
| 9579 | } |
| 9580 | return binderStatusFromStatusT(status); |
| 9581 | } |
| 9582 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9583 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 9584 | *outPriority = mFlinger->getGpuContextPriority(); |
| 9585 | return binder::Status::ok(); |
| 9586 | } |
| 9587 | |
| 9588 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 9589 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9590 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9591 | } |
| 9592 | |
| 9593 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9594 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 9595 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9596 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9597 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9598 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9599 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 9600 | // WindowInfosListeners |
| 9601 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9602 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9603 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9604 | } else { |
| 9605 | status = PERMISSION_DENIED; |
| 9606 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9607 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9608 | } |
| 9609 | |
| 9610 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 9611 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 9612 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9613 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9614 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 9615 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 9616 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9617 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 9618 | } else { |
| 9619 | status = PERMISSION_DENIED; |
| 9620 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9621 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9622 | } |
| 9623 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9624 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 9625 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 9626 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 9627 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 9628 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 9629 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 9630 | } |
| 9631 | |
| 9632 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 9633 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 9634 | if (stalledTransactionInfo) { |
| 9635 | gui::StalledTransactionInfo result; |
| 9636 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 9637 | result.bufferId = stalledTransactionInfo->bufferId, |
| 9638 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 9639 | outInfo->emplace(std::move(result)); |
| 9640 | } else { |
| 9641 | outInfo->reset(); |
| 9642 | } |
| 9643 | return binderStatusFromStatusT(status); |
| 9644 | } |
| 9645 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9646 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 9647 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 9648 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9649 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 9650 | ipc->getCallingUid()); |
| 9651 | return PERMISSION_DENIED; |
| 9652 | } |
| 9653 | return OK; |
| 9654 | } |
| 9655 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9656 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 9657 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9658 | const int pid = ipc->getCallingPid(); |
| 9659 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 9660 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9661 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 9662 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 9663 | return PERMISSION_DENIED; |
| 9664 | } |
| 9665 | return OK; |
| 9666 | } |
| 9667 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 9668 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 9669 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9670 | const int pid = ipc->getCallingPid(); |
| 9671 | const int uid = ipc->getCallingUid(); |
| 9672 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 9673 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 9674 | return PERMISSION_DENIED; |
| 9675 | } |
| 9676 | return OK; |
| 9677 | } |
| 9678 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 9679 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 9680 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 9681 | } |
| 9682 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 9683 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 9684 | for (const auto& [_, display] : mDisplays) { |
| 9685 | if (display->getLayerStack() == layerStack) { |
| 9686 | return display.get(); |
| 9687 | } |
| 9688 | } |
| 9689 | return nullptr; |
| 9690 | } |
| 9691 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 9692 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 9693 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 9694 | #if defined(__gl_h_) |
| 9695 | #error "don't include gl/gl.h in this file" |
| 9696 | #endif |
| 9697 | |
| 9698 | #if defined(__gl2_h_) |
| 9699 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 9700 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 9701 | |
| 9702 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 9703 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |