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> |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 43 | #include <common/FlagManager.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 44 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 45 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 46 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 47 | #include <compositionengine/DisplayColorProfile.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 48 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 49 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 50 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 51 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 52 | #include <compositionengine/RenderSurface.h> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 53 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 54 | #include <compositionengine/impl/OutputCompositionState.h> |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 55 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 56 | #include <configstore/Utils.h> |
| 57 | #include <cutils/compiler.h> |
| 58 | #include <cutils/properties.h> |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 59 | #include <fmt/format.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 60 | #include <ftl/algorithm.h> |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 61 | #include <ftl/concat.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 62 | #include <ftl/fake_guard.h> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 63 | #include <ftl/future.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 64 | #include <ftl/unit.h> |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 65 | #include <gui/AidlStatusUtil.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 66 | #include <gui/BufferQueue.h> |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 67 | #include <gui/DebugEGLImageTracker.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 68 | #include <gui/IProducerListener.h> |
Lloyd Pique | 4603f3c | 2020-02-11 12:06:56 -0800 | [diff] [blame] | 69 | #include <gui/LayerMetadata.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 70 | #include <gui/LayerState.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 71 | #include <gui/Surface.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 72 | #include <gui/SurfaceComposerClient.h> |
rnlee | 60f46b5 | 2021-05-21 15:14:07 -0700 | [diff] [blame] | 73 | #include <gui/TraceUtils.h> |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 74 | #include <hidl/ServiceManagement.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 75 | #include <layerproto/LayerProtoParser.h> |
Elliott Hughes | e3ffd13 | 2023-06-28 19:45:15 +0000 | [diff] [blame] | 76 | #include <linux/sched/types.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 77 | #include <log/log.h> |
| 78 | #include <private/android_filesystem_config.h> |
| 79 | #include <private/gui/SyncFeatures.h> |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 80 | #include <processgroup/processgroup.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 81 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 82 | #include <renderengine/impl/ExternalTexture.h> |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 83 | #include <scheduler/FrameTargeter.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 84 | #include <sys/types.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 85 | #include <ui/ColorSpace.h> |
| 86 | #include <ui/DebugUtils.h> |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 87 | #include <ui/DisplayId.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 88 | #include <ui/DisplayMode.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 89 | #include <ui/DisplayStatInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 90 | #include <ui/DisplayState.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 91 | #include <ui/DynamicDisplayInfo.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 92 | #include <ui/GraphicBufferAllocator.h> |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 93 | #include <ui/HdrRenderTypeUtils.h> |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 94 | #include <ui/LayerStack.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 95 | #include <ui/PixelFormat.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 96 | #include <ui/StaticDisplayInfo.h> |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 97 | #include <unistd.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | #include <utils/StopWatch.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 99 | #include <utils/String16.h> |
| 100 | #include <utils/String8.h> |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 101 | #include <utils/Timers.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 102 | #include <utils/misc.h> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 103 | #include <algorithm> |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 104 | #include <cerrno> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 105 | #include <cinttypes> |
| 106 | #include <cmath> |
| 107 | #include <cstdint> |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 108 | #include <filesystem> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 109 | #include <functional> |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 110 | #include <memory> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 111 | #include <mutex> |
| 112 | #include <optional> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 113 | #include <string> |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 114 | #include <type_traits> |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 115 | #include <unordered_map> |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 116 | #include <vector> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Alec Mouri | 9b133ca | 2023-11-14 19:00:01 +0000 | [diff] [blame] | 118 | #include <common/FlagManager.h> |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 119 | #include <gui/LayerStatePermissions.h> |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 120 | #include <gui/SchedulingPolicy.h> |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 121 | #include <gui/SyncScreenCaptureListener.h> |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 122 | #include <ui/DisplayIdentification.h> |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 123 | #include "BackgroundExecutor.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 124 | #include "Client.h" |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 125 | #include "ClientCache.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 126 | #include "Colorizer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 127 | #include "DisplayDevice.h" |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 128 | #include "DisplayHardware/ComposerHal.h" |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 129 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 130 | #include "DisplayHardware/HWComposer.h" |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 131 | #include "DisplayHardware/Hal.h" |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 132 | #include "DisplayHardware/PowerAdvisor.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 133 | #include "DisplayHardware/VirtualDisplaySurface.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 134 | #include "DisplayRenderArea.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 135 | #include "Effects/Daltonizer.h" |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 136 | #include "FpsReporter.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 137 | #include "FrameTimeline/FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 138 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 139 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 140 | #include "FrontEnd/LayerHandle.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 141 | #include "FrontEnd/LayerLifecycleManager.h" |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 142 | #include "FrontEnd/LayerLog.h" |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 143 | #include "FrontEnd/LayerSnapshot.h" |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 144 | #include "HdrLayerInfoReporter.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 145 | #include "Layer.h" |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 146 | #include "LayerProtoHelper.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 147 | #include "LayerRenderArea.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 148 | #include "LayerVector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 149 | #include "MutexUtils.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 150 | #include "NativeWindowSurface.h" |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 151 | #include "RegionSamplingThread.h" |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 152 | #include "RenderAreaBuilder.h" |
Ana Krulec | fefcb58 | 2018-08-07 14:22:37 -0700 | [diff] [blame] | 153 | #include "Scheduler/EventThread.h" |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 154 | #include "Scheduler/LayerHistory.h" |
Ana Krulec | 98b5b24 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 155 | #include "Scheduler/Scheduler.h" |
Ady Abraham | c581d3c | 2020-08-06 17:34:27 -0700 | [diff] [blame] | 156 | #include "Scheduler/VsyncConfiguration.h" |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 157 | #include "Scheduler/VsyncModulator.h" |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 158 | #include "ScreenCaptureOutput.h" |
Alec Mouri | 5f487d4 | 2020-02-06 09:26:19 -0800 | [diff] [blame] | 159 | #include "SurfaceFlingerProperties.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 160 | #include "TimeStats/TimeStats.h" |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 161 | #include "TunnelModeEnabledReporter.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 162 | #include "Utils/Dumper.h" |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 163 | #include "WindowInfosListenerInvoker.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 164 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 165 | #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 166 | #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 167 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 168 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 169 | #undef NO_THREAD_SAFETY_ANALYSIS |
| 170 | #define NO_THREAD_SAFETY_ANALYSIS \ |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 171 | _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] | 172 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | namespace android { |
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 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 233 | std::chrono::milliseconds getIdleTimerTimeout(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 234 | if (const int32_t displayIdleTimerMs = |
| 235 | base::GetIntProperty("debug.sf.set_idle_timer_ms_"s + |
| 236 | std::to_string(displayId.value), |
| 237 | 0); |
| 238 | displayIdleTimerMs > 0) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 239 | return std::chrono::milliseconds(displayIdleTimerMs); |
| 240 | } |
| 241 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 242 | const int32_t setIdleTimerMs = base::GetIntProperty("debug.sf.set_idle_timer_ms"s, 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 243 | const int32_t millis = setIdleTimerMs ? setIdleTimerMs : sysprop::set_idle_timer_ms(0); |
| 244 | return std::chrono::milliseconds(millis); |
| 245 | } |
| 246 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 247 | bool getKernelIdleTimerSyspropConfig(PhysicalDisplayId displayId) { |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 248 | const bool displaySupportKernelIdleTimer = |
| 249 | base::GetBoolProperty("debug.sf.support_kernel_idle_timer_"s + |
| 250 | std::to_string(displayId.value), |
| 251 | false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 252 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 253 | return displaySupportKernelIdleTimer || sysprop::support_kernel_idle_timer(false); |
Ady Abraham | 6d88593 | 2021-09-03 18:05:48 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 256 | bool isAbove4k30(const ui::DisplayMode& outMode) { |
| 257 | using fps_approx_ops::operator>; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 258 | Fps refreshRate = Fps::fromValue(outMode.peakRefreshRate); |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 259 | return outMode.resolution.getWidth() >= FOUR_K_WIDTH && |
| 260 | outMode.resolution.getHeight() >= FOUR_K_HEIGHT && refreshRate > 30_Hz; |
| 261 | } |
| 262 | |
| 263 | void excludeDolbyVisionIf4k30Present(const std::vector<ui::Hdr>& displayHdrTypes, |
| 264 | ui::DisplayMode& outMode) { |
| 265 | if (isAbove4k30(outMode) && |
| 266 | std::any_of(displayHdrTypes.begin(), displayHdrTypes.end(), |
| 267 | [](ui::Hdr type) { return type == ui::Hdr::DOLBY_VISION_4K30; })) { |
| 268 | for (ui::Hdr type : displayHdrTypes) { |
| 269 | if (type != ui::Hdr::DOLBY_VISION_4K30 && type != ui::Hdr::DOLBY_VISION) { |
| 270 | outMode.supportedHdrTypes.push_back(type); |
| 271 | } |
| 272 | } |
| 273 | } else { |
| 274 | for (ui::Hdr type : displayHdrTypes) { |
| 275 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 276 | outMode.supportedHdrTypes.push_back(type); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | HdrCapabilities filterOut4k30(const HdrCapabilities& displayHdrCapabilities) { |
| 283 | std::vector<ui::Hdr> hdrTypes; |
| 284 | for (ui::Hdr type : displayHdrCapabilities.getSupportedHdrTypes()) { |
| 285 | if (type != ui::Hdr::DOLBY_VISION_4K30) { |
| 286 | hdrTypes.push_back(type); |
| 287 | } |
| 288 | } |
| 289 | return {hdrTypes, displayHdrCapabilities.getDesiredMaxLuminance(), |
| 290 | displayHdrCapabilities.getDesiredMaxAverageLuminance(), |
| 291 | displayHdrCapabilities.getDesiredMinLuminance()}; |
| 292 | } |
| 293 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 294 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 295 | if (!surfaceControl) { |
| 296 | return UNASSIGNED_LAYER_ID; |
| 297 | } |
| 298 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 299 | } |
| 300 | |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 301 | /** |
| 302 | * Returns true if the file at path exists and is newer than duration. |
| 303 | */ |
| 304 | bool fileNewerThan(const std::string& path, std::chrono::minutes duration) { |
| 305 | using Clock = std::filesystem::file_time_type::clock; |
| 306 | std::error_code error; |
| 307 | std::filesystem::file_time_type updateTime = std::filesystem::last_write_time(path, error); |
| 308 | if (error) { |
| 309 | return false; |
| 310 | } |
| 311 | return duration > (Clock::now() - updateTime); |
| 312 | } |
| 313 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 314 | bool isFrameIntervalOnCadence(TimePoint expectedPresentTime, TimePoint lastExpectedPresentTimestamp, |
| 315 | Fps lastFrameInterval, Period timeout, Duration threshold) { |
| 316 | if (lastFrameInterval.getPeriodNsecs() == 0) { |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | const auto expectedPresentTimeDeltaNs = |
| 321 | expectedPresentTime.ns() - lastExpectedPresentTimestamp.ns(); |
| 322 | |
| 323 | if (expectedPresentTimeDeltaNs > timeout.ns()) { |
| 324 | return false; |
| 325 | } |
| 326 | |
| 327 | const auto expectedPresentPeriods = static_cast<nsecs_t>( |
| 328 | std::round(static_cast<float>(expectedPresentTimeDeltaNs) / |
| 329 | static_cast<float>(lastFrameInterval.getPeriodNsecs()))); |
| 330 | const auto calculatedPeriodsOutNs = lastFrameInterval.getPeriodNsecs() * expectedPresentPeriods; |
| 331 | const auto calculatedExpectedPresentTimeNs = |
| 332 | lastExpectedPresentTimestamp.ns() + calculatedPeriodsOutNs; |
| 333 | const auto presentTimeDelta = |
| 334 | std::abs(expectedPresentTime.ns() - calculatedExpectedPresentTimeNs); |
| 335 | return presentTimeDelta < threshold.ns(); |
| 336 | } |
| 337 | |
| 338 | bool isExpectedPresentWithinTimeout(TimePoint expectedPresentTime, |
| 339 | TimePoint lastExpectedPresentTimestamp, |
| 340 | std::optional<Period> timeoutOpt, Duration threshold) { |
| 341 | if (!timeoutOpt) { |
| 342 | // Always within timeout if timeoutOpt is absent and don't send hint |
| 343 | // for the timeout |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | if (timeoutOpt->ns() == 0) { |
| 348 | // Always outside timeout if timeoutOpt is 0 and always send |
| 349 | // the hint for the timeout. |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | if (expectedPresentTime.ns() < lastExpectedPresentTimestamp.ns() + timeoutOpt->ns()) { |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | // Check if within the threshold as it can be just outside the timeout |
| 358 | return std::abs(expectedPresentTime.ns() - |
| 359 | (lastExpectedPresentTimestamp.ns() + timeoutOpt->ns())) < threshold.ns(); |
| 360 | } |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 361 | } // namespace anonymous |
| 362 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | // --------------------------------------------------------------------------- |
| 364 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 365 | const String16 sHardwareTest("android.permission.HARDWARE_TEST"); |
| 366 | const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"); |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 367 | const String16 sRotateSurfaceFlinger("android.permission.ROTATE_SURFACE_FLINGER"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 368 | const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER"); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 369 | const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS"); |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 370 | const String16 sDump("android.permission.DUMP"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 371 | const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT"); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 372 | const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW"); |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 373 | const String16 sWakeupSurfaceFlinger("android.permission.WAKEUP_SURFACE_FLINGER"); |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 374 | |
Amy Hsu | c8cdfef | 2020-05-07 13:06:25 +0800 | [diff] [blame] | 375 | const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled"; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 376 | |
| 377 | // --------------------------------------------------------------------------- |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 378 | int64_t SurfaceFlinger::dispSyncPresentTimeOffset; |
| 379 | bool SurfaceFlinger::useHwcForRgbToYuv; |
| 380 | bool SurfaceFlinger::hasSyncFramework; |
| 381 | int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; |
| 382 | int64_t SurfaceFlinger::minAcquiredBuffers = 1; |
| 383 | uint32_t SurfaceFlinger::maxGraphicsWidth; |
| 384 | uint32_t SurfaceFlinger::maxGraphicsHeight; |
| 385 | bool SurfaceFlinger::useContextPriority; |
| 386 | Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; |
| 387 | ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
| 388 | Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; |
| 389 | ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 390 | LatchUnsignaledConfig SurfaceFlinger::enableLatchUnsignaledConfig; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 391 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 392 | std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { |
| 393 | switch(displayColorSetting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 394 | case DisplayColorSetting::kManaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 395 | return std::string("Managed"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 396 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 397 | return std::string("Unmanaged"); |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 398 | case DisplayColorSetting::kEnhanced: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 399 | return std::string("Enhanced"); |
| 400 | default: |
| 401 | return std::string("Unknown ") + |
| 402 | std::to_string(static_cast<int>(displayColorSetting)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 403 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 406 | bool callingThreadHasPermission(const String16& permission) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 407 | IPCThreadState* ipc = IPCThreadState::self(); |
| 408 | const int pid = ipc->getCallingPid(); |
| 409 | const int uid = ipc->getCallingUid(); |
| 410 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 411 | PermissionCache::checkPermission(permission, pid, uid); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 414 | ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; |
| 415 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 416 | SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) |
| 417 | : mFactory(factory), |
| 418 | mPid(getpid()), |
Yiwei Zhang | f0229a7 | 2019-09-09 19:28:02 -0700 | [diff] [blame] | 419 | mTimeStats(std::make_shared<impl::TimeStats>()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 420 | mFrameTracer(mFactory.createFrameTracer()), |
| 421 | mFrameTimeline(mFactory.createFrameTimeline(mTimeStats, mPid)), |
| 422 | mCompositionEngine(mFactory.createCompositionEngine()), |
| 423 | mHwcServiceName(base::GetProperty("debug.sf.hwc_service_name"s, "default"s)), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 424 | mTunnelModeEnabledReporter(sp<TunnelModeEnabledReporter>::make()), |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 425 | mEmulatedDisplayDensity(getDensityFromProperty("qemu.sf.lcd_density", false)), |
| 426 | mInternalDisplayDensity( |
| 427 | getDensityFromProperty("ro.sf.lcd_density", !mEmulatedDisplayDensity)), |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 428 | mPowerAdvisor(std::make_unique<Hwc2::impl::PowerAdvisor>(*this)), |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 429 | mWindowInfosListenerInvoker(sp<WindowInfosListenerInvoker>::make()), |
| 430 | mSkipPowerOnForQuiescent(base::GetBoolProperty("ro.boot.quiescent"s, false)) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 431 | ALOGI("Using HWComposer service: %s", mHwcServiceName.c_str()); |
| 432 | } |
Fabien Sanglard | 0cc1938 | 2017-03-06 11:54:40 -0800 | [diff] [blame] | 433 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 434 | SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { |
| 435 | ATRACE_CALL(); |
| 436 | ALOGI("SurfaceFlinger is starting"); |
| 437 | |
| 438 | hasSyncFramework = running_without_sync_framework(true); |
| 439 | |
| 440 | dispSyncPresentTimeOffset = present_time_offset_from_vsync_ns(0); |
| 441 | |
| 442 | useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); |
| 443 | |
| 444 | maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); |
| 445 | minAcquiredBuffers = |
| 446 | SurfaceFlingerProperties::min_acquired_buffers().value_or(minAcquiredBuffers); |
| 447 | |
| 448 | maxGraphicsWidth = std::max(max_graphics_width(0), 0); |
| 449 | maxGraphicsHeight = std::max(max_graphics_height(0), 0); |
| 450 | |
| 451 | mSupportsWideColor = has_wide_color_display(false); |
| 452 | mDefaultCompositionDataspace = |
| 453 | static_cast<ui::Dataspace>(default_composition_dataspace(Dataspace::V0_SRGB)); |
| 454 | mWideColorGamutCompositionDataspace = static_cast<ui::Dataspace>(wcg_composition_dataspace( |
| 455 | mSupportsWideColor ? Dataspace::DISPLAY_P3 : Dataspace::V0_SRGB)); |
| 456 | defaultCompositionDataspace = mDefaultCompositionDataspace; |
| 457 | wideColorGamutCompositionDataspace = mWideColorGamutCompositionDataspace; |
| 458 | defaultCompositionPixelFormat = static_cast<ui::PixelFormat>( |
| 459 | default_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 460 | wideColorGamutCompositionPixelFormat = |
| 461 | static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888)); |
| 462 | |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 463 | mLayerCachingEnabled = |
| 464 | base::GetBoolProperty("debug.sf.enable_layer_caching"s, |
| 465 | sysprop::SurfaceFlingerProperties::enable_layer_caching() |
| 466 | .value_or(false)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 467 | |
| 468 | useContextPriority = use_context_priority(true); |
| 469 | |
| 470 | mInternalDisplayPrimaries = sysprop::getDisplayNativePrimaries(); |
| 471 | |
| 472 | // debugging stuff... |
| 473 | char value[PROPERTY_VALUE_MAX]; |
| 474 | |
| 475 | property_get("ro.build.type", value, "user"); |
| 476 | mIsUserBuild = strcmp(value, "user") == 0; |
| 477 | |
| 478 | mDebugFlashDelay = base::GetUintProperty("debug.sf.showupdates"s, 0u); |
| 479 | |
| 480 | mBackpressureGpuComposition = base::GetBoolProperty("debug.sf.enable_gl_backpressure"s, true); |
| 481 | ALOGI_IF(mBackpressureGpuComposition, "Enabling backpressure for GPU composition"); |
| 482 | |
| 483 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 484 | bool supportsBlurs = atoi(value); |
| 485 | mSupportsBlur = supportsBlurs; |
| 486 | ALOGI_IF(!mSupportsBlur, "Disabling blur effects, they are not supported."); |
| 487 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 488 | property_get("debug.sf.luma_sampling", value, "1"); |
| 489 | mLumaSampling = atoi(value); |
| 490 | |
| 491 | property_get("debug.sf.disable_client_composition_cache", value, "0"); |
| 492 | mDisableClientCompositionCache = atoi(value); |
| 493 | |
| 494 | property_get("debug.sf.predict_hwc_composition_strategy", value, "1"); |
| 495 | mPredictCompositionStrategy = atoi(value); |
| 496 | |
| 497 | property_get("debug.sf.treat_170m_as_sRGB", value, "0"); |
| 498 | mTreat170mAsSrgb = atoi(value); |
| 499 | |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 500 | property_get("debug.sf.dim_in_gamma_in_enhanced_screenshots", value, 0); |
| 501 | mDimInGammaSpaceForEnhancedScreenshots = atoi(value); |
| 502 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 503 | mIgnoreHwcPhysicalDisplayOrientation = |
| 504 | base::GetBoolProperty("debug.sf.ignore_hwc_physical_display_orientation"s, false); |
| 505 | |
| 506 | // We should be reading 'persist.sys.sf.color_saturation' here |
| 507 | // but since /data may be encrypted, we need to wait until after vold |
| 508 | // comes online to attempt to read the property. The property is |
| 509 | // instead read after the boot animation |
| 510 | |
| 511 | if (base::GetBoolProperty("debug.sf.treble_testing_override"s, false)) { |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 512 | // Without the override SurfaceFlinger cannot connect to HIDL |
| 513 | // services that are not listed in the manifests. Considered |
| 514 | // deriving the setting from the set service name, but it |
| 515 | // would be brittle if the name that's not 'default' is used |
| 516 | // for production purposes later on. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 517 | ALOGI("Enabling Treble testing override"); |
Steven Moreland | 7c8af94 | 2020-07-08 18:35:51 +0000 | [diff] [blame] | 518 | android::hardware::details::setTrebleTestingOverride(true); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 519 | } |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 520 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 521 | // TODO (b/270966065) Update the HWC based refresh rate overlay to support spinner |
| 522 | mRefreshRateOverlaySpinner = property_get_bool("debug.sf.show_refresh_rate_overlay_spinner", 0); |
| 523 | mRefreshRateOverlayRenderRate = |
| 524 | property_get_bool("debug.sf.show_refresh_rate_overlay_render_rate", 0); |
| 525 | mRefreshRateOverlayShowInMiddle = |
| 526 | property_get_bool("debug.sf.show_refresh_rate_overlay_in_middle", 0); |
| 527 | |
| 528 | if (!mIsUserBuild && base::GetBoolProperty("debug.sf.enable_transaction_tracing"s, true)) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 529 | mTransactionTracing.emplace(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 530 | mLayerTracing.setTransactionTracing(*mTransactionTracing); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 531 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 532 | |
| 533 | mIgnoreHdrCameraLayers = ignore_hdr_camera_layers(false); |
| 534 | |
| 535 | mLayerLifecycleManagerEnabled = |
Vishnu Nair | f42d9bd | 2023-08-23 21:35:33 +0000 | [diff] [blame] | 536 | base::GetBoolProperty("persist.debug.sf.enable_layer_lifecycle_manager"s, true); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 537 | |
| 538 | // These are set by the HWC implementation to indicate that they will use the workarounds. |
| 539 | mIsHotplugErrViaNegVsync = |
| 540 | base::GetBoolProperty("debug.sf.hwc_hotplug_error_via_neg_vsync"s, false); |
| 541 | |
| 542 | mIsHdcpViaNegVsync = base::GetBoolProperty("debug.sf.hwc_hdcp_via_neg_vsync"s, false); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | LatchUnsignaledConfig SurfaceFlinger::getLatchUnsignaledConfig() { |
Ady Abraham | d9e8d1b | 2022-02-25 00:36:10 +0000 | [diff] [blame] | 546 | if (base::GetBoolProperty("debug.sf.auto_latch_unsignaled"s, true)) { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 547 | return LatchUnsignaledConfig::AutoSingleLayer; |
| 548 | } |
| 549 | |
| 550 | return LatchUnsignaledConfig::Disabled; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 553 | SurfaceFlinger::~SurfaceFlinger() = default; |
| 554 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 555 | void SurfaceFlinger::binderDied(const wp<IBinder>&) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 556 | // the window manager died on us. prepare its eulogy. |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 557 | mBootFinished = false; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 558 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 559 | static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 560 | // Sever the link to inputflinger since it's gone as well. |
| 561 | mInputFlinger.clear(); |
Vishnu Nair | b9df470 | 2021-03-01 11:53:15 -0800 | [diff] [blame] | 562 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 563 | initializeDisplays(); |
| 564 | })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 565 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 566 | mInitBootPropsFuture.callOnce([this] { |
| 567 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 568 | }); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 569 | |
| 570 | mInitBootPropsFuture.wait(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 573 | void SurfaceFlinger::run() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 574 | mScheduler->run(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 577 | sp<IBinder> SurfaceFlinger::createVirtualDisplay(const std::string& displayName, bool isSecure, |
| 578 | const std::string& uniqueId, |
| 579 | float requestedRefreshRate) { |
Patrick Williams | e58a92b | 2024-02-29 14:52:25 -0600 | [diff] [blame] | 580 | // SurfaceComposerAIDL checks for some permissions, but adding an additional check here. |
| 581 | // This is to ensure that only root, system, and graphics can request to create a secure |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 582 | // display. Secure displays can show secure content so we add an additional restriction on it. |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 583 | const uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 584 | if (isSecure && uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM) { |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 585 | ALOGE("Only privileged processes can create a secure display"); |
| 586 | return nullptr; |
| 587 | } |
| 588 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 589 | class DisplayToken : public BBinder { |
| 590 | sp<SurfaceFlinger> flinger; |
| 591 | virtual ~DisplayToken() { |
| 592 | // no more references, this display must be terminated |
| 593 | Mutex::Autolock _l(flinger->mStateLock); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 594 | flinger->mCurrentState.displays.removeItem(wp<IBinder>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 595 | flinger->setTransactionFlags(eDisplayTransactionNeeded); |
| 596 | } |
| 597 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 598 | explicit DisplayToken(const sp<SurfaceFlinger>& flinger) |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 599 | : flinger(flinger) { |
| 600 | } |
| 601 | }; |
| 602 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 603 | sp<BBinder> token = sp<DisplayToken>::make(sp<SurfaceFlinger>::fromExisting(this)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 604 | |
| 605 | Mutex::Autolock _l(mStateLock); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 606 | // Display ID is assigned when virtual display is allocated by HWC. |
| 607 | DisplayDeviceState state; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 608 | state.isSecure = isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 609 | // Set display as protected when marked as secure to ensure no behavior change |
| 610 | // TODO (b/314820005): separate as a different arg when creating the display. |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 611 | state.isProtected = isSecure; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 612 | state.displayName = displayName; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 613 | state.uniqueId = uniqueId; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 614 | state.requestedRefreshRate = Fps::fromValue(requestedRefreshRate); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 615 | mCurrentState.displays.add(token, state); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 616 | return token; |
| 617 | } |
| 618 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 619 | status_t SurfaceFlinger::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 620 | Mutex::Autolock lock(mStateLock); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 621 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 622 | const ssize_t index = mCurrentState.displays.indexOfKey(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 623 | if (index < 0) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 624 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 625 | return NAME_NOT_FOUND; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 628 | const DisplayDeviceState& state = mCurrentState.displays.valueAt(index); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 629 | if (state.physical) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 630 | ALOGE("%s: Invalid operation on physical display", __func__); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 631 | return INVALID_OPERATION; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 632 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 633 | mCurrentState.displays.removeItemsAt(index); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 634 | setTransactionFlags(eDisplayTransactionNeeded); |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 635 | return NO_ERROR; |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 638 | void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { |
| 639 | auto& generator = mVirtualDisplayIdGenerators.hal; |
| 640 | if (!generator && enable) { |
| 641 | ALOGI("Enabling HAL virtual displays"); |
| 642 | generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); |
| 643 | } else if (generator && !enable) { |
| 644 | ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); |
| 645 | generator.reset(); |
| 646 | } |
| 647 | } |
| 648 | |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 649 | VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, |
| 650 | ui::PixelFormat format) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 651 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 652 | if (const auto id = generator->generateId()) { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 653 | if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format)) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 654 | return *id; |
| 655 | } |
| 656 | |
| 657 | generator->releaseId(*id); |
| 658 | } else { |
| 659 | ALOGW("%s: Exhausted HAL virtual displays", __func__); |
| 660 | } |
| 661 | |
| 662 | ALOGW("%s: Falling back to GPU virtual display", __func__); |
| 663 | } |
| 664 | |
| 665 | const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); |
| 666 | LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); |
| 667 | return *id; |
| 668 | } |
| 669 | |
| 670 | void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { |
| 671 | if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { |
| 672 | if (auto& generator = mVirtualDisplayIdGenerators.hal) { |
| 673 | generator->releaseId(*id); |
| 674 | } |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | const auto id = GpuVirtualDisplayId::tryCast(displayId); |
| 679 | LOG_ALWAYS_FATAL_IF(!id); |
| 680 | mVirtualDisplayIdGenerators.gpu.releaseId(*id); |
| 681 | } |
| 682 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 683 | std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() const { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 684 | std::vector<PhysicalDisplayId> displayIds; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 685 | displayIds.reserve(mPhysicalDisplays.size()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 686 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 687 | const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 688 | displayIds.push_back(defaultDisplayId); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 689 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 690 | for (const auto& [id, display] : mPhysicalDisplays) { |
Ady Abraham | 2a0066d | 2021-07-15 20:16:58 -0700 | [diff] [blame] | 691 | if (id != defaultDisplayId) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 692 | displayIds.push_back(id); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 693 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 694 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 695 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 696 | return displayIds; |
| 697 | } |
| 698 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 699 | std::optional<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdLocked( |
| 700 | const sp<display::DisplayToken>& displayToken) const { |
| 701 | return ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 702 | .transform(&ftl::to_key<PhysicalDisplays>); |
| 703 | } |
| 704 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 705 | sp<IBinder> SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { |
| 706 | Mutex::Autolock lock(mStateLock); |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 707 | return getPhysicalDisplayTokenLocked(displayId); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 710 | HWComposer& SurfaceFlinger::getHwComposer() const { |
| 711 | return mCompositionEngine->getHwComposer(); |
| 712 | } |
| 713 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 714 | renderengine::RenderEngine& SurfaceFlinger::getRenderEngine() const { |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 715 | return *mRenderEngine; |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 718 | compositionengine::CompositionEngine& SurfaceFlinger::getCompositionEngine() const { |
| 719 | return *mCompositionEngine.get(); |
| 720 | } |
| 721 | |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 722 | void SurfaceFlinger::bootFinished() { |
Rob Carr | 2aa78cb | 2020-03-10 14:27:49 -0700 | [diff] [blame] | 723 | if (mBootFinished == true) { |
| 724 | ALOGE("Extra call to bootFinished"); |
| 725 | return; |
| 726 | } |
| 727 | mBootFinished = true; |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 728 | FlagManager::getMutableInstance().markBootCompleted(); |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 729 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 730 | mInitBootPropsFuture.wait(); |
| 731 | mRenderEnginePrimeCacheFuture.wait(); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 732 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | const nsecs_t now = systemTime(); |
| 734 | const nsecs_t duration = now - mBootTime; |
Steve Block | a19954a | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 735 | ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 736 | |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 737 | mFrameTracer->initialize(); |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 738 | mFrameTimeline->onBootFinished(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 739 | getRenderEngine().setEnableTracing(FlagManager::getInstance().use_skia_tracing()); |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 740 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 741 | // wait patiently for the window manager death |
| 742 | const String16 name("window"); |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 743 | mWindowManager = defaultServiceManager()->waitForService(name); |
Steven Moreland | a904bb9 | 2019-07-02 17:37:23 -0700 | [diff] [blame] | 744 | if (mWindowManager != 0) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 745 | mWindowManager->linkToDeath(sp<IBinder::DeathRecipient>::fromExisting(this)); |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // stop boot animation |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 749 | // formerly we would just kill the process, but we now ask it to exit so it |
| 750 | // can choose where to stop the animation. |
| 751 | property_set("service.bootanim.exit", "1"); |
Yusuke Sato | 0a688f5 | 2015-07-30 23:05:39 -0700 | [diff] [blame] | 752 | |
| 753 | const int LOGTAG_SF_STOP_BOOTANIM = 60110; |
| 754 | LOG_EVENT_LONG(LOGTAG_SF_STOP_BOOTANIM, |
| 755 | ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 756 | |
Cody Heiner | bcfa7fa | 2023-04-17 18:34:30 -0700 | [diff] [blame] | 757 | sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 758 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 759 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 760 | if (input == nullptr) { |
| 761 | ALOGE("Failed to link to input service"); |
| 762 | } else { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 763 | mInputFlinger = interface_cast<os::IInputFlinger>(input); |
Denis Hsu | e70cc6c | 2020-06-17 10:17:30 +0800 | [diff] [blame] | 764 | } |
| 765 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 766 | readPersistentProperties(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 767 | const bool hintSessionEnabled = FlagManager::getInstance().use_adpf_cpu_hint(); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 768 | mPowerAdvisor->enablePowerHintSession(hintSessionEnabled); |
| 769 | const bool hintSessionUsed = mPowerAdvisor->usePowerHintSession(); |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 770 | // Ordering is important here, as onBootFinished signals to PowerAdvisor that concurrency |
| 771 | // is safe because its variables are initialized. |
| 772 | mPowerAdvisor->onBootFinished(); |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 773 | ALOGD("Power hint is %s", |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 774 | hintSessionUsed ? "supported" : (hintSessionEnabled ? "unsupported" : "disabled")); |
| 775 | if (hintSessionUsed) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 776 | std::optional<pid_t> renderEngineTid = getRenderEngine().getRenderEngineTid(); |
| 777 | std::vector<int32_t> tidList; |
| 778 | tidList.emplace_back(gettid()); |
| 779 | if (renderEngineTid.has_value()) { |
| 780 | tidList.emplace_back(*renderEngineTid); |
| 781 | } |
Matt Buckley | 547cc0c | 2023-10-27 22:22:36 +0000 | [diff] [blame] | 782 | if (!mPowerAdvisor->startPowerHintSession(std::move(tidList))) { |
Matt Buckley | 618c43f | 2022-08-12 18:09:48 +0000 | [diff] [blame] | 783 | ALOGW("Cannot start power hint session"); |
Xiang Wang | e12b4fa | 2022-03-25 23:48:40 +0000 | [diff] [blame] | 784 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 787 | mBootStage = BootStage::FINISHED; |
Ana Krulec | bd6654b | 2019-02-15 15:18:15 -0800 | [diff] [blame] | 788 | |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 789 | if (base::GetBoolProperty("sf.debug.show_refresh_rate_overlay"s, false)) { |
| 790 | ftl::FakeGuard guard(mStateLock); |
| 791 | enableRefreshRateOverlay(true); |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 792 | } |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 793 | })); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 796 | void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& builder) { |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 797 | char prop[PROPERTY_VALUE_MAX]; |
Leon Scroggins III | f840ae5 | 2024-01-25 15:10:12 -0500 | [diff] [blame] | 798 | property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, ""); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 799 | |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 800 | // TODO: b/293371537 - Once GraphiteVk is deemed relatively stable, log a warning that |
| 801 | // PROPERTY_DEBUG_RENDERENGINE_BACKEND is deprecated |
Alec Mouri | e2b61c6 | 2023-08-15 19:04:54 +0000 | [diff] [blame] | 802 | if (strcmp(prop, "skiagl") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 803 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 804 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 805 | } else if (strcmp(prop, "skiaglthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 806 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 807 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::GL); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 808 | } else if (strcmp(prop, "skiavk") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 809 | builder.setThreaded(renderengine::RenderEngine::Threaded::NO) |
| 810 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 811 | } else if (strcmp(prop, "skiavkthreaded") == 0) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 812 | builder.setThreaded(renderengine::RenderEngine::Threaded::YES) |
| 813 | .setGraphicsApi(renderengine::RenderEngine::GraphicsApi::VK); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 814 | } else { |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 815 | const auto kVulkan = renderengine::RenderEngine::GraphicsApi::VK; |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 816 | const bool useGraphite = FlagManager::getInstance().graphite_renderengine() && |
| 817 | renderengine::RenderEngine::canSupport(kVulkan); |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 818 | const bool useVulkan = useGraphite || |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 819 | (FlagManager::getInstance().vulkan_renderengine() && |
| 820 | renderengine::RenderEngine::canSupport(kVulkan)); |
Nolan Scobie | 576e77f | 2024-03-26 10:59:59 -0400 | [diff] [blame] | 821 | |
| 822 | builder.setSkiaBackend(useGraphite ? renderengine::RenderEngine::SkiaBackend::GRAPHITE |
| 823 | : renderengine::RenderEngine::SkiaBackend::GANESH); |
Leon Scroggins III | f3369ed | 2024-02-16 17:52:42 -0500 | [diff] [blame] | 824 | builder.setGraphicsApi(useVulkan ? kVulkan : renderengine::RenderEngine::GraphicsApi::GL); |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 828 | /** |
| 829 | * Choose a suggested blurring algorithm if supportsBlur is true. By default Kawase will be |
| 830 | * suggested as it's faster than a full Gaussian blur and looks close enough. |
| 831 | */ |
| 832 | renderengine::RenderEngine::BlurAlgorithm chooseBlurAlgorithm(bool supportsBlur) { |
| 833 | if (!supportsBlur) { |
| 834 | return renderengine::RenderEngine::BlurAlgorithm::NONE; |
| 835 | } |
| 836 | |
| 837 | auto const algorithm = base::GetProperty(PROPERTY_DEBUG_RENDERENGINE_BLUR_ALGORITHM, ""); |
| 838 | if (algorithm == "gaussian") { |
| 839 | return renderengine::RenderEngine::BlurAlgorithm::GAUSSIAN; |
| 840 | } else { |
| 841 | return renderengine::RenderEngine::BlurAlgorithm::KAWASE; |
| 842 | } |
| 843 | } |
| 844 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 845 | void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { |
Parth Sane | 343626c | 2023-04-06 16:17:04 +0000 | [diff] [blame] | 846 | ATRACE_CALL(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 847 | ALOGI( "SurfaceFlinger's main thread ready to run. " |
| 848 | "Initializing graphics H/W..."); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 849 | addTransactionReadyFilters(); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 850 | Mutex::Autolock lock(mStateLock); |
Kevin DuBois | 413287f | 2019-02-25 08:46:47 -0800 | [diff] [blame] | 851 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 852 | // Get a RenderEngine for the given display / config (can't fail) |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 853 | // 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] | 854 | // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 855 | auto builder = renderengine::RenderEngineCreationArgs::Builder() |
| 856 | .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) |
| 857 | .setImageCacheSize(maxFrameBufferAcquiredBuffers) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 858 | .setEnableProtectedContext(enable_protected_contents(false)) |
| 859 | .setPrecacheToneMapperShaderOnly(false) |
Robin Lee | 7338bd9 | 2024-04-04 14:05:07 +0000 | [diff] [blame] | 860 | .setBlurAlgorithm(chooseBlurAlgorithm(mSupportsBlur)) |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 861 | .setContextPriority( |
| 862 | useContextPriority |
| 863 | ? renderengine::RenderEngine::ContextPriority::REALTIME |
| 864 | : renderengine::RenderEngine::ContextPriority::MEDIUM); |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 865 | chooseRenderEngineType(builder); |
Patrick Williams | 0a525a4 | 2022-10-26 20:20:50 +0000 | [diff] [blame] | 866 | mRenderEngine = renderengine::RenderEngine::create(builder.build()); |
| 867 | mCompositionEngine->setRenderEngine(mRenderEngine.get()); |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 868 | mMaxRenderTargetSize = |
| 869 | std::min(getRenderEngine().getMaxTextureSize(), getRenderEngine().getMaxViewportDims()); |
Wei Wang | 976a645 | 2021-06-11 15:26:00 -0700 | [diff] [blame] | 870 | |
| 871 | // Set SF main policy after initializing RenderEngine which has its own policy. |
| 872 | if (!SetTaskProfiles(0, {"SFMainPolicy"})) { |
| 873 | ALOGW("Failed to set main task profile"); |
| 874 | } |
| 875 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 876 | mCompositionEngine->setTimeStats(mTimeStats); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 877 | mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 878 | mCompositionEngine->getHwComposer().setCallback(*this); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 879 | ClientCache::getInstance().setRenderEngine(&getRenderEngine()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 880 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 881 | mHasReliablePresentFences = |
| 882 | !getHwComposer().hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE); |
| 883 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 884 | enableLatchUnsignaledConfig = getLatchUnsignaledConfig(); |
| 885 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 886 | if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { |
| 887 | enableHalVirtualDisplays(true); |
| 888 | } |
| 889 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 890 | // Process hotplug for displays connected at boot. |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 891 | LOG_ALWAYS_FATAL_IF(!configureLocked(), |
| 892 | "Initial display configuration failed: HWC did not hotplug"); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 893 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 894 | // Commit primary display. |
| 895 | sp<const DisplayDevice> display; |
| 896 | if (const auto indexOpt = mCurrentState.getDisplayIndex(getPrimaryDisplayIdLocked())) { |
| 897 | const auto& displays = mCurrentState.displays; |
| 898 | |
| 899 | const auto& token = displays.keyAt(*indexOpt); |
| 900 | const auto& state = displays.valueAt(*indexOpt); |
| 901 | |
| 902 | processDisplayAdded(token, state); |
| 903 | mDrawingState.displays.add(token, state); |
| 904 | |
| 905 | display = getDefaultDisplayDeviceLocked(); |
| 906 | } |
| 907 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 908 | LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); |
| 909 | LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(display->getPhysicalId()), |
| 910 | "Primary display is disconnected"); |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 911 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 912 | // TODO(b/241285876): The Scheduler needlessly depends on creating the CompositionEngine part of |
| 913 | // the DisplayDevice, hence the above commit of the primary display. Remove that special case by |
| 914 | // initializing the Scheduler after configureLocked, once decoupled from DisplayDevice. |
| 915 | initScheduler(display); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 916 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 917 | mLayerTracing.setTakeLayersSnapshotProtoFunction([&](uint32_t traceFlags) { |
| 918 | auto snapshot = perfetto::protos::LayersSnapshotProto{}; |
| 919 | mScheduler |
| 920 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 921 | snapshot = takeLayersSnapshotProto(traceFlags, TimePoint::now(), |
| 922 | mLastCommittedVsyncId, true); |
| 923 | }) |
| 924 | .wait(); |
| 925 | return snapshot; |
| 926 | }); |
| 927 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 928 | // Commit secondary display(s). |
| 929 | processDisplayChangesLocked(); |
| 930 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 931 | // initialize our drawing state |
| 932 | mDrawingState = mCurrentState; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 933 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 934 | onActiveDisplayChangedLocked(nullptr, *display); |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 935 | |
| 936 | static_cast<void>(mScheduler->schedule( |
| 937 | [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); })); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 938 | |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 939 | mPowerAdvisor->init(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 940 | |
Bruno BELANYI | fd02878 | 2023-10-13 14:39:53 +0000 | [diff] [blame] | 941 | if (base::GetBoolProperty("service.sf.prime_shader_cache"s, true)) { |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 942 | if (setSchedFifo(false) != NO_ERROR) { |
| 943 | ALOGW("Can't set SCHED_OTHER for primeCache"); |
| 944 | } |
| 945 | |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 946 | mRenderEnginePrimeCacheFuture.callOnce([this] { |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 947 | renderengine::PrimeCacheConfig config; |
| 948 | config.cacheHolePunchLayer = |
| 949 | base::GetBoolProperty("debug.sf.prime_shader_cache.hole_punch"s, true); |
| 950 | config.cacheSolidLayers = |
| 951 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_layers"s, true); |
| 952 | config.cacheSolidDimmedLayers = |
| 953 | base::GetBoolProperty("debug.sf.prime_shader_cache.solid_dimmed_layers"s, true); |
| 954 | config.cacheImageLayers = |
| 955 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_layers"s, true); |
| 956 | config.cacheImageDimmedLayers = |
| 957 | base::GetBoolProperty("debug.sf.prime_shader_cache.image_dimmed_layers"s, true); |
| 958 | config.cacheClippedLayers = |
| 959 | base::GetBoolProperty("debug.sf.prime_shader_cache.clipped_layers"s, true); |
| 960 | config.cacheShadowLayers = |
| 961 | base::GetBoolProperty("debug.sf.prime_shader_cache.shadow_layers"s, true); |
| 962 | config.cachePIPImageLayers = |
| 963 | base::GetBoolProperty("debug.sf.prime_shader_cache.pip_image_layers"s, true); |
| 964 | config.cacheTransparentImageDimmedLayers = base:: |
| 965 | GetBoolProperty("debug.sf.prime_shader_cache.transparent_image_dimmed_layers"s, |
| 966 | true); |
| 967 | config.cacheClippedDimmedImageLayers = base:: |
| 968 | GetBoolProperty("debug.sf.prime_shader_cache.clipped_dimmed_image_layers"s, |
| 969 | true); |
| 970 | // ro.surface_flinger.prime_chader_cache.ultrahdr exists as a previous ro property |
| 971 | // which we maintain for backwards compatibility. |
| 972 | config.cacheUltraHDR = |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 973 | base::GetBoolProperty("ro.surface_flinger.prime_shader_cache.ultrahdr"s, false); |
Russell Myers | 3348c74 | 2024-04-29 20:22:42 +0000 | [diff] [blame] | 974 | return getRenderEngine().primeCache(config); |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 975 | }); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 976 | |
| 977 | if (setSchedFifo(true) != NO_ERROR) { |
linkai | d696a4f | 2023-11-14 10:13:36 +0800 | [diff] [blame] | 978 | ALOGW("Can't set SCHED_FIFO after primeCache"); |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 979 | } |
Steven Thomas | 137d4bc | 2019-07-25 16:55:14 -0700 | [diff] [blame] | 980 | } |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 981 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 982 | // Avoid blocking the main thread on `init` to set properties. |
Dominik Laskowski | d4a2275 | 2024-03-08 17:39:04 -0500 | [diff] [blame] | 983 | mInitBootPropsFuture.callOnce([this] { |
| 984 | return std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this); |
| 985 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 987 | initTransactionTraceWriter(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 988 | ALOGV("Done initializing"); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 991 | // During boot, offload `initBootProperties` to another thread. `property_set` depends on |
| 992 | // `property_service`, which may be delayed by slow operations like `mount_all --late` in |
| 993 | // the `init` process. See b/34499826 and b/63844978. |
| 994 | void SurfaceFlinger::initBootProperties() { |
| 995 | property_set("service.sf.present_timestamp", mHasReliablePresentFences ? "1" : "0"); |
| 996 | |
Dominik Laskowski | b0fdfe7 | 2024-02-21 10:42:23 -0500 | [diff] [blame] | 997 | if (base::GetBoolProperty("debug.sf.boot_animation"s, true)) { |
| 998 | // Reset and (if needed) start BootAnimation. |
| 999 | property_set("service.bootanim.exit", "0"); |
| 1000 | property_set("service.bootanim.progress", "0"); |
| 1001 | property_set("ctl.start", "bootanim"); |
| 1002 | } |
Dominik Laskowski | efb131e | 2024-02-16 10:57:40 -0500 | [diff] [blame] | 1003 | } |
| 1004 | |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1005 | void SurfaceFlinger::initTransactionTraceWriter() { |
| 1006 | if (!mTransactionTracing) { |
| 1007 | return; |
| 1008 | } |
| 1009 | TransactionTraceWriter::getInstance().setWriterFunction( |
| 1010 | [&](const std::string& filename, bool overwrite) { |
| 1011 | auto writeFn = [&]() { |
Patrick Williams | 8b731c1 | 2023-10-24 09:56:24 -0500 | [diff] [blame] | 1012 | if (!overwrite && fileNewerThan(filename, std::chrono::minutes{10})) { |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1013 | ALOGD("TransactionTraceWriter: file=%s already exists", filename.c_str()); |
| 1014 | return; |
| 1015 | } |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1016 | ALOGD("TransactionTraceWriter: writing file=%s", filename.c_str()); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1017 | mTransactionTracing->writeToFile(filename); |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 1018 | mTransactionTracing->flush(); |
Vishnu Nair | 8c5b700 | 2023-08-17 21:03:57 -0700 | [diff] [blame] | 1019 | }; |
| 1020 | if (std::this_thread::get_id() == mMainThreadId) { |
| 1021 | writeFn(); |
| 1022 | } else { |
| 1023 | mScheduler->schedule(writeFn).get(); |
| 1024 | } |
| 1025 | }); |
| 1026 | } |
| 1027 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1028 | void SurfaceFlinger::readPersistentProperties() { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1029 | Mutex::Autolock _l(mStateLock); |
| 1030 | |
Romain Guy | 11d63f4 | 2017-07-20 12:47:14 -0700 | [diff] [blame] | 1031 | char value[PROPERTY_VALUE_MAX]; |
| 1032 | |
| 1033 | property_get("persist.sys.sf.color_saturation", value, "1.0"); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1034 | mGlobalSaturationFactor = atof(value); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 1035 | updateColorMatrixLocked(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1036 | ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 1037 | |
| 1038 | property_get("persist.sys.sf.native_mode", value, "0"); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 1039 | mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value)); |
Peiyong Lin | a3ea559 | 2019-02-10 14:45:00 -0800 | [diff] [blame] | 1040 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1041 | mForceColorMode = |
| 1042 | 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] | 1043 | } |
| 1044 | |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1045 | status_t SurfaceFlinger::getSupportedFrameTimestamps( |
| 1046 | std::vector<FrameEvent>* outSupported) const { |
| 1047 | *outSupported = { |
| 1048 | FrameEvent::REQUESTED_PRESENT, |
| 1049 | FrameEvent::ACQUIRE, |
| 1050 | FrameEvent::LATCH, |
| 1051 | FrameEvent::FIRST_REFRESH_START, |
| 1052 | FrameEvent::LAST_REFRESH_START, |
| 1053 | FrameEvent::GPU_COMPOSITION_DONE, |
| 1054 | FrameEvent::DEQUEUE_READY, |
| 1055 | FrameEvent::RELEASE, |
| 1056 | }; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1057 | |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 1058 | if (mHasReliablePresentFences) { |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1059 | outSupported->push_back(FrameEvent::DISPLAY_PRESENT); |
| 1060 | } |
| 1061 | return NO_ERROR; |
| 1062 | } |
| 1063 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1064 | status_t SurfaceFlinger::getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState* state) { |
| 1065 | if (!displayToken || !state) { |
| 1066 | return BAD_VALUE; |
| 1067 | } |
| 1068 | |
| 1069 | Mutex::Autolock lock(mStateLock); |
| 1070 | |
| 1071 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1072 | if (!display) { |
| 1073 | return NAME_NOT_FOUND; |
| 1074 | } |
| 1075 | |
| 1076 | state->layerStack = display->getLayerStack(); |
| 1077 | state->orientation = display->getOrientation(); |
| 1078 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1079 | const Rect layerStackRect = display->getLayerStackSpaceRect(); |
| 1080 | state->layerStackSpaceRect = |
| 1081 | layerStackRect.isValid() ? layerStackRect.getSize() : display->getSize(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1082 | |
| 1083 | return NO_ERROR; |
| 1084 | } |
| 1085 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1086 | status_t SurfaceFlinger::getStaticDisplayInfo(int64_t displayId, ui::StaticDisplayInfo* info) { |
| 1087 | if (!info) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1088 | return BAD_VALUE; |
| 1089 | } |
| 1090 | |
| 1091 | Mutex::Autolock lock(mStateLock); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1092 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 1093 | const auto displayOpt = mPhysicalDisplays.get(*id).and_then(getDisplayDeviceAndSnapshot()); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1094 | |
| 1095 | if (!displayOpt) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1096 | return NAME_NOT_FOUND; |
| 1097 | } |
| 1098 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1099 | const auto& [display, snapshotRef] = *displayOpt; |
| 1100 | const auto& snapshot = snapshotRef.get(); |
| 1101 | |
| 1102 | info->connectionType = snapshot.connectionType(); |
| 1103 | info->deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1104 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1105 | if (mEmulatedDisplayDensity) { |
| 1106 | info->density = mEmulatedDisplayDensity; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1107 | } else { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1108 | info->density = info->connectionType == ui::DisplayConnectionType::Internal |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1109 | ? mInternalDisplayDensity |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1110 | : FALLBACK_DENSITY; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1111 | } |
Dominik Laskowski | d125d0e | 2020-05-08 12:36:39 -0700 | [diff] [blame] | 1112 | info->density /= ACONFIGURATION_DENSITY_MEDIUM; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1113 | |
| 1114 | info->secure = display->isSecure(); |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1115 | info->installOrientation = display->getPhysicalOrientation(); |
Vishnu Nair | d0a8965 | 2022-01-13 12:05:54 -0800 | [diff] [blame] | 1116 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1117 | return NO_ERROR; |
| 1118 | } |
| 1119 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1120 | void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info, |
| 1121 | const sp<DisplayDevice>& display, |
| 1122 | const display::DisplaySnapshot& snapshot) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1123 | const auto& displayModes = snapshot.displayModes(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1124 | info->supportedDisplayModes.clear(); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1125 | info->supportedDisplayModes.reserve(displayModes.size()); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1126 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1127 | for (const auto& [id, mode] : displayModes) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1128 | ui::DisplayMode outMode; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1129 | outMode.id = ftl::to_underlying(id); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1130 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 1131 | auto [width, height] = mode->getResolution(); |
| 1132 | auto [xDpi, yDpi] = mode->getDpi(); |
Yiwei Zhang | 27de5df | 2018-08-23 17:04:51 -0700 | [diff] [blame] | 1133 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 1134 | if (const auto physicalOrientation = display->getPhysicalOrientation(); |
| 1135 | physicalOrientation == ui::ROTATION_90 || physicalOrientation == ui::ROTATION_270) { |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1136 | std::swap(width, height); |
| 1137 | std::swap(xDpi, yDpi); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1140 | outMode.resolution = ui::Size(width, height); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1141 | |
Huan Song | f7eeb10 | 2022-03-28 11:02:38 -0700 | [diff] [blame] | 1142 | outMode.xDpi = xDpi; |
| 1143 | outMode.yDpi = yDpi; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1144 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1145 | const auto peakFps = mode->getPeakFps(); |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1146 | outMode.peakRefreshRate = peakFps.getValue(); |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 1147 | outMode.vsyncRate = mode->getVsyncRate().getValue(); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 1148 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1149 | const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate( |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 1150 | Fps::fromValue(outMode.peakRefreshRate)); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1151 | outMode.appVsyncOffset = vsyncConfigSet.late.appOffset; |
| 1152 | outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset; |
| 1153 | outMode.group = mode->getGroup(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1154 | |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1155 | // This is how far in advance a buffer must be queued for |
| 1156 | // presentation at a given time. If you want a buffer to appear |
| 1157 | // on the screen at time N, you must submit the buffer before |
| 1158 | // (N - presentationDeadline). |
| 1159 | // |
| 1160 | // Normally it's one full refresh period (to give SF a chance to |
| 1161 | // latch the buffer), but this can be reduced by configuring a |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 1162 | // VsyncController offset. Any additional delays introduced by the hardware |
Andy McFadden | 91b2ca8 | 2014-06-13 14:04:23 -0700 | [diff] [blame] | 1163 | // composer or panel must be accounted for here. |
| 1164 | // |
| 1165 | // We add an additional 1ms to allow for processing time and |
| 1166 | // differences between the ideal and actual refresh rate. |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1167 | outMode.presentationDeadline = peakFps.getPeriodNsecs() - outMode.sfVsyncOffset + 1000000; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1168 | excludeDolbyVisionIf4k30Present(display->getHdrCapabilities().getSupportedHdrTypes(), |
| 1169 | outMode); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1170 | info->supportedDisplayModes.push_back(outMode); |
Mathias Agopian | 8b736f1 | 2012-08-13 17:54:26 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1173 | info->supportedColorModes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1174 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1175 | const PhysicalDisplayId displayId = snapshot.displayId(); |
| 1176 | |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1177 | const auto mode = display->refreshRateSelector().getActiveMode(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1178 | info->activeDisplayModeId = ftl::to_underlying(mode.modePtr->getId()); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1179 | info->renderFrameRate = mode.fps.getValue(); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 1180 | info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 1181 | info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1182 | |
Marin Shalamanov | b173f75 | 2021-02-16 19:38:36 +0100 | [diff] [blame] | 1183 | info->autoLowLatencyModeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1184 | getHwComposer().hasDisplayCapability(displayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1185 | DisplayCapability::AUTO_LOW_LATENCY_MODE); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1186 | info->gameContentTypeSupported = |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1187 | getHwComposer().supportsContentType(displayId, hal::ContentType::GAME); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1188 | |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1189 | info->preferredBootDisplayMode = static_cast<ui::DisplayModeId>(-1); |
Kriti Dang | ac0a74d | 2022-03-16 11:52:35 +0100 | [diff] [blame] | 1190 | |
| 1191 | if (getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1192 | if (const auto hwcId = getHwComposer().getPreferredBootDisplayMode(displayId)) { |
| 1193 | if (const auto modeId = snapshot.translateModeId(*hwcId)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1194 | info->preferredBootDisplayMode = ftl::to_underlying(*modeId); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | } |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1198 | } |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 1199 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 1200 | status_t SurfaceFlinger::getDynamicDisplayInfoFromId(int64_t physicalDisplayId, |
| 1201 | ui::DynamicDisplayInfo* info) { |
| 1202 | if (!info) { |
| 1203 | return BAD_VALUE; |
| 1204 | } |
| 1205 | |
| 1206 | Mutex::Autolock lock(mStateLock); |
| 1207 | |
| 1208 | const auto id_ = |
| 1209 | DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(physicalDisplayId)); |
| 1210 | const auto displayOpt = mPhysicalDisplays.get(*id_).and_then(getDisplayDeviceAndSnapshot()); |
| 1211 | |
| 1212 | if (!displayOpt) { |
| 1213 | return NAME_NOT_FOUND; |
| 1214 | } |
| 1215 | |
| 1216 | const auto& [display, snapshotRef] = *displayOpt; |
| 1217 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
| 1218 | return NO_ERROR; |
| 1219 | } |
| 1220 | |
| 1221 | status_t SurfaceFlinger::getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken, |
| 1222 | ui::DynamicDisplayInfo* info) { |
| 1223 | if (!displayToken || !info) { |
| 1224 | return BAD_VALUE; |
| 1225 | } |
| 1226 | |
| 1227 | Mutex::Autolock lock(mStateLock); |
| 1228 | |
| 1229 | const auto displayOpt = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1230 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1231 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1232 | |
| 1233 | if (!displayOpt) { |
| 1234 | return NAME_NOT_FOUND; |
| 1235 | } |
| 1236 | |
| 1237 | const auto& [display, snapshotRef] = *displayOpt; |
| 1238 | getDynamicDisplayInfoInternal(info, display, snapshotRef.get()); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 1239 | return NO_ERROR; |
| 1240 | } |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 1241 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1242 | status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, |
| 1243 | DisplayStatInfo* outStats) { |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 1244 | if (!outStats) { |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1245 | return BAD_VALUE; |
| 1246 | } |
| 1247 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1248 | std::optional<PhysicalDisplayId> displayIdOpt; |
| 1249 | { |
| 1250 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1251 | if (displayToken) { |
| 1252 | displayIdOpt = getPhysicalDisplayIdLocked(displayToken); |
| 1253 | if (!displayIdOpt) { |
| 1254 | ALOGW("%s: Invalid physical display token %p", __func__, displayToken.get()); |
| 1255 | return NAME_NOT_FOUND; |
| 1256 | } |
| 1257 | } else { |
| 1258 | // TODO (b/277364366): Clients should be updated to pass in the display they |
| 1259 | // want, rather than us picking an arbitrary one (the active display, in this |
| 1260 | // case). |
| 1261 | displayIdOpt = mActiveDisplayId; |
| 1262 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1263 | } |
| 1264 | |
Leon Scroggins III | 4235ea0 | 2023-04-17 15:14:20 -0400 | [diff] [blame] | 1265 | const auto schedule = mScheduler->getVsyncSchedule(displayIdOpt); |
| 1266 | if (!schedule) { |
| 1267 | ALOGE("%s: Missing VSYNC schedule for display %s!", __func__, |
| 1268 | to_string(*displayIdOpt).c_str()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1269 | return NAME_NOT_FOUND; |
| 1270 | } |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1271 | outStats->vsyncTime = schedule->vsyncDeadlineAfter(TimePoint::now()).ns(); |
| 1272 | outStats->vsyncPeriod = schedule->period().ns(); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 1273 | return NO_ERROR; |
| 1274 | } |
| 1275 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1276 | void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { |
| 1277 | const auto mode = desiredMode.mode; |
| 1278 | const auto displayId = mode.modePtr->getPhysicalDisplayId(); |
| 1279 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1280 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
| 1281 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1282 | const auto display = getDisplayDeviceLocked(displayId); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1283 | if (!display) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1284 | ALOGW("%s: display is no longer valid", __func__); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 1285 | return; |
| 1286 | } |
| 1287 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1288 | const bool emitEvent = desiredMode.emitEvent; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 1289 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1290 | switch (display->setDesiredMode(std::move(desiredMode))) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1291 | case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: |
| 1292 | // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1293 | mScheduler->setRenderRate(displayId, display->refreshRateSelector().getActiveMode().fps, |
| 1294 | /*applyImmediately*/ true); |
Ady Abraham | 95a37e2 | 2023-01-18 22:57:28 -0800 | [diff] [blame] | 1295 | |
| 1296 | // Schedule a new frame to initiate the display mode switch. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1297 | scheduleComposite(FrameHint::kNone); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 1298 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1299 | // Start receiving vsync samples now, so that we can detect a period |
| 1300 | // switch. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1301 | mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 1302 | mode.modePtr.get()); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1303 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1304 | // As we called to set period, we will call to onRefreshRateChangeCompleted once |
| 1305 | // VsyncController model is locked. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 1306 | mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1307 | |
| 1308 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1309 | mScheduler->updatePhaseConfiguration(mode.fps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1310 | } |
| 1311 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1312 | mScheduler->setModeChangePending(true); |
| 1313 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1314 | case DisplayDevice::DesiredModeAction::InitiateRenderRateSwitch: |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1315 | mScheduler->setRenderRate(displayId, mode.fps, /*applyImmediately*/ false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1316 | |
| 1317 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1318 | mScheduler->updatePhaseConfiguration(mode.fps); |
Ady Abraham | 67434eb | 2022-12-01 17:48:12 -0800 | [diff] [blame] | 1319 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1320 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1321 | if (emitEvent) { |
| 1322 | dispatchDisplayModeChangeEvent(displayId, mode); |
| 1323 | } |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1324 | break; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1325 | case DisplayDevice::DesiredModeAction::None: |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1326 | break; |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1327 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1330 | status_t SurfaceFlinger::setActiveModeFromBackdoor(const sp<display::DisplayToken>& displayToken, |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1331 | DisplayModeId modeId, Fps minFps, Fps maxFps) { |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1332 | ATRACE_CALL(); |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1333 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 1334 | if (!displayToken) { |
| 1335 | return BAD_VALUE; |
| 1336 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 1337 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1338 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1339 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1340 | const auto displayOpt = |
| 1341 | FTL_FAKE_GUARD(mStateLock, |
| 1342 | ftl::find_if(mPhysicalDisplays, |
| 1343 | PhysicalDisplay::hasToken(displayToken)) |
| 1344 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1345 | .and_then(getDisplayDeviceAndSnapshot())); |
| 1346 | if (!displayOpt) { |
| 1347 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1348 | return NAME_NOT_FOUND; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1349 | } |
| 1350 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1351 | const auto& [display, snapshotRef] = *displayOpt; |
| 1352 | const auto& snapshot = snapshotRef.get(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1353 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1354 | const auto fpsOpt = snapshot.displayModes().get(modeId).transform( |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 1355 | [](const DisplayModePtr& mode) { return mode->getPeakFps(); }); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1356 | |
| 1357 | if (!fpsOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1358 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1359 | to_string(snapshot.displayId()).c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1360 | return BAD_VALUE; |
| 1361 | } |
| 1362 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1363 | const Fps fps = *fpsOpt; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1364 | const FpsRange physical = {fps, fps}; |
| 1365 | const FpsRange render = {minFps.isValid() ? minFps : fps, maxFps.isValid() ? maxFps : fps}; |
| 1366 | const FpsRanges ranges = {physical, render}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1367 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1368 | // Keep the old switching type. |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1369 | const bool allowGroupSwitching = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1370 | display->refreshRateSelector().getCurrentPolicy().allowGroupSwitching; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1371 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 1372 | const scheduler::RefreshRateSelector::DisplayManagerPolicy policy{modeId, ranges, ranges, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 1373 | allowGroupSwitching}; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1374 | |
| 1375 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 1376 | }); |
| 1377 | |
| 1378 | return future.get(); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1381 | void SurfaceFlinger::finalizeDisplayModeChange(DisplayDevice& display) { |
| 1382 | const auto displayId = display.getPhysicalId(); |
| 1383 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1384 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1385 | const auto pendingModeOpt = display.getPendingMode(); |
| 1386 | if (!pendingModeOpt) { |
| 1387 | // There is no pending mode change. This can happen if the active |
| 1388 | // display changed and the mode change happened on a different display. |
| 1389 | return; |
| 1390 | } |
Ady Abraham | faac6da | 2021-07-15 10:04:40 -0700 | [diff] [blame] | 1391 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1392 | const auto& activeMode = pendingModeOpt->mode; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1393 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1394 | if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) { |
| 1395 | auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken()); |
| 1396 | // We need to generate new sequenceId in order to recreate the display (and this |
| 1397 | // way the framebuffer). |
| 1398 | state.sequenceId = DisplayDeviceState{}.sequenceId; |
| 1399 | state.physical->activeMode = activeMode.modePtr.get(); |
| 1400 | processDisplayChangesLocked(); |
Marin Shalamanov | 993ddf4 | 2021-05-26 16:54:40 +0200 | [diff] [blame] | 1401 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1402 | // processDisplayChangesLocked will update all necessary components so we're done here. |
| 1403 | return; |
| 1404 | } |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 1405 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1406 | display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(), |
| 1407 | activeMode.fps); |
| 1408 | |
| 1409 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1410 | mScheduler->updatePhaseConfiguration(activeMode.fps); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | if (pendingModeOpt->emitEvent) { |
| 1414 | dispatchDisplayModeChangeEvent(displayId, activeMode); |
| 1415 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1418 | void SurfaceFlinger::dropModeRequest(const sp<DisplayDevice>& display) { |
| 1419 | display->clearDesiredMode(); |
| 1420 | if (display->getPhysicalId() == mActiveDisplayId) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1421 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1422 | mScheduler->setModeChangePending(false); |
| 1423 | } |
Ady Abraham | 53852a5 | 2019-05-28 18:07:44 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1426 | void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) { |
| 1427 | const auto activeModeOpt = display->getDesiredMode(); |
| 1428 | auto activeModePtr = activeModeOpt->mode.modePtr; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1429 | const auto displayId = activeModePtr->getPhysicalDisplayId(); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1430 | const auto renderFps = activeModeOpt->mode.fps; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1431 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1432 | dropModeRequest(display); |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 1433 | |
| 1434 | constexpr bool kAllowToEnable = true; |
| 1435 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take()); |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 1436 | mScheduler->setRenderRate(displayId, renderFps, /*applyImmediately*/ true); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1437 | |
| 1438 | if (displayId == mActiveDisplayId) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 1439 | mScheduler->updatePhaseConfiguration(renderFps); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1440 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1443 | void SurfaceFlinger::initiateDisplayModeChanges() { |
Alec Mouri | fe3dc94 | 2019-02-12 14:19:18 -0800 | [diff] [blame] | 1444 | ATRACE_CALL(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1445 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1446 | std::optional<PhysicalDisplayId> displayToUpdateImmediately; |
| 1447 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1448 | for (const auto& [id, physical] : mPhysicalDisplays) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1449 | const auto display = getDisplayDeviceLocked(id); |
| 1450 | if (!display) continue; |
| 1451 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1452 | auto desiredModeOpt = display->getDesiredMode(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 1453 | if (!desiredModeOpt) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1454 | continue; |
| 1455 | } |
| 1456 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1457 | const auto desiredModeId = desiredModeOpt->mode.modePtr->getId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1458 | const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1459 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 1460 | if (!displayModePtrOpt) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1461 | ALOGW("Desired display mode is no longer supported. Mode ID = %d", |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1462 | ftl::to_underlying(desiredModeId)); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1463 | continue; |
| 1464 | } |
| 1465 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1466 | ALOGV("%s changing active mode to %d(%s) for display %s", __func__, |
| 1467 | ftl::to_underlying(desiredModeId), |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1468 | to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), |
| 1469 | to_string(display->getId()).c_str()); |
| 1470 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 1471 | if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && |
| 1472 | display->getActiveMode() == desiredModeOpt->mode) { |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1473 | applyActiveMode(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1474 | continue; |
| 1475 | } |
| 1476 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1477 | // Desired active mode was set, it is different than the mode currently in use, however |
| 1478 | // allowed modes might have changed by the time we process the refresh. |
| 1479 | // Make sure the desired mode is still allowed |
| 1480 | if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) { |
| 1481 | dropModeRequest(display); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1482 | continue; |
| 1483 | } |
| 1484 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1485 | // TODO(b/142753666) use constrains |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1486 | hal::VsyncPeriodChangeConstraints constraints; |
| 1487 | constraints.desiredTimeNanos = systemTime(); |
| 1488 | constraints.seamlessRequired = false; |
| 1489 | hal::VsyncPeriodChangeTimeline outTimeline; |
| 1490 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1491 | if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1492 | continue; |
| 1493 | } |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 1494 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 1495 | display->refreshRateSelector().onModeChangeInitiated(); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 1496 | mScheduler->onNewVsyncPeriodChangeTimeline(outTimeline); |
| 1497 | |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1498 | if (outTimeline.refreshRequired) { |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 1499 | scheduleComposite(FrameHint::kNone); |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1500 | } else { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1501 | // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange` |
| 1502 | // for all displays. This was only needed when the loop iterated over `mDisplays` rather |
| 1503 | // than `mPhysicalDisplays`. |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1504 | displayToUpdateImmediately = display->getPhysicalId(); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | if (displayToUpdateImmediately) { |
Marin Shalamanov | dd59431 | 2021-11-09 16:37:37 +0100 | [diff] [blame] | 1509 | const auto display = getDisplayDeviceLocked(*displayToUpdateImmediately); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 1510 | finalizeDisplayModeChange(*display); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 1511 | |
| 1512 | const auto desiredModeOpt = display->getDesiredMode(); |
| 1513 | if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) { |
| 1514 | applyActiveMode(display); |
| 1515 | } |
Ana Krulec | a5bdd9d | 2019-01-29 19:00:58 -0800 | [diff] [blame] | 1516 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1517 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1518 | |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1519 | void SurfaceFlinger::disableExpensiveRendering() { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1520 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1521 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 4d5052d | 2022-03-23 10:35:47 -0700 | [diff] [blame] | 1522 | ATRACE_NAME(whence); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1523 | if (mPowerAdvisor->isUsingExpensiveRendering()) { |
Dominik Laskowski | bc6c860 | 2022-01-11 08:53:24 -0800 | [diff] [blame] | 1524 | for (const auto& [_, display] : mDisplays) { |
| 1525 | constexpr bool kDisable = false; |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 1526 | mPowerAdvisor->setExpensiveRenderingExpected(display->getId(), kDisable); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1529 | }); |
| 1530 | |
| 1531 | future.wait(); |
Alec Mouri | dea1ac5 | 2021-06-23 18:12:18 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1534 | status_t SurfaceFlinger::getDisplayNativePrimaries(const sp<IBinder>& displayToken, |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1535 | ui::DisplayPrimaries& primaries) { |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1536 | if (!displayToken) { |
| 1537 | return BAD_VALUE; |
| 1538 | } |
| 1539 | |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1540 | Mutex::Autolock lock(mStateLock); |
| 1541 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1542 | const auto display = ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1543 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>); |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1544 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1545 | return NAME_NOT_FOUND; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1548 | if (!display.transform(&PhysicalDisplay::isInternal).value()) { |
Dominik Laskowski | 3c36324 | 2022-04-07 10:44:12 -0700 | [diff] [blame] | 1549 | return INVALID_OPERATION; |
| 1550 | } |
| 1551 | |
| 1552 | // 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] | 1553 | primaries = mInternalDisplayPrimaries; |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1554 | return NO_ERROR; |
| 1555 | } |
| 1556 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1557 | status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode mode) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1558 | if (!displayToken) { |
| 1559 | return BAD_VALUE; |
| 1560 | } |
| 1561 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1562 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1563 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1564 | const auto displayOpt = |
| 1565 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1566 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1567 | .and_then(getDisplayDeviceAndSnapshot()); |
| 1568 | |
| 1569 | if (!displayOpt) { |
| 1570 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1571 | return NAME_NOT_FOUND; |
| 1572 | } |
| 1573 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1574 | const auto& [display, snapshotRef] = *displayOpt; |
| 1575 | const auto& snapshot = snapshotRef.get(); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 1576 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1577 | const auto modes = snapshot.filterColorModes(mSupportsWideColor); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1578 | const bool exists = std::find(modes.begin(), modes.end(), mode) != modes.end(); |
| 1579 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 1580 | if (mode < ui::ColorMode::NATIVE || !exists) { |
| 1581 | ALOGE("%s: Invalid color mode %s (%d) for display %s", whence, |
| 1582 | decodeColorMode(mode).c_str(), mode, to_string(snapshot.displayId()).c_str()); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1583 | return BAD_VALUE; |
| 1584 | } |
| 1585 | |
| 1586 | display->getCompositionDisplay()->setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 1587 | {mode, Dataspace::UNKNOWN, RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 1588 | |
| 1589 | return NO_ERROR; |
| 1590 | }); |
| 1591 | |
Dominik Laskowski | 0a5f921 | 2021-08-05 17:00:04 -0700 | [diff] [blame] | 1592 | // TODO(b/195698395): Propagate error. |
| 1593 | future.wait(); |
| 1594 | return NO_ERROR; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 1595 | } |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1596 | |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1597 | status_t SurfaceFlinger::getBootDisplayModeSupport(bool* outSupport) const { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 1598 | auto future = mScheduler->schedule( |
| 1599 | [this] { return getHwComposer().hasCapability(Capability::BOOT_DISPLAY_CONFIG); }); |
| 1600 | |
| 1601 | *outSupport = future.get(); |
| 1602 | return NO_ERROR; |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1605 | status_t SurfaceFlinger::getOverlaySupport(gui::OverlayProperties* outProperties) const { |
| 1606 | const auto& aidlProperties = getHwComposer().getOverlaySupport(); |
| 1607 | // convert aidl OverlayProperties to gui::OverlayProperties |
| 1608 | outProperties->combinations.reserve(aidlProperties.combinations.size()); |
| 1609 | for (const auto& combination : aidlProperties.combinations) { |
| 1610 | std::vector<int32_t> pixelFormats; |
| 1611 | pixelFormats.reserve(combination.pixelFormats.size()); |
| 1612 | std::transform(combination.pixelFormats.cbegin(), combination.pixelFormats.cend(), |
| 1613 | std::back_inserter(pixelFormats), |
| 1614 | [](const auto& val) { return static_cast<int32_t>(val); }); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1615 | std::vector<int32_t> standards; |
| 1616 | standards.reserve(combination.standards.size()); |
| 1617 | std::transform(combination.standards.cbegin(), combination.standards.cend(), |
| 1618 | std::back_inserter(standards), |
| 1619 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1620 | std::vector<int32_t> transfers; |
| 1621 | transfers.reserve(combination.transfers.size()); |
| 1622 | std::transform(combination.transfers.cbegin(), combination.transfers.cend(), |
| 1623 | std::back_inserter(transfers), |
| 1624 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1625 | std::vector<int32_t> ranges; |
| 1626 | ranges.reserve(combination.ranges.size()); |
| 1627 | std::transform(combination.ranges.cbegin(), combination.ranges.cend(), |
| 1628 | std::back_inserter(ranges), |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1629 | [](const auto& val) { return static_cast<int32_t>(val); }); |
| 1630 | gui::OverlayProperties::SupportedBufferCombinations outCombination; |
| 1631 | outCombination.pixelFormats = std::move(pixelFormats); |
Sally Qi | 4119e22 | 2023-01-13 14:52:18 -0800 | [diff] [blame] | 1632 | outCombination.standards = std::move(standards); |
| 1633 | outCombination.transfers = std::move(transfers); |
| 1634 | outCombination.ranges = std::move(ranges); |
Sally Qi | bb866c1 | 2022-10-17 11:31:20 -0700 | [diff] [blame] | 1635 | outProperties->combinations.emplace_back(outCombination); |
| 1636 | } |
Sally Qi | 8b4cb55 | 2022-12-14 16:24:31 -0800 | [diff] [blame] | 1637 | outProperties->supportMixedColorSpaces = aidlProperties.supportMixedColorSpaces; |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 1638 | return NO_ERROR; |
| 1639 | } |
| 1640 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1641 | status_t SurfaceFlinger::setBootDisplayMode(const sp<display::DisplayToken>& displayToken, |
| 1642 | DisplayModeId modeId) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1643 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1644 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1645 | const auto snapshotOpt = |
| 1646 | ftl::find_if(mPhysicalDisplays, PhysicalDisplay::hasToken(displayToken)) |
| 1647 | .transform(&ftl::to_mapped_ref<PhysicalDisplays>) |
| 1648 | .transform(&PhysicalDisplay::snapshotRef); |
| 1649 | |
| 1650 | if (!snapshotOpt) { |
| 1651 | ALOGE("%s: Invalid physical display token %p", whence, displayToken.get()); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1652 | return NAME_NOT_FOUND; |
| 1653 | } |
Kriti Dang | f50d677 | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 1654 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1655 | const auto& snapshot = snapshotOpt->get(); |
| 1656 | const auto hwcIdOpt = snapshot.displayModes().get(modeId).transform( |
| 1657 | [](const DisplayModePtr& mode) { return mode->getHwcId(); }); |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1658 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1659 | if (!hwcIdOpt) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 1660 | ALOGE("%s: Invalid mode %d for display %s", whence, ftl::to_underlying(modeId), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1661 | to_string(snapshot.displayId()).c_str()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1662 | return BAD_VALUE; |
| 1663 | } |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1664 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1665 | return getHwComposer().setBootDisplayMode(snapshot.displayId(), *hwcIdOpt); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1666 | }); |
| 1667 | return future.get(); |
| 1668 | } |
| 1669 | |
| 1670 | status_t SurfaceFlinger::clearBootDisplayMode(const sp<IBinder>& displayToken) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1671 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1672 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1673 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1674 | return getHwComposer().clearBootDisplayMode(*displayId); |
| 1675 | } else { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1676 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Kriti Dang | 7defaf3 | 2021-11-15 11:55:43 +0100 | [diff] [blame] | 1677 | return BAD_VALUE; |
| 1678 | } |
| 1679 | }); |
| 1680 | return future.get(); |
| 1681 | } |
| 1682 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1683 | status_t SurfaceFlinger::getHdrConversionCapabilities( |
| 1684 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) const { |
| 1685 | bool hdrOutputConversionSupport; |
| 1686 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1687 | if (hdrOutputConversionSupport == false) { |
| 1688 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1689 | return INVALID_OPERATION; |
| 1690 | } |
| 1691 | const auto aidlConversionCapability = getHwComposer().getHdrConversionCapabilities(); |
| 1692 | for (auto capability : aidlConversionCapability) { |
| 1693 | gui::HdrConversionCapability tempCapability; |
Kriti Dang | 3c243dc | 2023-03-07 15:00:13 +0100 | [diff] [blame] | 1694 | tempCapability.sourceType = static_cast<int>(capability.sourceType); |
| 1695 | tempCapability.outputType = static_cast<int>(capability.outputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1696 | tempCapability.addsLatency = capability.addsLatency; |
| 1697 | hdrConversionCapabilities->push_back(tempCapability); |
| 1698 | } |
| 1699 | return NO_ERROR; |
| 1700 | } |
| 1701 | |
| 1702 | status_t SurfaceFlinger::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1703 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 1704 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1705 | bool hdrOutputConversionSupport; |
| 1706 | getHdrOutputConversionSupport(&hdrOutputConversionSupport); |
| 1707 | if (hdrOutputConversionSupport == false) { |
| 1708 | ALOGE("hdrOutputConversion is not supported by this device."); |
| 1709 | return INVALID_OPERATION; |
| 1710 | } |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1711 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) mutable -> status_t { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1712 | using AidlHdrConversionStrategy = |
| 1713 | aidl::android::hardware::graphics::common::HdrConversionStrategy; |
| 1714 | using GuiHdrConversionStrategyTag = gui::HdrConversionStrategy::Tag; |
| 1715 | AidlHdrConversionStrategy aidlConversionStrategy; |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1716 | status_t status; |
| 1717 | aidl::android::hardware::graphics::common::Hdr aidlPreferredHdrOutputType; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1718 | switch (hdrConversionStrategy.getTag()) { |
| 1719 | case GuiHdrConversionStrategyTag::passthrough: { |
| 1720 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::passthrough>( |
| 1721 | hdrConversionStrategy.get<GuiHdrConversionStrategyTag::passthrough>()); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1722 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1723 | &aidlPreferredHdrOutputType); |
| 1724 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1725 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1726 | } |
| 1727 | case GuiHdrConversionStrategyTag::autoAllowedHdrTypes: { |
| 1728 | auto autoHdrTypes = |
| 1729 | hdrConversionStrategy |
| 1730 | .get<GuiHdrConversionStrategyTag::autoAllowedHdrTypes>(); |
| 1731 | std::vector<aidl::android::hardware::graphics::common::Hdr> aidlAutoHdrTypes; |
| 1732 | for (auto type : autoHdrTypes) { |
| 1733 | aidlAutoHdrTypes.push_back( |
| 1734 | static_cast<aidl::android::hardware::graphics::common::Hdr>(type)); |
| 1735 | } |
| 1736 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::autoAllowedHdrTypes>( |
| 1737 | aidlAutoHdrTypes); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1738 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1739 | &aidlPreferredHdrOutputType); |
| 1740 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1741 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1742 | } |
| 1743 | case GuiHdrConversionStrategyTag::forceHdrConversion: { |
| 1744 | auto forceHdrConversion = |
| 1745 | hdrConversionStrategy |
| 1746 | .get<GuiHdrConversionStrategyTag::forceHdrConversion>(); |
| 1747 | aidlConversionStrategy.set<AidlHdrConversionStrategy::Tag::forceHdrConversion>( |
| 1748 | static_cast<aidl::android::hardware::graphics::common::Hdr>( |
| 1749 | forceHdrConversion)); |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 1750 | status = getHwComposer().setHdrConversionStrategy(aidlConversionStrategy, |
| 1751 | &aidlPreferredHdrOutputType); |
| 1752 | *outPreferredHdrOutputType = static_cast<int32_t>(aidlPreferredHdrOutputType); |
| 1753 | return status; |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | }); |
| 1757 | return future.get(); |
| 1758 | } |
| 1759 | |
| 1760 | status_t SurfaceFlinger::getHdrOutputConversionSupport(bool* outSupport) const { |
| 1761 | auto future = mScheduler->schedule([this] { |
| 1762 | return getHwComposer().hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG); |
| 1763 | }); |
| 1764 | |
| 1765 | *outSupport = future.get(); |
| 1766 | return NO_ERROR; |
| 1767 | } |
| 1768 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1769 | void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1770 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1771 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1772 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1773 | getHwComposer().setAutoLowLatencyMode(*displayId, on); |
| 1774 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1775 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1776 | } |
| 1777 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1778 | } |
| 1779 | |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1780 | void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1781 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1782 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1783 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1784 | const auto type = on ? hal::ContentType::GAME : hal::ContentType::NONE; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1785 | getHwComposer().setContentType(*displayId, type); |
| 1786 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1787 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1788 | } |
| 1789 | })); |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1792 | status_t SurfaceFlinger::overrideHdrTypes(const sp<IBinder>& displayToken, |
| 1793 | const std::vector<ui::Hdr>& hdrTypes) { |
| 1794 | Mutex::Autolock lock(mStateLock); |
| 1795 | |
| 1796 | auto display = getDisplayDeviceLocked(displayToken); |
| 1797 | if (!display) { |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 1798 | ALOGE("%s: Invalid display token %p", __func__, displayToken.get()); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1799 | return NAME_NOT_FOUND; |
| 1800 | } |
| 1801 | |
| 1802 | display->overrideHdrTypes(hdrTypes); |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 1803 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 1804 | return NO_ERROR; |
| 1805 | } |
| 1806 | |
Huihong Luo | 30aa437 | 2022-10-03 14:54:12 -0700 | [diff] [blame] | 1807 | status_t SurfaceFlinger::onPullAtom(const int32_t atomId, std::vector<uint8_t>* pulledData, |
| 1808 | bool* success) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 1809 | *success = mTimeStats->onPullAtom(atomId, pulledData); |
| 1810 | return NO_ERROR; |
| 1811 | } |
| 1812 | |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1813 | status_t SurfaceFlinger::getDisplayedContentSamplingAttributes(const sp<IBinder>& displayToken, |
| 1814 | ui::PixelFormat* outFormat, |
| 1815 | ui::Dataspace* outDataspace, |
| 1816 | uint8_t* outComponentMask) const { |
| 1817 | if (!outFormat || !outDataspace || !outComponentMask) { |
| 1818 | return BAD_VALUE; |
| 1819 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1820 | |
| 1821 | Mutex::Autolock lock(mStateLock); |
| 1822 | |
| 1823 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1824 | if (!displayId) { |
| 1825 | return NAME_NOT_FOUND; |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1826 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1827 | |
| 1828 | return getHwComposer().getDisplayedContentSamplingAttributes(*displayId, outFormat, |
Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 1829 | outDataspace, outComponentMask); |
| 1830 | } |
| 1831 | |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1832 | status_t SurfaceFlinger::setDisplayContentSamplingEnabled(const sp<IBinder>& displayToken, |
| 1833 | bool enable, uint8_t componentMask, |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1834 | uint64_t maxFrames) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1835 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1836 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) -> status_t { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1837 | if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { |
| 1838 | return getHwComposer().setDisplayContentSamplingEnabled(*displayId, enable, |
| 1839 | componentMask, maxFrames); |
| 1840 | } else { |
| 1841 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
| 1842 | return NAME_NOT_FOUND; |
| 1843 | } |
| 1844 | }); |
| 1845 | |
| 1846 | return future.get(); |
Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1849 | status_t SurfaceFlinger::getDisplayedContentSample(const sp<IBinder>& displayToken, |
| 1850 | uint64_t maxFrames, uint64_t timestamp, |
| 1851 | DisplayedFrameStats* outStats) const { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1852 | Mutex::Autolock lock(mStateLock); |
| 1853 | |
| 1854 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1855 | if (!displayId) { |
| 1856 | return NAME_NOT_FOUND; |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1859 | return getHwComposer().getDisplayedContentSample(*displayId, maxFrames, timestamp, outStats); |
Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Peiyong Lin | 3c2791e | 2019-01-14 17:05:18 -0800 | [diff] [blame] | 1862 | status_t SurfaceFlinger::getProtectedContentSupport(bool* outSupported) const { |
| 1863 | if (!outSupported) { |
| 1864 | return BAD_VALUE; |
| 1865 | } |
| 1866 | *outSupported = getRenderEngine().supportsProtectedContent(); |
| 1867 | return NO_ERROR; |
| 1868 | } |
| 1869 | |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1870 | status_t SurfaceFlinger::isWideColorDisplay(const sp<IBinder>& displayToken, |
| 1871 | bool* outIsWideColorDisplay) const { |
| 1872 | if (!displayToken || !outIsWideColorDisplay) { |
| 1873 | return BAD_VALUE; |
| 1874 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1875 | |
| 1876 | Mutex::Autolock lock(mStateLock); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1877 | const auto display = getDisplayDeviceLocked(displayToken); |
| 1878 | if (!display) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1879 | return NAME_NOT_FOUND; |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1880 | } |
Peiyong Lin | ff84a15 | 2019-05-17 18:36:19 -0700 | [diff] [blame] | 1881 | |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1882 | *outIsWideColorDisplay = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1883 | display->isPrimary() ? mSupportsWideColor : display->hasWideColorGamut(); |
Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 1884 | return NO_ERROR; |
| 1885 | } |
| 1886 | |
Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 1887 | status_t SurfaceFlinger::getCompositionPreference( |
| 1888 | Dataspace* outDataspace, ui::PixelFormat* outPixelFormat, |
| 1889 | Dataspace* outWideColorGamutDataspace, |
| 1890 | ui::PixelFormat* outWideColorGamutPixelFormat) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 1891 | *outDataspace = mDefaultCompositionDataspace; |
| 1892 | *outPixelFormat = defaultCompositionPixelFormat; |
| 1893 | *outWideColorGamutDataspace = mWideColorGamutCompositionDataspace; |
| 1894 | *outWideColorGamutPixelFormat = wideColorGamutCompositionPixelFormat; |
Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 1895 | return NO_ERROR; |
| 1896 | } |
| 1897 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1898 | status_t SurfaceFlinger::addRegionSamplingListener(const Rect& samplingArea, |
| 1899 | const sp<IBinder>& stopLayerHandle, |
| 1900 | const sp<IRegionSamplingListener>& listener) { |
Leon Scroggins III | ae16b80 | 2022-01-12 11:42:05 -0500 | [diff] [blame] | 1901 | if (!listener || samplingArea == Rect::INVALID_RECT || samplingArea.isEmpty()) { |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1902 | return BAD_VALUE; |
| 1903 | } |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 1904 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1905 | // LayerHandle::getLayer promotes the layer object in a binder thread but we will not destroy |
| 1906 | // 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] | 1907 | const sp<Layer> stopLayer = LayerHandle::getLayer(stopLayerHandle); |
| 1908 | mRegionSamplingThread->addListener(samplingArea, |
| 1909 | stopLayer ? stopLayer->getSequence() : UNASSIGNED_LAYER_ID, |
| 1910 | listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1911 | return NO_ERROR; |
| 1912 | } |
| 1913 | |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1914 | status_t SurfaceFlinger::removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { |
tangrobin | af45f01 | 2019-02-26 18:10:10 +0800 | [diff] [blame] | 1915 | if (!listener) { |
| 1916 | return BAD_VALUE; |
| 1917 | } |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 1918 | mRegionSamplingThread->removeListener(listener); |
Dan Stoza | 84ab937 | 2018-12-17 15:27:57 -0800 | [diff] [blame] | 1919 | return NO_ERROR; |
| 1920 | } |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1921 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1922 | status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) { |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1923 | if (!listener) { |
| 1924 | return BAD_VALUE; |
| 1925 | } |
| 1926 | |
Alec Mouri | a9a68a6 | 2021-03-04 19:14:50 -0800 | [diff] [blame] | 1927 | mFpsReporter->addListener(listener, taskId); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1928 | return NO_ERROR; |
| 1929 | } |
| 1930 | |
| 1931 | status_t SurfaceFlinger::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 1932 | if (!listener) { |
| 1933 | return BAD_VALUE; |
| 1934 | } |
| 1935 | mFpsReporter->removeListener(listener); |
| 1936 | return NO_ERROR; |
| 1937 | } |
| 1938 | |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 1939 | status_t SurfaceFlinger::addTunnelModeEnabledListener( |
| 1940 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1941 | if (!listener) { |
| 1942 | return BAD_VALUE; |
| 1943 | } |
| 1944 | |
| 1945 | mTunnelModeEnabledReporter->addListener(listener); |
| 1946 | return NO_ERROR; |
| 1947 | } |
| 1948 | |
| 1949 | status_t SurfaceFlinger::removeTunnelModeEnabledListener( |
| 1950 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 1951 | if (!listener) { |
| 1952 | return BAD_VALUE; |
| 1953 | } |
| 1954 | |
| 1955 | mTunnelModeEnabledReporter->removeListener(listener); |
| 1956 | return NO_ERROR; |
| 1957 | } |
| 1958 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1959 | status_t SurfaceFlinger::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 1960 | bool* outSupport) const { |
| 1961 | if (!displayToken || !outSupport) { |
| 1962 | return BAD_VALUE; |
| 1963 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1964 | |
| 1965 | Mutex::Autolock lock(mStateLock); |
| 1966 | |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1967 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 1968 | if (!displayId) { |
| 1969 | return NAME_NOT_FOUND; |
| 1970 | } |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 1971 | *outSupport = getHwComposer().hasDisplayCapability(*displayId, DisplayCapability::BRIGHTNESS); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1972 | return NO_ERROR; |
| 1973 | } |
| 1974 | |
John Reck | 22be696 | 2021-03-10 12:59:54 -0500 | [diff] [blame] | 1975 | status_t SurfaceFlinger::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 1976 | const gui::DisplayBrightness& brightness) { |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 1977 | if (!displayToken) { |
| 1978 | return BAD_VALUE; |
| 1979 | } |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1980 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 1981 | const char* const whence = __func__; |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 1982 | return ftl::Future(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 1983 | // TODO(b/241285876): Validate that the display is physical instead of failing later. |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 1984 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 1985 | const bool supportsDisplayBrightnessCommand = |
| 1986 | getHwComposer().getComposer()->isSupported( |
| 1987 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 1988 | // If we support applying display brightness as a command, then we also support |
| 1989 | // dimming SDR layers. |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 1990 | if (supportsDisplayBrightnessCommand) { |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1991 | auto compositionDisplay = display->getCompositionDisplay(); |
| 1992 | float currentDimmingRatio = |
| 1993 | compositionDisplay->editState().sdrWhitePointNits / |
| 1994 | compositionDisplay->editState().displayBrightnessNits; |
Sally Qi | 0ea47b5 | 2023-06-22 13:27:20 -0700 | [diff] [blame] | 1995 | static constexpr float kDimmingThreshold = 0.02f; |
| 1996 | if (brightness.sdrWhitePointNits == 0.f || |
| 1997 | abs(brightness.sdrWhitePointNits - brightness.displayBrightnessNits) / |
| 1998 | brightness.sdrWhitePointNits >= |
| 1999 | kDimmingThreshold) { |
| 2000 | // to optimize, skip brightness setter if the brightness difference ratio |
| 2001 | // is lower than threshold |
| 2002 | compositionDisplay |
| 2003 | ->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2004 | brightness.displayBrightnessNits); |
| 2005 | } else { |
| 2006 | compositionDisplay->setDisplayBrightness(brightness.sdrWhitePointNits, |
| 2007 | brightness.sdrWhitePointNits); |
| 2008 | } |
| 2009 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2010 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2011 | display->stageBrightness(brightness.displayBrightness)); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2012 | float currentHdrSdrRatio = |
| 2013 | compositionDisplay->editState().displayBrightnessNits / |
| 2014 | compositionDisplay->editState().sdrWhitePointNits; |
| 2015 | FTL_FAKE_GUARD(kMainThreadContext, |
| 2016 | display->updateHdrSdrRatioOverlayRatio(currentHdrSdrRatio)); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2017 | |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 2018 | if (brightness.sdrWhitePointNits / brightness.displayBrightnessNits != |
| 2019 | currentDimmingRatio) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2020 | scheduleComposite(FrameHint::kNone); |
| 2021 | } else { |
| 2022 | scheduleCommit(FrameHint::kNone); |
| 2023 | } |
| 2024 | return ftl::yield<status_t>(OK); |
| 2025 | } else { |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2026 | return getHwComposer() |
| 2027 | .setDisplayBrightness(display->getPhysicalId(), |
| 2028 | brightness.displayBrightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 2029 | brightness.displayBrightnessNits, |
Alec Mouri | 90a1927 | 2021-12-30 14:11:38 -0800 | [diff] [blame] | 2030 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 2031 | .applyImmediately = true}); |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 2032 | } |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2033 | } else { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2034 | ALOGE("%s: Invalid display token %p", whence, displayToken.get()); |
Dominik Laskowski | 4e2b71f | 2020-11-10 15:05:32 -0800 | [diff] [blame] | 2035 | return ftl::yield<status_t>(NAME_NOT_FOUND); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2036 | } |
Dominik Laskowski | 5690bde | 2020-04-23 19:04:22 -0700 | [diff] [blame] | 2037 | })) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 2038 | .then([](ftl::Future<status_t> task) { return task; }) |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 2039 | .get(); |
Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2042 | status_t SurfaceFlinger::addHdrLayerInfoListener(const sp<IBinder>& displayToken, |
| 2043 | const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2044 | if (!displayToken) { |
| 2045 | return BAD_VALUE; |
| 2046 | } |
| 2047 | |
| 2048 | Mutex::Autolock lock(mStateLock); |
| 2049 | |
| 2050 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2051 | if (!display) { |
| 2052 | return NAME_NOT_FOUND; |
| 2053 | } |
| 2054 | const auto displayId = display->getId(); |
| 2055 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2056 | if (!hdrInfoReporter) { |
| 2057 | hdrInfoReporter = sp<HdrLayerInfoReporter>::make(); |
| 2058 | } |
| 2059 | hdrInfoReporter->addListener(listener); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2060 | |
| 2061 | |
| 2062 | mAddingHDRLayerInfoListener = true; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 2063 | return OK; |
| 2064 | } |
| 2065 | |
| 2066 | status_t SurfaceFlinger::removeHdrLayerInfoListener( |
| 2067 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 2068 | if (!displayToken) { |
| 2069 | return BAD_VALUE; |
| 2070 | } |
| 2071 | |
| 2072 | Mutex::Autolock lock(mStateLock); |
| 2073 | |
| 2074 | const auto display = getDisplayDeviceLocked(displayToken); |
| 2075 | if (!display) { |
| 2076 | return NAME_NOT_FOUND; |
| 2077 | } |
| 2078 | const auto displayId = display->getId(); |
| 2079 | sp<HdrLayerInfoReporter>& hdrInfoReporter = mHdrLayerInfoListeners[displayId]; |
| 2080 | if (hdrInfoReporter) { |
| 2081 | hdrInfoReporter->removeListener(listener); |
| 2082 | } |
| 2083 | return OK; |
| 2084 | } |
| 2085 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2086 | status_t SurfaceFlinger::notifyPowerBoost(int32_t boostId) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 2087 | using aidl::android::hardware::power::Boost; |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2088 | Boost powerBoost = static_cast<Boost>(boostId); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2089 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 2090 | if (powerBoost == Boost::INTERACTION) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2091 | mScheduler->onTouchHint(); |
Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | return NO_ERROR; |
| 2095 | } |
| 2096 | |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2097 | status_t SurfaceFlinger::getDisplayDecorationSupport( |
| 2098 | const sp<IBinder>& displayToken, |
| 2099 | std::optional<DisplayDecorationSupport>* outSupport) const { |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2100 | if (!displayToken || !outSupport) { |
| 2101 | return BAD_VALUE; |
| 2102 | } |
| 2103 | |
| 2104 | Mutex::Autolock lock(mStateLock); |
| 2105 | |
| 2106 | const auto displayId = getPhysicalDisplayIdLocked(displayToken); |
| 2107 | if (!displayId) { |
| 2108 | return NAME_NOT_FOUND; |
| 2109 | } |
Leon Scroggins III | e7c51c6 | 2022-02-01 15:53:54 -0500 | [diff] [blame] | 2110 | getHwComposer().getDisplayDecorationSupport(*displayId, outSupport); |
Leon Scroggins III | e5cff63 | 2021-12-29 11:53:36 -0500 | [diff] [blame] | 2111 | return NO_ERROR; |
| 2112 | } |
| 2113 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 2114 | // ---------------------------------------------------------------------------- |
| 2115 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 2116 | sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection( |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 2117 | gui::ISurfaceComposer::VsyncSource vsyncSource, EventRegistrationFlags eventRegistration, |
| 2118 | const sp<IBinder>& layerHandle) { |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2119 | const auto cycle = [&] { |
| 2120 | if (FlagManager::getInstance().deprecate_vsync_sf()) { |
| 2121 | ALOGW_IF(vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger, |
| 2122 | "requested unsupported config eVsyncSourceSurfaceFlinger"); |
| 2123 | return scheduler::Cycle::Render; |
| 2124 | } |
Dominik Laskowski | ccf37d7 | 2019-02-01 16:47:58 -0800 | [diff] [blame] | 2125 | |
Ady Abraham | b334758 | 2024-04-03 01:01:51 +0000 | [diff] [blame] | 2126 | return vsyncSource == gui::ISurfaceComposer::VsyncSource::eVsyncSourceSurfaceFlinger |
| 2127 | ? scheduler::Cycle::LastComposite |
| 2128 | : scheduler::Cycle::Render; |
| 2129 | }(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 2130 | return mScheduler->createDisplayEventConnection(cycle, eventRegistration, layerHandle); |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2133 | void SurfaceFlinger::scheduleCommit(FrameHint hint) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2134 | if (hint == FrameHint::kActive) { |
| 2135 | mScheduler->resetIdleTimer(); |
| 2136 | } |
Matt Buckley | 15ecd1c | 2022-11-01 21:57:16 +0000 | [diff] [blame] | 2137 | mPowerAdvisor->notifyDisplayUpdateImminentAndCpuReset(); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 2138 | mScheduler->scheduleFrame(); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2141 | void SurfaceFlinger::scheduleComposite(FrameHint hint) { |
| 2142 | mMustComposite = true; |
| 2143 | scheduleCommit(hint); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | void SurfaceFlinger::scheduleRepaint() { |
| 2147 | mGeometryDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2148 | scheduleComposite(FrameHint::kActive); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2151 | void SurfaceFlinger::scheduleSample() { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 2152 | static_cast<void>(mScheduler->schedule([this] { sample(); })); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 2153 | } |
| 2154 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 2155 | nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2156 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
| 2157 | return display->getVsyncPeriodFromHWC(); |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 2160 | return 0; |
Dominik Laskowski | 83b8821 | 2018-12-11 13:34:06 -0800 | [diff] [blame] | 2161 | } |
| 2162 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2163 | void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, |
| 2164 | std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2165 | if (FlagManager::getInstance().connected_display() && timestamp < 0 && |
| 2166 | vsyncPeriod.has_value()) { |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2167 | // use ~0 instead of -1 as AidlComposerHal.cpp passes the param as unsigned int32 |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2168 | if (mIsHotplugErrViaNegVsync && vsyncPeriod.value() == ~0) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2169 | const auto errorCode = static_cast<int32_t>(-timestamp); |
| 2170 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2171 | mScheduler->dispatchHotplugError(errorCode); |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2172 | return; |
| 2173 | } |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2174 | |
| 2175 | if (mIsHdcpViaNegVsync && vsyncPeriod.value() == ~1) { |
| 2176 | const int32_t value = static_cast<int32_t>(-timestamp); |
| 2177 | // one byte is good enough to encode android.hardware.drm.HdcpLevel |
| 2178 | const int32_t maxLevel = (value >> 8) & 0xFF; |
| 2179 | const int32_t connectedLevel = value & 0xFF; |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2180 | ALOGD("%s: HDCP levels changed (connected=%d, max=%d) for display %" PRIu64, __func__, |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 2181 | connectedLevel, maxLevel, hwcDisplayId); |
| 2182 | updateHdcpLevels(hwcDisplayId, connectedLevel, maxLevel); |
| 2183 | return; |
| 2184 | } |
Huihong Luo | aac3a77 | 2023-09-19 20:51:59 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Dominik Laskowski | 3d48304 | 2023-02-22 17:58:56 -0500 | [diff] [blame] | 2187 | ATRACE_NAME(vsyncPeriod |
| 2188 | ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str() |
| 2189 | : ftl::Concat(__func__, ' ', hwcDisplayId).c_str()); |
Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 2190 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2191 | Mutex::Autolock lock(mStateLock); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2192 | if (const auto displayIdOpt = getHwComposer().onVsync(hwcDisplayId, timestamp)) { |
| 2193 | if (mScheduler->addResyncSample(*displayIdOpt, timestamp, vsyncPeriod)) { |
| 2194 | // period flushed |
| 2195 | mScheduler->modulateVsync(displayIdOpt, &VsyncModulator::onRefreshRateChangeCompleted); |
| 2196 | } |
Alec Mouri | 754c98a | 2019-03-18 18:53:42 -0700 | [diff] [blame] | 2197 | } |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2200 | void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, |
| 2201 | DisplayHotplugEvent event) { |
| 2202 | if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { |
| 2203 | hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) |
| 2204 | ? hal::Connection::CONNECTED |
| 2205 | : hal::Connection::DISCONNECTED; |
| 2206 | { |
| 2207 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 2208 | mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); |
| 2209 | } |
| 2210 | |
| 2211 | if (mScheduler) { |
| 2212 | mScheduler->scheduleConfigure(); |
| 2213 | } |
| 2214 | |
| 2215 | return; |
Jiwen 'Steve' Cai | ccfd682 | 2018-02-21 16:15:58 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2218 | if (FlagManager::getInstance().hotplug2()) { |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 2219 | // TODO(b/311403559): use enum type instead of int |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 2220 | const auto errorCode = static_cast<int32_t>(event); |
| 2221 | ALOGD("%s: Hotplug error %d for display %" PRIu64, __func__, errorCode, hwcDisplayId); |
| 2222 | mScheduler->dispatchHotplugError(errorCode); |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2223 | } |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2226 | void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( |
| 2227 | hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2228 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2229 | mScheduler->onNewVsyncPeriodChangeTimeline(timeline); |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2230 | |
| 2231 | if (timeline.refreshRequired) { |
| 2232 | scheduleComposite(FrameHint::kNone); |
| 2233 | } |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2236 | void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { |
Marin Shalamanov | 3ea1d60 | 2020-12-16 19:59:39 +0100 | [diff] [blame] | 2237 | // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and |
Ady Abraham | b0433bc | 2020-01-08 17:31:06 -0800 | [diff] [blame] | 2238 | // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. |
| 2239 | } |
| 2240 | |
Dominik Laskowski | 0deb06e | 2021-04-16 23:18:31 -0700 | [diff] [blame] | 2241 | void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2242 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2243 | scheduleComposite(FrameHint::kNone); |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2246 | void SurfaceFlinger::onComposerHalVsyncIdle(hal::HWDisplayId) { |
Ady Abraham | e9befd7 | 2022-02-24 17:24:44 -0800 | [diff] [blame] | 2247 | ATRACE_CALL(); |
| 2248 | mScheduler->forceNextResync(); |
Yichi Chen | 3401b56 | 2022-01-17 15:42:35 +0800 | [diff] [blame] | 2249 | } |
| 2250 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 2251 | void SurfaceFlinger::onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) { |
| 2252 | ATRACE_CALL(); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2253 | const char* const whence = __func__; |
| 2254 | static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
| 2255 | kMainThreadContext) { |
| 2256 | if (const auto displayIdOpt = getHwComposer().toPhysicalDisplayId(data.display)) { |
| 2257 | if (const auto display = getDisplayDeviceLocked(*displayIdOpt)) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 2258 | const Fps refreshRate = Fps::fromPeriodNsecs( |
| 2259 | getHwComposer().getComposer()->isVrrSupported() ? data.refreshPeriodNanos |
| 2260 | : data.vsyncPeriodNanos); |
| 2261 | ATRACE_FORMAT("%s refresh rate = %d", whence, refreshRate.getIntValue()); |
| 2262 | display->updateRefreshRateOverlayRate(refreshRate, display->getActiveMode().fps, |
| 2263 | /* showRefreshRate */ true); |
Dominik Laskowski | 7372a60 | 2024-04-29 16:40:42 -0400 | [diff] [blame] | 2264 | } |
| 2265 | } |
| 2266 | })); |
ramindani | 12bfe6b | 2023-02-03 13:29:19 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2269 | void SurfaceFlinger::configure() { |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 2270 | Mutex::Autolock lock(mStateLock); |
| 2271 | if (configureLocked()) { |
| 2272 | setTransactionFlags(eDisplayTransactionNeeded); |
| 2273 | } |
| 2274 | } |
| 2275 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2276 | bool SurfaceFlinger::updateLayerSnapshotsLegacy(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2277 | bool flushTransactions, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2278 | bool& outTransactionsAreEmpty) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2279 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2280 | frontend::Update update; |
| 2281 | if (flushTransactions) { |
| 2282 | update = flushLifecycleUpdates(); |
| 2283 | if (mTransactionTracing) { |
| 2284 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2285 | update, mFrontEndDisplayInfos, |
| 2286 | mFrontEndDisplayInfosChanged); |
| 2287 | } |
| 2288 | } |
| 2289 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2290 | bool needsTraversal = false; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2291 | if (flushTransactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2292 | needsTraversal |= commitMirrorDisplays(vsyncId); |
| 2293 | needsTraversal |= commitCreatedLayers(vsyncId, update.layerCreatedStates); |
| 2294 | needsTraversal |= applyTransactions(update.transactions, vsyncId); |
| 2295 | } |
| 2296 | outTransactionsAreEmpty = !needsTraversal; |
| 2297 | const bool shouldCommit = (getTransactionFlags() & ~eTransactionFlushNeeded) || needsTraversal; |
| 2298 | if (shouldCommit) { |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2299 | commitTransactionsLegacy(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | bool mustComposite = latchBuffers() || shouldCommit; |
| 2303 | updateLayerGeometry(); |
| 2304 | return mustComposite; |
| 2305 | } |
| 2306 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2307 | void SurfaceFlinger::updateLayerHistory(nsecs_t now) { |
| 2308 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 2309 | using Changes = frontend::RequestedLayerState::Changes; |
| 2310 | if (snapshot->path.isClone()) { |
| 2311 | continue; |
| 2312 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2313 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame] | 2314 | const bool updateSmallDirty = FlagManager::getInstance().enable_small_area_detection() && |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2315 | ((snapshot->clientChanges & layer_state_t::eSurfaceDamageRegionChanged) || |
| 2316 | snapshot->changes.any(Changes::Geometry)); |
| 2317 | |
| 2318 | const bool hasChanges = |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2319 | snapshot->changes.any(Changes::FrameRate | Changes::Buffer | Changes::Animation | |
| 2320 | Changes::Geometry | Changes::Visibility) || |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2321 | (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) != |
| 2322 | 0; |
| 2323 | |
| 2324 | if (!updateSmallDirty && !hasChanges) { |
| 2325 | continue; |
| 2326 | } |
| 2327 | |
| 2328 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 2329 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2330 | "Couldn't find layer object for %s", |
| 2331 | snapshot->getDebugString().c_str()); |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2332 | |
| 2333 | if (updateSmallDirty) { |
| 2334 | // Update small dirty flag while surface damage region or geometry changed |
| 2335 | it->second->setIsSmallDirty(snapshot.get()); |
| 2336 | } |
| 2337 | |
| 2338 | if (!hasChanges) { |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2339 | continue; |
| 2340 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2341 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2342 | const auto layerProps = scheduler::LayerProps{ |
| 2343 | .visible = snapshot->isVisible, |
| 2344 | .bounds = snapshot->geomLayerBounds, |
| 2345 | .transform = snapshot->geomLayerTransform, |
| 2346 | .setFrameRateVote = snapshot->frameRate, |
| 2347 | .frameRateSelectionPriority = snapshot->frameRateSelectionPriority, |
Arthur Hung | 69f9522 | 2023-10-04 07:39:02 +0000 | [diff] [blame] | 2348 | .isSmallDirty = snapshot->isSmallDirty, |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 2349 | .isFrontBuffered = snapshot->isFrontBuffered(), |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2350 | }; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2351 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 2352 | if (snapshot->changes.any(Changes::Geometry | Changes::Visibility)) { |
| 2353 | mScheduler->setLayerProperties(snapshot->sequence, layerProps); |
| 2354 | } |
| 2355 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2356 | if (snapshot->clientChanges & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 2357 | mScheduler->setDefaultFrameRateCompatibility(snapshot->sequence, |
| 2358 | snapshot->defaultFrameRateCompatibility); |
| 2359 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2360 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2361 | if (snapshot->changes.test(Changes::Animation)) { |
| 2362 | it->second->recordLayerHistoryAnimationTx(layerProps, now); |
| 2363 | } |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 2364 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2365 | if (snapshot->changes.test(Changes::FrameRate)) { |
| 2366 | it->second->setFrameRateForLayerTree(snapshot->frameRate, layerProps, now); |
| 2367 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2368 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 2369 | if (snapshot->changes.test(Changes::Buffer)) { |
| 2370 | it->second->recordLayerHistoryBufferUpdate(layerProps, now); |
| 2371 | } |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2375 | bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, |
| 2376 | bool flushTransactions, bool& outTransactionsAreEmpty) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2377 | using Changes = frontend::RequestedLayerState::Changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 2378 | ATRACE_CALL(); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2379 | frontend::Update update; |
| 2380 | if (flushTransactions) { |
| 2381 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 2382 | // Locking: |
| 2383 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 2384 | // we must keep a copy of the transactions (specifically the composer |
| 2385 | // states) around outside the scope of the lock. |
| 2386 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 2387 | // transactions with layers still in the createdLayer queue, collect the transactions |
| 2388 | // before committing the created layers. |
| 2389 | // 3. Transactions can only be flushed after adding layers, since the layer can be a newly |
| 2390 | // created one |
| 2391 | mTransactionHandler.collectTransactions(); |
| 2392 | { |
| 2393 | // TODO(b/238781169) lockless queue this and keep order. |
| 2394 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 2395 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 2396 | mCreatedLayers.clear(); |
| 2397 | update.newLayers = std::move(mNewLayers); |
| 2398 | mNewLayers.clear(); |
| 2399 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 2400 | mNewLayerArgs.clear(); |
| 2401 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 2402 | mDestroyedHandles.clear(); |
| 2403 | } |
| 2404 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2405 | mLayerLifecycleManager.addLayers(std::move(update.newLayers)); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2406 | update.transactions = mTransactionHandler.flushTransactions(); |
| 2407 | if (mTransactionTracing) { |
| 2408 | mTransactionTracing->addCommittedTransactions(ftl::to_underlying(vsyncId), frameTimeNs, |
| 2409 | update, mFrontEndDisplayInfos, |
| 2410 | mFrontEndDisplayInfosChanged); |
| 2411 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2412 | mLayerLifecycleManager.applyTransactions(update.transactions); |
| 2413 | mLayerLifecycleManager.onHandlesDestroyed(update.destroyedHandles); |
| 2414 | for (auto& legacyLayer : update.layerCreatedStates) { |
| 2415 | sp<Layer> layer = legacyLayer.layer.promote(); |
| 2416 | if (layer) { |
| 2417 | mLegacyLayers[layer->sequence] = layer; |
| 2418 | } |
| 2419 | } |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 2420 | mLayerHierarchyBuilder.update(mLayerLifecycleManager); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2423 | // Keep a copy of the drawing state (that is going to be overwritten |
| 2424 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 2425 | // effects of the State assignment don't happen with mStateLock held, |
| 2426 | // which can cause deadlocks. |
| 2427 | State drawingState(mDrawingState); |
| 2428 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2429 | bool mustComposite = false; |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 2430 | mustComposite |= applyAndCommitDisplayTransactionStatesLocked(update.transactions); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2431 | |
| 2432 | { |
| 2433 | ATRACE_NAME("LayerSnapshotBuilder:update"); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2434 | frontend::LayerSnapshotBuilder::Args |
| 2435 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 2436 | .layerLifecycleManager = mLayerLifecycleManager, |
Melody Hsu | 63e3dcc | 2024-04-03 23:22:20 +0000 | [diff] [blame] | 2437 | .includeMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2438 | compositionengine::Feature::kSnapshotLayerMetadata), |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2439 | .displays = mFrontEndDisplayInfos, |
| 2440 | .displayChanges = mFrontEndDisplayInfosChanged, |
| 2441 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2442 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 2443 | .forceFullDamage = mForceFullDamage, |
| 2444 | .supportedLayerGenericMetadata = |
| 2445 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 2446 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 2447 | .skipRoundCornersWhenProtected = |
| 2448 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2449 | mLayerSnapshotBuilder.update(args); |
| 2450 | } |
| 2451 | |
| 2452 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Geometry | Changes::Input | |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 2453 | Changes::Hierarchy | Changes::Visibility)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2454 | mUpdateInputInfo = true; |
| 2455 | } |
| 2456 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::VisibleRegion | Changes::Hierarchy | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 2457 | Changes::Visibility | Changes::Geometry)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2458 | mVisibleRegionsDirty = true; |
| 2459 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2460 | if (mLayerLifecycleManager.getGlobalChanges().any(Changes::Hierarchy | Changes::FrameRate)) { |
| 2461 | // The frame rate of attached choreographers can only change as a result of a |
| 2462 | // FrameRate change (including when Hierarchy changes). |
| 2463 | mUpdateAttachedChoreographer = true; |
| 2464 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2465 | outTransactionsAreEmpty = mLayerLifecycleManager.getGlobalChanges().get() == 0; |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2466 | if (FlagManager::getInstance().vrr_bugfix_24q4()) { |
Ady Abraham | 6846ade | 2024-05-20 21:58:27 +0000 | [diff] [blame] | 2467 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().any( |
| 2468 | frontend::RequestedLayerState::kMustComposite); |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 2469 | } else { |
| 2470 | mustComposite |= mLayerLifecycleManager.getGlobalChanges().get() != 0; |
| 2471 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2472 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2473 | bool newDataLatched = false; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2474 | ATRACE_NAME("DisplayCallbackAndStatsUpdates"); |
| 2475 | mustComposite |= applyTransactionsLocked(update.transactions, vsyncId); |
| 2476 | traverseLegacyLayers([&](Layer* layer) { layer->commitTransaction(); }); |
| 2477 | const nsecs_t latchTime = systemTime(); |
| 2478 | bool unused = false; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2479 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2480 | for (auto& layer : mLayerLifecycleManager.getLayers()) { |
| 2481 | if (layer->changes.test(frontend::RequestedLayerState::Changes::Created) && |
| 2482 | layer->bgColorLayer) { |
| 2483 | sp<Layer> bgColorLayer = getFactory().createEffectLayer( |
| 2484 | LayerCreationArgs(this, nullptr, layer->name, |
| 2485 | ISurfaceComposerClient::eFXSurfaceEffect, LayerMetadata(), |
| 2486 | std::make_optional(layer->id), true)); |
| 2487 | mLegacyLayers[bgColorLayer->sequence] = bgColorLayer; |
| 2488 | } |
| 2489 | const bool willReleaseBufferOnLatch = layer->willReleaseBufferOnLatch(); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2490 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2491 | auto it = mLegacyLayers.find(layer->id); |
| 2492 | if (it == mLegacyLayers.end() && |
| 2493 | layer->changes.test(frontend::RequestedLayerState::Changes::Destroyed)) { |
| 2494 | // Layer handle was created and immediately destroyed. It was destroyed before it |
| 2495 | // was added to the map. |
| 2496 | continue; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2499 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 2500 | "Couldnt find layer object for %s", |
| 2501 | layer->getDebugString().c_str()); |
| 2502 | if (!layer->hasReadyFrame() && !willReleaseBufferOnLatch) { |
| 2503 | if (!it->second->hasBuffer()) { |
| 2504 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 2505 | // instead of a missed frame. This is used to identify scenarios where we |
| 2506 | // could not latch a buffer or apply a transaction due to backpressure. |
| 2507 | // We only update the latch time for buffer less layers here, the latch time |
| 2508 | // is updated for buffer layers when the buffer is latched. |
| 2509 | it->second->updateLastLatchTime(latchTime); |
| 2510 | } |
| 2511 | continue; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2514 | const bool bgColorOnly = |
| 2515 | !layer->externalTexture && (layer->bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 2516 | if (willReleaseBufferOnLatch) { |
| 2517 | mLayersWithBuffersRemoved.emplace(it->second); |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2518 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2519 | it->second->latchBufferImpl(unused, latchTime, bgColorOnly); |
| 2520 | newDataLatched = true; |
Matthew DeVore | ce6bde8 | 2024-04-28 16:58:06 +0000 | [diff] [blame] | 2521 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2522 | mLayersWithQueuedFrames.emplace(it->second); |
| 2523 | mLayersIdsWithQueuedFrames.emplace(it->second->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2524 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2525 | |
| 2526 | updateLayerHistory(latchTime); |
| 2527 | mLayerSnapshotBuilder.forEachVisibleSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 2528 | if (mLayersIdsWithQueuedFrames.find(snapshot.path.id) == mLayersIdsWithQueuedFrames.end()) |
| 2529 | return; |
| 2530 | Region visibleReg; |
| 2531 | visibleReg.set(snapshot.transformedBoundsWithoutTransparentRegion); |
| 2532 | invalidateLayerStack(snapshot.outputFilter, visibleReg); |
| 2533 | }); |
| 2534 | |
| 2535 | for (auto& destroyedLayer : mLayerLifecycleManager.getDestroyedLayers()) { |
| 2536 | mLegacyLayers.erase(destroyedLayer->id); |
| 2537 | } |
| 2538 | |
| 2539 | { |
| 2540 | ATRACE_NAME("LLM:commitChanges"); |
| 2541 | mLayerLifecycleManager.commitChanges(); |
| 2542 | } |
| 2543 | |
| 2544 | // enter boot animation on first buffer latch |
| 2545 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 2546 | ALOGI("Enter boot animation"); |
| 2547 | mBootStage = BootStage::BOOTANIMATION; |
| 2548 | } |
| 2549 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 2550 | mustComposite |= (getTransactionFlags() & ~eTransactionFlushNeeded) || newDataLatched; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2551 | if (mustComposite) { |
Vishnu Nair | 8134c1a | 2023-10-17 22:55:49 -0700 | [diff] [blame] | 2552 | commitTransactions(); |
| 2553 | } |
| 2554 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2555 | return mustComposite; |
| 2556 | } |
| 2557 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2558 | bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, |
| 2559 | const scheduler::FrameTargets& frameTargets) { |
| 2560 | const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); |
| 2561 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2562 | const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); |
| 2563 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2564 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2565 | if (pacesetterFrameTarget.didMissFrame()) { |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2566 | mTimeStats->incrementMissedFrames(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2569 | // If a mode set is pending and the fence hasn't fired yet, wait for the next commit. |
| 2570 | if (std::any_of(frameTargets.begin(), frameTargets.end(), |
| 2571 | [this](const auto& pair) FTL_FAKE_GUARD(mStateLock) |
| 2572 | FTL_FAKE_GUARD(kMainThreadContext) { |
| 2573 | if (!pair.second->isFramePending()) return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2574 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 2575 | if (const auto display = getDisplayDeviceLocked(pair.first)) { |
| 2576 | return display->isModeSetPending(); |
| 2577 | } |
| 2578 | |
| 2579 | return false; |
| 2580 | })) { |
| 2581 | mScheduler->scheduleFrame(); |
| 2582 | return false; |
| 2583 | } |
| 2584 | |
| 2585 | { |
| 2586 | Mutex::Autolock lock(mStateLock); |
| 2587 | |
| 2588 | for (const auto [id, target] : frameTargets) { |
| 2589 | // TODO(b/241285876): This is `nullptr` when the DisplayDevice is about to be removed in |
| 2590 | // this commit, since the PhysicalDisplay has already been removed. Rather than checking |
| 2591 | // for `nullptr` below, change Scheduler::onFrameSignal to filter out the FrameTarget of |
| 2592 | // the removed display. |
| 2593 | const auto display = getDisplayDeviceLocked(id); |
| 2594 | |
| 2595 | if (display && display->isModeSetPending()) { |
| 2596 | finalizeDisplayModeChange(*display); |
| 2597 | } |
yuhui.zhang | 087d374 | 2021-12-11 15:23:52 +0800 | [diff] [blame] | 2598 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2601 | if (pacesetterFrameTarget.isFramePending()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2602 | if (mBackpressureGpuComposition || pacesetterFrameTarget.didMissHwcFrame()) { |
Ady Abraham | e988303 | 2023-11-20 17:54:54 -0800 | [diff] [blame] | 2603 | if (FlagManager::getInstance().vrr_config()) { |
| 2604 | mScheduler->getVsyncSchedule()->getTracker().onFrameMissed( |
| 2605 | pacesetterFrameTarget.expectedPresentTime()); |
| 2606 | } |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2607 | scheduleCommit(FrameHint::kNone); |
| 2608 | return false; |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2612 | const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period(); |
| 2613 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2614 | // Save this once per commit + composite to ensure consistency |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2615 | // TODO (b/240619471): consider removing active display check once AOD is fixed |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 2616 | const auto activeDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(mActiveDisplayId)); |
Matt Buckley | ba8d15a | 2022-08-02 20:10:15 +0000 | [diff] [blame] | 2617 | mPowerHintSessionEnabled = mPowerAdvisor->usePowerHintSession() && activeDisplay && |
| 2618 | activeDisplay->getPowerMode() == hal::PowerMode::ON; |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2619 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2620 | mPowerAdvisor->setCommitStart(pacesetterFrameTarget.frameBeginTime()); |
| 2621 | mPowerAdvisor->setExpectedPresentTime(pacesetterFrameTarget.expectedPresentTime()); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2622 | |
| 2623 | // 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] | 2624 | const Duration idealSfWorkDuration = |
| 2625 | mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2626 | const Duration frameDelay = |
| 2627 | idealSfWorkDuration - pacesetterFrameTarget.expectedFrameDuration(); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 2628 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2629 | mPowerAdvisor->setFrameDelay(frameDelay); |
| 2630 | mPowerAdvisor->setTotalFrameTargetWorkDuration(idealSfWorkDuration); |
Matt Buckley | 676e439 | 2023-05-25 22:09:26 +0000 | [diff] [blame] | 2631 | |
| 2632 | const auto& display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()).get(); |
| 2633 | const Period idealVsyncPeriod = display->getActiveMode().fps.getPeriod(); |
| 2634 | mPowerAdvisor->updateTargetWorkDuration(idealVsyncPeriod); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2637 | if (mRefreshRateOverlaySpinner || mHdrSdrRatioOverlay) { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 2638 | Mutex::Autolock lock(mStateLock); |
| 2639 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 2640 | display->animateOverlay(); |
Ady Abraham | 29d0da3 | 2020-07-16 18:39:33 -0700 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2644 | // Composite if transactions were committed, or if requested by HWC. |
| 2645 | bool mustComposite = mMustComposite.exchange(false); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2646 | { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2647 | mFrameTimeline->setSfWakeUp(ftl::to_underlying(vsyncId), |
| 2648 | pacesetterFrameTarget.frameBeginTime().ns(), |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 2649 | Fps::fromPeriodNsecs(vsyncPeriod.ns()), |
| 2650 | mScheduler->getPacesetterRefreshRate()); |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 2651 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2652 | const bool flushTransactions = clearTransactionFlags(eTransactionFlushNeeded); |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 2653 | bool transactionsAreEmpty = false; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2654 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2655 | mustComposite |= |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 2656 | updateLayerSnapshots(vsyncId, pacesetterFrameTarget.frameBeginTime().ns(), |
| 2657 | flushTransactions, transactionsAreEmpty); |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2658 | } |
| 2659 | |
Ady Abraham | aa7ebd6 | 2024-03-26 02:27:57 +0000 | [diff] [blame] | 2660 | // Tell VsyncTracker that we are going to present this frame before scheduling |
| 2661 | // setTransactionFlags which will schedule another SF frame. This was if the tracker |
| 2662 | // needs to adjust the vsync timeline, it will be done before the next frame. |
| 2663 | if (FlagManager::getInstance().vrr_config() && mustComposite) { |
| 2664 | mScheduler->getVsyncSchedule()->getTracker().onFrameBegin( |
| 2665 | pacesetterFrameTarget.expectedPresentTime(), |
| 2666 | pacesetterFrameTarget.lastSignaledFrameTime()); |
| 2667 | } |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2668 | if (transactionFlushNeeded()) { |
| 2669 | setTransactionFlags(eTransactionFlushNeeded); |
| 2670 | } |
| 2671 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2672 | // This has to be called after latchBuffers because we want to include the layers that have |
| 2673 | // been latched in the commit callback |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2674 | if (transactionsAreEmpty) { |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 2675 | // Invoke empty transaction callbacks early. |
| 2676 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 2677 | } else { |
| 2678 | // Invoke OnCommit callbacks. |
| 2679 | mTransactionCallbackInvoker.sendCallbacks(true /* onCommitOnly */); |
| 2680 | } |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | // Layers need to get updated (in the previous line) before we can use them for |
| 2684 | // choosing the refresh rate. |
| 2685 | // Hold mStateLock as chooseRefreshRateForContent promotes wp<Layer> to sp<Layer> |
| 2686 | // and may eventually call to ~Layer() if it holds the last reference |
| 2687 | { |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2688 | bool updateAttachedChoreographer = mUpdateAttachedChoreographer; |
| 2689 | mUpdateAttachedChoreographer = false; |
| 2690 | |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 2691 | Mutex::Autolock lock(mStateLock); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 2692 | mScheduler->chooseRefreshRateForContent(mLayerLifecycleManagerEnabled |
| 2693 | ? &mLayerHierarchyBuilder.getHierarchy() |
| 2694 | : nullptr, |
| 2695 | updateAttachedChoreographer); |
Ady Abraham | 0b10360 | 2024-05-21 20:37:49 +0000 | [diff] [blame] | 2696 | initiateDisplayModeChanges(); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2699 | updateCursorAsync(); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2700 | if (!mustComposite) { |
| 2701 | updateInputFlinger(vsyncId, pacesetterFrameTarget.frameBeginTime()); |
| 2702 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2703 | doActiveLayersTracingIfNeeded(false, mVisibleRegionsDirty, |
| 2704 | pacesetterFrameTarget.frameBeginTime(), vsyncId); |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 2705 | |
Pablo Gamito | 6be8244 | 2022-06-13 11:04:34 +0000 | [diff] [blame] | 2706 | mLastCommittedVsyncId = vsyncId; |
Vishnu Nair | b64a3b4 | 2022-01-13 15:29:32 -0800 | [diff] [blame] | 2707 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2708 | persistDisplayBrightness(mustComposite); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 2709 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2710 | return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); |
Dan Stoza | 28d46a5 | 2020-04-28 09:54:54 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2713 | CompositeResultsPerDisplay SurfaceFlinger::composite( |
| 2714 | PhysicalDisplayId pacesetterId, const scheduler::FrameTargeters& frameTargeters) { |
| 2715 | const scheduler::FrameTarget& pacesetterTarget = |
| 2716 | frameTargeters.get(pacesetterId)->get()->target(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2717 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2718 | const VsyncId vsyncId = pacesetterTarget.vsyncId(); |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2719 | ATRACE_NAME(ftl::Concat(__func__, ' ', ftl::to_underlying(vsyncId)).c_str()); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2720 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2721 | compositionengine::CompositionRefreshArgs refreshArgs; |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 2722 | refreshArgs.powerCallback = this; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2723 | const auto& displays = FTL_FAKE_GUARD(mStateLock, mDisplays); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2724 | refreshArgs.outputs.reserve(displays.size()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2725 | |
| 2726 | // Add outputs for physical displays. |
| 2727 | for (const auto& [id, targeter] : frameTargeters) { |
| 2728 | ftl::FakeGuard guard(mStateLock); |
| 2729 | |
| 2730 | if (const auto display = getCompositionDisplayLocked(id)) { |
| 2731 | refreshArgs.outputs.push_back(display); |
| 2732 | } |
Leon Scroggins III | 370b8b5 | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 2733 | |
| 2734 | refreshArgs.frameTargets.try_emplace(id, &targeter->target()); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2735 | } |
| 2736 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2737 | std::vector<DisplayId> displayIds; |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 2738 | for (const auto& [_, display] : displays) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2739 | displayIds.push_back(display->getId()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2740 | display->tracePowerMode(); |
| 2741 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2742 | // Add outputs for virtual displays. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2743 | if (display->isVirtual()) { |
| 2744 | const Fps refreshRate = display->getAdjustedRefreshRate(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2745 | |
| 2746 | if (!refreshRate.isValid() || |
| 2747 | mScheduler->isVsyncInPhase(pacesetterTarget.frameBeginTime(), refreshRate)) { |
| 2748 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2749 | } |
| 2750 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2751 | } |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2752 | mPowerAdvisor->setDisplays(displayIds); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2753 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 2754 | const bool updateTaskMetadata = mCompositionEngine->getFeatureFlags().test( |
| 2755 | compositionengine::Feature::kSnapshotLayerMetadata); |
| 2756 | if (updateTaskMetadata && (mVisibleRegionsDirty || mLayerMetadataSnapshotNeeded)) { |
| 2757 | updateLayerMetadataSnapshot(); |
| 2758 | mLayerMetadataSnapshotNeeded = false; |
| 2759 | } |
| 2760 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2761 | refreshArgs.bufferIdsToUncache = std::move(mBufferIdsToUncache); |
| 2762 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2763 | if (!FlagManager::getInstance().ce_fence_promise()) { |
| 2764 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
| 2765 | for (auto& layer : mLayersWithQueuedFrames) { |
| 2766 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) |
| 2767 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
| 2768 | } |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2769 | } |
| 2770 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2771 | refreshArgs.outputColorSetting = mDisplayColorSetting; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 2772 | refreshArgs.forceOutputColorMode = mForceColorMode; |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2773 | |
| 2774 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
Vishnu Nair | 995f4cf | 2024-03-07 19:40:03 -0800 | [diff] [blame] | 2775 | refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || |
| 2776 | mVisibleRegionsDirty || mDrawingState.colorMatrixChanged; |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 2777 | refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2778 | |
| 2779 | if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { |
| 2780 | refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; |
| 2781 | mDrawingState.colorMatrixChanged = false; |
| 2782 | } |
| 2783 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2784 | refreshArgs.devOptForceClientComposition = mDebugDisableHWC; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2785 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2786 | if (mDebugFlashDelay != 0) { |
| 2787 | refreshArgs.devOptForceClientComposition = true; |
| 2788 | refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay); |
Lloyd Pique | f8cf14d | 2019-02-28 16:03:12 -0800 | [diff] [blame] | 2789 | } |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2790 | |
ramindani | 0491e64 | 2023-11-16 17:42:14 -0800 | [diff] [blame] | 2791 | // TODO(b/255601557) Update frameInterval per display |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2792 | refreshArgs.frameInterval = |
| 2793 | mScheduler->getNextFrameInterval(pacesetterId, pacesetterTarget.expectedPresentTime()); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 2794 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 2795 | const auto scheduledFrameTimeOpt = scheduledFrameResultOpt |
| 2796 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 2797 | : std::nullopt; |
| 2798 | refreshArgs.scheduledFrameTime = scheduledFrameTimeOpt; |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 2799 | refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0; |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2800 | // Store the present time just before calling to the composition engine so we could notify |
| 2801 | // the scheduler. |
| 2802 | const auto presentTime = systemTime(); |
| 2803 | |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 2804 | constexpr bool kCursorOnly = false; |
| 2805 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
| 2806 | |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2807 | if (mLayerLifecycleManagerEnabled && !mVisibleRegionsDirty) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2808 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 2809 | auto compositionDisplay = display->getCompositionDisplay(); |
| 2810 | if (!compositionDisplay->getState().isEnabled) continue; |
| 2811 | for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) { |
Vishnu Nair | 0109d3d | 2023-08-22 20:23:32 -0700 | [diff] [blame] | 2812 | if (outputLayer->getLayerFE().getCompositionState() == nullptr) { |
| 2813 | // This is unexpected but instead of crashing, capture traces to disk |
| 2814 | // and recover gracefully by forcing CE to rebuild layer stack. |
| 2815 | ALOGE("Output layer %s for display %s %" PRIu64 " has a null " |
| 2816 | "snapshot. Forcing mVisibleRegionsDirty", |
| 2817 | outputLayer->getLayerFE().getDebugName(), |
| 2818 | compositionDisplay->getName().c_str(), compositionDisplay->getId().value); |
| 2819 | |
| 2820 | TransactionTraceWriter::getInstance().invoke(__func__, /* overwrite= */ false); |
| 2821 | mVisibleRegionsDirty = true; |
| 2822 | refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; |
| 2823 | refreshArgs.updatingGeometryThisFrame = mVisibleRegionsDirty; |
| 2824 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } |
| 2827 | } |
| 2828 | |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2829 | refreshArgs.refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2830 | for (auto& [layer, layerFE] : layers) { |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 2831 | layer->onPreComposition(refreshArgs.refreshStartTime); |
| 2832 | } |
| 2833 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2834 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 2835 | for (auto& [layer, layerFE] : layers) { |
| 2836 | attachReleaseFenceFutureToLayer(layer, layerFE, |
| 2837 | layerFE->mSnapshot->outputFilter.layerStack); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2838 | } |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 2839 | |
| 2840 | refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); |
| 2841 | for (auto& layer : mLayersWithQueuedFrames) { |
| 2842 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 2843 | refreshArgs.layersWithQueuedFrames.push_back(layerFE); |
| 2844 | // Some layers are not displayed and do not yet have a future release fence |
| 2845 | if (layerFE->getReleaseFencePromiseStatus() == |
| 2846 | LayerFE::ReleaseFencePromiseStatus::UNINITIALIZED || |
| 2847 | layerFE->getReleaseFencePromiseStatus() == |
| 2848 | LayerFE::ReleaseFencePromiseStatus::FULFILLED) { |
| 2849 | // layerStack is invalid because layer is not on a display |
| 2850 | attachReleaseFenceFutureToLayer(layer.get(), layerFE.get(), |
| 2851 | ui::INVALID_LAYER_STACK); |
| 2852 | } |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | mCompositionEngine->present(refreshArgs); |
| 2857 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
| 2858 | |
| 2859 | for (auto& [layer, layerFE] : layers) { |
| 2860 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
| 2861 | if (compositionResult.lastClientCompositionFence) { |
| 2862 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | } else { |
| 2867 | mCompositionEngine->present(refreshArgs); |
| 2868 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
| 2869 | |
| 2870 | for (auto [layer, layerFE] : layers) { |
| 2871 | CompositionResult compositionResult{layerFE->stealCompositionResult()}; |
| 2872 | for (auto& [releaseFence, layerStack] : compositionResult.releaseFences) { |
| 2873 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 2874 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
| 2875 | owningLayer->onLayerDisplayed(std::move(releaseFence), layerStack); |
| 2876 | } |
| 2877 | if (compositionResult.lastClientCompositionFence) { |
| 2878 | layer->setWasClientComposed(compositionResult.lastClientCompositionFence); |
| 2879 | } |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2883 | mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 2884 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2885 | // Send a power hint after presentation is finished. |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2886 | if (mPowerHintSessionEnabled) { |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2887 | // Now that the current frame has been presented above, PowerAdvisor needs the present time |
| 2888 | // of the previous frame (whose fence is signaled by now) to determine how long the HWC had |
| 2889 | // waited on that fence to retire before presenting. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2890 | const auto& previousPresentFence = pacesetterTarget.presentFenceForPreviousFrame(); |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 2891 | |
Dominik Laskowski | 61dfca4 | 2023-05-19 14:42:24 -0400 | [diff] [blame] | 2892 | mPowerAdvisor->setSfPresentTiming(TimePoint::fromNs(previousPresentFence->getSignalTime()), |
| 2893 | TimePoint::now()); |
Matt Buckley | 0538cae | 2022-11-08 23:12:04 +0000 | [diff] [blame] | 2894 | mPowerAdvisor->reportActualWorkDuration(); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2897 | if (mScheduler->onCompositionPresented(presentTime)) { |
Dominik Laskowski | dd5827a | 2022-03-17 12:44:23 -0700 | [diff] [blame] | 2898 | scheduleComposite(FrameHint::kNone); |
| 2899 | } |
Ady Abraham | 3a77a7b | 2019-12-02 18:46:59 -0800 | [diff] [blame] | 2900 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 2901 | mNotifyExpectedPresentMap[pacesetterId].hintStatus = NotifyExpectedPresentHintStatus::Start; |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 2902 | onCompositionPresented(pacesetterId, frameTargeters, presentTime); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 2903 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2904 | const bool hadGpuComposited = |
| 2905 | multiDisplayUnion(mCompositionCoverage).test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2906 | mCompositionCoverage.clear(); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2907 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2908 | TimeStats::ClientCompositionRecord clientCompositionRecord; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2909 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2910 | for (const auto& [_, display] : displays) { |
| 2911 | const auto& state = display->getCompositionDisplay()->getState(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2912 | CompositionCoverageFlags& flags = |
| 2913 | mCompositionCoverage.try_emplace(display->getId()).first->second; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2914 | |
| 2915 | if (state.usesDeviceComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2916 | flags |= CompositionCoverage::Hwc; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | if (state.reusedClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2920 | flags |= CompositionCoverage::GpuReuse; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2921 | } else if (state.usesClientComposition) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2922 | flags |= CompositionCoverage::Gpu; |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2923 | } |
| 2924 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2925 | clientCompositionRecord.predicted |= |
| 2926 | (state.strategyPrediction != CompositionStrategyPredictionState::DISABLED); |
| 2927 | clientCompositionRecord.predictionSucceeded |= |
| 2928 | (state.strategyPrediction == CompositionStrategyPredictionState::SUCCESS); |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2931 | const auto coverage = multiDisplayUnion(mCompositionCoverage); |
| 2932 | const bool hasGpuComposited = coverage.test(CompositionCoverage::Gpu); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2933 | |
| 2934 | clientCompositionRecord.hadClientComposition = hasGpuComposited; |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2935 | clientCompositionRecord.reused = coverage.test(CompositionCoverage::GpuReuse); |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2936 | clientCompositionRecord.changed = hadGpuComposited != hasGpuComposited; |
| 2937 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 2938 | mTimeStats->pushCompositionStrategyState(clientCompositionRecord); |
| 2939 | |
Dominik Laskowski | 63f1279 | 2023-01-21 16:58:22 -0500 | [diff] [blame] | 2940 | using namespace ftl::flag_operators; |
| 2941 | |
| 2942 | // TODO(b/160583065): Enable skip validation when SF caches all client composition layers. |
| 2943 | const bool hasGpuUseOrReuse = |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2944 | coverage.any(CompositionCoverage::Gpu | CompositionCoverage::GpuReuse); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 2945 | mScheduler->modulateVsync({}, &VsyncModulator::onDisplayRefresh, hasGpuUseOrReuse); |
Dan Stoza | 14cd37c | 2015-07-09 12:43:33 -0700 | [diff] [blame] | 2946 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 2947 | mLayersWithQueuedFrames.clear(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 2948 | mLayersIdsWithQueuedFrames.clear(); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 2949 | doActiveLayersTracingIfNeeded(true, mVisibleRegionsDirty, pacesetterTarget.frameBeginTime(), |
| 2950 | vsyncId); |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 2951 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2952 | updateInputFlinger(vsyncId, pacesetterTarget.frameBeginTime()); |
Vishnu Nair | d2bfbb3 | 2023-07-18 00:45:45 +0000 | [diff] [blame] | 2953 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2954 | if (mVisibleRegionsDirty) mHdrLayerInfoChanged = true; |
Vishnu Nair | 31a8dbc | 2020-10-27 17:37:49 -0700 | [diff] [blame] | 2955 | mVisibleRegionsDirty = false; |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2956 | |
| 2957 | if (mCompositionEngine->needsAnotherUpdate()) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2958 | scheduleCommit(FrameHint::kNone); |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 2959 | } |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2960 | |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 2961 | if (mPowerHintSessionEnabled) { |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 2962 | mPowerAdvisor->setCompositeEnd(TimePoint::now()); |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame] | 2963 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 2964 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 2965 | CompositeResultsPerDisplay resultsPerDisplay; |
| 2966 | |
| 2967 | // Filter out virtual displays. |
| 2968 | for (const auto& [id, coverage] : mCompositionCoverage) { |
| 2969 | if (const auto idOpt = PhysicalDisplayId::tryCast(id)) { |
| 2970 | resultsPerDisplay.try_emplace(*idOpt, CompositeResult{coverage}); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | return resultsPerDisplay; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 2975 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2976 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 2977 | void SurfaceFlinger::updateLayerGeometry() { |
David Sodman | fa9b2af | 2017-12-24 13:28:59 -0800 | [diff] [blame] | 2978 | ATRACE_CALL(); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 2979 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2980 | if (mVisibleRegionsDirty) { |
| 2981 | computeLayerBounds(); |
| 2982 | } |
| 2983 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2984 | for (auto& layer : mLayersPendingRefresh) { |
| 2985 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 2986 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 2987 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 2988 | } |
| 2989 | mLayersPendingRefresh.clear(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2992 | bool SurfaceFlinger::isHdrLayer(const frontend::LayerSnapshot& snapshot) const { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 2993 | // Even though the camera layer may be using an HDR transfer function or otherwise be "HDR" |
| 2994 | // the device may need to avoid boosting the brightness as a result of these layers to |
| 2995 | // reduce power consumption during camera recording |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 2996 | if (mIgnoreHdrCameraLayers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 2997 | if (snapshot.externalTexture && |
| 2998 | (snapshot.externalTexture->getUsage() & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 2999 | return false; |
| 3000 | } |
| 3001 | } |
Sally Qi | f6918d4 | 2023-08-07 15:28:30 -0700 | [diff] [blame] | 3002 | // RANGE_EXTENDED layer may identify themselves as being "HDR" |
| 3003 | // via a desired hdr/sdr ratio |
| 3004 | auto pixelFormat = snapshot.buffer |
| 3005 | ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat())) |
| 3006 | : std::nullopt; |
| 3007 | |
| 3008 | if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) != |
| 3009 | HdrRenderType::SDR) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3010 | return true; |
| 3011 | } |
| 3012 | // If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable |
| 3013 | // dimming in order to keep animations invoking SDR screenshots of HDR layers seamless. |
| 3014 | // Treat such tagged layers as HDR so that DisplayManagerService does not try to change |
| 3015 | // the screen brightness |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 3016 | if (!snapshot.dimmingEnabled) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3017 | return true; |
| 3018 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3019 | return false; |
John Reck | 49d9ad3 | 2022-02-23 19:03:31 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3022 | ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId, |
| 3023 | bool isPrimary) const { |
| 3024 | const auto id = PhysicalDisplayId::tryCast(displayId); |
| 3025 | if (!id) { |
| 3026 | return ui::ROTATION_0; |
| 3027 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3028 | if (!mIgnoreHwcPhysicalDisplayOrientation && |
Neha Jain | 7b31cca | 2023-01-09 23:10:42 +0000 | [diff] [blame] | 3029 | getHwComposer().getComposer()->isSupported( |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3030 | Hwc2::Composer::OptionalFeature::PhysicalDisplayOrientation)) { |
| 3031 | switch (getHwComposer().getPhysicalDisplayOrientation(*id)) { |
| 3032 | case Hwc2::AidlTransform::ROT_90: |
| 3033 | return ui::ROTATION_90; |
| 3034 | case Hwc2::AidlTransform::ROT_180: |
| 3035 | return ui::ROTATION_180; |
| 3036 | case Hwc2::AidlTransform::ROT_270: |
| 3037 | return ui::ROTATION_270; |
| 3038 | default: |
| 3039 | return ui::ROTATION_0; |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | if (isPrimary) { |
| 3044 | using Values = SurfaceFlingerProperties::primary_display_orientation_values; |
| 3045 | switch (primary_display_orientation(Values::ORIENTATION_0)) { |
| 3046 | case Values::ORIENTATION_90: |
| 3047 | return ui::ROTATION_90; |
| 3048 | case Values::ORIENTATION_180: |
| 3049 | return ui::ROTATION_180; |
| 3050 | case Values::ORIENTATION_270: |
| 3051 | return ui::ROTATION_270; |
| 3052 | default: |
| 3053 | break; |
| 3054 | } |
| 3055 | } |
| 3056 | return ui::ROTATION_0; |
| 3057 | } |
| 3058 | |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3059 | void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, |
| 3060 | const scheduler::FrameTargeters& frameTargeters, |
| 3061 | nsecs_t presentStartTime) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3062 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 3063 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3064 | ui::PhysicalDisplayMap<PhysicalDisplayId, std::shared_ptr<FenceTime>> presentFences; |
| 3065 | ui::PhysicalDisplayMap<PhysicalDisplayId, const sp<Fence>> gpuCompositionDoneFences; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3066 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3067 | for (const auto& [id, targeter] : frameTargeters) { |
| 3068 | auto presentFence = getHwComposer().getPresentFence(id); |
| 3069 | |
| 3070 | if (id == pacesetterId) { |
| 3071 | mTransactionCallbackInvoker.addPresentFence(presentFence); |
| 3072 | } |
| 3073 | |
| 3074 | if (auto fenceTime = targeter->setPresentFence(std::move(presentFence)); |
| 3075 | fenceTime->isValid()) { |
| 3076 | presentFences.try_emplace(id, std::move(fenceTime)); |
| 3077 | } |
| 3078 | |
| 3079 | ftl::FakeGuard guard(mStateLock); |
| 3080 | if (const auto display = getCompositionDisplayLocked(id); |
| 3081 | display && display->getState().usesClientComposition) { |
| 3082 | gpuCompositionDoneFences |
| 3083 | .try_emplace(id, display->getRenderSurface()->getClientTargetAcquireFence()); |
| 3084 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3085 | } |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 3086 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3087 | const auto pacesetterDisplay = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(pacesetterId)); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3088 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3089 | std::shared_ptr<FenceTime> pacesetterPresentFenceTime = |
| 3090 | presentFences.get(pacesetterId) |
| 3091 | .transform([](const FenceTimePtr& ptr) { return ptr; }) |
| 3092 | .value_or(FenceTime::NO_FENCE); |
| 3093 | |
| 3094 | std::shared_ptr<FenceTime> pacesetterGpuCompositionDoneFenceTime = |
| 3095 | gpuCompositionDoneFences.get(pacesetterId) |
| 3096 | .transform([](sp<Fence> fence) { |
| 3097 | return std::make_shared<FenceTime>(std::move(fence)); |
| 3098 | }) |
| 3099 | .value_or(FenceTime::NO_FENCE); |
| 3100 | |
Matt Buckley | 2fa8501 | 2022-08-30 22:38:45 +0000 | [diff] [blame] | 3101 | const TimePoint presentTime = TimePoint::now(); |
Vishnu Nair | 9a69a04 | 2021-06-18 13:19:49 -0700 | [diff] [blame] | 3102 | |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3103 | // Set presentation information before calling Layer::releasePendingBuffer, such that jank |
| 3104 | // information from previous' frame classification is already available when sending jank info |
| 3105 | // to clients, so they get jank classification as early as possible. |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3106 | mFrameTimeline->setSfPresent(presentTime.ns(), pacesetterPresentFenceTime, |
| 3107 | pacesetterGpuCompositionDoneFenceTime); |
Jorim Jaggi | 8d34c90 | 2020-12-16 21:43:07 +0100 | [diff] [blame] | 3108 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 3109 | // We use the CompositionEngine::getLastFrameRefreshTimestamp() which might |
| 3110 | // 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] | 3111 | // but that should be okay since CompositorTiming has snapping logic. |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3112 | const TimePoint compositeTime = |
| 3113 | TimePoint::fromNs(mCompositionEngine->getLastFrameRefreshTimestamp()); |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 3114 | const Duration presentLatency = mHasReliablePresentFences |
| 3115 | ? mPresentLatencyTracker.trackPendingFrame(compositeTime, pacesetterPresentFenceTime) |
| 3116 | : Duration::zero(); |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3117 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3118 | const auto schedule = mScheduler->getVsyncSchedule(); |
| 3119 | const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime); |
| 3120 | const Period vsyncPeriod = schedule->period(); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3121 | const nsecs_t vsyncPhase = |
| 3122 | mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset; |
Dominik Laskowski | 5d164f2 | 2022-07-07 07:56:07 -0700 | [diff] [blame] | 3123 | |
Dominik Laskowski | 5a5e01e | 2022-07-08 07:52:44 -0700 | [diff] [blame] | 3124 | const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase, |
Dominik Laskowski | 80c7727 | 2022-07-08 12:47:29 -0700 | [diff] [blame] | 3125 | presentLatency.ns()); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 3126 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 3127 | ui::DisplayMap<ui::LayerStack, const DisplayDevice*> layerStackToDisplay; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3128 | { |
| 3129 | if (!mLayersWithBuffersRemoved.empty() || mNumTrustedPresentationListeners > 0) { |
| 3130 | Mutex::Autolock lock(mStateLock); |
| 3131 | for (const auto& [token, display] : mDisplays) { |
| 3132 | layerStackToDisplay.emplace_or_replace(display->getLayerStack(), display.get()); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | for (auto layer : mLayersWithBuffersRemoved) { |
Vishnu Nair | f10a87b | 2023-05-01 14:02:51 -0700 | [diff] [blame] | 3138 | std::vector<ui::LayerStack> previouslyPresentedLayerStacks = |
| 3139 | std::move(layer->mPreviouslyPresentedLayerStacks); |
| 3140 | layer->mPreviouslyPresentedLayerStacks.clear(); |
| 3141 | for (auto layerStack : previouslyPresentedLayerStacks) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3142 | auto optDisplay = layerStackToDisplay.get(layerStack); |
| 3143 | if (optDisplay && !optDisplay->get()->isVirtual()) { |
| 3144 | auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId()); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3145 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 3146 | layer->prepareReleaseCallbacks(ftl::yield<FenceResult>(fence), |
| 3147 | ui::INVALID_LAYER_STACK); |
| 3148 | } else { |
| 3149 | layer->onLayerDisplayed(ftl::yield<FenceResult>(fence).share(), |
| 3150 | ui::INVALID_LAYER_STACK); |
| 3151 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3152 | } |
| 3153 | } |
| 3154 | layer->releasePendingBuffer(presentTime.ns()); |
| 3155 | } |
| 3156 | mLayersWithBuffersRemoved.clear(); |
| 3157 | |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3158 | for (const auto& layer: mLayersWithQueuedFrames) { |
Leon Scroggins III | 5b58149 | 2023-10-31 14:29:41 -0400 | [diff] [blame] | 3159 | layer->onCompositionPresented(pacesetterDisplay.get(), |
| 3160 | pacesetterGpuCompositionDoneFenceTime, |
| 3161 | pacesetterPresentFenceTime, compositorTiming); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3162 | layer->releasePendingBuffer(presentTime.ns()); |
Robert Carr | c747ad0 | 2021-06-11 14:01:24 -0700 | [diff] [blame] | 3163 | } |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 3164 | |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3165 | std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>> |
| 3166 | hdrInfoListeners; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3167 | bool haveNewListeners = false; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3168 | { |
| 3169 | Mutex::Autolock lock(mStateLock); |
| 3170 | if (mFpsReporter) { |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 3171 | mFpsReporter->dispatchLayerFps(mLayerHierarchyBuilder.getHierarchy()); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3172 | } |
Galia Peycheva | 8f04b30 | 2021-04-27 13:25:38 +0200 | [diff] [blame] | 3173 | |
| 3174 | if (mTunnelModeEnabledReporter) { |
| 3175 | mTunnelModeEnabledReporter->updateTunnelModeStatus(); |
| 3176 | } |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3177 | hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 3178 | for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { |
| 3179 | if (reporter && reporter->hasListeners()) { |
| 3180 | if (const auto display = getDisplayDeviceLocked(displayId)) { |
| 3181 | hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3182 | } |
| 3183 | } |
| 3184 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3185 | haveNewListeners = mAddingHDRLayerInfoListener; // grab this with state lock |
| 3186 | mAddingHDRLayerInfoListener = false; |
John Reck | 8827090 | 2021-03-18 11:27:35 -0400 | [diff] [blame] | 3187 | } |
| 3188 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3189 | if (haveNewListeners || mHdrLayerInfoChanged) { |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3190 | for (auto& [compositionDisplay, listener] : hdrInfoListeners) { |
| 3191 | HdrLayerInfoReporter::HdrLayerInfo info; |
| 3192 | int32_t maxArea = 0; |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3193 | |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3194 | auto updateInfoFn = |
| 3195 | [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, |
| 3196 | const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { |
| 3197 | if (snapshot.isVisible && |
| 3198 | compositionDisplay->includesLayer(snapshot.outputFilter)) { |
| 3199 | if (isHdrLayer(snapshot)) { |
| 3200 | const auto* outputLayer = |
| 3201 | compositionDisplay->getOutputLayerForLayer(layerFe); |
| 3202 | if (outputLayer) { |
| 3203 | const float desiredHdrSdrRatio = |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 3204 | snapshot.desiredHdrSdrRatio < 1.f |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3205 | ? std::numeric_limits<float>::infinity() |
| 3206 | : snapshot.desiredHdrSdrRatio; |
| 3207 | info.mergeDesiredRatio(desiredHdrSdrRatio); |
| 3208 | info.numberOfHdrLayers++; |
| 3209 | const auto displayFrame = outputLayer->getState().displayFrame; |
| 3210 | const int32_t area = |
| 3211 | displayFrame.width() * displayFrame.height(); |
| 3212 | if (area > maxArea) { |
| 3213 | maxArea = area; |
| 3214 | info.maxW = displayFrame.width(); |
| 3215 | info.maxH = displayFrame.height(); |
| 3216 | } |
| 3217 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3218 | } |
John Reck | db1a16b | 2021-07-09 13:05:52 -0400 | [diff] [blame] | 3219 | } |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3220 | }; |
| 3221 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3222 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3223 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 3224 | [&, compositionDisplay = compositionDisplay]( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 3225 | std::unique_ptr<frontend::LayerSnapshot>& |
| 3226 | snapshot) FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3227 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 3228 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 3229 | "Couldnt find layer object for %s", |
| 3230 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 9a5463a | 2023-06-17 12:18:36 -0700 | [diff] [blame] | 3231 | auto& legacyLayer = it->second; |
| 3232 | sp<LayerFE> layerFe = |
| 3233 | legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
| 3234 | |
| 3235 | updateInfoFn(compositionDisplay, *snapshot, layerFe); |
| 3236 | }); |
| 3237 | } else { |
| 3238 | mDrawingState.traverse([&, compositionDisplay = compositionDisplay](Layer* layer) { |
| 3239 | const auto layerFe = layer->getCompositionEngineLayerFE(); |
| 3240 | const frontend::LayerSnapshot& snapshot = *layer->getLayerSnapshot(); |
| 3241 | updateInfoFn(compositionDisplay, snapshot, layerFe); |
| 3242 | }); |
| 3243 | } |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3244 | listener->dispatchHdrLayerInfo(info); |
| 3245 | } |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3248 | mHdrLayerInfoChanged = false; |
Robert Carr | 167bdde | 2021-07-28 11:26:51 -0700 | [diff] [blame] | 3249 | |
Vishnu Nair | 1fe1117 | 2023-04-03 18:10:09 +0000 | [diff] [blame] | 3250 | mTransactionCallbackInvoker.sendCallbacks(false /* onCommitOnly */); |
| 3251 | mTransactionCallbackInvoker.clearCompletedTransactions(); |
| 3252 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3253 | mTimeStats->incrementTotalFrames(); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3254 | mTimeStats->setPresentFenceGlobal(pacesetterPresentFenceTime); |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3255 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3256 | for (auto&& [id, presentFence] : presentFences) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3257 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3258 | const bool isInternalDisplay = |
| 3259 | mPhysicalDisplays.get(id).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 3260 | |
| 3261 | if (isInternalDisplay) { |
| 3262 | mScheduler->addPresentFence(id, std::move(presentFence)); |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3263 | } |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3266 | const bool hasPacesetterDisplay = |
| 3267 | pacesetterDisplay && getHwComposer().isConnected(pacesetterId); |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 3268 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3269 | if (!hasSyncFramework) { |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3270 | if (hasPacesetterDisplay && pacesetterDisplay->isPoweredOn()) { |
| 3271 | mScheduler->enableHardwareVsync(pacesetterId); |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 3275 | if (hasPacesetterDisplay && !pacesetterDisplay->isPoweredOn()) { |
Lars Svensson | d9e5469 | 2021-12-21 07:41:57 +0100 | [diff] [blame] | 3276 | getRenderEngine().cleanupPostRender(); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 3277 | return; |
| 3278 | } |
| 3279 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 3280 | // Cleanup any outstanding resources due to rendering a prior frame. |
| 3281 | getRenderEngine().cleanupPostRender(); |
| 3282 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3283 | if (mNumTrustedPresentationListeners > 0) { |
| 3284 | // We avoid any reverse traversal upwards so this shouldn't be too expensive |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 3285 | traverseLegacyLayers([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3286 | if (!layer->hasTrustedPresentationListener()) { |
| 3287 | return; |
| 3288 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3289 | const frontend::LayerSnapshot* snapshot = mLayerLifecycleManagerEnabled |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3290 | ? mLayerSnapshotBuilder.getSnapshot(layer->sequence) |
| 3291 | : layer->getLayerSnapshot(); |
| 3292 | std::optional<const DisplayDevice*> displayOpt = std::nullopt; |
| 3293 | if (snapshot) { |
| 3294 | displayOpt = layerStackToDisplay.get(snapshot->outputFilter.layerStack); |
| 3295 | } |
Vishnu Nair | fad494c | 2023-02-01 19:52:54 +0000 | [diff] [blame] | 3296 | const DisplayDevice* display = displayOpt.value_or(nullptr); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 3297 | layer->updateTrustedPresentationState(display, snapshot, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 3298 | nanoseconds_to_milliseconds(presentStartTime), |
| 3299 | false); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 3300 | }); |
| 3301 | } |
| 3302 | |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3303 | // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the |
| 3304 | // side-effect of getTotalSize(), so we check that again here |
| 3305 | if (ATRACE_ENABLED()) { |
Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 3306 | // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger |
Dan Stoza | 45de5ba | 2019-04-25 14:12:09 -0700 | [diff] [blame] | 3307 | ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); |
| 3308 | } |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 3309 | |
| 3310 | logFrameStats(presentTime); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3313 | FloatRect SurfaceFlinger::getMaxDisplayBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3314 | const ui::Size maxSize = [this] { |
| 3315 | ftl::FakeGuard guard(mStateLock); |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3316 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3317 | // The LayerTraceGenerator tool runs without displays. |
| 3318 | if (mDisplays.empty()) return ui::Size{5000, 5000}; |
Vishnu Nair | f6f5695 | 2022-03-01 20:29:46 -0800 | [diff] [blame] | 3319 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3320 | return std::accumulate(mDisplays.begin(), mDisplays.end(), ui::kEmptySize, |
| 3321 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 3322 | const auto& display = pair.second; |
| 3323 | return {std::max(size.getWidth(), display->getWidth()), |
| 3324 | std::max(size.getHeight(), display->getHeight())}; |
| 3325 | }); |
| 3326 | }(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3327 | |
| 3328 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 3329 | // to ensure it's bigger than an actual display will be. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3330 | const float xMax = maxSize.getWidth() * 10.f; |
| 3331 | const float yMax = maxSize.getHeight() * 10.f; |
| 3332 | |
| 3333 | return {-xMax, -yMax, xMax, yMax}; |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | void SurfaceFlinger::computeLayerBounds() { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 3337 | const FloatRect maxBounds = getMaxDisplayBounds(); |
chaviw | b09c655 | 2021-08-12 17:20:43 -0500 | [diff] [blame] | 3338 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 3339 | layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3343 | void SurfaceFlinger::commitTransactions() { |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3344 | ATRACE_CALL(); |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 3345 | mDebugInTransaction = systemTime(); |
| 3346 | |
| 3347 | // Here we're guaranteed that some transaction flags are set |
| 3348 | // so we can call commitTransactionsLocked unconditionally. |
| 3349 | // We clear the flags with mStateLock held to guarantee that |
| 3350 | // mCurrentState won't change until the transaction is committed. |
| 3351 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
| 3352 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
| 3353 | mDebugInTransaction = 0; |
| 3354 | } |
| 3355 | |
| 3356 | void SurfaceFlinger::commitTransactionsLegacy() { |
| 3357 | ATRACE_CALL(); |
Mathias Agopian | 841cde5 | 2012-03-01 15:44:37 -0800 | [diff] [blame] | 3358 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3359 | // Keep a copy of the drawing state (that is going to be overwritten |
| 3360 | // by commitTransactionsLocked) outside of mStateLock so that the side |
| 3361 | // effects of the State assignment don't happen with mStateLock held, |
| 3362 | // which can cause deadlocks. |
Mathias Agopian | 7cc6df5 | 2013-06-05 14:30:54 -0700 | [diff] [blame] | 3363 | State drawingState(mDrawingState); |
| 3364 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3365 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 3366 | mDebugInTransaction = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3368 | // Here we're guaranteed that some transaction flags are set |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3369 | // so we can call commitTransactionsLocked unconditionally. |
| 3370 | // We clear the flags with mStateLock held to guarantee that |
| 3371 | // mCurrentState won't change until the transaction is committed. |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 3372 | mScheduler->modulateVsync({}, &VsyncModulator::onTransactionCommit); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 3373 | commitTransactionsLocked(clearTransactionFlags(eTransactionMask)); |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 3374 | |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 3375 | mDebugInTransaction = 0; |
Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3378 | std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( |
| 3379 | PhysicalDisplayId displayId) const { |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3380 | std::vector<HWComposer::HWCDisplayMode> hwcModes; |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3381 | std::optional<hal::HWConfigId> activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3382 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3383 | const bool isExternalDisplay = FlagManager::getInstance().connected_display() && |
| 3384 | getHwComposer().getDisplayConnectionType(displayId) == |
| 3385 | ui::DisplayConnectionType::External; |
| 3386 | |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3387 | int attempt = 0; |
| 3388 | constexpr int kMaxAttempts = 3; |
| 3389 | do { |
ramindani | 263a3f1 | 2023-07-18 20:44:49 -0700 | [diff] [blame] | 3390 | hwcModes = getHwComposer().getModes(displayId, |
| 3391 | scheduler::RefreshRateSelector::kMinSupportedFrameRate |
| 3392 | .getPeriodNsecs()); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3393 | const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); |
| 3394 | activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); |
| 3395 | |
| 3396 | if (isExternalDisplay && |
| 3397 | activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { |
| 3398 | constexpr nsecs_t k59HzVsyncPeriod = 16949153; |
| 3399 | constexpr nsecs_t k60HzVsyncPeriod = 16666667; |
| 3400 | |
| 3401 | // DM sets the initial mode for an external display to 1080p@60, but |
| 3402 | // this comes after SF creates its own state (including the |
| 3403 | // DisplayDevice). For now, pick the same mode in order to avoid |
| 3404 | // inconsistent state and unnecessary mode switching. |
| 3405 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3406 | // |
| 3407 | // Try to find 1920x1080 @ 60 Hz |
| 3408 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3409 | [](const auto& mode) { |
| 3410 | return mode.width == 1920 && |
| 3411 | mode.height == 1080 && |
| 3412 | mode.vsyncPeriod == k60HzVsyncPeriod; |
| 3413 | }); |
| 3414 | iter != hwcModes.end()) { |
| 3415 | activeModeHwcIdOpt = iter->hwcId; |
| 3416 | break; |
| 3417 | } |
| 3418 | |
| 3419 | // Try to find 1920x1080 @ 59-60 Hz |
| 3420 | if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), |
| 3421 | [](const auto& mode) { |
| 3422 | return mode.width == 1920 && |
| 3423 | mode.height == 1080 && |
| 3424 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3425 | mode.vsyncPeriod <= k59HzVsyncPeriod; |
| 3426 | }); |
| 3427 | iter != hwcModes.end()) { |
| 3428 | activeModeHwcIdOpt = iter->hwcId; |
| 3429 | break; |
| 3430 | } |
| 3431 | |
| 3432 | // The display does not support 1080p@60, and this is the last attempt to pick a display |
| 3433 | // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. |
| 3434 | if (attempt + 1 == kMaxAttempts) { |
| 3435 | std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; |
| 3436 | |
| 3437 | for (const auto& mode : hwcModes) { |
| 3438 | if (mode.width <= 1920 && mode.height <= 1080 && |
| 3439 | mode.vsyncPeriod >= k60HzVsyncPeriod && |
| 3440 | mode.vsyncPeriod <= k59HzVsyncPeriod) { |
| 3441 | hwcModeOpts.push_back(mode); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), |
| 3446 | [](const auto& a, const auto& b) { |
| 3447 | const auto aSize = a.width * a.height; |
| 3448 | const auto bSize = b.width * b.height; |
| 3449 | if (aSize < bSize) |
| 3450 | return true; |
| 3451 | else if (aSize == bSize) |
| 3452 | return a.vsyncPeriod > b.vsyncPeriod; |
| 3453 | else |
| 3454 | return false; |
| 3455 | }); |
| 3456 | iter != hwcModeOpts.end()) { |
| 3457 | activeModeHwcIdOpt = iter->hwcId; |
| 3458 | break; |
| 3459 | } |
| 3460 | |
| 3461 | // hwcModeOpts was empty, use hwcModes[0] as the last resort |
| 3462 | activeModeHwcIdOpt = hwcModes[0].hwcId; |
| 3463 | } |
| 3464 | } |
Marin Shalamanov | d3b5c5d | 2021-02-11 18:26:14 +0100 | [diff] [blame] | 3465 | |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3466 | const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { |
| 3467 | return mode.hwcId == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3468 | }; |
| 3469 | |
| 3470 | if (std::any_of(hwcModes.begin(), hwcModes.end(), isActiveMode)) { |
| 3471 | break; |
| 3472 | } |
| 3473 | } while (++attempt < kMaxAttempts); |
| 3474 | |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3475 | if (attempt == kMaxAttempts) { |
| 3476 | const std::string activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3477 | activeModeHwcIdOpt ? std::to_string(*activeModeHwcIdOpt) : "unknown"s; |
Dominik Laskowski | bab5128 | 2022-08-12 09:28:55 -0700 | [diff] [blame] | 3478 | ALOGE("HWC failed to report an active mode that is supported: activeModeHwcId=%s, " |
| 3479 | "hwcModes={%s}", |
| 3480 | activeMode.c_str(), base::Join(hwcModes, ", ").c_str()); |
| 3481 | return {}; |
| 3482 | } |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3483 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3484 | const DisplayModes oldModes = mPhysicalDisplays.get(displayId) |
| 3485 | .transform([](const PhysicalDisplay& display) { |
| 3486 | return display.snapshot().displayModes(); |
| 3487 | }) |
| 3488 | .value_or(DisplayModes{}); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3489 | |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3490 | DisplayModeId nextModeId = std::accumulate(oldModes.begin(), oldModes.end(), DisplayModeId(-1), |
| 3491 | [](DisplayModeId max, const auto& pair) { |
| 3492 | return std::max(max, pair.first); |
| 3493 | }); |
| 3494 | ++nextModeId; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3495 | |
| 3496 | DisplayModes newModes; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3497 | for (const auto& hwcMode : hwcModes) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 3498 | const auto id = nextModeId++; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3499 | newModes.try_emplace(id, |
| 3500 | DisplayMode::Builder(hwcMode.hwcId) |
| 3501 | .setId(id) |
| 3502 | .setPhysicalDisplayId(displayId) |
| 3503 | .setResolution({hwcMode.width, hwcMode.height}) |
| 3504 | .setVsyncPeriod(hwcMode.vsyncPeriod) |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3505 | .setVrrConfig(hwcMode.vrrConfig) |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3506 | .setDpiX(hwcMode.dpiX) |
| 3507 | .setDpiY(hwcMode.dpiY) |
| 3508 | .setGroup(hwcMode.configGroup) |
| 3509 | .build()); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3510 | } |
| 3511 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3512 | const bool sameModes = |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3513 | std::equal(newModes.begin(), newModes.end(), oldModes.begin(), oldModes.end(), |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3514 | [](const auto& lhs, const auto& rhs) { |
| 3515 | return equalsExceptDisplayModeId(*lhs.second, *rhs.second); |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3516 | }); |
| 3517 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3518 | // Keep IDs if modes have not changed. |
| 3519 | const auto& modes = sameModes ? oldModes : newModes; |
| 3520 | const DisplayModePtr activeMode = |
Dominik Laskowski | d940a01 | 2024-01-28 13:25:44 -0500 | [diff] [blame] | 3521 | std::find_if(modes.begin(), modes.end(), [activeModeHwcIdOpt](const auto& pair) { |
| 3522 | return pair.second->getHwcId() == activeModeHwcIdOpt; |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3523 | })->second; |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 3524 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3525 | if (isExternalDisplay) { |
| 3526 | ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), |
| 3527 | to_string(*activeMode).c_str()); |
| 3528 | } |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3529 | return {modes, activeMode}; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3530 | } |
| 3531 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3532 | bool SurfaceFlinger::configureLocked() { |
| 3533 | std::vector<HotplugEvent> events; |
| 3534 | { |
| 3535 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 3536 | events = std::move(mPendingHotplugEvents); |
| 3537 | } |
| 3538 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3539 | for (const auto [hwcDisplayId, connection] : events) { |
| 3540 | if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) { |
| 3541 | const auto displayId = info->id; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3542 | const ftl::Concat displayString("display ", displayId.value, "(HAL ID ", hwcDisplayId, |
| 3543 | ')'); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3544 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3545 | if (connection == hal::Connection::CONNECTED) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3546 | const auto activeModeIdOpt = |
| 3547 | processHotplugConnect(displayId, hwcDisplayId, std::move(*info), |
| 3548 | displayString.c_str()); |
| 3549 | if (!activeModeIdOpt) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3550 | if (FlagManager::getInstance().hotplug2()) { |
| 3551 | mScheduler->dispatchHotplugError( |
| 3552 | static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN)); |
| 3553 | } |
| 3554 | getHwComposer().disconnectDisplay(displayId); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3555 | continue; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3556 | } |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3557 | |
| 3558 | const auto [kernelIdleTimerController, idleTimerTimeoutMs] = |
| 3559 | getKernelIdleTimerProperties(displayId); |
| 3560 | |
| 3561 | using Config = scheduler::RefreshRateSelector::Config; |
| 3562 | const Config config = |
| 3563 | {.enableFrameRateOverride = sysprop::enable_frame_rate_override(true) |
| 3564 | ? Config::FrameRateOverride::Enabled |
| 3565 | : Config::FrameRateOverride::Disabled, |
| 3566 | .frameRateMultipleThreshold = |
| 3567 | base::GetIntProperty("debug.sf.frame_rate_multiple_threshold"s, 0), |
| 3568 | .legacyIdleTimerTimeout = idleTimerTimeoutMs, |
| 3569 | .kernelIdleTimerController = kernelIdleTimerController}; |
| 3570 | |
| 3571 | const auto snapshotOpt = |
| 3572 | mPhysicalDisplays.get(displayId).transform(&PhysicalDisplay::snapshotRef); |
| 3573 | LOG_ALWAYS_FATAL_IF(!snapshotOpt); |
| 3574 | |
| 3575 | mDisplayModeController.registerDisplay(*snapshotOpt, *activeModeIdOpt, config); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3576 | } else { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3577 | // Unregister before destroying the DisplaySnapshot below. |
| 3578 | mDisplayModeController.unregisterDisplay(displayId); |
| 3579 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3580 | processHotplugDisconnect(displayId, displayString.c_str()); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3581 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3582 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3583 | } |
| 3584 | |
Dominik Laskowski | f11728a | 2022-07-28 13:07:42 -0700 | [diff] [blame] | 3585 | return !events.empty(); |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3588 | std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDisplayId displayId, |
| 3589 | hal::HWDisplayId hwcDisplayId, |
| 3590 | DisplayIdentificationInfo&& info, |
| 3591 | const char* displayString) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3592 | auto [displayModes, activeMode] = loadDisplayModes(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3593 | if (!activeMode) { |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3594 | ALOGE("Failed to hotplug %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3595 | return std::nullopt; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3598 | const DisplayModeId activeModeId = activeMode->getId(); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3599 | ui::ColorModes colorModes = getHwComposer().getColorModes(displayId); |
| 3600 | |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3601 | if (const auto displayOpt = mPhysicalDisplays.get(displayId)) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3602 | const auto& display = displayOpt->get(); |
| 3603 | const auto& snapshot = display.snapshot(); |
| 3604 | |
| 3605 | std::optional<DeviceProductInfo> deviceProductInfo; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3606 | if (getHwComposer().updatesDeviceProductInfoOnHotplugReconnect()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3607 | deviceProductInfo = std::move(info.deviceProductInfo); |
| 3608 | } else { |
| 3609 | deviceProductInfo = snapshot.deviceProductInfo(); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3610 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3611 | |
| 3612 | const auto it = |
| 3613 | mPhysicalDisplays.try_replace(displayId, display.token(), displayId, |
| 3614 | snapshot.connectionType(), std::move(displayModes), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3615 | std::move(colorModes), std::move(deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3616 | |
| 3617 | auto& state = mCurrentState.displays.editValueFor(it->second.token()); |
| 3618 | state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId. |
| 3619 | state.physical->activeMode = std::move(activeMode); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3620 | ALOGI("Reconnecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3621 | return activeModeId; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3624 | const sp<IBinder> token = sp<BBinder>::make(); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3625 | const ui::DisplayConnectionType connectionType = |
| 3626 | getHwComposer().getDisplayConnectionType(displayId); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3627 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3628 | mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3629 | std::move(displayModes), std::move(colorModes), |
| 3630 | std::move(info.deviceProductInfo)); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3631 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3632 | DisplayDeviceState state; |
| 3633 | state.physical = {.id = displayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3634 | .hwcDisplayId = hwcDisplayId, |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3635 | .activeMode = std::move(activeMode)}; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 3636 | state.isSecure = connectionType == ui::DisplayConnectionType::Internal; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3637 | state.isProtected = true; |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3638 | state.displayName = std::move(info.name); |
| 3639 | |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3640 | mCurrentState.displays.add(token, state); |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3641 | ALOGI("Connecting %s", displayString); |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3642 | return activeModeId; |
Dominik Laskowski | bb8267b | 2024-04-26 16:23:07 -0400 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | void SurfaceFlinger::processHotplugDisconnect(PhysicalDisplayId displayId, |
| 3646 | const char* displayString) { |
| 3647 | ALOGI("Disconnecting %s", displayString); |
| 3648 | |
| 3649 | const auto displayOpt = mPhysicalDisplays.get(displayId); |
| 3650 | LOG_ALWAYS_FATAL_IF(!displayOpt); |
| 3651 | const auto& display = displayOpt->get(); |
| 3652 | |
| 3653 | if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) { |
| 3654 | mCurrentState.displays.removeItemsAt(index); |
| 3655 | } |
| 3656 | |
| 3657 | mPhysicalDisplays.erase(displayId); |
Dominik Laskowski | bb66e63 | 2022-08-17 08:00:25 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3660 | void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId, |
| 3661 | const scheduler::FrameRateMode& mode) { |
| 3662 | // TODO(b/255635821): Merge code paths and move to Scheduler. |
| 3663 | const auto onDisplayModeChanged = displayId == mActiveDisplayId |
| 3664 | ? &scheduler::Scheduler::onPrimaryDisplayModeChanged |
| 3665 | : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged; |
| 3666 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 3667 | ((*mScheduler).*onDisplayModeChanged)(scheduler::Cycle::Render, mode); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3668 | } |
| 3669 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3670 | sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3671 | const wp<IBinder>& displayToken, |
| 3672 | std::shared_ptr<compositionengine::Display> compositionDisplay, |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3673 | const DisplayDeviceState& state, |
| 3674 | const sp<compositionengine::DisplaySurface>& displaySurface, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3675 | const sp<IGraphicBufferProducer>& producer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3676 | DisplayDeviceCreationArgs creationArgs(sp<SurfaceFlinger>::fromExisting(this), getHwComposer(), |
| 3677 | displayToken, compositionDisplay); |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 3678 | creationArgs.sequenceId = state.sequenceId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3679 | creationArgs.isSecure = state.isSecure; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3680 | creationArgs.isProtected = state.isProtected; |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3681 | creationArgs.displaySurface = displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3682 | creationArgs.hasWideColorGamut = false; |
| 3683 | creationArgs.supportedPerFrameMetadata = 0; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 3684 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3685 | if (const auto physicalIdOpt = PhysicalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3686 | const auto physicalId = *physicalIdOpt; |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 3687 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3688 | creationArgs.isPrimary = physicalId == getPrimaryDisplayIdLocked(); |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 3689 | creationArgs.refreshRateSelector = |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3690 | FTL_FAKE_GUARD(kMainThreadContext, |
| 3691 | mDisplayModeController.selectorPtrFor(physicalId)); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 3692 | |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3693 | mPhysicalDisplays.get(physicalId) |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3694 | .transform(&PhysicalDisplay::snapshotRef) |
| 3695 | .transform(ftl::unit_fn([&](const display::DisplaySnapshot& snapshot) { |
| 3696 | for (const auto mode : snapshot.colorModes()) { |
| 3697 | creationArgs.hasWideColorGamut |= ui::isWideColorMode(mode); |
| 3698 | creationArgs.hwcColorModes |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 3699 | .emplace(mode, getHwComposer().getRenderIntents(physicalId, mode)); |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3700 | } |
| 3701 | })); |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 3702 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3703 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3704 | if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) { |
| 3705 | getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities); |
| 3706 | creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id); |
Chia-I Wu | 0f509fb | 2018-06-21 15:52:50 +0800 | [diff] [blame] | 3707 | } |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3708 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 3709 | auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3710 | auto nativeWindow = nativeWindowSurface->getNativeWindow(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3711 | creationArgs.nativeWindow = nativeWindow; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3712 | |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3713 | // Make sure that composition can never be stalled by a virtual display |
| 3714 | // 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] | 3715 | // here, in case the display is composed entirely by HWC. |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 3716 | if (state.isVirtual()) { |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3717 | nativeWindow->setSwapInterval(nativeWindow.get(), 0); |
| 3718 | } |
| 3719 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3720 | creationArgs.physicalOrientation = |
ramindani | 06e518e | 2022-03-14 18:47:53 +0000 | [diff] [blame] | 3721 | getPhysicalDisplayOrientation(compositionDisplay->getId(), creationArgs.isPrimary); |
| 3722 | ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 3723 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 3724 | creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3725 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3726 | creationArgs.requestedRefreshRate = state.requestedRefreshRate; |
| 3727 | |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 3728 | sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3729 | |
Ady Abraham | 8565ad2 | 2021-06-22 17:45:44 -0700 | [diff] [blame] | 3730 | nativeWindowSurface->preallocateBuffers(); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3731 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3732 | ui::ColorMode defaultColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 3733 | Dataspace defaultDataSpace = Dataspace::UNKNOWN; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 3734 | if (display->hasWideColorGamut()) { |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 3735 | defaultColorMode = ui::ColorMode::SRGB; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 3736 | defaultDataSpace = Dataspace::V0_SRGB; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3737 | } |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 3738 | display->getCompositionDisplay()->setColorProfile( |
| 3739 | compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 3740 | RenderIntent::COLORIMETRIC}); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3741 | |
| 3742 | if (const auto& physical = state.physical) { |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 3743 | const auto& mode = *physical->activeMode; |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 3744 | display->setActiveMode(mode.getId(), mode.getVsyncRate(), mode.getVsyncRate()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 3745 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3746 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3747 | display->setLayerFilter(makeLayerFilterForDisplay(display->getId(), state.layerStack)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3748 | display->setProjection(state.orientation, state.layerStackSpaceRect, |
| 3749 | state.orientedDisplaySpaceRect); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3750 | display->setDisplayName(state.displayName); |
Vishnu Nair | a119aaa | 2021-09-24 07:19:35 -0700 | [diff] [blame] | 3751 | display->setFlags(state.flags); |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3752 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3753 | return display; |
Lloyd Pique | 99d3da5 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 3754 | } |
| 3755 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3756 | void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, |
| 3757 | const DisplayDeviceState& state) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3758 | ui::Size resolution(0, 0); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3759 | ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); |
| 3760 | if (state.physical) { |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 3761 | resolution = state.physical->activeMode->getResolution(); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3762 | pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888); |
| 3763 | } else if (state.surface != nullptr) { |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3764 | int status = state.surface->query(NATIVE_WINDOW_WIDTH, &resolution.width); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3765 | ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3766 | status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3767 | ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3768 | int format; |
| 3769 | status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3770 | ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3771 | pixelFormat = static_cast<ui::PixelFormat>(format); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3772 | } else { |
| 3773 | // Virtual displays without a surface are dormant: |
| 3774 | // they have external state (layer stack, projection, |
| 3775 | // etc.) but no internal state (i.e. a DisplayDevice). |
| 3776 | return; |
| 3777 | } |
| 3778 | |
| 3779 | compositionengine::DisplayCreationArgsBuilder builder; |
| 3780 | if (const auto& physical = state.physical) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3781 | builder.setId(physical->id); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3782 | } else { |
Dominik Laskowski | 263eec4 | 2021-07-21 23:13:24 -0700 | [diff] [blame] | 3783 | builder.setId(acquireVirtualDisplay(resolution, pixelFormat)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3784 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3785 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 3786 | builder.setPixels(resolution); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3787 | builder.setIsSecure(state.isSecure); |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 3788 | builder.setIsProtected(state.isProtected); |
Xiang Wang | 839fe5b | 2022-04-04 17:39:38 +0000 | [diff] [blame] | 3789 | builder.setPowerAdvisor(mPowerAdvisor.get()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3790 | builder.setName(state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3791 | auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3792 | compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3793 | |
| 3794 | sp<compositionengine::DisplaySurface> displaySurface; |
| 3795 | sp<IGraphicBufferProducer> producer; |
| 3796 | sp<IGraphicBufferProducer> bqProducer; |
| 3797 | sp<IGraphicBufferConsumer> bqConsumer; |
| 3798 | getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); |
| 3799 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3800 | if (state.isVirtual()) { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3801 | const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); |
| 3802 | LOG_FATAL_IF(!displayId); |
| 3803 | auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3804 | bqProducer, bqConsumer, state.displayName); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3805 | displaySurface = surface; |
| 3806 | producer = std::move(surface); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3807 | } else { |
| 3808 | ALOGE_IF(state.surface != nullptr, |
| 3809 | "adding a supported display, but rendering " |
| 3810 | "surface is provided (%p), ignoring it", |
| 3811 | state.surface.get()); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3812 | const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); |
| 3813 | LOG_FATAL_IF(!displayId); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 3814 | displaySurface = |
| 3815 | sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, |
| 3816 | state.physical->activeMode->getResolution(), |
| 3817 | ui::Size(maxGraphicsWidth, maxGraphicsHeight)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3818 | producer = bqProducer; |
| 3819 | } |
| 3820 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3821 | LOG_FATAL_IF(!displaySurface); |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3822 | auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), state, |
| 3823 | displaySurface, producer); |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 3824 | |
| 3825 | if (mScheduler && !display->isVirtual()) { |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3826 | // TODO(b/241285876): Annotate `processDisplayAdded` instead. |
| 3827 | ftl::FakeGuard guard(kMainThreadContext); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 3828 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 3829 | // For hotplug reconnect, renew the registration since display modes have been reloaded. |
| 3830 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3831 | } |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3832 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3833 | if (display->isVirtual()) { |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 3834 | display->adjustRefreshRate(mScheduler->getPacesetterRefreshRate()); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Dominik Laskowski | eb62731 | 2022-04-07 09:13:16 -0700 | [diff] [blame] | 3837 | mDisplays.try_emplace(displayToken, std::move(display)); |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 3838 | |
| 3839 | // For an external display, loadDisplayModes already attempted to select the same mode |
| 3840 | // as DM, but SF still needs to be updated to match. |
| 3841 | // TODO (b/318534874): Let DM decide the initial mode. |
| 3842 | if (const auto& physical = state.physical; |
| 3843 | mScheduler && physical && FlagManager::getInstance().connected_display()) { |
| 3844 | const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) |
| 3845 | .transform(&PhysicalDisplay::isInternal) |
| 3846 | .value_or(false); |
| 3847 | |
| 3848 | if (!isInternalDisplay) { |
| 3849 | auto activeModePtr = physical->activeMode; |
| 3850 | const auto fps = activeModePtr->getPeakFps(); |
| 3851 | |
| 3852 | setDesiredMode( |
| 3853 | {.mode = scheduler::FrameRateMode{fps, |
| 3854 | ftl::as_non_null(std::move(activeModePtr))}, |
| 3855 | .emitEvent = false, |
| 3856 | .force = true}); |
| 3857 | } |
| 3858 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3862 | auto display = getDisplayDeviceLocked(displayToken); |
| 3863 | if (display) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3864 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3865 | |
| 3866 | if (display->isVirtual()) { |
| 3867 | releaseVirtualDisplay(display->getVirtualId()); |
| 3868 | } else { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 3869 | mScheduler->unregisterDisplay(display->getPhysicalId()); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | mDisplays.erase(displayToken); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3874 | |
| 3875 | if (display && display->isVirtual()) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 3876 | static_cast<void>(mScheduler->schedule([display = std::move(display)] { |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 3877 | // Destroy the display without holding the mStateLock. |
| 3878 | // This is a temporary solution until we can manage transaction queues without |
| 3879 | // holding the mStateLock. |
| 3880 | // With blast, the IGBP that is passed to the VirtualDisplaySurface is owned by the |
| 3881 | // client. When the IGBP is disconnected, its buffer cache in SF will be cleared |
| 3882 | // via SurfaceComposerClient::doUncacheBufferTransaction. This call from the client |
| 3883 | // ends up running on the main thread causing a deadlock since setTransactionstate |
| 3884 | // will try to acquire the mStateLock. Instead we extend the lifetime of |
| 3885 | // DisplayDevice and destroy it in the main thread without holding the mStateLock. |
| 3886 | // The display will be disconnected and removed from the mDisplays list so it will |
| 3887 | // not be accessible. |
| 3888 | })); |
| 3889 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, |
| 3893 | const DisplayDeviceState& currentState, |
| 3894 | const DisplayDeviceState& drawingState) { |
| 3895 | const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); |
| 3896 | const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3897 | |
| 3898 | // Recreate the DisplayDevice if the surface or sequence ID changed. |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3899 | if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3900 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3901 | display->disconnect(); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3902 | if (display->isVirtual()) { |
| 3903 | releaseVirtualDisplay(display->getVirtualId()); |
| 3904 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3905 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3906 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3907 | mDisplays.erase(displayToken); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3908 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3909 | if (const auto& physical = currentState.physical) { |
| 3910 | getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); |
| 3911 | } |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3912 | |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3913 | processDisplayAdded(displayToken, currentState); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 3914 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3915 | if (currentState.physical) { |
Marin Shalamanov | 4c5e301 | 2020-06-04 21:41:42 +0200 | [diff] [blame] | 3916 | const auto display = getDisplayDeviceLocked(displayToken); |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 3917 | if (!mSkipPowerOnForQuiescent) { |
| 3918 | setPowerModeInternal(display, hal::PowerMode::ON); |
| 3919 | } |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3920 | |
| 3921 | // TODO(b/175678251) Call a listener instead. |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 3922 | if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 3923 | mScheduler->resetPhaseConfiguration(display->getActiveMode().fps); |
Marin Shalamanov | f7f6b3c | 2020-12-09 13:19:38 +0100 | [diff] [blame] | 3924 | } |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 3925 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3926 | return; |
| 3927 | } |
| 3928 | |
| 3929 | if (const auto display = getDisplayDeviceLocked(displayToken)) { |
| 3930 | if (currentState.layerStack != drawingState.layerStack) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 3931 | display->setLayerFilter( |
| 3932 | makeLayerFilterForDisplay(display->getId(), currentState.layerStack)); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3933 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 3934 | if (currentState.flags != drawingState.flags) { |
| 3935 | display->setFlags(currentState.flags); |
| 3936 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3937 | if ((currentState.orientation != drawingState.orientation) || |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3938 | (currentState.layerStackSpaceRect != drawingState.layerStackSpaceRect) || |
| 3939 | (currentState.orientedDisplaySpaceRect != drawingState.orientedDisplaySpaceRect)) { |
| 3940 | display->setProjection(currentState.orientation, currentState.layerStackSpaceRect, |
| 3941 | currentState.orientedDisplaySpaceRect); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3942 | if (display->getId() == mActiveDisplayId) { |
Ady Abraham | 1273ac1 | 2021-08-26 17:31:53 -0700 | [diff] [blame] | 3943 | mActiveDisplayTransformHint = display->getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 3944 | sActiveDisplayRotationFlags = |
| 3945 | ui::Transform::toRotationFlags(display->getOrientation()); |
Arthur Hung | b6aa9a0 | 2021-06-09 14:23:01 +0800 | [diff] [blame] | 3946 | } |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3947 | } |
| 3948 | if (currentState.width != drawingState.width || |
| 3949 | currentState.height != drawingState.height) { |
| 3950 | display->setDisplaySize(currentState.width, currentState.height); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 3951 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 3952 | if (display->getId() == mActiveDisplayId) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 3953 | onActiveDisplaySizeChanged(*display); |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3954 | } |
| 3955 | } |
| 3956 | } |
| 3957 | } |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 3958 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3959 | void SurfaceFlinger::processDisplayChangesLocked() { |
| 3960 | // here we take advantage of Vector's copy-on-write semantics to |
| 3961 | // improve performance by skipping the transaction entirely when |
| 3962 | // know that the lists are identical |
| 3963 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays); |
| 3964 | const KeyedVector<wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays); |
| 3965 | if (!curr.isIdenticalTo(draw)) { |
| 3966 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 3967 | mUpdateInputInfo = true; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3968 | |
Dominik Laskowski | 01f191c | 2024-01-29 11:51:23 -0500 | [diff] [blame] | 3969 | // Apply the current color matrix to any added or changed display. |
| 3970 | mCurrentState.colorMatrixChanged = true; |
| 3971 | |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3972 | // find the displays that were removed |
| 3973 | // (ie: in drawing state but not in current state) |
| 3974 | // also handle displays that changed |
| 3975 | // (ie: displays that are in both lists) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3976 | for (size_t i = 0; i < draw.size(); i++) { |
| 3977 | const wp<IBinder>& displayToken = draw.keyAt(i); |
| 3978 | const ssize_t j = curr.indexOfKey(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3979 | if (j < 0) { |
| 3980 | // in drawing state but not in current state |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3981 | processDisplayRemoved(displayToken); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3982 | } else { |
| 3983 | // this display is in both lists. see if something changed. |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3984 | const DisplayDeviceState& currentState = curr[j]; |
| 3985 | const DisplayDeviceState& drawingState = draw[i]; |
| 3986 | processDisplayChanged(displayToken, currentState, drawingState); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3987 | } |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | // find displays that were added |
| 3991 | // (ie: in current state but not in drawing state) |
Marin Shalamanov | ae68559 | 2020-02-12 17:12:22 +0100 | [diff] [blame] | 3992 | for (size_t i = 0; i < curr.size(); i++) { |
| 3993 | const wp<IBinder>& displayToken = curr.keyAt(i); |
| 3994 | if (draw.indexOfKey(displayToken) < 0) { |
| 3995 | processDisplayAdded(displayToken, curr[i]); |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 3996 | } |
| 3997 | } |
| 3998 | } |
Lloyd Pique | ba04e62 | 2017-12-14 17:11:26 -0800 | [diff] [blame] | 3999 | |
| 4000 | mDrawingState.displays = mCurrentState.displays; |
Lloyd Pique | 347200f | 2017-12-14 17:00:15 -0800 | [diff] [blame] | 4001 | } |
| 4002 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4003 | void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { |
| 4004 | // Commit display transactions. |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4005 | const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4006 | mFrontEndDisplayInfosChanged = displayTransactionNeeded; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4007 | if (displayTransactionNeeded && !mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4008 | processDisplayChangesLocked(); |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4009 | mFrontEndDisplayInfos.clear(); |
| 4010 | for (const auto& [_, display] : mDisplays) { |
| 4011 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 4012 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 4013 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4014 | mForceTransactionDisplayChange = displayTransactionNeeded; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 4016 | if (mSomeChildrenChanged) { |
| 4017 | mVisibleRegionsDirty = true; |
| 4018 | mSomeChildrenChanged = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4019 | mUpdateInputInfo = true; |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4022 | // Update transform hint. |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 4023 | if (transactionFlags & (eTransformHintUpdateNeeded | eDisplayTransactionNeeded)) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4024 | // 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] | 4025 | // |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 4026 | // 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] | 4027 | // the hint is set before we acquire a buffer from the surface texture. |
| 4028 | // |
| 4029 | // NOTE: layer transactions have taken place already, so we use their |
| 4030 | // drawing state. However, SurfaceFlinger's own transaction has not |
| 4031 | // happened yet, so we must use the current state layer list |
| 4032 | // (soon to become the drawing state list). |
| 4033 | // |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4034 | sp<const DisplayDevice> hintDisplay; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4035 | ui::LayerStack layerStack; |
| 4036 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4037 | mCurrentState.traverse([&](Layer* layer) REQUIRES(mStateLock) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4038 | // NOTE: we rely on the fact that layers are sorted by |
| 4039 | // layerStack first (so we don't have to traverse the list |
| 4040 | // of displays for every layer). |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4041 | if (const auto filter = layer->getOutputFilter(); layerStack != filter.layerStack) { |
| 4042 | layerStack = filter.layerStack; |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4043 | hintDisplay = nullptr; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4044 | |
| 4045 | // Find the display that includes the layer. |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 4046 | for (const auto& [token, display] : mDisplays) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4047 | if (!display->getCompositionDisplay()->includesLayer(filter)) { |
| 4048 | continue; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4049 | } |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4050 | |
| 4051 | // Pick the primary display if another display mirrors the layer. |
| 4052 | if (hintDisplay) { |
| 4053 | hintDisplay = nullptr; |
| 4054 | break; |
| 4055 | } |
| 4056 | |
| 4057 | hintDisplay = display; |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4058 | } |
| 4059 | } |
Chet Haase | 91d2593 | 2013-04-11 15:24:55 -0700 | [diff] [blame] | 4060 | |
Melody Hsu | 9af3070 | 2024-04-17 18:23:43 +0000 | [diff] [blame] | 4061 | if (hintDisplay) { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 4062 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
Vishnu Nair | e3066de | 2022-06-08 12:16:25 -0700 | [diff] [blame] | 4063 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4064 | }); |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 4065 | } |
| 4066 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4067 | if (mLayersAdded) { |
| 4068 | mLayersAdded = false; |
| 4069 | // Layers have been added. |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4070 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4071 | mUpdateInputInfo = true; |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | // some layers might have been removed, so |
| 4075 | // we need to update the regions they're exposing. |
| 4076 | if (mLayersRemoved) { |
| 4077 | mLayersRemoved = false; |
| 4078 | mVisibleRegionsDirty = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4079 | mUpdateInputInfo = true; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4080 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4081 | if (mLayersPendingRemoval.indexOf(sp<Layer>::fromExisting(layer)) >= 0) { |
Mathias Agopian | 3559b07 | 2012-08-15 13:46:03 -0700 | [diff] [blame] | 4082 | // this layer is not visible anymore |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4083 | Region visibleReg; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 4084 | visibleReg.set(layer->getScreenBounds()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4085 | invalidateLayerStack(layer->getOutputFilter(), visibleReg); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 4086 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4087 | }); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | } |
| 4089 | |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 4090 | if (transactionFlags & eInputInfoUpdateNeeded) { |
| 4091 | mUpdateInputInfo = true; |
| 4092 | } |
| 4093 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4094 | doCommitTransactions(); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4097 | void SurfaceFlinger::updateInputFlinger(VsyncId vsyncId, TimePoint frameTime) { |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4098 | if (!mInputFlinger || (!mUpdateInputInfo && mInputWindowCommands.empty())) { |
Vishnu Nair | 42a27b5 | 2021-11-18 15:35:22 -0800 | [diff] [blame] | 4099 | return; |
| 4100 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4101 | ATRACE_CALL(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4102 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4103 | std::vector<WindowInfo> windowInfos; |
| 4104 | std::vector<DisplayInfo> displayInfos; |
| 4105 | bool updateWindowInfo = false; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4106 | if (mUpdateInputInfo) { |
| 4107 | mUpdateInputInfo = false; |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4108 | updateWindowInfo = true; |
| 4109 | buildWindowInfos(windowInfos, displayInfos); |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4110 | } |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 4111 | |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4112 | std::unordered_set<int32_t> visibleWindowIds; |
| 4113 | for (WindowInfo& windowInfo : windowInfos) { |
| 4114 | if (!windowInfo.inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { |
| 4115 | visibleWindowIds.insert(windowInfo.id); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4116 | } |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4117 | } |
| 4118 | bool visibleWindowsChanged = false; |
| 4119 | if (visibleWindowIds != mVisibleWindowIds) { |
| 4120 | visibleWindowsChanged = true; |
| 4121 | mVisibleWindowIds = std::move(visibleWindowIds); |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4122 | } |
| 4123 | |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4124 | BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo, |
| 4125 | windowInfos = std::move(windowInfos), |
| 4126 | displayInfos = std::move(displayInfos), |
| 4127 | inputWindowCommands = |
| 4128 | std::move(mInputWindowCommands), |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4129 | inputFlinger = mInputFlinger, this, |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4130 | visibleWindowsChanged, vsyncId, frameTime]() { |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4131 | ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); |
| 4132 | if (updateWindowInfo) { |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4133 | mWindowInfosListenerInvoker |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4134 | ->windowInfosChanged(gui::WindowInfosUpdate{std::move(windowInfos), |
| 4135 | std::move(displayInfos), |
| 4136 | ftl::to_underlying(vsyncId), |
| 4137 | frameTime.ns()}, |
Patrick Williams | 1caf3b7 | 2023-03-31 10:59:10 -0500 | [diff] [blame] | 4138 | std::move( |
| 4139 | inputWindowCommands.windowInfosReportedListeners), |
Patrick Williams | d86bd8c | 2023-04-21 11:54:11 -0500 | [diff] [blame] | 4140 | /* forceImmediateCall= */ visibleWindowsChanged || |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 4141 | !inputWindowCommands.focusRequests.empty()); |
Patrick Williams | 641f7f2 | 2022-06-22 19:25:35 +0000 | [diff] [blame] | 4142 | } else { |
| 4143 | // If there are listeners but no changes to input windows, call the listeners |
| 4144 | // immediately. |
| 4145 | for (const auto& listener : inputWindowCommands.windowInfosReportedListeners) { |
| 4146 | if (IInterface::asBinder(listener)->isBinderAlive()) { |
| 4147 | listener->onWindowInfosReported(); |
| 4148 | } |
| 4149 | } |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4150 | } |
| 4151 | for (const auto& focusRequest : inputWindowCommands.focusRequests) { |
| 4152 | inputFlinger->setFocusedWindow(focusRequest); |
| 4153 | } |
Alec Mouri | 8d7d0f4 | 2022-05-10 23:33:40 +0000 | [diff] [blame] | 4154 | }}); |
Jaineel Mehta | ac331c5 | 2021-11-29 21:38:10 +0000 | [diff] [blame] | 4155 | |
Arthur Hung | 6cbb975 | 2019-09-05 16:38:18 +0800 | [diff] [blame] | 4156 | mInputWindowCommands.clear(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4157 | } |
| 4158 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4159 | void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { |
| 4160 | const bool supportsDisplayBrightnessCommand = getHwComposer().getComposer()->isSupported( |
| 4161 | Hwc2::Composer::OptionalFeature::DisplayBrightnessCommand); |
| 4162 | if (!supportsDisplayBrightnessCommand) { |
| 4163 | return; |
| 4164 | } |
| 4165 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4166 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4167 | if (const auto brightness = display->getStagedBrightness(); brightness) { |
| 4168 | if (!needsComposite) { |
| 4169 | const status_t error = |
| 4170 | getHwComposer() |
| 4171 | .setDisplayBrightness(display->getPhysicalId(), *brightness, |
Alec Mouri | 4d8a05d | 2022-03-23 18:14:26 +0000 | [diff] [blame] | 4172 | display->getCompositionDisplay() |
| 4173 | ->getState() |
| 4174 | .displayBrightnessNits, |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4175 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 4176 | .applyImmediately = true}) |
| 4177 | .get(); |
| 4178 | |
| 4179 | ALOGE_IF(error != NO_ERROR, |
| 4180 | "Error setting display brightness for display %s: %d (%s)", |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 4181 | to_string(display->getId()).c_str(), error, strerror(error)); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 4182 | } |
| 4183 | display->persistBrightness(needsComposite); |
| 4184 | } |
| 4185 | } |
| 4186 | } |
| 4187 | |
Vishnu Nair | 03ccbd6 | 2021-12-01 17:21:16 -0800 | [diff] [blame] | 4188 | void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, |
| 4189 | std::vector<DisplayInfo>& outDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4190 | static size_t sNumWindowInfos = 0; |
| 4191 | outWindowInfos.reserve(sNumWindowInfos); |
| 4192 | sNumWindowInfos = 0; |
| 4193 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4194 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4195 | mLayerSnapshotBuilder.forEachInputSnapshot( |
| 4196 | [&outWindowInfos](const frontend::LayerSnapshot& snapshot) { |
| 4197 | outWindowInfos.push_back(snapshot.inputInfo); |
| 4198 | }); |
| 4199 | } else { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4200 | mDrawingState.traverseInReverseZOrder([&](Layer* layer) FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4201 | if (!layer->needsInputInfo()) return; |
| 4202 | const auto opt = |
| 4203 | mFrontEndDisplayInfos.get(layer->getLayerStack()) |
| 4204 | .transform([](const frontend::DisplayInfo& info) { |
| 4205 | return Layer::InputDisplayArgs{&info.transform, info.isSecure}; |
| 4206 | }); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 4207 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4208 | outWindowInfos.push_back(layer->fillInputInfo(opt.value_or(Layer::InputDisplayArgs{}))); |
| 4209 | }); |
| 4210 | } |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4211 | |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4212 | sNumWindowInfos = outWindowInfos.size(); |
| 4213 | |
Vishnu Nair | 67b431c | 2022-11-16 01:54:05 +0000 | [diff] [blame] | 4214 | outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); |
| 4215 | for (const auto& [_, info] : mFrontEndDisplayInfos) { |
Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 4216 | outDisplayInfos.push_back(info.info); |
Prabir Pradhan | d0aba78 | 2021-12-14 00:44:21 -0800 | [diff] [blame] | 4217 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 4220 | void SurfaceFlinger::updateCursorAsync() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4221 | compositionengine::CompositionRefreshArgs refreshArgs; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4222 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 4223 | if (HalDisplayId::tryCast(display->getId())) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4224 | refreshArgs.outputs.push_back(display->getCompositionDisplay()); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 4225 | } |
| 4226 | } |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 4227 | |
| 4228 | constexpr bool kCursorOnly = true; |
| 4229 | const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 4230 | mCompositionEngine->updateCursorAsync(refreshArgs); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4231 | moveSnapshotsFromCompositionArgs(refreshArgs, layers); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 4234 | void SurfaceFlinger::requestHardwareVsync(PhysicalDisplayId displayId, bool enable) { |
| 4235 | getHwComposer().setVsyncEnabled(displayId, enable ? hal::Vsync::ENABLE : hal::Vsync::DISABLE); |
| 4236 | } |
| 4237 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4238 | void SurfaceFlinger::requestDisplayModes(std::vector<display::DisplayModeRequest> modeRequests) { |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 4239 | if (mBootStage != BootStage::FINISHED) { |
| 4240 | ALOGV("Currently in the boot stage, skipping display mode changes"); |
| 4241 | return; |
| 4242 | } |
| 4243 | |
| 4244 | ATRACE_CALL(); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4245 | |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4246 | // If this is called from the main thread mStateLock must be locked before |
| 4247 | // 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] | 4248 | // Scheduler::chooseRefreshRateForContent |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 4249 | |
| 4250 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
Marin Shalamanov | a63f9ae | 2021-11-03 15:05:16 +0100 | [diff] [blame] | 4251 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4252 | for (auto& request : modeRequests) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4253 | const auto& modePtr = request.mode.modePtr; |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 4254 | |
| 4255 | const auto displayId = modePtr->getPhysicalDisplayId(); |
| 4256 | const auto display = getDisplayDeviceLocked(displayId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4257 | |
| 4258 | if (!display) continue; |
| 4259 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4260 | if (display->refreshRateSelector().isModeAllowed(request.mode)) { |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 4261 | setDesiredMode(std::move(request)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4262 | } else { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 4263 | ALOGV("%s: Mode %d is disallowed for display %s", __func__, |
| 4264 | ftl::to_underlying(modePtr->getId()), to_string(displayId).c_str()); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 4265 | } |
| 4266 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4269 | void SurfaceFlinger::triggerOnFrameRateOverridesChanged() { |
| 4270 | PhysicalDisplayId displayId = [&]() { |
| 4271 | ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId); |
| 4272 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 4273 | }(); |
| 4274 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4275 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 4276 | } |
| 4277 | |
jimmyshiu | 4e21177 | 2023-06-15 15:18:38 +0000 | [diff] [blame] | 4278 | void SurfaceFlinger::notifyCpuLoadUp() { |
| 4279 | mPowerAdvisor->notifyCpuLoadUp(); |
| 4280 | } |
| 4281 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 4282 | void SurfaceFlinger::onChoreographerAttached() { |
| 4283 | ATRACE_CALL(); |
| 4284 | if (mLayerLifecycleManagerEnabled) { |
| 4285 | mUpdateAttachedChoreographer = true; |
| 4286 | scheduleCommit(FrameHint::kNone); |
| 4287 | } |
| 4288 | } |
| 4289 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4290 | void SurfaceFlinger::onExpectedPresentTimePosted(TimePoint expectedPresentTime, |
| 4291 | ftl::NonNull<DisplayModePtr> modePtr, |
| 4292 | Fps renderRate) { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4293 | const auto vsyncPeriod = modePtr->getVsyncRate().getPeriod(); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4294 | const auto timeoutOpt = [&]() -> std::optional<Period> { |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4295 | const auto vrrConfig = modePtr->getVrrConfig(); |
| 4296 | if (!vrrConfig) return std::nullopt; |
| 4297 | |
| 4298 | const auto notifyExpectedPresentConfig = |
| 4299 | modePtr->getVrrConfig()->notifyExpectedPresentConfig; |
| 4300 | if (!notifyExpectedPresentConfig) return std::nullopt; |
ramindani | cbd7a6d | 2023-12-19 16:00:30 -0800 | [diff] [blame] | 4301 | return Period::fromNs(notifyExpectedPresentConfig->timeoutNs); |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 4302 | }(); |
| 4303 | |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4304 | notifyExpectedPresentIfRequired(modePtr->getPhysicalDisplayId(), vsyncPeriod, |
| 4305 | expectedPresentTime, renderRate, timeoutOpt); |
| 4306 | } |
| 4307 | |
| 4308 | void SurfaceFlinger::notifyExpectedPresentIfRequired(PhysicalDisplayId displayId, |
| 4309 | Period vsyncPeriod, |
| 4310 | TimePoint expectedPresentTime, |
| 4311 | Fps frameInterval, |
| 4312 | std::optional<Period> timeoutOpt) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4313 | auto& data = mNotifyExpectedPresentMap[displayId]; |
| 4314 | const auto lastExpectedPresentTimestamp = data.lastExpectedPresentTimestamp; |
| 4315 | const auto lastFrameInterval = data.lastFrameInterval; |
| 4316 | data.lastFrameInterval = frameInterval; |
| 4317 | data.lastExpectedPresentTimestamp = expectedPresentTime; |
| 4318 | const auto threshold = Duration::fromNs(vsyncPeriod.ns() / 2); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4319 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4320 | const constexpr nsecs_t kOneSecondNs = |
| 4321 | std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count(); |
| 4322 | const auto timeout = |
| 4323 | Period::fromNs(timeoutOpt && timeoutOpt->ns() > 0 ? timeoutOpt->ns() : kOneSecondNs); |
| 4324 | const bool frameIntervalIsOnCadence = |
| 4325 | isFrameIntervalOnCadence(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4326 | lastFrameInterval, timeout, threshold); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4327 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4328 | const bool expectedPresentWithinTimeout = |
| 4329 | isExpectedPresentWithinTimeout(expectedPresentTime, lastExpectedPresentTimestamp, |
| 4330 | timeoutOpt, threshold); |
| 4331 | if (expectedPresentWithinTimeout && frameIntervalIsOnCadence) { |
| 4332 | return; |
| 4333 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4334 | |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4335 | auto hintStatus = data.hintStatus.load(); |
| 4336 | if (!expectedPresentWithinTimeout) { |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4337 | if ((hintStatus != NotifyExpectedPresentHintStatus::Sent && |
| 4338 | hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnTx) || |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4339 | (timeoutOpt && timeoutOpt->ns() == 0)) { |
| 4340 | // Send the hint immediately if timeout, as the hint gets |
| 4341 | // delayed otherwise, as the frame is scheduled close |
| 4342 | // to the actual present. |
| 4343 | if (data.hintStatus |
| 4344 | .compare_exchange_strong(hintStatus, |
| 4345 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4346 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4347 | return; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4348 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4349 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4350 | } |
| 4351 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4352 | if (hintStatus == NotifyExpectedPresentHintStatus::Sent && |
| 4353 | data.hintStatus.compare_exchange_strong(hintStatus, |
| 4354 | NotifyExpectedPresentHintStatus::ScheduleOnTx)) { |
| 4355 | return; |
| 4356 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4357 | if (hintStatus != NotifyExpectedPresentHintStatus::Start) { |
| 4358 | return; |
| 4359 | } |
| 4360 | data.hintStatus.store(NotifyExpectedPresentHintStatus::ScheduleOnPresent); |
| 4361 | mScheduler->scheduleFrame(); |
| 4362 | } |
| 4363 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4364 | void SurfaceFlinger::scheduleNotifyExpectedPresentHint(PhysicalDisplayId displayId, |
| 4365 | VsyncId vsyncId) { |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4366 | auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4367 | if (itr == mNotifyExpectedPresentMap.end()) { |
| 4368 | return; |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4369 | } |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4370 | |
| 4371 | const char* const whence = __func__; |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4372 | const auto sendHint = [=, this]() { |
| 4373 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4374 | TimePoint expectedPresentTime = data.lastExpectedPresentTimestamp; |
| 4375 | if (ftl::to_underlying(vsyncId) != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 4376 | const auto predictionOpt = mFrameTimeline->getTokenManager()->getPredictionsForToken( |
| 4377 | ftl::to_underlying(vsyncId)); |
| 4378 | const auto expectedPresentTimeOnPredictor = TimePoint::fromNs( |
| 4379 | predictionOpt ? predictionOpt->presentTime : expectedPresentTime.ns()); |
| 4380 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 4381 | const auto expectedPresentTimeOnScheduler = scheduledFrameResultOpt.has_value() |
| 4382 | ? scheduledFrameResultOpt->vsyncTime |
| 4383 | : TimePoint::fromNs(0); |
| 4384 | expectedPresentTime = |
| 4385 | std::max(expectedPresentTimeOnPredictor, expectedPresentTimeOnScheduler); |
| 4386 | } |
| 4387 | |
| 4388 | if (expectedPresentTime < TimePoint::now()) { |
| 4389 | expectedPresentTime = |
| 4390 | mScheduler->getVsyncSchedule()->vsyncDeadlineAfter(TimePoint::now()); |
| 4391 | if (mScheduler->vsyncModulator().getVsyncConfig().sfWorkDuration > |
| 4392 | mScheduler->getVsyncSchedule(displayId)->period()) { |
| 4393 | expectedPresentTime += mScheduler->getVsyncSchedule(displayId)->period(); |
| 4394 | } |
| 4395 | } |
| 4396 | const auto status = getHwComposer().notifyExpectedPresent(displayId, expectedPresentTime, |
| 4397 | data.lastFrameInterval); |
ramindani | c67d22c | 2023-11-28 14:58:47 -0800 | [diff] [blame] | 4398 | if (status != NO_ERROR) { |
| 4399 | ALOGE("%s failed to notifyExpectedPresentHint for display %" PRId64, whence, |
| 4400 | displayId.value); |
| 4401 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4402 | }; |
| 4403 | |
| 4404 | if (itr->second.hintStatus == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 4405 | return static_cast<void>(mScheduler->schedule([=, |
| 4406 | this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 4407 | auto& data = mNotifyExpectedPresentMap.at(displayId); |
| 4408 | auto scheduleHintOnTx = NotifyExpectedPresentHintStatus::ScheduleOnTx; |
| 4409 | if (data.hintStatus.compare_exchange_strong(scheduleHintOnTx, |
| 4410 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4411 | sendHint(); |
| 4412 | } |
| 4413 | })); |
| 4414 | } |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 4415 | auto scheduleHintOnPresent = NotifyExpectedPresentHintStatus::ScheduleOnPresent; |
| 4416 | if (itr->second.hintStatus.compare_exchange_strong(scheduleHintOnPresent, |
| 4417 | NotifyExpectedPresentHintStatus::Sent)) { |
| 4418 | sendHint(); |
| 4419 | } |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | void SurfaceFlinger::sendNotifyExpectedPresentHint(PhysicalDisplayId displayId) { |
| 4423 | if (auto itr = mNotifyExpectedPresentMap.find(displayId); |
| 4424 | itr == mNotifyExpectedPresentMap.end() || |
| 4425 | itr->second.hintStatus != NotifyExpectedPresentHintStatus::ScheduleOnPresent) { |
| 4426 | return; |
| 4427 | } |
| 4428 | scheduleNotifyExpectedPresentHint(displayId); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 4431 | void SurfaceFlinger::onCommitNotComposited(PhysicalDisplayId pacesetterDisplayId) { |
| 4432 | if (FlagManager::getInstance().commit_not_composited()) { |
| 4433 | mFrameTimeline->onCommitNotComposited(); |
| 4434 | } |
| 4435 | } |
| 4436 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4437 | void SurfaceFlinger::initScheduler(const sp<const DisplayDevice>& display) { |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4438 | using namespace scheduler; |
| 4439 | |
Dominik Laskowski | 6839927 | 2022-09-15 07:54:46 -0700 | [diff] [blame] | 4440 | LOG_ALWAYS_FATAL_IF(mScheduler); |
| 4441 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 4442 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 4443 | const Fps activeRefreshRate = activeMode.fps; |
Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 4444 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4445 | FeatureFlags features; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4446 | |
Ady Abraham | 3f84c50 | 2023-11-30 18:18:06 -0800 | [diff] [blame] | 4447 | const auto defaultContentDetectionValue = |
| 4448 | FlagManager::getInstance().enable_fro_dependent_features() && |
| 4449 | sysprop::enable_frame_rate_override(true); |
| 4450 | if (sysprop::use_content_detection_for_refresh_rate(defaultContentDetectionValue)) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4451 | features |= Feature::kContentDetection; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 4452 | if (FlagManager::getInstance().enable_small_area_detection()) { |
Arthur Hung | c70bee2 | 2023-06-02 01:35:52 +0000 | [diff] [blame] | 4453 | features |= Feature::kSmallDirtyContentDetection; |
| 4454 | } |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4455 | } |
| 4456 | if (base::GetBoolProperty("debug.sf.show_predicted_vsync"s, false)) { |
| 4457 | features |= Feature::kTracePredictedVsync; |
| 4458 | } |
| 4459 | if (!base::GetBoolProperty("debug.sf.vsync_reactor_ignore_present_fences"s, false) && |
Dominik Laskowski | e62606d | 2024-02-22 11:42:13 -0500 | [diff] [blame] | 4460 | mHasReliablePresentFences) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 4461 | features |= Feature::kPresentFences; |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4462 | } |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4463 | if (display->refreshRateSelector().kernelIdleTimerController()) { |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4464 | features |= Feature::kKernelIdleTimer; |
| 4465 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 4466 | if (mBackpressureGpuComposition) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4467 | features |= Feature::kBackpressureGpuComposition; |
| 4468 | } |
Leon Scroggins III | 0bd0d4c | 2022-12-08 13:20:45 -0500 | [diff] [blame] | 4469 | if (getHwComposer().getComposer()->isSupported( |
| 4470 | Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) { |
| 4471 | features |= Feature::kExpectedPresentTime; |
| 4472 | } |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 4473 | |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4474 | mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this), |
| 4475 | static_cast<ISchedulerCallback&>(*this), features, |
ramindani | ae64582 | 2024-01-11 10:57:29 -0800 | [diff] [blame] | 4476 | getFactory(), activeRefreshRate, *mTimeStats); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4477 | |
| 4478 | // The pacesetter must be registered before EventThread creation below. |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 4479 | mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector()); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4480 | if (FlagManager::getInstance().vrr_config()) { |
Ady Abraham | ee6365b | 2024-03-06 14:31:45 -0800 | [diff] [blame] | 4481 | mScheduler->setRenderRate(display->getPhysicalId(), activeMode.fps, |
| 4482 | /*applyImmediately*/ true); |
ramindani | d4354a9 | 2023-10-02 15:11:09 -0700 | [diff] [blame] | 4483 | } |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 4484 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 4485 | const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs(); |
Dominik Laskowski | 1c99a00 | 2023-01-20 17:10:36 -0500 | [diff] [blame] | 4486 | |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4487 | mScheduler->createEventThread(scheduler::Cycle::Render, mFrameTimeline->getTokenManager(), |
| 4488 | /* workDuration */ configs.late.appWorkDuration, |
| 4489 | /* readyDuration */ configs.late.sfWorkDuration); |
| 4490 | mScheduler->createEventThread(scheduler::Cycle::LastComposite, |
| 4491 | mFrameTimeline->getTokenManager(), |
| 4492 | /* workDuration */ activeRefreshRate.getPeriod(), |
| 4493 | /* readyDuration */ configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4494 | |
Dominik Laskowski | 091129a | 2024-02-21 14:26:03 -0500 | [diff] [blame] | 4495 | // Dispatch after EventThread creation, since registerDisplay above skipped dispatch. |
| 4496 | mScheduler->dispatchHotplug(display->getPhysicalId(), scheduler::Scheduler::Hotplug::Connected); |
| 4497 | |
Leon Scroggins III | a7be94e | 2024-01-23 12:24:30 -0500 | [diff] [blame] | 4498 | mScheduler->initVsync(*mFrameTimeline->getTokenManager(), configs.late.sfWorkDuration); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4499 | |
| 4500 | mRegionSamplingThread = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4501 | sp<RegionSamplingThread>::make(*this, |
| 4502 | RegionSamplingThread::EnvironmentTimingTunables()); |
Andy Yu | aef688b | 2024-01-23 17:14:23 -0800 | [diff] [blame] | 4503 | mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 4504 | |
| 4505 | // Timer callbacks may fire, so do this last. |
| 4506 | mScheduler->startTimers(); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4509 | void SurfaceFlinger::doCommitTransactions() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 4510 | ATRACE_CALL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4512 | if (!mLayersPendingRemoval.isEmpty()) { |
| 4513 | // Notify removed layers now that they can't be drawn from |
| 4514 | for (const auto& l : mLayersPendingRemoval) { |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4515 | // Ensure any buffers set to display on any children are released. |
| 4516 | if (l->isRemovedFromCurrentState()) { |
| 4517 | l->latchAndReleaseBuffer(); |
| 4518 | } |
| 4519 | |
chaviw | 6852bff | 2022-04-19 17:35:11 -0500 | [diff] [blame] | 4520 | // If a layer has a parent, we allow it to out-live it's handle |
| 4521 | // with the idea that the parent holds a reference and will eventually |
| 4522 | // be cleaned up. However no one cleans up the top-level so we do so |
| 4523 | // here. |
| 4524 | if (l->isAtRoot()) { |
| 4525 | l->setIsAtRoot(false); |
| 4526 | mCurrentState.layersSortedByZ.remove(l); |
| 4527 | } |
| 4528 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4529 | // If the layer has been removed and has no parent, then it will not be reachable |
| 4530 | // when traversing layers on screen. Add the layer to the offscreenLayers set to |
| 4531 | // ensure we can copy its current to drawing state. |
| 4532 | if (!l->getParent()) { |
| 4533 | mOffscreenLayers.emplace(l.get()); |
| 4534 | } |
| 4535 | } |
| 4536 | mLayersPendingRemoval.clear(); |
| 4537 | } |
| 4538 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4539 | mDrawingState = mCurrentState; |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4540 | mCurrentState.colorMatrixChanged = false; |
| 4541 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4542 | if (mVisibleRegionsDirty) { |
| 4543 | for (const auto& rootLayer : mDrawingState.layersSortedByZ) { |
| 4544 | rootLayer->commitChildList(); |
| 4545 | } |
Andrei Stanciu | dadac5a | 2020-08-05 17:02:34 +0300 | [diff] [blame] | 4546 | } |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 4547 | |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4548 | commitOffscreenLayers(); |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4549 | if (mLayerMirrorRoots.size() > 0) { |
| 4550 | std::deque<Layer*> pendingUpdates; |
| 4551 | pendingUpdates.insert(pendingUpdates.end(), mLayerMirrorRoots.begin(), |
| 4552 | mLayerMirrorRoots.end()); |
| 4553 | std::vector<Layer*> needsUpdating; |
| 4554 | for (Layer* cloneRoot : mLayerMirrorRoots) { |
| 4555 | pendingUpdates.pop_front(); |
| 4556 | if (cloneRoot->isRemovedFromCurrentState()) { |
| 4557 | continue; |
| 4558 | } |
| 4559 | if (cloneRoot->updateMirrorInfo(pendingUpdates)) { |
| 4560 | } else { |
| 4561 | needsUpdating.push_back(cloneRoot); |
| 4562 | } |
| 4563 | } |
| 4564 | for (Layer* cloneRoot : needsUpdating) { |
| 4565 | cloneRoot->updateMirrorInfo({}); |
| 4566 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4567 | } |
Lloyd Pique | 58e24a3 | 2019-08-01 15:50:14 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4570 | void SurfaceFlinger::commitOffscreenLayers() { |
| 4571 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4572 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, [](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4573 | if (layer->clearTransactionFlags(eTransactionNeeded)) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4574 | layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4575 | layer->commitChildList(); |
| 4576 | } |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 4577 | }); |
| 4578 | } |
| 4579 | } |
| 4580 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4581 | void SurfaceFlinger::invalidateLayerStack(const ui::LayerFilter& layerFilter, const Region& dirty) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 4582 | for (const auto& [token, displayDevice] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4583 | auto display = displayDevice->getCompositionDisplay(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4584 | if (display->includesLayer(layerFilter)) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4585 | display->editState().dirtyRegion.orSelf(dirty); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 4586 | } |
| 4587 | } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4590 | bool SurfaceFlinger::latchBuffers() { |
Ady Abraham | 09bd392 | 2019-04-08 10:44:56 -0700 | [diff] [blame] | 4591 | ATRACE_CALL(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 4592 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4593 | const nsecs_t latchTime = systemTime(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4595 | bool visibleRegions = false; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4596 | bool frameQueued = false; |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4597 | bool newDataLatched = false; |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 4598 | |
| 4599 | // Store the set of layers that need updates. This set must not change as |
| 4600 | // buffers are being latched, as this could result in a deadlock. |
| 4601 | // Example: Two producers share the same command stream and: |
| 4602 | // 1.) Layer 0 is latched |
| 4603 | // 2.) Layer 0 gets a new frame |
| 4604 | // 2.) Layer 1 gets a new frame |
| 4605 | // 3.) Layer 1 is latched. |
| 4606 | // Display is now waiting on Layer 1's frame, which is behind layer 0's |
| 4607 | // 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] | 4608 | mDrawingState.traverse([&](Layer* layer) { |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4609 | if (layer->clearTransactionFlags(eTransactionNeeded) || mForceTransactionDisplayChange) { |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame] | 4610 | const uint32_t flags = layer->doTransaction(0); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4611 | if (flags & Layer::eVisibleRegion) { |
| 4612 | mVisibleRegionsDirty = true; |
| 4613 | } |
| 4614 | } |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4615 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4616 | if (layer->hasReadyFrame() || layer->willReleaseBufferOnLatch()) { |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4617 | frameQueued = true; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 4618 | mLayersWithQueuedFrames.emplace(sp<Layer>::fromExisting(layer)); |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4619 | } else { |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 4620 | layer->useEmptyDamage(); |
Vishnu Nair | c09c023 | 2023-03-02 03:22:35 +0000 | [diff] [blame] | 4621 | if (!layer->hasBuffer()) { |
| 4622 | // The last latch time is used to classify a missed frame as buffer stuffing |
| 4623 | // instead of a missed frame. This is used to identify scenarios where we |
| 4624 | // could not latch a buffer or apply a transaction due to backpressure. |
| 4625 | // We only update the latch time for buffer less layers here, the latch time |
| 4626 | // is updated for buffer layers when the buffer is latched. |
| 4627 | layer->updateLastLatchTime(latchTime); |
| 4628 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4629 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4630 | }); |
Robert Carr | b552ff5 | 2021-06-11 13:35:54 -0700 | [diff] [blame] | 4631 | mForceTransactionDisplayChange = false; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 4632 | |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4633 | // The client can continue submitting buffers for offscreen layers, but they will not |
| 4634 | // be shown on screen. Therefore, we need to latch and release buffers of offscreen |
| 4635 | // layers to ensure dequeueBuffer doesn't block indefinitely. |
| 4636 | for (Layer* offscreenLayer : mOffscreenLayers) { |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 4637 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
chaviw | 49a108c | 2019-08-12 11:23:06 -0700 | [diff] [blame] | 4638 | [&](Layer* l) { l->latchAndReleaseBuffer(); }); |
| 4639 | } |
| 4640 | |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4641 | if (!mLayersWithQueuedFrames.empty()) { |
| 4642 | // mStateLock is needed for latchBuffer as LayerRejecter::reject() |
| 4643 | // writes to Layer current state. See also b/119481871 |
| 4644 | Mutex::Autolock lock(mStateLock); |
| 4645 | |
Alec Mouri | 2f7d9ae | 2020-11-30 19:32:33 -0800 | [diff] [blame] | 4646 | for (const auto& layer : mLayersWithQueuedFrames) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 4647 | if (layer->willReleaseBufferOnLatch()) { |
| 4648 | mLayersWithBuffersRemoved.emplace(layer); |
| 4649 | } |
Vishnu Nair | 397a0e3 | 2022-07-26 00:01:48 +0000 | [diff] [blame] | 4650 | if (layer->latchBuffer(visibleRegions, latchTime)) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 4651 | mLayersPendingRefresh.push_back(layer); |
Lloyd Pique | f2c7939 | 2018-12-20 16:23:33 -0800 | [diff] [blame] | 4652 | newDataLatched = true; |
| 4653 | } |
Vishnu Nair | 1b70019 | 2022-02-04 10:09:47 -0800 | [diff] [blame] | 4654 | layer->useSurfaceDamage(); |
Mike Stroyan | 0cd7619 | 2017-04-20 12:10:48 -0600 | [diff] [blame] | 4655 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 4656 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 4657 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 4658 | mVisibleRegionsDirty |= visibleRegions; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4659 | |
| 4660 | // If we will need to wake up at some time in the future to deal with a |
| 4661 | // queued frame that shouldn't be displayed during this vsync period, wake |
| 4662 | // up during the next vsync period to check again. |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 4663 | if (frameQueued && (mLayersWithQueuedFrames.empty() || !newDataLatched)) { |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 4664 | scheduleCommit(FrameHint::kNone); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4665 | } |
| 4666 | |
Chia-I Wu | 14c9c7b | 2018-06-26 10:18:18 +0800 | [diff] [blame] | 4667 | // enter boot animation on first buffer latch |
| 4668 | if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) { |
| 4669 | ALOGI("Enter boot animation"); |
| 4670 | mBootStage = BootStage::BOOTANIMATION; |
| 4671 | } |
| 4672 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4673 | if (mLayerMirrorRoots.size() > 0) { |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 4674 | mDrawingState.traverse([&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 4675 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 4676 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 4677 | // 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] | 4678 | return !mLayersWithQueuedFrames.empty() && newDataLatched; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4679 | } |
| 4680 | |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4681 | status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinder>& handle, |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4682 | const sp<Layer>& layer, const wp<Layer>& parent, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4683 | uint32_t* outTransformHint) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4684 | if (mNumLayers >= MAX_LAYERS) { |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4685 | ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 4686 | MAX_LAYERS); |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 4687 | static_cast<void>(mScheduler->schedule([=, this] { |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4688 | ALOGE("Dumping layer keeping > 20 children alive:"); |
| 4689 | bool leakingParentLayerFound = false; |
| 4690 | mDrawingState.traverse([&](Layer* layer) { |
| 4691 | if (leakingParentLayerFound) { |
| 4692 | return; |
| 4693 | } |
| 4694 | if (layer->getChildrenCount() > 20) { |
| 4695 | leakingParentLayerFound = true; |
| 4696 | sp<Layer> parent = sp<Layer>::fromExisting(layer); |
| 4697 | while (parent) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4698 | ALOGE("Parent Layer: %s%s", parent->getName().c_str(), |
| 4699 | (parent->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4700 | parent = parent->getParent(); |
| 4701 | } |
| 4702 | // Sample up to 100 layers |
| 4703 | ALOGE("Dumping random sampling of child layers total(%zu): ", |
| 4704 | layer->getChildrenCount()); |
| 4705 | int sampleSize = (layer->getChildrenCount() / 100) + 1; |
| 4706 | layer->traverseChildren([&](Layer* layer) { |
| 4707 | if (rand() % sampleSize == 0) { |
jiayongqiang | c476a34 | 2023-12-06 17:04:54 +0800 | [diff] [blame] | 4708 | ALOGE("Child Layer: %s%s", layer->getName().c_str(), |
| 4709 | (layer->isHandleAlive() ? "handleAlive" : "")); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4710 | } |
| 4711 | }); |
| 4712 | } |
| 4713 | }); |
| 4714 | |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4715 | int numLayers = 0; |
| 4716 | mDrawingState.traverse([&](Layer* layer) { numLayers++; }); |
| 4717 | |
| 4718 | ALOGE("Dumping random sampling of on-screen layers total(%u):", numLayers); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4719 | mDrawingState.traverse([&](Layer* layer) { |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4720 | // Aim to dump about 200 layers to avoid totally trashing |
| 4721 | // logcat. On the other hand, if there really are 4096 layers |
| 4722 | // something has gone totally wrong its probably the most |
| 4723 | // useful information in logcat. |
| 4724 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4725 | ALOGE("Layer: %s%s", layer->getName().c_str(), |
| 4726 | (layer->isHandleAlive() ? "handleAlive" : "")); |
| 4727 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4728 | } |
| 4729 | }); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 4730 | ALOGE("Dumping random sampling of off-screen layers total(%zu): ", |
| 4731 | mOffscreenLayers.size()); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4732 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 4733 | if (rand() % 20 == 13) { |
Vishnu Nair | 3be6190 | 2023-04-26 19:47:29 -0700 | [diff] [blame] | 4734 | ALOGE("Offscreen-layer: %s%s", offscreenLayer->getName().c_str(), |
| 4735 | (offscreenLayer->isHandleAlive() ? "handleAlive" : "")); |
| 4736 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Robert Carr | 26b98f4 | 2022-04-11 15:54:31 -0700 | [diff] [blame] | 4737 | } |
| 4738 | } |
| 4739 | })); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4740 | return NO_MEMORY; |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
Vishnu Nair | 86e1190 | 2022-09-06 16:03:27 +0000 | [diff] [blame] | 4743 | layer->updateTransformHint(mActiveDisplayTransformHint); |
| 4744 | if (outTransformHint) { |
| 4745 | *outTransformHint = mActiveDisplayTransformHint; |
| 4746 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 4747 | args.parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
| 4748 | args.layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4749 | { |
| 4750 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 4751 | mCreatedLayers.emplace_back(layer, parent, args.addToRoot); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 4752 | mNewLayers.emplace_back(std::make_unique<frontend::RequestedLayerState>(args)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 4753 | args.mirrorLayerHandle.clear(); |
| 4754 | args.parentHandle.clear(); |
| 4755 | mNewLayerArgs.emplace_back(std::move(args)); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4756 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 4757 | |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 4758 | setTransactionFlags(eTransactionNeeded); |
| 4759 | return NO_ERROR; |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 4760 | } |
| 4761 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4762 | uint32_t SurfaceFlinger::getTransactionFlags() const { |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 4763 | return mTransactionFlags; |
Mathias Agopian | dea20b1 | 2011-05-03 17:04:02 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 4766 | uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) { |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4767 | uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask); |
| 4768 | ATRACE_INT("mTransactionFlags", transactionFlags); |
| 4769 | return transactionFlags & mask; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4772 | void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule, |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4773 | const sp<IBinder>& applyToken, FrameHint frameHint) { |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 4774 | mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken); |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4775 | uint32_t transactionFlags = mTransactionFlags.fetch_or(mask); |
| 4776 | ATRACE_INT("mTransactionFlags", transactionFlags); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4777 | |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 4778 | if (const bool scheduled = transactionFlags & mask; !scheduled) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 4779 | scheduleCommit(frameHint); |
Ady Abraham | 27bcb55 | 2023-01-21 04:34:22 +0000 | [diff] [blame] | 4780 | } else if (frameHint == FrameHint::kActive) { |
| 4781 | // Even if the next frame is already scheduled, we should reset the idle timer |
| 4782 | // as a new activity just happened. |
| 4783 | mScheduler->resetIdleTimer(); |
Dominik Laskowski | 94000c4 | 2022-03-17 12:55:14 -0700 | [diff] [blame] | 4784 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4785 | } |
| 4786 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4787 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyTimelineCheck( |
| 4788 | const TransactionHandler::TransactionFlushState& flushState) { |
Dominik Laskowski | e85d7fa | 2023-05-15 10:50:22 -0400 | [diff] [blame] | 4789 | const auto& transaction = *flushState.transaction; |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4790 | |
| 4791 | const TimePoint desiredPresentTime = TimePoint::fromNs(transaction.desiredPresentTime); |
Dominik Laskowski | ec0eac2 | 2023-01-28 16:16:19 -0500 | [diff] [blame] | 4792 | const TimePoint expectedPresentTime = mScheduler->expectedPresentTimeForPacesetter(); |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4793 | |
| 4794 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4795 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4796 | // Do not present if the desiredPresentTime has not passed unless it is more than |
| 4797 | // one second in the future. We ignore timestamps more than 1 second in the future |
| 4798 | // for stability reasons. |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4799 | if (!transaction.isAutoTimestamp && desiredPresentTime >= expectedPresentTime && |
| 4800 | desiredPresentTime < expectedPresentTime + 1s) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4801 | ATRACE_FORMAT("not current desiredPresentTime: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4802 | desiredPresentTime, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4803 | return TransactionReadiness::NotReady; |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 4804 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4805 | |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4806 | const auto vsyncId = VsyncId{transaction.frameTimelineInfo.vsyncId}; |
| 4807 | |
| 4808 | // Transactions with VsyncId are already throttled by the vsyncId (i.e. Choreographer issued |
| 4809 | // the vsyncId according to the frame rate override cadence) so we shouldn't throttle again |
| 4810 | // when applying the transaction. Otherwise we might throttle older transactions |
| 4811 | // incorrectly as the frame rate of SF changed before it drained the older transactions. |
| 4812 | if (ftl::to_underlying(vsyncId) == FrameTimelineInfo::INVALID_VSYNC_ID && |
| 4813 | !mScheduler->isVsyncValid(expectedPresentTime, transaction.originUid)) { |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4814 | ATRACE_FORMAT("!isVsyncValid expectedPresentTime: %" PRId64 " uid: %d", expectedPresentTime, |
| 4815 | transaction.originUid); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4816 | return TransactionReadiness::NotReady; |
| 4817 | } |
| 4818 | |
| 4819 | // If the client didn't specify desiredPresentTime, use the vsyncId to determine the |
| 4820 | // expected present time of this transaction. |
Ady Abraham | 20024aa | 2024-03-05 01:32:49 +0000 | [diff] [blame] | 4821 | if (transaction.isAutoTimestamp && frameIsEarly(expectedPresentTime, vsyncId)) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4822 | ATRACE_FORMAT("frameIsEarly vsyncId: %" PRId64 " expectedPresentTime: %" PRId64, |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4823 | transaction.frameTimelineInfo.vsyncId, expectedPresentTime); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4824 | return TransactionReadiness::NotReady; |
| 4825 | } |
Dominik Laskowski | b418dd7 | 2023-06-13 17:31:04 -0400 | [diff] [blame] | 4826 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4827 | return TransactionReadiness::Ready; |
| 4828 | } |
| 4829 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4830 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheckLegacy( |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4831 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4832 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4833 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4834 | flushState.transaction->traverseStatesWithBuffersWhileTrue([&](const ResolvedComposerState& |
| 4835 | resolvedState) -> bool { |
| 4836 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 4837 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4838 | const auto& transaction = *flushState.transaction; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4839 | const auto& s = resolvedState.state; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4840 | // check for barrier frames |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4841 | if (s.bufferData->hasBarrier) { |
| 4842 | // The current producerId is already a newer producer than the buffer that has a |
| 4843 | // barrier. This means the incoming buffer is older and we can release it here. We |
| 4844 | // 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] | 4845 | if (layer->getDrawingState().barrierProducerId > s.bufferData->producerId) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4846 | layer->callReleaseBufferCallback(s.bufferData->releaseBufferListener, |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4847 | resolvedState.externalTexture->getBuffer(), |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 4848 | s.bufferData->frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4849 | s.bufferData->acquireFence); |
| 4850 | // Delete the entire state at this point and not just release the buffer because |
| 4851 | // 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] | 4852 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4853 | layer->getDebugName(), layer->getDrawingState().barrierProducerId, |
| 4854 | s.bufferData->producerId); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4855 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4856 | } |
| 4857 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 4858 | if (layer->getDrawingState().barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4859 | const bool willApplyBarrierFrame = |
| 4860 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4861 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4862 | s.bufferData->barrierFrameNumber)); |
| 4863 | if (!willApplyBarrierFrame) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4864 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 " > %" PRId64, |
| 4865 | layer->getDebugName(), |
| 4866 | layer->getDrawingState().barrierFrameNumber, |
| 4867 | s.bufferData->barrierFrameNumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4868 | ready = TransactionReadiness::NotReadyBarrier; |
| 4869 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4870 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4875 | // the transaction in the queue. |
| 4876 | const bool hasPendingBuffer = |
| 4877 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4878 | if (layer->backpressureEnabled() && hasPendingBuffer && transaction.isAutoTimestamp) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4879 | ATRACE_FORMAT("hasPendingBuffer %s", layer->getDebugName()); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4880 | ready = TransactionReadiness::NotReady; |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4881 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4884 | const bool acquireFenceAvailable = s.bufferData && |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4885 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4886 | s.bufferData->acquireFence; |
Ying Wei | 1fd9bfc | 2023-06-29 16:47:00 +0000 | [diff] [blame] | 4887 | const bool fenceSignaled = !acquireFenceAvailable || |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4888 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4889 | if (!fenceSignaled) { |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4890 | // check fence status |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4891 | const bool allowLatchUnsignaled = shouldLatchUnsignaled(s, transaction.states.size(), |
| 4892 | flushState.firstTransaction) && |
| 4893 | layer->isSimpleBufferUpdate(s); |
| 4894 | |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4895 | if (allowLatchUnsignaled) { |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4896 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 4897 | layer->getDebugName()); |
Vishnu Nair | f01a6f1 | 2023-04-03 22:34:17 +0000 | [diff] [blame] | 4898 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 4899 | } else { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4900 | ready = TransactionReadiness::NotReady; |
| 4901 | auto& listener = s.bufferData->releaseBufferListener; |
| 4902 | if (listener && |
| 4903 | (flushState.queueProcessTime - transaction.postTime) > |
| 4904 | std::chrono::nanoseconds(4s).count()) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4905 | // Used to add a stalled transaction which uses an internal lock. |
| 4906 | ftl::FakeGuard guard(kMainThreadContext); |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 4907 | mTransactionHandler |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 4908 | .onTransactionQueueStalled(transaction.id, |
| 4909 | {.pid = layer->getOwnerPid(), |
| 4910 | .layerId = static_cast<uint32_t>( |
| 4911 | layer->getSequence()), |
| 4912 | .layerName = layer->getDebugName(), |
| 4913 | .bufferId = s.bufferData->getId(), |
| 4914 | .frameNumber = s.bufferData->frameNumber}); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4915 | } |
Vishnu Nair | 73cc9fd | 2023-04-18 11:18:07 -0700 | [diff] [blame] | 4916 | ATRACE_FORMAT("fence unsignaled %s", layer->getDebugName()); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4917 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4918 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4919 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 4920 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4921 | }); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 4922 | return ready; |
| 4923 | } |
| 4924 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4925 | TransactionHandler::TransactionReadiness SurfaceFlinger::transactionReadyBufferCheck( |
| 4926 | const TransactionHandler::TransactionFlushState& flushState) { |
| 4927 | using TransactionReadiness = TransactionHandler::TransactionReadiness; |
| 4928 | auto ready = TransactionReadiness::Ready; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4929 | flushState.transaction->traverseStatesWithBuffersWhileTrue( |
| 4930 | [&](const ResolvedComposerState& resolvedState) FTL_FAKE_GUARD( |
| 4931 | kMainThreadContext) -> bool { |
| 4932 | const frontend::RequestedLayerState* layer = |
| 4933 | mLayerLifecycleManager.getLayerFromId(resolvedState.layerId); |
| 4934 | const auto& transaction = *flushState.transaction; |
| 4935 | const auto& s = resolvedState.state; |
| 4936 | // check for barrier frames |
| 4937 | if (s.bufferData->hasBarrier) { |
| 4938 | // The current producerId is already a newer producer than the buffer that has a |
| 4939 | // barrier. This means the incoming buffer is older and we can release it here. |
| 4940 | // We don't wait on the barrier since we know that's stale information. |
| 4941 | if (layer->barrierProducerId > s.bufferData->producerId) { |
| 4942 | if (s.bufferData->releaseBufferListener) { |
| 4943 | uint32_t currentMaxAcquiredBufferCount = |
| 4944 | getMaxAcquiredBufferCountForCurrentRefreshRate( |
| 4945 | layer->ownerUid.val()); |
| 4946 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, |
| 4947 | layer->name.c_str(), s.bufferData->frameNumber); |
| 4948 | s.bufferData->releaseBufferListener |
| 4949 | ->onReleaseBuffer({resolvedState.externalTexture->getBuffer() |
| 4950 | ->getId(), |
| 4951 | s.bufferData->frameNumber}, |
| 4952 | s.bufferData->acquireFence |
| 4953 | ? s.bufferData->acquireFence |
| 4954 | : Fence::NO_FENCE, |
| 4955 | currentMaxAcquiredBufferCount); |
| 4956 | } |
| 4957 | |
| 4958 | // Delete the entire state at this point and not just release the buffer |
| 4959 | // because everything associated with the Layer in this Transaction is now |
| 4960 | // out of date. |
| 4961 | ATRACE_FORMAT("DeleteStaleBuffer %s barrierProducerId:%d > %d", |
| 4962 | layer->name.c_str(), layer->barrierProducerId, |
| 4963 | s.bufferData->producerId); |
| 4964 | return TraverseBuffersReturnValues::DELETE_AND_CONTINUE_TRAVERSAL; |
| 4965 | } |
| 4966 | |
| 4967 | if (layer->barrierFrameNumber < s.bufferData->barrierFrameNumber) { |
| 4968 | const bool willApplyBarrierFrame = |
| 4969 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()) && |
| 4970 | ((flushState.bufferLayersReadyToPresent.get(s.surface.get()) >= |
| 4971 | s.bufferData->barrierFrameNumber)); |
| 4972 | if (!willApplyBarrierFrame) { |
| 4973 | ATRACE_FORMAT("NotReadyBarrier %s barrierFrameNumber:%" PRId64 |
| 4974 | " > %" PRId64, |
| 4975 | layer->name.c_str(), layer->barrierFrameNumber, |
| 4976 | s.bufferData->barrierFrameNumber); |
| 4977 | ready = TransactionReadiness::NotReadyBarrier; |
| 4978 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4979 | } |
| 4980 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4981 | } |
| 4982 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4983 | // If backpressure is enabled and we already have a buffer to commit, keep |
| 4984 | // the transaction in the queue. |
| 4985 | const bool hasPendingBuffer = |
| 4986 | flushState.bufferLayersReadyToPresent.contains(s.surface.get()); |
| 4987 | if (layer->backpressureEnabled() && hasPendingBuffer && |
| 4988 | transaction.isAutoTimestamp) { |
| 4989 | ATRACE_FORMAT("hasPendingBuffer %s", layer->name.c_str()); |
| 4990 | ready = TransactionReadiness::NotReady; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4991 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 4992 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 4993 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 4994 | const bool acquireFenceAvailable = s.bufferData && |
| 4995 | s.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged) && |
| 4996 | s.bufferData->acquireFence; |
| 4997 | const bool fenceSignaled = !acquireFenceAvailable || |
| 4998 | s.bufferData->acquireFence->getStatus() != Fence::Status::Unsignaled; |
| 4999 | if (!fenceSignaled) { |
| 5000 | // check fence status |
| 5001 | const bool allowLatchUnsignaled = |
| 5002 | shouldLatchUnsignaled(s, transaction.states.size(), |
| 5003 | flushState.firstTransaction) && |
| 5004 | layer->isSimpleBufferUpdate(s); |
| 5005 | if (allowLatchUnsignaled) { |
| 5006 | ATRACE_FORMAT("fence unsignaled try allowLatchUnsignaled %s", |
| 5007 | layer->name.c_str()); |
| 5008 | ready = TransactionReadiness::NotReadyUnsignaled; |
| 5009 | } else { |
| 5010 | ready = TransactionReadiness::NotReady; |
| 5011 | auto& listener = s.bufferData->releaseBufferListener; |
| 5012 | if (listener && |
| 5013 | (flushState.queueProcessTime - transaction.postTime) > |
| 5014 | std::chrono::nanoseconds(4s).count()) { |
| 5015 | mTransactionHandler |
| 5016 | .onTransactionQueueStalled(transaction.id, |
| 5017 | {.pid = layer->ownerPid.val(), |
| 5018 | .layerId = layer->id, |
| 5019 | .layerName = layer->name, |
| 5020 | .bufferId = s.bufferData->getId(), |
| 5021 | .frameNumber = |
| 5022 | s.bufferData->frameNumber}); |
| 5023 | } |
| 5024 | ATRACE_FORMAT("fence unsignaled %s", layer->name.c_str()); |
| 5025 | return TraverseBuffersReturnValues::STOP_TRAVERSAL; |
| 5026 | } |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5027 | } |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5028 | return TraverseBuffersReturnValues::CONTINUE_TRAVERSAL; |
| 5029 | }); |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5030 | return ready; |
| 5031 | } |
| 5032 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5033 | void SurfaceFlinger::addTransactionReadyFilters() { |
| 5034 | mTransactionHandler.addTransactionReadyFilter( |
| 5035 | std::bind(&SurfaceFlinger::transactionReadyTimelineCheck, this, std::placeholders::_1)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5036 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5037 | mTransactionHandler.addTransactionReadyFilter( |
| 5038 | std::bind(&SurfaceFlinger::transactionReadyBufferCheck, this, |
| 5039 | std::placeholders::_1)); |
| 5040 | } else { |
| 5041 | mTransactionHandler.addTransactionReadyFilter( |
| 5042 | std::bind(&SurfaceFlinger::transactionReadyBufferCheckLegacy, this, |
| 5043 | std::placeholders::_1)); |
| 5044 | } |
Ady Abraham | e1bfaac | 2022-02-22 21:32:08 -0800 | [diff] [blame] | 5045 | } |
| 5046 | |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5047 | // For tests only |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5048 | bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5049 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5050 | std::vector<TransactionState> transactions = mTransactionHandler.flushTransactions(); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5051 | return applyTransactions(transactions, vsyncId); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5054 | bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions, |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5055 | VsyncId vsyncId) { |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 5056 | Mutex::Autolock lock(mStateLock); |
Vishnu Nair | 42ad319 | 2023-01-24 19:17:59 -0800 | [diff] [blame] | 5057 | return applyTransactionsLocked(transactions, vsyncId); |
| 5058 | } |
| 5059 | |
| 5060 | bool SurfaceFlinger::applyTransactionsLocked(std::vector<TransactionState>& transactions, |
| 5061 | VsyncId vsyncId) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5062 | bool needsTraversal = false; |
| 5063 | // Now apply all transactions. |
Robert Carr | ff7663b | 2022-02-08 12:46:49 -0800 | [diff] [blame] | 5064 | for (auto& transaction : transactions) { |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5065 | needsTraversal |= |
| 5066 | applyTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 5067 | transaction.displays, transaction.flags, |
| 5068 | transaction.inputWindowCommands, |
| 5069 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5070 | std::move(transaction.uncacheBufferIds), transaction.postTime, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5071 | transaction.hasListenerCallbacks, |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5072 | transaction.listenerCallbacks, transaction.originPid, |
| 5073 | transaction.originUid, transaction.id); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 5074 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5075 | return needsTraversal; |
Marissa Wall | e6e3c0d | 2019-03-29 10:28:30 -0700 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | bool SurfaceFlinger::transactionFlushNeeded() { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5079 | return mTransactionHandler.hasPendingTransactions(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5080 | } |
| 5081 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5082 | bool SurfaceFlinger::frameIsEarly(TimePoint expectedPresentTime, VsyncId vsyncId) const { |
| 5083 | const auto prediction = |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 5084 | mFrameTimeline->getTokenManager()->getPredictionsForToken(ftl::to_underlying(vsyncId)); |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5085 | if (!prediction) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5086 | return false; |
| 5087 | } |
| 5088 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5089 | const auto predictedPresentTime = TimePoint::fromNs(prediction->presentTime); |
| 5090 | |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 5091 | if (std::chrono::abs(predictedPresentTime - expectedPresentTime) >= |
| 5092 | scheduler::VsyncConfig::kEarlyLatchMaxThreshold) { |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5093 | return false; |
| 5094 | } |
| 5095 | |
Ady Abraham | 3db8a3c | 2023-11-20 17:53:47 -0800 | [diff] [blame] | 5096 | const Duration earlyLatchVsyncThreshold = mScheduler->getVsyncSchedule()->minFramePeriod() / 2; |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5097 | |
| 5098 | return predictedPresentTime >= expectedPresentTime && |
| 5099 | predictedPresentTime - expectedPresentTime >= earlyLatchVsyncThreshold; |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5100 | } |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 5101 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5102 | bool SurfaceFlinger::shouldLatchUnsignaled(const layer_state_t& state, size_t numStates, |
| 5103 | bool firstTransaction) const { |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5104 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::Disabled) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5105 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::Disabled)", __func__); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5106 | return false; |
| 5107 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5108 | |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5109 | // We only want to latch unsignaled when a single layer is updated in this |
| 5110 | // transaction (i.e. not a blast sync transaction). |
| 5111 | if (numStates != 1) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5112 | ATRACE_FORMAT_INSTANT("%s: false (numStates=%zu)", __func__, numStates); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5113 | return false; |
| 5114 | } |
| 5115 | |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5116 | if (enableLatchUnsignaledConfig == LatchUnsignaledConfig::AutoSingleLayer) { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5117 | if (!firstTransaction) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5118 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; not first " |
| 5119 | "transaction)", |
| 5120 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | // We don't want to latch unsignaled if are in early / client composition |
| 5125 | // as it leads to jank due to RenderEngine waiting for unsignaled buffer |
| 5126 | // or window animations being slow. |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 5127 | if (mScheduler->vsyncModulator().isVsyncConfigEarly()) { |
Ady Abraham | 005398b | 2023-06-05 13:59:41 -0700 | [diff] [blame] | 5128 | ATRACE_FORMAT_INSTANT("%s: false (LatchUnsignaledConfig::AutoSingleLayer; " |
| 5129 | "isVsyncConfigEarly)", |
| 5130 | __func__); |
Ady Abraham | 2739e83 | 2022-02-14 17:42:00 -0800 | [diff] [blame] | 5131 | return false; |
| 5132 | } |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5133 | } |
| 5134 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 5135 | return true; |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 5136 | } |
| 5137 | |
chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 5138 | status_t SurfaceFlinger::setTransactionState( |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5139 | const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5140 | const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5141 | InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, |
| 5142 | const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5143 | const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, |
| 5144 | const std::vector<uint64_t>& mergedTransactionIds) { |
Jamie Gennis | 7c41bf7 | 2012-10-17 09:29:47 -0700 | [diff] [blame] | 5145 | ATRACE_CALL(); |
Robert Carr | 14167e0 | 2019-02-13 13:50:55 -0800 | [diff] [blame] | 5146 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5147 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5148 | const int originPid = ipc->getCallingPid(); |
| 5149 | const int originUid = ipc->getCallingUid(); |
| 5150 | uint32_t permissions = LayerStatePermissions::getTransactionPermissions(originPid, originUid); |
Patrick Williams | 04e4176 | 2024-04-23 19:05:38 -0500 | [diff] [blame] | 5151 | for (auto& composerState : states) { |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5152 | composerState.state.sanitize(permissions); |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5153 | } |
| 5154 | |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5155 | for (DisplayState display : displays) { |
| 5156 | display.sanitize(permissions); |
| 5157 | } |
| 5158 | |
| 5159 | if (!inputWindowCommands.empty() && |
| 5160 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) { |
| 5161 | ALOGE("Only privileged callers are allowed to send input commands."); |
| 5162 | inputWindowCommands.clear(); |
Leon Scroggins | 9a20f72 | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 5163 | } |
| 5164 | |
Vishnu Nair | 884549f | 2022-12-01 17:20:59 -0800 | [diff] [blame] | 5165 | if (flags & (eEarlyWakeupStart | eEarlyWakeupEnd)) { |
| 5166 | const bool hasPermission = |
| 5167 | (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) || |
| 5168 | callingThreadHasPermission(sWakeupSurfaceFlinger); |
| 5169 | if (!hasPermission) { |
| 5170 | ALOGE("Caller needs permission android.permission.WAKEUP_SURFACE_FLINGER to use " |
| 5171 | "eEarlyWakeup[Start|End] flags"); |
| 5172 | flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd); |
| 5173 | } |
arthurhung | f1b7c7b | 2021-03-03 17:42:23 +0800 | [diff] [blame] | 5174 | } |
| 5175 | |
Vishnu Nair | 24e3bba | 2021-02-23 14:19:36 -0800 | [diff] [blame] | 5176 | const int64_t postTime = systemTime(); |
| 5177 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5178 | std::vector<uint64_t> uncacheBufferIds; |
| 5179 | uncacheBufferIds.reserve(uncacheBuffers.size()); |
| 5180 | for (const auto& uncacheBuffer : uncacheBuffers) { |
| 5181 | sp<GraphicBuffer> buffer = ClientCache::getInstance().erase(uncacheBuffer); |
| 5182 | if (buffer != nullptr) { |
| 5183 | uncacheBufferIds.push_back(buffer->getId()); |
| 5184 | } |
| 5185 | } |
| 5186 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5187 | std::vector<ResolvedComposerState> resolvedStates; |
| 5188 | resolvedStates.reserve(states.size()); |
| 5189 | for (auto& state : states) { |
| 5190 | resolvedStates.emplace_back(std::move(state)); |
| 5191 | auto& resolvedState = resolvedStates.back(); |
| 5192 | if (resolvedState.state.hasBufferChanges() && resolvedState.state.hasValidBuffer() && |
| 5193 | resolvedState.state.surface) { |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5194 | sp<Layer> layer = LayerHandle::getLayer(resolvedState.state.surface); |
| 5195 | std::string layerName = (layer) ? |
| 5196 | layer->getDebugName() : std::to_string(resolvedState.state.layerId); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5197 | resolvedState.externalTexture = |
| 5198 | getExternalTextureFromBufferData(*resolvedState.state.bufferData, |
Vishnu Nair | c6086dd | 2022-11-04 04:39:35 +0000 | [diff] [blame] | 5199 | layerName.c_str(), transactionId); |
Patrick Williams | 38d920e | 2023-08-31 17:31:18 -0500 | [diff] [blame] | 5200 | if (resolvedState.externalTexture) { |
| 5201 | resolvedState.state.bufferData->buffer = resolvedState.externalTexture->getBuffer(); |
| 5202 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5203 | mBufferCountTracker.increment(resolvedState.state.surface->localBinder()); |
| 5204 | } |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 5205 | resolvedState.layerId = LayerHandle::getLayerId(resolvedState.state.surface); |
| 5206 | if (resolvedState.state.what & layer_state_t::eReparent) { |
| 5207 | resolvedState.parentId = |
| 5208 | getLayerIdFromSurfaceControl(resolvedState.state.parentSurfaceControlForChild); |
| 5209 | } |
| 5210 | if (resolvedState.state.what & layer_state_t::eRelativeLayerChanged) { |
| 5211 | resolvedState.relativeParentId = |
| 5212 | getLayerIdFromSurfaceControl(resolvedState.state.relativeLayerSurfaceControl); |
| 5213 | } |
| 5214 | if (resolvedState.state.what & layer_state_t::eInputInfoChanged) { |
| 5215 | wp<IBinder>& touchableRegionCropHandle = |
| 5216 | resolvedState.state.windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 5217 | resolvedState.touchCropId = |
| 5218 | LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
| 5219 | } |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5222 | TransactionState state{frameTimelineInfo, |
| 5223 | resolvedStates, |
| 5224 | displays, |
| 5225 | flags, |
| 5226 | applyToken, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5227 | std::move(inputWindowCommands), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5228 | desiredPresentTime, |
| 5229 | isAutoTimestamp, |
| 5230 | std::move(uncacheBufferIds), |
| 5231 | postTime, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5232 | hasListenerCallbacks, |
| 5233 | listenerCallbacks, |
| 5234 | originPid, |
| 5235 | originUid, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 5236 | transactionId, |
| 5237 | mergedTransactionIds}; |
Vishnu Nair | 83df034 | 2021-03-30 11:50:44 -0700 | [diff] [blame] | 5238 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 5239 | if (mTransactionTracing) { |
| 5240 | mTransactionTracing->addQueuedTransaction(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 5241 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 5242 | |
| 5243 | const auto schedule = [](uint32_t flags) { |
| 5244 | if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd; |
| 5245 | if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart; |
| 5246 | return TransactionSchedule::Late; |
| 5247 | }(state.flags); |
| 5248 | |
| 5249 | const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 5250 | { |
| 5251 | // Transactions are added via a lockless queue and does not need to be added from the main |
| 5252 | // thread. |
| 5253 | ftl::FakeGuard guard(kMainThreadContext); |
| 5254 | mTransactionHandler.queueTransaction(std::move(state)); |
| 5255 | } |
| 5256 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 5257 | for (const auto& [displayId, data] : mNotifyExpectedPresentMap) { |
| 5258 | if (data.hintStatus.load() == NotifyExpectedPresentHintStatus::ScheduleOnTx) { |
| 5259 | scheduleNotifyExpectedPresentHint(displayId, VsyncId{frameTimelineInfo.vsyncId}); |
| 5260 | } |
| 5261 | } |
Vishnu Nair | e4f00c5 | 2023-01-31 20:20:18 -0800 | [diff] [blame] | 5262 | setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint); |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5263 | return NO_ERROR; |
| 5264 | } |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 5265 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5266 | bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5267 | std::vector<ResolvedComposerState>& states, |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 5268 | Vector<DisplayState>& displays, uint32_t flags, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5269 | const InputWindowCommands& inputWindowCommands, |
| 5270 | const int64_t desiredPresentTime, bool isAutoTimestamp, |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5271 | const std::vector<uint64_t>& uncacheBufferIds, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5272 | const int64_t postTime, bool hasListenerCallbacks, |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5273 | const std::vector<ListenerCallbacks>& listenerCallbacks, |
| 5274 | int originPid, int originUid, uint64_t transactionId) { |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 5275 | uint32_t transactionFlags = 0; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5276 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5277 | for (DisplayState& display : displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5278 | transactionFlags |= setDisplayStateLocked(display); |
| 5279 | } |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5282 | // start and end registration for listeners w/ no surface so they can get their callback. Note |
| 5283 | // that listeners with SurfaceControls will start registration during setClientStateLocked |
| 5284 | // below. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5285 | for (const auto& listener : listenerCallbacks) { |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5286 | mTransactionCallbackInvoker.addEmptyTransaction(listener); |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 5287 | } |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 5288 | nsecs_t now = systemTime(); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5289 | uint32_t clientStateFlags = 0; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5290 | for (auto& resolvedState : states) { |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 5291 | clientStateFlags |= |
| 5292 | updateLayerCallbacksAndStats(frameTimelineInfo, resolvedState, desiredPresentTime, |
| 5293 | isAutoTimestamp, postTime, transactionId); |
Melody Hsu | 2606ec0 | 2024-04-04 22:31:34 +0000 | [diff] [blame] | 5294 | if (!mLayerLifecycleManagerEnabled) { |
| 5295 | if ((flags & eAnimation) && resolvedState.state.surface) { |
| 5296 | if (const auto layer = LayerHandle::getLayer(resolvedState.state.surface)) { |
| 5297 | const auto layerProps = scheduler::LayerProps{ |
| 5298 | .visible = layer->isVisible(), |
| 5299 | .bounds = layer->getBounds(), |
| 5300 | .transform = layer->getTransform(), |
| 5301 | .setFrameRateVote = layer->getFrameRateForLayerTree(), |
| 5302 | .frameRateSelectionPriority = layer->getFrameRateSelectionPriority(), |
| 5303 | .isFrontBuffered = layer->isFrontBuffered(), |
| 5304 | }; |
| 5305 | layer->recordLayerHistoryAnimationTx(layerProps, now); |
| 5306 | } |
Ady Abraham | 5def733 | 2020-05-29 16:13:47 -0700 | [diff] [blame] | 5307 | } |
| 5308 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 5309 | } |
| 5310 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5311 | transactionFlags |= clientStateFlags; |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5312 | transactionFlags |= addInputWindowCommands(inputWindowCommands); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5313 | |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 5314 | for (uint64_t uncacheBufferId : uncacheBufferIds) { |
| 5315 | mBufferIdsToUncache.push_back(uncacheBufferId); |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
Jorim Jaggi | bdcf09c | 2017-08-08 15:22:08 +0200 | [diff] [blame] | 5318 | // If a synchronous transaction is explicitly requested without any changes, force a transaction |
| 5319 | // anyway. This can be used as a flush mechanism for previous async transactions. |
| 5320 | // Empty animation transaction can be used to simulate back-pressure, so also force a |
| 5321 | // transaction for empty animation transactions. |
Vishnu Nair | 1523dad | 2022-09-29 16:05:18 -0700 | [diff] [blame] | 5322 | if (transactionFlags == 0 && (flags & eAnimation)) { |
Robert Carr | 2a7dbb4 | 2016-05-24 11:41:28 -0700 | [diff] [blame] | 5323 | transactionFlags = eTransactionNeeded; |
| 5324 | } |
| 5325 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5326 | bool needsTraversal = false; |
Mathias Agopian | 386aa98 | 2011-11-07 21:58:03 -0800 | [diff] [blame] | 5327 | if (transactionFlags) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5328 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5329 | // 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] | 5330 | if (transactionFlags & eTraversalNeeded) { |
| 5331 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5332 | needsTraversal = true; |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5333 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5334 | if (transactionFlags) { |
| 5335 | setTransactionFlags(transactionFlags); |
Arthur Hung | 1bedccb | 2020-09-24 10:09:25 +0000 | [diff] [blame] | 5336 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5337 | } |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5338 | |
| 5339 | return needsTraversal; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5340 | } |
| 5341 | |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 5342 | bool SurfaceFlinger::applyAndCommitDisplayTransactionStatesLocked( |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5343 | std::vector<TransactionState>& transactions) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5344 | bool needsTraversal = false; |
| 5345 | uint32_t transactionFlags = 0; |
| 5346 | for (auto& transaction : transactions) { |
| 5347 | for (DisplayState& display : transaction.displays) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5348 | transactionFlags |= setDisplayStateLocked(display); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | if (transactionFlags) { |
| 5353 | // We are on the main thread, we are about to perform a traversal. Clear the traversal bit |
| 5354 | // so we don't have to wake up again next frame to perform an unnecessary traversal. |
| 5355 | if (transactionFlags & eTraversalNeeded) { |
| 5356 | transactionFlags = transactionFlags & (~eTraversalNeeded); |
| 5357 | needsTraversal = true; |
| 5358 | } |
| 5359 | if (transactionFlags) { |
| 5360 | setTransactionFlags(transactionFlags); |
| 5361 | } |
| 5362 | } |
| 5363 | |
| 5364 | mFrontEndDisplayInfosChanged = mTransactionFlags & eDisplayTransactionNeeded; |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 5365 | if (mFrontEndDisplayInfosChanged) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5366 | processDisplayChangesLocked(); |
| 5367 | mFrontEndDisplayInfos.clear(); |
| 5368 | for (const auto& [_, display] : mDisplays) { |
| 5369 | mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); |
| 5370 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5371 | needsTraversal = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | return needsTraversal; |
| 5375 | } |
| 5376 | |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5377 | uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s) { |
| 5378 | const ssize_t index = mCurrentState.displays.indexOfKey(s.token); |
| 5379 | if (index < 0) return 0; |
Jesse Hall | 9a14392 | 2012-10-04 16:29:19 -0700 | [diff] [blame] | 5380 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5381 | uint32_t flags = 0; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5382 | DisplayDeviceState& state = mCurrentState.displays.editValueAt(index); |
| 5383 | |
| 5384 | const uint32_t what = s.what; |
| 5385 | if (what & DisplayState::eSurfaceChanged) { |
| 5386 | if (IInterface::asBinder(state.surface) != IInterface::asBinder(s.surface)) { |
| 5387 | state.surface = s.surface; |
| 5388 | flags |= eDisplayTransactionNeeded; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 5389 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5390 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5391 | if (what & DisplayState::eLayerStackChanged) { |
| 5392 | if (state.layerStack != s.layerStack) { |
| 5393 | state.layerStack = s.layerStack; |
| 5394 | flags |= eDisplayTransactionNeeded; |
| 5395 | } |
| 5396 | } |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 5397 | if (what & DisplayState::eFlagsChanged) { |
| 5398 | if (state.flags != s.flags) { |
| 5399 | state.flags = s.flags; |
| 5400 | flags |= eDisplayTransactionNeeded; |
| 5401 | } |
| 5402 | } |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5403 | if (what & DisplayState::eDisplayProjectionChanged) { |
| 5404 | if (state.orientation != s.orientation) { |
| 5405 | state.orientation = s.orientation; |
| 5406 | flags |= eDisplayTransactionNeeded; |
| 5407 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5408 | if (state.orientedDisplaySpaceRect != s.orientedDisplaySpaceRect) { |
| 5409 | state.orientedDisplaySpaceRect = s.orientedDisplaySpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5410 | flags |= eDisplayTransactionNeeded; |
| 5411 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 5412 | if (state.layerStackSpaceRect != s.layerStackSpaceRect) { |
| 5413 | state.layerStackSpaceRect = s.layerStackSpaceRect; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 5414 | flags |= eDisplayTransactionNeeded; |
| 5415 | } |
| 5416 | } |
| 5417 | if (what & DisplayState::eDisplaySizeChanged) { |
| 5418 | if (state.width != s.width) { |
| 5419 | state.width = s.width; |
| 5420 | flags |= eDisplayTransactionNeeded; |
| 5421 | } |
| 5422 | if (state.height != s.height) { |
| 5423 | state.height = s.height; |
| 5424 | flags |= eDisplayTransactionNeeded; |
| 5425 | } |
| 5426 | } |
| 5427 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5428 | return flags; |
| 5429 | } |
| 5430 | |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5431 | bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5432 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5433 | const int pid = ipc->getCallingPid(); |
| 5434 | const int uid = ipc->getCallingUid(); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5435 | if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) && |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 5436 | (usePermissionCache ? !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid) |
| 5437 | : !checkPermission(sAccessSurfaceFlinger, pid, uid))) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 5438 | return false; |
| 5439 | } |
| 5440 | return true; |
| 5441 | } |
| 5442 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5443 | uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5444 | ResolvedComposerState& composerState, |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 5445 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 5446 | int64_t postTime, uint64_t transactionId) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5447 | layer_state_t& s = composerState.state; |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5448 | |
| 5449 | std::vector<ListenerCallbacks> filteredListeners; |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5450 | for (auto& listener : s.listeners) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5451 | // Starts a registration but separates the callback ids according to callback type. This |
| 5452 | // allows the callback invoker to send on latch callbacks earlier. |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5453 | // note that startRegistration will not re-register if the listener has |
| 5454 | // already be registered for a prior surface control |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5455 | |
| 5456 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5457 | if (!onCommitCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5458 | filteredListeners.push_back(onCommitCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5462 | if (!onCompleteCallbacks.callbackIds.empty()) { |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5463 | filteredListeners.push_back(onCompleteCallbacks); |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 5464 | } |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5465 | } |
| 5466 | |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 5467 | const uint64_t what = s.what; |
| 5468 | uint32_t flags = 0; |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5469 | sp<Layer> layer = nullptr; |
| 5470 | if (s.surface) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5471 | layer = LayerHandle::getLayer(s.surface); |
Vishnu Nair | dc6f5b9 | 2019-12-03 07:33:37 -0800 | [diff] [blame] | 5472 | } else { |
| 5473 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5474 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5475 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5476 | if (layer == nullptr) { |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 5477 | for (auto& [listener, callbackIds] : s.listeners) { |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 5478 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5479 | callbackIds, |
| 5480 | s.surface), |
| 5481 | std::vector<JankData>()); |
Marissa Wall | 88e2048 | 2019-06-24 10:49:42 -0700 | [diff] [blame] | 5482 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5483 | return 0; |
| 5484 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 5485 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5486 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 5487 | ui::LayerStack oldLayerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5488 | |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 5489 | // Only set by BLAST adapter layers |
| 5490 | if (what & layer_state_t::eProducerDisconnect) { |
| 5491 | layer->onDisconnect(); |
| 5492 | } |
| 5493 | |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5494 | if (what & layer_state_t::ePositionChanged) { |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 5495 | if (layer->setPosition(s.x, s.y)) { |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5496 | flags |= eTraversalNeeded; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5497 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5498 | } |
| 5499 | if (what & layer_state_t::eLayerChanged) { |
| 5500 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5501 | const auto& p = layer->getParent(); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5502 | if (p == nullptr) { |
chaviw | 64f7b42 | 2017-07-12 10:31:58 -0700 | [diff] [blame] | 5503 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5504 | if (layer->setLayer(s.z) && idx >= 0) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5505 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5506 | mCurrentState.layersSortedByZ.add(layer); |
| 5507 | // we need traversal (state changed) |
| 5508 | // AND transaction (list changed) |
| 5509 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5510 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5511 | } else { |
| 5512 | if (p->setChildLayer(layer, s.z)) { |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5513 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5514 | } |
| 5515 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5516 | } |
| 5517 | if (what & layer_state_t::eRelativeLayerChanged) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5518 | // NOTE: index needs to be calculated before we update the state |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 5519 | const auto& p = layer->getParent(); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5520 | const auto& relativeHandle = s.relativeLayerSurfaceControl ? |
| 5521 | s.relativeLayerSurfaceControl->getHandle() : nullptr; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5522 | if (p == nullptr) { |
| 5523 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5524 | if (layer->setRelativeLayer(relativeHandle, s.z) && |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5525 | idx >= 0) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5526 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5527 | mCurrentState.layersSortedByZ.add(layer); |
| 5528 | // we need traversal (state changed) |
| 5529 | // AND transaction (list changed) |
| 5530 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5531 | } |
| 5532 | } else { |
Robert Carr | bc38496 | 2021-01-27 15:44:50 -0800 | [diff] [blame] | 5533 | if (p->setChildRelativeLayer(layer, relativeHandle, s.z)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5534 | flags |= eTransactionNeeded|eTraversalNeeded; |
| 5535 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5536 | } |
| 5537 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5538 | if (what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5539 | if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5540 | } |
| 5541 | if (what & layer_state_t::eColorChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5542 | if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5543 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 5544 | if (what & layer_state_t::eColorTransformChanged) { |
| 5545 | if (layer->setColorTransform(s.colorTransform)) { |
| 5546 | flags |= eTraversalNeeded; |
| 5547 | } |
| 5548 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5549 | if (what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5550 | if (layer->setBackgroundColor(s.bgColor.rgb, s.bgColor.a, s.bgColorDataspace)) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 5551 | flags |= eTraversalNeeded; |
| 5552 | } |
| 5553 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5554 | if (what & layer_state_t::eMatrixChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5555 | if (layer->setMatrix(s.matrix)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5556 | } |
| 5557 | if (what & layer_state_t::eTransparentRegionChanged) { |
| 5558 | if (layer->setTransparentRegionHint(s.transparentRegion)) |
| 5559 | flags |= eTraversalNeeded; |
| 5560 | } |
| 5561 | if (what & layer_state_t::eFlagsChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5562 | if (layer->setFlags(s.flags, s.mask)) flags |= eTraversalNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5563 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 5564 | if (what & layer_state_t::eCornerRadiusChanged) { |
| 5565 | if (layer->setCornerRadius(s.cornerRadius)) |
| 5566 | flags |= eTraversalNeeded; |
| 5567 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 5568 | if (what & layer_state_t::eBackgroundBlurRadiusChanged && mSupportsBlur) { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5569 | if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded; |
| 5570 | } |
Galia Peycheva | e11d575 | 2021-01-22 13:50:16 +0000 | [diff] [blame] | 5571 | if (what & layer_state_t::eBlurRegionsChanged) { |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5572 | if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded; |
| 5573 | } |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5574 | if (what & layer_state_t::eLayerStackChanged) { |
| 5575 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer); |
| 5576 | // We only allow setting layer stacks for top level layers, |
| 5577 | // everything else inherits layer stack from its parent. |
| 5578 | if (layer->hasParent()) { |
| 5579 | 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] | 5580 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5581 | } else if (idx < 0) { |
| 5582 | ALOGE("Attempt to set layer stack on layer without parent (%s) that " |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 5583 | "that also does not appear in the top level layer list. Something" |
| 5584 | " has gone wrong.", |
| 5585 | layer->getDebugName()); |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5586 | } else if (layer->setLayerStack(s.layerStack)) { |
| 5587 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 5588 | mCurrentState.layersSortedByZ.add(layer); |
| 5589 | // we need traversal (state changed) |
| 5590 | // AND transaction (list changed) |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5591 | flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 5592 | } |
| 5593 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 5594 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5595 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5596 | } |
| 5597 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5598 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5599 | flags |= eTraversalNeeded; |
| 5600 | } |
| 5601 | if (what & layer_state_t::eCropChanged) { |
| 5602 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5603 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5604 | if (what & layer_state_t::eDataspaceChanged) { |
| 5605 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5606 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5607 | if (what & layer_state_t::eSurfaceDamageRegionChanged) { |
| 5608 | if (layer->setSurfaceDamageRegion(s.surfaceDamageRegion)) flags |= eTraversalNeeded; |
| 5609 | } |
| 5610 | if (what & layer_state_t::eApiChanged) { |
| 5611 | if (layer->setApi(s.api)) flags |= eTraversalNeeded; |
| 5612 | } |
| 5613 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5614 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5615 | flags |= eTraversalNeeded; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5616 | } |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5617 | if (what & layer_state_t::eInputInfoChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5618 | layer->setInputInfo(*s.windowInfoHandle->getInfo()); |
| 5619 | flags |= eTraversalNeeded; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 5620 | } |
Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 5621 | std::optional<nsecs_t> dequeueBufferTimestamp; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5622 | if (what & layer_state_t::eMetadataChanged) { |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5623 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5624 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 5625 | if (const int32_t gameMode = s.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 5626 | gameMode != -1) { |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5627 | // The transaction will be received on the Task layer and needs to be applied to all |
| 5628 | // child layers. Child layers that are added at a later point will obtain the game mode |
| 5629 | // info through addChild(). |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5630 | layer->setGameModeForTree(static_cast<GameMode>(gameMode)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 5631 | } |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 5632 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 5633 | if (layer->setMetadata(s.metadata)) { |
| 5634 | flags |= eTraversalNeeded; |
| 5635 | mLayerMetadataSnapshotNeeded = true; |
| 5636 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 5637 | } |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 5638 | if (what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 5639 | if (layer->setColorSpaceAgnostic(s.colorSpaceAgnostic)) { |
| 5640 | flags |= eTraversalNeeded; |
| 5641 | } |
| 5642 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 5643 | if (what & layer_state_t::eShadowRadiusChanged) { |
| 5644 | if (layer->setShadowRadius(s.shadowRadius)) flags |= eTraversalNeeded; |
| 5645 | } |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 5646 | if (what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 5647 | const auto compatibility = |
| 5648 | Layer::FrameRate::convertCompatibility(s.defaultFrameRateCompatibility); |
| 5649 | |
| 5650 | if (layer->setDefaultFrameRateCompatibility(compatibility)) { |
| 5651 | flags |= eTraversalNeeded; |
| 5652 | } |
| 5653 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5654 | if (what & layer_state_t::eFrameRateSelectionPriority) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5655 | if (layer->setFrameRateSelectionPriority(s.frameRateSelectionPriority)) { |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 5656 | flags |= eTraversalNeeded; |
| 5657 | } |
| 5658 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5659 | if (what & layer_state_t::eFrameRateChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5660 | const auto compatibility = |
| 5661 | Layer::FrameRate::convertCompatibility(s.frameRateCompatibility); |
| 5662 | const auto strategy = |
| 5663 | Layer::FrameRate::convertChangeFrameRateStrategy(s.changeFrameRateStrategy); |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 5664 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5665 | if (layer->setFrameRate(Layer::FrameRate::FrameRateVote(Fps::fromValue(s.frameRate), |
| 5666 | compatibility, strategy))) { |
| 5667 | flags |= eTraversalNeeded; |
| 5668 | } |
| 5669 | } |
| 5670 | if (what & layer_state_t::eFrameRateCategoryChanged) { |
| 5671 | const FrameRateCategory category = Layer::FrameRate::convertCategory(s.frameRateCategory); |
Rachel Lee | 67afbea | 2023-09-28 15:35:07 -0700 | [diff] [blame] | 5672 | if (layer->setFrameRateCategory(category, s.frameRateCategorySmoothSwitchOnly)) { |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 5673 | flags |= eTraversalNeeded; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 5674 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 5675 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 5676 | if (what & layer_state_t::eFrameRateSelectionStrategyChanged) { |
| 5677 | const scheduler::LayerInfo::FrameRateSelectionStrategy strategy = |
| 5678 | scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 5679 | s.frameRateSelectionStrategy); |
| 5680 | if (layer->setFrameRateSelectionStrategy(strategy)) { |
| 5681 | flags |= eTraversalNeeded; |
| 5682 | } |
| 5683 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 5684 | if (what & layer_state_t::eFixedTransformHintChanged) { |
| 5685 | if (layer->setFixedTransformHint(s.fixedTransformHint)) { |
| 5686 | flags |= eTraversalNeeded | eTransformHintUpdateNeeded; |
| 5687 | } |
| 5688 | } |
Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 5689 | if (what & layer_state_t::eAutoRefreshChanged) { |
| 5690 | layer->setAutoRefresh(s.autoRefresh); |
| 5691 | } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 5692 | if (what & layer_state_t::eDimmingEnabledChanged) { |
| 5693 | if (layer->setDimmingEnabled(s.dimmingEnabled)) flags |= eTraversalNeeded; |
| 5694 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5695 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 5696 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5697 | flags |= eTraversalNeeded; |
| 5698 | } |
| 5699 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5700 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5701 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5702 | flags |= eTraversalNeeded; |
| 5703 | } |
| 5704 | } |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 5705 | if (what & layer_state_t::eCachingHintChanged) { |
| 5706 | if (layer->setCachingHint(s.cachingHint)) { |
| 5707 | flags |= eTraversalNeeded; |
| 5708 | } |
| 5709 | } |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 5710 | if (what & layer_state_t::eHdrMetadataChanged) { |
| 5711 | if (layer->setHdrMetadata(s.hdrMetadata)) flags |= eTraversalNeeded; |
| 5712 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5713 | if (what & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 5714 | if (layer->setTrustedOverlay(s.trustedOverlay == gui::TrustedOverlay::ENABLED)) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5715 | flags |= eTraversalNeeded; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 5716 | } |
| 5717 | } |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 5718 | if (what & layer_state_t::eStretchChanged) { |
| 5719 | if (layer->setStretchEffect(s.stretchEffect)) { |
| 5720 | flags |= eTraversalNeeded; |
| 5721 | } |
| 5722 | } |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 5723 | if (what & layer_state_t::eBufferCropChanged) { |
| 5724 | if (layer->setBufferCrop(s.bufferCrop)) { |
| 5725 | flags |= eTraversalNeeded; |
| 5726 | } |
| 5727 | } |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 5728 | if (what & layer_state_t::eDestinationFrameChanged) { |
| 5729 | if (layer->setDestinationFrame(s.destinationFrame)) { |
| 5730 | flags |= eTraversalNeeded; |
| 5731 | } |
| 5732 | } |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5733 | if (what & layer_state_t::eDropInputModeChanged) { |
Robert Carr | de6d7b4 | 2022-01-07 18:23:06 -0800 | [diff] [blame] | 5734 | if (layer->setDropInputMode(s.dropInputMode)) { |
| 5735 | flags |= eTraversalNeeded; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 5736 | mUpdateInputInfo = true; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 5737 | } |
| 5738 | } |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5739 | // This has to happen after we reparent children because when we reparent to null we remove |
| 5740 | // child layers from current state and remove its relative z. If the children are reparented in |
| 5741 | // the same transaction, then we have to make sure we reparent the children first so we do not |
| 5742 | // lose its relative z order. |
| 5743 | if (what & layer_state_t::eReparent) { |
| 5744 | bool hadParent = layer->hasParent(); |
Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 5745 | auto parentHandle = (s.parentSurfaceControlForChild) |
| 5746 | ? s.parentSurfaceControlForChild->getHandle() |
| 5747 | : nullptr; |
| 5748 | if (layer->reparent(parentHandle)) { |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5749 | if (!hadParent) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 5750 | layer->setIsAtRoot(false); |
Vishnu Nair | 14d7692 | 2019-08-05 08:41:20 -0700 | [diff] [blame] | 5751 | mCurrentState.layersSortedByZ.remove(layer); |
| 5752 | } |
| 5753 | flags |= eTransactionNeeded | eTraversalNeeded; |
| 5754 | } |
| 5755 | } |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5756 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5757 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5758 | for (auto& [listener, callbackIds] : filteredListeners) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 5759 | callbackHandles.emplace_back( |
| 5760 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 5761 | } |
| 5762 | } |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 5763 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5764 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 5765 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5766 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 5767 | frameTimelineInfo)) { |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 5768 | flags |= eTraversalNeeded; |
| 5769 | } |
Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 5770 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5771 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 5772 | } |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 5773 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5774 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5775 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5776 | } |
| 5777 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5778 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5779 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5780 | s.trustedPresentationListener)) { |
| 5781 | flags |= eTraversalNeeded; |
| 5782 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
Pascal Muetschard | b39918f | 2023-01-27 11:36:11 +0100 | [diff] [blame] | 5785 | if (what & layer_state_t::eFlushJankData) { |
| 5786 | // Do nothing. Processing the transaction completed listeners currently cause the flush. |
| 5787 | } |
| 5788 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5789 | if (layer->setTransactionCompletedListeners(callbackHandles, |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5790 | layer->willPresentCurrentTransaction() || |
| 5791 | layer->willReleaseBufferOnLatch())) { |
Vishnu Nair | d691322 | 2023-02-01 22:56:21 +0000 | [diff] [blame] | 5792 | flags |= eTraversalNeeded; |
| 5793 | } |
| 5794 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 5795 | // Do not put anything that updates layer state or modifies flags after |
| 5796 | // setTransactionCompletedListener |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5797 | |
| 5798 | // 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] | 5799 | if (((flags & eTransformHintUpdateNeeded) == 0) && |
| 5800 | oldLayerStack != layer->getLayerStack(LayerVector::StateSet::Current)) { |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 5801 | flags |= eTransformHintUpdateNeeded; |
| 5802 | } |
| 5803 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 5804 | return flags; |
| 5805 | } |
| 5806 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5807 | uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& frameTimelineInfo, |
| 5808 | ResolvedComposerState& composerState, |
| 5809 | int64_t desiredPresentTime, |
| 5810 | bool isAutoTimestamp, int64_t postTime, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5811 | uint64_t transactionId) { |
| 5812 | layer_state_t& s = composerState.state; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5813 | |
| 5814 | std::vector<ListenerCallbacks> filteredListeners; |
| 5815 | for (auto& listener : s.listeners) { |
| 5816 | // Starts a registration but separates the callback ids according to callback type. This |
| 5817 | // allows the callback invoker to send on latch callbacks earlier. |
| 5818 | // note that startRegistration will not re-register if the listener has |
| 5819 | // already be registered for a prior surface control |
| 5820 | |
| 5821 | ListenerCallbacks onCommitCallbacks = listener.filter(CallbackId::Type::ON_COMMIT); |
| 5822 | if (!onCommitCallbacks.callbackIds.empty()) { |
| 5823 | filteredListeners.push_back(onCommitCallbacks); |
| 5824 | } |
| 5825 | |
| 5826 | ListenerCallbacks onCompleteCallbacks = listener.filter(CallbackId::Type::ON_COMPLETE); |
| 5827 | if (!onCompleteCallbacks.callbackIds.empty()) { |
| 5828 | filteredListeners.push_back(onCompleteCallbacks); |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | const uint64_t what = s.what; |
| 5833 | uint32_t flags = 0; |
| 5834 | sp<Layer> layer = nullptr; |
| 5835 | if (s.surface) { |
| 5836 | layer = LayerHandle::getLayer(s.surface); |
| 5837 | } else { |
| 5838 | // The client may provide us a null handle. Treat it as if the layer was removed. |
| 5839 | ALOGW("Attempt to set client state with a null layer handle"); |
| 5840 | } |
| 5841 | if (layer == nullptr) { |
| 5842 | for (auto& [listener, callbackIds] : s.listeners) { |
| 5843 | mTransactionCallbackInvoker.addCallbackHandle(sp<CallbackHandle>::make(listener, |
| 5844 | callbackIds, |
| 5845 | s.surface), |
| 5846 | std::vector<JankData>()); |
| 5847 | } |
| 5848 | return 0; |
| 5849 | } |
| 5850 | if (what & layer_state_t::eProducerDisconnect) { |
| 5851 | layer->onDisconnect(); |
| 5852 | } |
| 5853 | std::optional<nsecs_t> dequeueBufferTimestamp; |
| 5854 | if (what & layer_state_t::eMetadataChanged) { |
| 5855 | dequeueBufferTimestamp = s.metadata.getInt64(gui::METADATA_DEQUEUE_TIME); |
| 5856 | } |
| 5857 | |
| 5858 | std::vector<sp<CallbackHandle>> callbackHandles; |
| 5859 | if ((what & layer_state_t::eHasListenerCallbacksChanged) && (!filteredListeners.empty())) { |
| 5860 | for (auto& [listener, callbackIds] : filteredListeners) { |
| 5861 | callbackHandles.emplace_back( |
| 5862 | sp<CallbackHandle>::make(listener, callbackIds, s.surface)); |
| 5863 | } |
| 5864 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5865 | // TODO(b/238781169) remove after screenshot refactor, currently screenshots |
| 5866 | // requires to read drawing state from binder thread. So we need to fix that |
| 5867 | // before removing this. |
Vishnu Nair | aeaf9d7 | 2023-09-12 15:47:41 -0700 | [diff] [blame] | 5868 | if (what & layer_state_t::eBufferTransformChanged) { |
| 5869 | if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded; |
| 5870 | } |
| 5871 | if (what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 5872 | if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse)) |
| 5873 | flags |= eTraversalNeeded; |
| 5874 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5875 | if (what & layer_state_t::eCropChanged) { |
| 5876 | if (layer->setCrop(s.crop)) flags |= eTraversalNeeded; |
| 5877 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5878 | if (what & layer_state_t::eSidebandStreamChanged) { |
Dorin Drimus | e5374e5 | 2023-08-02 17:52:43 +0000 | [diff] [blame] | 5879 | if (layer->setSidebandStream(s.sidebandStream, frameTimelineInfo, postTime)) |
| 5880 | flags |= eTraversalNeeded; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5881 | } |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 5882 | if (what & layer_state_t::eDataspaceChanged) { |
| 5883 | if (layer->setDataspace(s.dataspace)) flags |= eTraversalNeeded; |
| 5884 | } |
Vishnu Nair | c5e3416 | 2023-08-22 13:21:20 -0700 | [diff] [blame] | 5885 | if (what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 5886 | if (layer->setExtendedRangeBrightness(s.currentHdrSdrRatio, s.desiredHdrSdrRatio)) { |
| 5887 | flags |= eTraversalNeeded; |
| 5888 | } |
| 5889 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 5890 | if (what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 5891 | if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { |
| 5892 | flags |= eTraversalNeeded; |
| 5893 | } |
| 5894 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5895 | if (what & layer_state_t::eBufferChanged) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 5896 | std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; |
| 5897 | frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); |
| 5898 | if (snapshot) { |
| 5899 | transformHint = snapshot->transformHint; |
| 5900 | } |
| 5901 | layer->setTransformHint(transformHint); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5902 | if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime, |
| 5903 | desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp, |
| 5904 | frameTimelineInfo)) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5905 | flags |= eTraversalNeeded; |
| 5906 | } |
| 5907 | mLayersWithQueuedFrames.emplace(layer); |
| 5908 | } else if (frameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) { |
| 5909 | layer->setFrameTimelineVsyncForBufferlessTransaction(frameTimelineInfo, postTime); |
| 5910 | } |
| 5911 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 5912 | if ((what & layer_state_t::eBufferChanged) == 0) { |
| 5913 | layer->setDesiredPresentTime(desiredPresentTime, isAutoTimestamp); |
| 5914 | } |
| 5915 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5916 | if (what & layer_state_t::eTrustedPresentationInfoChanged) { |
Chavi Weingarten | 328a831 | 2023-01-26 21:17:52 +0000 | [diff] [blame] | 5917 | if (layer->setTrustedPresentationInfo(s.trustedPresentationThresholds, |
| 5918 | s.trustedPresentationListener)) { |
| 5919 | flags |= eTraversalNeeded; |
| 5920 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5923 | const auto& requestedLayerState = mLayerLifecycleManager.getLayerFromId(layer->getSequence()); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 5924 | bool willPresentCurrentTransaction = requestedLayerState && |
| 5925 | (requestedLayerState->hasReadyFrame() || |
| 5926 | requestedLayerState->willReleaseBufferOnLatch()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5927 | if (layer->setTransactionCompletedListeners(callbackHandles, willPresentCurrentTransaction)) |
| 5928 | flags |= eTraversalNeeded; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 5929 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5930 | return flags; |
| 5931 | } |
| 5932 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5933 | uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& inputWindowCommands) { |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 5934 | bool hasChanges = mInputWindowCommands.merge(inputWindowCommands); |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 5935 | return hasChanges ? eTraversalNeeded : 0; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 5936 | } |
| 5937 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 5938 | status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5939 | const sp<IBinder>& mirrorFromHandle, |
| 5940 | gui::CreateSurfaceResult& outResult) { |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5941 | if (!mirrorFromHandle) { |
| 5942 | return NAME_NOT_FOUND; |
| 5943 | } |
| 5944 | |
| 5945 | sp<Layer> mirrorLayer; |
| 5946 | sp<Layer> mirrorFrom; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5947 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5948 | { |
| 5949 | Mutex::Autolock _l(mStateLock); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 5950 | mirrorFrom = LayerHandle::getLayer(mirrorFromHandle); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5951 | if (!mirrorFrom) { |
| 5952 | return NAME_NOT_FOUND; |
| 5953 | } |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 5954 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5955 | mirrorArgs.mirrorLayerHandle = mirrorFromHandle; |
| 5956 | mirrorArgs.addToRoot = false; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5957 | status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5958 | if (result != NO_ERROR) { |
| 5959 | return result; |
| 5960 | } |
| 5961 | |
Melody Hsu | 12ecd08 | 2024-04-17 19:03:13 +0000 | [diff] [blame] | 5962 | mirrorLayer->setClonedChild(mirrorFrom->createClone()); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5965 | outResult.layerId = mirrorLayer->sequence; |
| 5966 | outResult.layerName = String16(mirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 5967 | return addClientLayer(mirrorArgs, outResult.handle, mirrorLayer /* layer */, |
| 5968 | nullptr /* parent */, nullptr /* outTransformHint */); |
chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5971 | status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args, |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5972 | gui::CreateSurfaceResult& outResult) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5973 | IPCThreadState* ipc = IPCThreadState::self(); |
| 5974 | const int uid = ipc->getCallingUid(); |
| 5975 | if (uid != AID_ROOT && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 5976 | ALOGE("Permission denied when trying to mirror display"); |
| 5977 | return PERMISSION_DENIED; |
| 5978 | } |
| 5979 | |
| 5980 | ui::LayerStack layerStack; |
| 5981 | sp<Layer> rootMirrorLayer; |
| 5982 | status_t result = 0; |
| 5983 | |
| 5984 | { |
| 5985 | Mutex::Autolock lock(mStateLock); |
| 5986 | |
| 5987 | const auto display = getDisplayDeviceLocked(displayId); |
| 5988 | if (!display) { |
| 5989 | return NAME_NOT_FOUND; |
| 5990 | } |
| 5991 | |
| 5992 | layerStack = display->getLayerStack(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 5993 | LayerCreationArgs mirrorArgs = LayerCreationArgs::fromOtherArgs(args); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 5994 | mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 5995 | mirrorArgs.addToRoot = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 5996 | mirrorArgs.layerStackToMirror = layerStack; |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 5997 | result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer); |
| 5998 | outResult.layerId = rootMirrorLayer->sequence; |
| 5999 | outResult.layerName = String16(rootMirrorLayer->getDebugName()); |
Vishnu Nair | 8319e36 | 2022-10-24 18:59:20 +0000 | [diff] [blame] | 6000 | result |= addClientLayer(mirrorArgs, outResult.handle, rootMirrorLayer /* layer */, |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6001 | nullptr /* parent */, nullptr /* outTransformHint */); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | if (result != NO_ERROR) { |
| 6005 | return result; |
| 6006 | } |
| 6007 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 6008 | setTransactionFlags(eTransactionFlushNeeded); |
| 6009 | return NO_ERROR; |
| 6010 | } |
| 6011 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6012 | status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6013 | status_t result = NO_ERROR; |
| 6014 | |
| 6015 | sp<Layer> layer; |
| 6016 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6017 | switch (args.flags & ISurfaceComposerClient::eFXSurfaceMask) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 6018 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 6019 | case ISurfaceComposerClient::eFXSurfaceContainer: |
| 6020 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 6021 | args.flags |= ISurfaceComposerClient::eNoColorFill; |
Siarhei Vishniakou | 8d66013 | 2024-01-11 16:48:44 -0800 | [diff] [blame] | 6022 | [[fallthrough]]; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 6023 | case ISurfaceComposerClient::eFXSurfaceEffect: { |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6024 | result = createBufferStateLayer(args, &outResult.handle, &layer); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 6025 | std::atomic<int32_t>* pendingBufferCounter = layer->getPendingBufferCounter(); |
| 6026 | if (pendingBufferCounter) { |
| 6027 | std::string counterName = layer->getPendingBufferCounterName(); |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6028 | mBufferCountTracker.add(outResult.handle->localBinder(), counterName, |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 6029 | pendingBufferCounter); |
| 6030 | } |
| 6031 | } break; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6032 | default: |
| 6033 | result = BAD_VALUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6034 | break; |
| 6035 | } |
| 6036 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6037 | if (result != NO_ERROR) { |
| 6038 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6040 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6041 | args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6042 | // We can safely promote the parent layer in binder thread because we have a strong reference |
| 6043 | // to the layer's handle inside this scope. |
| 6044 | sp<Layer> parent = LayerHandle::getLayer(args.parentHandle.promote()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6045 | if (args.parentHandle != nullptr && parent == nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 6046 | ALOGE("Invalid parent handle %p", args.parentHandle.promote().get()); |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6047 | args.addToRoot = false; |
Garfield Tan | dbc93d7 | 2021-10-26 18:28:57 -0700 | [diff] [blame] | 6048 | } |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 6049 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6050 | uint32_t outTransformHint; |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 6051 | result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint); |
Vishnu Nair | 047fb33 | 2021-12-09 09:54:36 -0800 | [diff] [blame] | 6052 | if (result != NO_ERROR) { |
| 6053 | return result; |
| 6054 | } |
| 6055 | |
Patrick Williams | a361de6 | 2022-10-06 20:34:10 +0000 | [diff] [blame] | 6056 | outResult.transformHint = static_cast<int32_t>(outTransformHint); |
| 6057 | outResult.layerId = layer->sequence; |
| 6058 | outResult.layerName = String16(layer->getDebugName()); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6059 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6060 | } |
| 6061 | |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6062 | status_t SurfaceFlinger::createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 6063 | sp<Layer>* outLayer) { |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6064 | *outLayer = getFactory().createBufferStateLayer(args); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6065 | *handle = (*outLayer)->getHandle(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 6066 | return NO_ERROR; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 6067 | } |
| 6068 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 6069 | status_t SurfaceFlinger::createEffectLayer(const LayerCreationArgs& args, sp<IBinder>* handle, |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 6070 | sp<Layer>* outLayer) { |
| 6071 | *outLayer = getFactory().createEffectLayer(args); |
| 6072 | *handle = (*outLayer)->getHandle(); |
| 6073 | return NO_ERROR; |
| 6074 | } |
| 6075 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 6076 | void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) { |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 6077 | mLayersPendingRemoval.add(layer); |
| 6078 | mLayersRemoved = true; |
| 6079 | setTransactionFlags(eTransactionNeeded); |
| 6080 | } |
| 6081 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6082 | void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32_t layerId) { |
| 6083 | { |
| 6084 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 6085 | mDestroyedHandles.emplace_back(layerId, layer->getDebugName()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6088 | { |
| 6089 | // Used to remove stalled transactions which uses an internal lock. |
| 6090 | ftl::FakeGuard guard(kMainThreadContext); |
| 6091 | mTransactionHandler.onLayerDestroyed(layerId); |
| 6092 | } |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 6093 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 6094 | Mutex::Autolock lock(mStateLock); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 6095 | markLayerPendingRemovalLocked(layer); |
Vishnu Nair | 787aa78 | 2023-03-17 13:46:46 -0700 | [diff] [blame] | 6096 | layer->onHandleDestroyed(); |
Vishnu Nair | f909665 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 6097 | mBufferCountTracker.remove(handle); |
Robert Carr | 695d528 | 2018-12-18 15:27:58 -0800 | [diff] [blame] | 6098 | layer.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 6099 | |
| 6100 | setTransactionFlags(eTransactionFlushNeeded); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
Dominik Laskowski | b5f40e5 | 2022-09-29 13:25:05 -0400 | [diff] [blame] | 6103 | void SurfaceFlinger::initializeDisplays() { |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6104 | TransactionState state; |
| 6105 | state.inputWindowCommands = mInputWindowCommands; |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6106 | const nsecs_t now = systemTime(); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6107 | state.desiredPresentTime = now; |
| 6108 | state.postTime = now; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6109 | state.originPid = mPid; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6110 | state.originUid = static_cast<int>(getuid()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6111 | const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++; |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6112 | state.id = transactionId; |
| 6113 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6114 | auto layerStack = ui::DEFAULT_LAYER_STACK.id; |
| 6115 | for (const auto& [id, display] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) { |
| 6116 | state.displays.push(DisplayState(display.token(), ui::LayerStack::fromValue(layerStack++))); |
| 6117 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 6118 | |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6119 | std::vector<TransactionState> transactions; |
| 6120 | transactions.emplace_back(state); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 6121 | |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 6122 | { |
Vishnu Nair | 878911f | 2024-03-27 22:20:24 -0700 | [diff] [blame] | 6123 | Mutex::Autolock lock(mStateLock); |
| 6124 | applyAndCommitDisplayTransactionStatesLocked(transactions); |
Vishnu Nair | a7caedc | 2023-02-26 03:24:58 +0000 | [diff] [blame] | 6125 | } |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6126 | |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6127 | { |
| 6128 | ftl::FakeGuard guard(mStateLock); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6129 | |
| 6130 | // In case of a restart, ensure all displays are off. |
| 6131 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6132 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::OFF); |
| 6133 | } |
| 6134 | |
| 6135 | // Power on all displays. The primary display is first, so becomes the active display. Also, |
| 6136 | // the DisplayCapability set of a display is populated on its first powering on. Do this now |
| 6137 | // before responding to any Binder query from DisplayManager about display capabilities. |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 6138 | // Additionally, do not turn on displays if the boot should be quiescent. |
| 6139 | if (!mSkipPowerOnForQuiescent) { |
| 6140 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6141 | setPowerModeInternal(getDisplayDeviceLocked(id), hal::PowerMode::ON); |
| 6142 | } |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6143 | } |
Dominik Laskowski | 1686374 | 2022-09-29 11:57:40 -0400 | [diff] [blame] | 6144 | } |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6147 | void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6148 | if (display->isVirtual()) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6149 | // TODO(b/241285876): This code path should not be reachable, so enforce this at compile |
| 6150 | // time. |
Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 6151 | ALOGE("%s: Invalid operation on virtual display", __func__); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6152 | return; |
| 6153 | } |
| 6154 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6155 | const auto displayId = display->getPhysicalId(); |
| 6156 | 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] | 6157 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6158 | const auto currentMode = display->getPowerMode(); |
| 6159 | if (currentMode == mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6160 | return; |
| 6161 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6162 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6163 | const bool isInternalDisplay = mPhysicalDisplays.get(displayId) |
| 6164 | .transform(&PhysicalDisplay::isInternal) |
| 6165 | .value_or(false); |
| 6166 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 6167 | const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId); |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6168 | |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6169 | ALOGW_IF(display != activeDisplay && isInternalDisplay && activeDisplay && |
| 6170 | activeDisplay->isPoweredOn(), |
Dominik Laskowski | c132a15 | 2022-11-30 15:44:52 -0500 | [diff] [blame] | 6171 | "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] | 6172 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6173 | display->setPowerMode(mode); |
| 6174 | |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6175 | const auto activeMode = display->refreshRateSelector().getActiveMode().modePtr; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6176 | if (currentMode == hal::PowerMode::OFF) { |
Ady Abraham | 4f960d1 | 2021-10-13 16:59:49 -0700 | [diff] [blame] | 6177 | // Turn on the display |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6178 | |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6179 | // Activate the display (which involves a modeset to the active mode) when the inner or |
| 6180 | // outer display of a foldable is powered on. This condition relies on the above |
| 6181 | // DisplayDevice::setPowerMode. If `display` and `activeDisplay` are the same display, |
| 6182 | // then the `activeDisplay->isPoweredOn()` below is true, such that the display is not |
| 6183 | // activated every time it is powered on. |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6184 | // |
| 6185 | // TODO(b/255635821): Remove the concept of active display. |
Dominik Laskowski | a39e32f | 2023-02-08 16:40:13 -0500 | [diff] [blame] | 6186 | if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) { |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 6187 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 6188 | } |
Dominik Laskowski | 31afdda | 2022-12-08 19:15:15 -0500 | [diff] [blame] | 6189 | |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6190 | if (displayId == mActiveDisplayId) { |
| 6191 | // TODO(b/281692563): Merge the syscalls. For now, keep uclamp in a separate syscall and |
| 6192 | // set it before SCHED_FIFO due to b/190237315. |
| 6193 | if (setSchedAttr(true) != NO_ERROR) { |
| 6194 | ALOGW("Failed to set uclamp.min after powering on active display: %s", |
| 6195 | strerror(errno)); |
| 6196 | } |
| 6197 | if (setSchedFifo(true) != NO_ERROR) { |
| 6198 | ALOGW("Failed to set SCHED_FIFO after powering on active display: %s", |
| 6199 | strerror(errno)); |
| 6200 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 6201 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6202 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6203 | getHwComposer().setPowerMode(displayId, mode); |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6204 | if (mode != hal::PowerMode::DOZE_SUSPEND && |
| 6205 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6206 | const bool enable = |
| 6207 | mScheduler->getVsyncSchedule(displayId)->getPendingHardwareVsyncState(); |
| 6208 | requestHardwareVsync(displayId, enable); |
| 6209 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6210 | if (displayId == mActiveDisplayId) { |
| 6211 | mScheduler->enableSyntheticVsync(false); |
| 6212 | } |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6213 | |
| 6214 | constexpr bool kAllowToEnable = true; |
Ady Abraham | c585dba | 2023-11-15 18:41:35 -0800 | [diff] [blame] | 6215 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6216 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6218 | mVisibleRegionsDirty = true; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 6219 | scheduleComposite(FrameHint::kActive); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6220 | } else if (mode == hal::PowerMode::OFF) { |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6221 | const bool currentModeNotDozeSuspend = (currentMode != hal::PowerMode::DOZE_SUSPEND); |
Tim Murray | f9d4e44 | 2016-08-02 15:43:59 -0700 | [diff] [blame] | 6222 | // Turn off the display |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6223 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6224 | if (const auto display = getActivatableDisplay()) { |
| 6225 | onActiveDisplayChangedLocked(activeDisplay.get(), *display); |
| 6226 | } else { |
| 6227 | if (setSchedFifo(false) != NO_ERROR) { |
| 6228 | ALOGW("Failed to set SCHED_OTHER after powering off active display: %s", |
| 6229 | strerror(errno)); |
| 6230 | } |
| 6231 | if (setSchedAttr(false) != NO_ERROR) { |
| 6232 | ALOGW("Failed set uclamp.min after powering off active display: %s", |
| 6233 | strerror(errno)); |
| 6234 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6235 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6236 | if (currentModeNotDozeSuspend) { |
| 6237 | if (!FlagManager::getInstance().multithreaded_present()) { |
| 6238 | mScheduler->disableHardwareVsync(displayId, true); |
| 6239 | } |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 6240 | mScheduler->enableSyntheticVsync(); |
| 6241 | } |
Dominik Laskowski | cf0bb43 | 2023-05-09 11:49:16 -0400 | [diff] [blame] | 6242 | } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 6243 | } |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6244 | if (currentModeNotDozeSuspend && FlagManager::getInstance().multithreaded_present()) { |
| 6245 | constexpr bool kDisallow = true; |
| 6246 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6247 | } |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6248 | |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6249 | // We must disable VSYNC *before* turning off the display. The call to |
| 6250 | // disableHardwareVsync, above, schedules a task to turn it off after |
| 6251 | // this method returns. But by that point, the display is OFF, so the |
| 6252 | // call just updates the pending state, without actually disabling |
| 6253 | // VSYNC. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6254 | requestHardwareVsync(displayId, false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6255 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6256 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6257 | mVisibleRegionsDirty = true; |
| 6258 | // from this point on, SF will stop drawing on this display |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6259 | } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6260 | // Update display while dozing |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6261 | getHwComposer().setPowerMode(displayId, mode); |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 6262 | if (currentMode == hal::PowerMode::DOZE_SUSPEND && |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6263 | (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present())) { |
| 6264 | if (displayId == mActiveDisplayId) { |
| 6265 | ALOGI("Force repainting for DOZE_SUSPEND -> DOZE or ON."); |
| 6266 | mVisibleRegionsDirty = true; |
| 6267 | scheduleRepaint(); |
| 6268 | mScheduler->enableSyntheticVsync(false); |
| 6269 | } |
| 6270 | constexpr bool kAllowToEnable = true; |
| 6271 | mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, activeMode.get()); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6272 | } |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6273 | } else if (mode == hal::PowerMode::DOZE_SUSPEND) { |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6274 | // Leave display going to doze |
Leon Scroggins III | 1fc9e7f | 2023-04-28 17:11:28 -0400 | [diff] [blame] | 6275 | if (displayId == mActiveDisplayId || FlagManager::getInstance().multithreaded_present()) { |
| 6276 | constexpr bool kDisallow = true; |
| 6277 | mScheduler->disableHardwareVsync(displayId, kDisallow); |
| 6278 | } |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6279 | if (displayId == mActiveDisplayId) { |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6280 | mScheduler->enableSyntheticVsync(); |
Zheng Zhang | 8a43fe6 | 2017-03-17 11:19:39 +0100 | [diff] [blame] | 6281 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6282 | getHwComposer().setPowerMode(displayId, mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 6283 | } else { |
Matthew Bouyack | 38d4961 | 2017-05-12 12:49:32 -0700 | [diff] [blame] | 6284 | ALOGE("Attempting to set unknown power mode: %d\n", mode); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6285 | getHwComposer().setPowerMode(displayId, mode); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6286 | } |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6287 | |
Dominik Laskowski | e99b98c | 2023-02-02 12:37:23 -0500 | [diff] [blame] | 6288 | if (displayId == mActiveDisplayId) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 6289 | mTimeStats->setPowerMode(mode); |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 6290 | mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 6291 | } |
| 6292 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 6293 | mScheduler->setDisplayPowerMode(displayId, mode); |
| 6294 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6295 | 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] | 6296 | } |
| 6297 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6298 | void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) { |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 6299 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD( |
Dominik Laskowski | f8734e0 | 2022-08-26 09:06:59 -0700 | [diff] [blame] | 6300 | kMainThreadContext) { |
Robert Horvath | dce110a | 2022-09-16 11:08:47 +0200 | [diff] [blame] | 6301 | mSkipPowerOnForQuiescent = false; |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 6302 | const auto display = getDisplayDeviceLocked(displayToken); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 6303 | if (!display) { |
| 6304 | ALOGE("Attempt to set power mode %d for invalid display token %p", mode, |
| 6305 | displayToken.get()); |
| 6306 | } else if (display->isVirtual()) { |
| 6307 | ALOGW("Attempt to set power mode %d for virtual display", mode); |
| 6308 | } else { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 6309 | setPowerModeInternal(display, static_cast<hal::PowerMode>(mode)); |
Andy McFadden | c01a79d | 2012-09-27 16:02:06 -0700 | [diff] [blame] | 6310 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6311 | }); |
| 6312 | |
| 6313 | future.wait(); |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 6314 | } |
| 6315 | |
Dominik Laskowski | 0a1435d | 2020-04-21 00:27:31 -0700 | [diff] [blame] | 6316 | status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6317 | std::string result; |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 6318 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6319 | IPCThreadState* ipc = IPCThreadState::self(); |
| 6320 | const int pid = ipc->getCallingPid(); |
| 6321 | const int uid = ipc->getCallingUid(); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 6322 | |
Mathias Agopian | bd11533 | 2013-04-18 16:41:04 -0700 | [diff] [blame] | 6323 | if ((uid != AID_SHELL) && |
| 6324 | !PermissionCache::checkPermission(sDump, pid, uid)) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6325 | StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", |
| 6326 | pid, uid); |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6327 | write(fd, result.c_str(), result.size()); |
| 6328 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | } |
Ady Abraham | 5ffd98a | 2023-08-24 17:37:01 -0700 | [diff] [blame] | 6330 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6331 | if (asProto && args.empty()) { |
| 6332 | perfetto::protos::LayersTraceFileProto traceFileProto = |
| 6333 | mLayerTracing.createTraceFileProto(); |
| 6334 | perfetto::protos::LayersSnapshotProto* layersTrace = traceFileProto.add_entry(); |
| 6335 | perfetto::protos::LayersProto layersProto = dumpProtoFromMainThread(); |
| 6336 | layersTrace->mutable_layers()->Swap(&layersProto); |
| 6337 | auto displayProtos = dumpDisplayProto(); |
| 6338 | layersTrace->mutable_displays()->Swap(&displayProtos); |
| 6339 | result.append(traceFileProto.SerializeAsString()); |
| 6340 | write(fd, result.c_str(), result.size()); |
| 6341 | return NO_ERROR; |
| 6342 | } |
| 6343 | |
| 6344 | static const std::unordered_map<std::string, Dumper> dumpers = { |
| 6345 | {"--comp-displays"s, dumper(&SurfaceFlinger::dumpCompositionDisplays)}, |
| 6346 | {"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)}, |
| 6347 | {"--displays"s, dumper(&SurfaceFlinger::dumpDisplays)}, |
| 6348 | {"--edid"s, argsDumper(&SurfaceFlinger::dumpRawDisplayIdentificationData)}, |
| 6349 | {"--events"s, dumper(&SurfaceFlinger::dumpEvents)}, |
| 6350 | {"--frametimeline"s, argsDumper(&SurfaceFlinger::dumpFrameTimeline)}, |
| 6351 | {"--frontend"s, mainThreadDumper(&SurfaceFlinger::dumpFrontEnd)}, |
| 6352 | {"--hdrinfo"s, dumper(&SurfaceFlinger::dumpHdrInfo)}, |
| 6353 | {"--hwclayers"s, mainThreadDumper(&SurfaceFlinger::dumpHwcLayersMinidump)}, |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6354 | {"--latency"s, argsMainThreadDumper(&SurfaceFlinger::dumpStats)}, |
| 6355 | {"--latency-clear"s, argsMainThreadDumper(&SurfaceFlinger::clearStats)}, |
| 6356 | {"--list"s, mainThreadDumper(&SurfaceFlinger::listLayers)}, |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6357 | {"--planner"s, argsDumper(&SurfaceFlinger::dumpPlannerInfo)}, |
| 6358 | {"--scheduler"s, dumper(&SurfaceFlinger::dumpScheduler)}, |
| 6359 | {"--timestats"s, protoDumper(&SurfaceFlinger::dumpTimeStats)}, |
| 6360 | {"--vsync"s, dumper(&SurfaceFlinger::dumpVsync)}, |
| 6361 | {"--wide-color"s, dumper(&SurfaceFlinger::dumpWideColorInfo)}, |
| 6362 | }; |
| 6363 | |
| 6364 | const auto flag = args.empty() ? ""s : std::string(String8(args[0])); |
| 6365 | if (const auto it = dumpers.find(flag); it != dumpers.end()) { |
| 6366 | (it->second)(args, asProto, result); |
| 6367 | write(fd, result.c_str(), result.size()); |
| 6368 | return NO_ERROR; |
| 6369 | } |
| 6370 | |
| 6371 | // Traversal of drawing state must happen on the main thread. |
| 6372 | // Otherwise, SortedVector may have shared ownership during concurrent |
| 6373 | // traversals, which can result in use-after-frees. |
| 6374 | std::string compositionLayers; |
| 6375 | mScheduler |
| 6376 | ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6377 | dumpVisibleFrontEnd(compositionLayers); |
| 6378 | }) |
| 6379 | .get(); |
| 6380 | dumpAll(args, compositionLayers, result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6381 | write(fd, result.c_str(), result.size()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | return NO_ERROR; |
| 6383 | } |
| 6384 | |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6385 | status_t SurfaceFlinger::dumpCritical(int fd, const DumpArgs&, bool asProto) { |
Nataniel Borges | 8e7dc72 | 2019-02-28 15:10:28 -0800 | [diff] [blame] | 6386 | return doDump(fd, DumpArgs(), asProto); |
| 6387 | } |
| 6388 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6389 | void SurfaceFlinger::listLayers(std::string& result) const { |
| 6390 | for (const auto& layer : mLayerLifecycleManager.getLayers()) { |
| 6391 | StringAppendF(&result, "%s\n", layer->getDebugString().c_str()); |
| 6392 | } |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6393 | } |
| 6394 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6395 | void SurfaceFlinger::dumpStats(const DumpArgs& args, std::string& result) const { |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 6396 | StringAppendF(&result, "%" PRId64 "\n", getVsyncPeriodFromHWC()); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6397 | if (args.size() < 2) return; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 6398 | |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6399 | const auto name = String8(args[1]); |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6400 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6401 | if (layer->getName() == name.c_str()) { |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6402 | layer->dumpFrameStats(result); |
| 6403 | } |
| 6404 | }); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6405 | } |
| 6406 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6407 | void SurfaceFlinger::clearStats(const DumpArgs& args, std::string&) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 6408 | const bool clearAll = args.size() < 2; |
| 6409 | const auto name = clearAll ? String8() : String8(args[1]); |
| 6410 | |
Vishnu Nair | d1a0578 | 2024-03-19 04:37:38 +0000 | [diff] [blame] | 6411 | traverseLegacyLayers([&](Layer* layer) { |
Tomasz Wasilczyk | b19fe0c | 2023-08-11 00:06:51 +0000 | [diff] [blame] | 6412 | if (clearAll || layer->getName() == name.c_str()) { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 6413 | layer->clearFrameStats(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6414 | } |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 6415 | }); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 6416 | } |
| 6417 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6418 | void SurfaceFlinger::dumpTimeStats(const DumpArgs& args, bool asProto, std::string& result) const { |
| 6419 | mTimeStats->parseArgs(asProto, args, result); |
| 6420 | } |
| 6421 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 6422 | void SurfaceFlinger::dumpFrameTimeline(const DumpArgs& args, std::string& result) const { |
| 6423 | mFrameTimeline->parseArgs(args, result); |
| 6424 | } |
| 6425 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6426 | void SurfaceFlinger::logFrameStats(TimePoint now) { |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 6427 | static TimePoint sTimestamp = now; |
| 6428 | if (now - sTimestamp < 30min) return; |
| 6429 | sTimestamp = now; |
| 6430 | |
| 6431 | ATRACE_CALL(); |
Dominik Laskowski | 66296b2 | 2022-07-12 08:20:36 -0700 | [diff] [blame] | 6432 | mDrawingState.traverse([&](Layer* layer) { layer->logFrameStats(); }); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 6433 | } |
| 6434 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6435 | void SurfaceFlinger::appendSfConfigString(std::string& result) const { |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6436 | result.append(" [sf"); |
Fabien Sanglard | c93afd5 | 2017-03-13 13:02:42 -0700 | [diff] [blame] | 6437 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6438 | StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); |
| 6439 | StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 6440 | StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", |
| 6441 | getHwComposer().getMaxVirtualDisplayDimension()); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6442 | StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6443 | StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6444 | maxFrameBufferAcquiredBuffers); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 6445 | result.append("]"); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6448 | void SurfaceFlinger::dumpScheduler(std::string& result) const { |
| 6449 | utils::Dumper dumper{result}; |
| 6450 | |
| 6451 | mScheduler->dump(dumper); |
| 6452 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6453 | // TODO(b/241285876): Move to DisplayModeController. |
| 6454 | dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor); |
| 6455 | dumper.eol(); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6456 | |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6457 | StringAppendF(&result, |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6458 | " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 |
| 6459 | " ns\n\n", |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6460 | dispSyncPresentTimeOffset, getVsyncPeriodFromHWC()); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6461 | } |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6462 | |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6463 | void SurfaceFlinger::dumpEvents(std::string& result) const { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 6464 | mScheduler->dump(scheduler::Cycle::Render, result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | void SurfaceFlinger::dumpVsync(std::string& result) const { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 6468 | mScheduler->dumpVsync(result); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6469 | } |
| 6470 | |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 6471 | void SurfaceFlinger::dumpPlannerInfo(const DumpArgs& args, std::string& result) const { |
| 6472 | for (const auto& [token, display] : mDisplays) { |
| 6473 | const auto compositionDisplay = display->getCompositionDisplay(); |
| 6474 | compositionDisplay->dumpPlannerInfo(args, result); |
| 6475 | } |
| 6476 | } |
| 6477 | |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6478 | void SurfaceFlinger::dumpCompositionDisplays(std::string& result) const { |
| 6479 | for (const auto& [token, display] : mDisplays) { |
| 6480 | display->getCompositionDisplay()->dump(result); |
| 6481 | result += '\n'; |
| 6482 | } |
| 6483 | } |
| 6484 | |
| 6485 | void SurfaceFlinger::dumpDisplays(std::string& result) const { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6486 | utils::Dumper dumper{result}; |
| 6487 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6488 | for (const auto& [id, display] : mPhysicalDisplays) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6489 | utils::Dumper::Section section(dumper, ftl::Concat("Display ", id.value).str()); |
| 6490 | |
| 6491 | display.snapshot().dump(dumper); |
| 6492 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6493 | if (const auto device = getDisplayDeviceLocked(id)) { |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6494 | device->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6495 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6496 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6497 | |
| 6498 | for (const auto& [token, display] : mDisplays) { |
| 6499 | if (display->isVirtual()) { |
Dominik Laskowski | 5d7de5f | 2022-11-03 12:38:32 -0400 | [diff] [blame] | 6500 | const auto displayId = display->getId(); |
| 6501 | utils::Dumper::Section section(dumper, |
| 6502 | ftl::Concat("Virtual Display ", displayId.value).str()); |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 6503 | display->dump(dumper); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 6504 | } |
| 6505 | } |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6506 | } |
| 6507 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6508 | void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 6509 | for (const auto& [token, display] : mDisplays) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6510 | const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6511 | if (!displayId) { |
| 6512 | continue; |
| 6513 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 6514 | const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6515 | if (!hwcDisplayId) { |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6516 | continue; |
| 6517 | } |
| 6518 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6519 | StringAppendF(&result, |
| 6520 | "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), |
| 6521 | *hwcDisplayId); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6522 | uint8_t port; |
| 6523 | DisplayIdentificationData data; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 6524 | if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 6525 | result.append("no display identification data\n"); |
| 6526 | continue; |
| 6527 | } |
| 6528 | |
| 6529 | if (data.empty()) { |
| 6530 | result.append("empty display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6531 | continue; |
| 6532 | } |
| 6533 | |
| 6534 | if (!isEdid(data)) { |
Brian Lindahl | 8a96ef9 | 2024-05-24 14:46:29 +0000 | [diff] [blame] | 6535 | result.append("unknown format for display identification data\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6536 | continue; |
| 6537 | } |
| 6538 | |
| 6539 | const auto edid = parseEdid(data); |
| 6540 | if (!edid) { |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6541 | result.append("invalid EDID\n"); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6542 | continue; |
| 6543 | } |
| 6544 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6545 | StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6546 | result.append(edid->displayName.data(), edid->displayName.length()); |
| 6547 | result.append("\"\n"); |
| 6548 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6549 | } |
| 6550 | |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6551 | void SurfaceFlinger::dumpRawDisplayIdentificationData(const DumpArgs& args, |
| 6552 | std::string& result) const { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 6553 | hal::HWDisplayId hwcDisplayId; |
Dominik Laskowski | b6e5437 | 2019-09-04 14:06:28 -0700 | [diff] [blame] | 6554 | uint8_t port; |
| 6555 | DisplayIdentificationData data; |
| 6556 | |
| 6557 | if (args.size() > 1 && base::ParseUint(String8(args[1]), &hwcDisplayId) && |
| 6558 | getHwComposer().getDisplayIdentificationData(hwcDisplayId, &port, &data)) { |
| 6559 | result.append(reinterpret_cast<const char*>(data.data()), data.size()); |
| 6560 | } |
| 6561 | } |
| 6562 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6563 | void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 6564 | StringAppendF(&result, "Device supports wide color: %d\n", mSupportsWideColor); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6565 | StringAppendF(&result, "DisplayColorSetting: %s\n", |
| 6566 | decodeDisplayColorSetting(mDisplayColorSetting).c_str()); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6567 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6568 | // TODO: print out if wide-color mode is active or not. |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6569 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6570 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 6571 | StringAppendF(&result, "Display %s color modes:\n", to_string(id).c_str()); |
| 6572 | for (const auto mode : display.snapshot().colorModes()) { |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6573 | StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), |
| 6574 | fmt::underlying(mode)); |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6575 | } |
| 6576 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6577 | if (const auto display = getDisplayDeviceLocked(id)) { |
| 6578 | ui::ColorMode currentMode = display->getCompositionDisplay()->getState().colorMode; |
| 6579 | StringAppendF(&result, " Current color mode: %s (%d)\n", |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 6580 | decodeColorMode(currentMode).c_str(), fmt::underlying(currentMode)); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 6581 | } |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6582 | } |
| 6583 | result.append("\n"); |
| 6584 | } |
| 6585 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6586 | void SurfaceFlinger::dumpHdrInfo(std::string& result) const { |
| 6587 | for (const auto& [displayId, listener] : mHdrLayerInfoListeners) { |
| 6588 | StringAppendF(&result, "HDR events for display %" PRIu64 "\n", displayId.value); |
| 6589 | listener->dump(result); |
| 6590 | result.append("\n"); |
| 6591 | } |
| 6592 | } |
| 6593 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6594 | void SurfaceFlinger::dumpFrontEnd(std::string& result) { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6595 | std::ostringstream out; |
| 6596 | out << "\nComposition list\n"; |
| 6597 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6598 | for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) { |
| 6599 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6600 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6601 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6602 | } |
| 6603 | out << " " << *snapshot << "\n"; |
| 6604 | } |
| 6605 | |
| 6606 | out << "\nInput list\n"; |
| 6607 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6608 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6609 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6610 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6611 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6612 | } |
| 6613 | out << " " << snapshot << "\n"; |
| 6614 | }); |
| 6615 | |
| 6616 | out << "\nLayer Hierarchy\n" |
| 6617 | << mLayerHierarchyBuilder.getHierarchy().dump() << "\nOffscreen Hierarchy\n" |
| 6618 | << mLayerHierarchyBuilder.getOffscreenHierarchy().dump() << "\n\n"; |
| 6619 | result.append(out.str()); |
| 6620 | } |
| 6621 | |
| 6622 | void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) { |
| 6623 | if (!mLayerLifecycleManagerEnabled) { |
| 6624 | StringAppendF(&result, "Composition layers\n"); |
| 6625 | mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 6626 | auto* compositionState = layer->getCompositionState(); |
| 6627 | if (!compositionState || !compositionState->isVisible) return; |
| 6628 | android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer, |
| 6629 | layer->getDebugName() ? layer->getDebugName() |
| 6630 | : "<unknown>"); |
| 6631 | compositionState->dump(result); |
| 6632 | }); |
| 6633 | |
| 6634 | StringAppendF(&result, "Offscreen Layers\n"); |
| 6635 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6636 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
| 6637 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
| 6638 | } |
| 6639 | } else { |
| 6640 | std::ostringstream out; |
| 6641 | out << "\nComposition list\n"; |
| 6642 | ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6643 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6644 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 6645 | if (snapshot->hasSomethingToDraw()) { |
| 6646 | if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) { |
| 6647 | lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack; |
| 6648 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6649 | } |
| 6650 | out << " " << *snapshot << "\n"; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6651 | } |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6652 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6653 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6654 | out << "\nInput list\n"; |
| 6655 | lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK; |
| 6656 | mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 6657 | if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) { |
| 6658 | lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack; |
| 6659 | out << "LayerStack=" << lastPrintedLayerStackHeader.id << "\n"; |
| 6660 | } |
| 6661 | out << " " << snapshot << "\n"; |
| 6662 | }); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6663 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6664 | out << "\nLayer Hierarchy\n" |
| 6665 | << mLayerHierarchyBuilder.getHierarchy() << "\nOffscreen Hierarchy\n" |
| 6666 | << mLayerHierarchyBuilder.getOffscreenHierarchy() << "\n\n"; |
| 6667 | result = out.str(); |
| 6668 | dumpHwcLayersMinidump(result); |
| 6669 | } |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6672 | perfetto::protos::LayersProto SurfaceFlinger::dumpDrawingStateProto(uint32_t traceFlags) const { |
Nataniel Borges | 63b3c87 | 2022-11-03 16:22:24 +0000 | [diff] [blame] | 6673 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 6674 | |
| 6675 | // Determine if virtual layers display should be skipped |
| 6676 | if ((traceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 6677 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
| 6678 | if (display->isVirtual()) { |
| 6679 | stackIdsToSkip.insert(display->getLayerStack().id); |
| 6680 | } |
| 6681 | } |
| 6682 | } |
| 6683 | |
Vishnu Nair | 22be349 | 2023-04-20 10:08:21 -0700 | [diff] [blame] | 6684 | return LayerProtoFromSnapshotGenerator(mLayerSnapshotBuilder, mFrontEndDisplayInfos, |
| 6685 | mLegacyLayers, traceFlags) |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 6686 | .generate(mLayerHierarchyBuilder.getHierarchy()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6687 | } |
| 6688 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6689 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> |
| 6690 | SurfaceFlinger::dumpDisplayProto() const { |
| 6691 | google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays; |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 6692 | for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6693 | perfetto::protos::DisplayProto* displayProto = displays.Add(); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6694 | displayProto->set_id(display->getId().value); |
| 6695 | displayProto->set_name(display->getDisplayName()); |
| 6696 | displayProto->set_layer_stack(display->getLayerStack().id); |
DoÄŸancan Emek | fc4b6ed | 2023-07-26 15:24:04 +0000 | [diff] [blame] | 6697 | |
| 6698 | if (!display->isVirtual()) { |
| 6699 | const auto dpi = display->refreshRateSelector().getActiveMode().modePtr->getDpi(); |
| 6700 | displayProto->set_dpi_x(dpi.x); |
| 6701 | displayProto->set_dpi_y(dpi.y); |
| 6702 | } |
| 6703 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6704 | LayerProtoHelper::writeSizeToProto(display->getWidth(), display->getHeight(), |
| 6705 | [&]() { return displayProto->mutable_size(); }); |
| 6706 | LayerProtoHelper::writeToProto(display->getLayerStackSpaceRect(), [&]() { |
| 6707 | return displayProto->mutable_layer_stack_space_rect(); |
| 6708 | }); |
| 6709 | LayerProtoHelper::writeTransformToProto(display->getTransform(), |
| 6710 | displayProto->mutable_transform()); |
Vishnu Nair | 791d48a | 2021-12-02 16:55:13 -0800 | [diff] [blame] | 6711 | displayProto->set_is_virtual(display->isVirtual()); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6712 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 6713 | return displays; |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 6714 | } |
| 6715 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 6716 | void SurfaceFlinger::dumpHwc(std::string& result) const { |
| 6717 | getHwComposer().dump(result); |
| 6718 | } |
| 6719 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6720 | void SurfaceFlinger::dumpOffscreenLayersProto(perfetto::protos::LayersProto& layersProto, |
| 6721 | uint32_t traceFlags) const { |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6722 | // Add a fake invisible root layer to the proto output and parent all the offscreen layers to |
| 6723 | // it. |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6724 | perfetto::protos::LayerProto* rootProto = layersProto.add_layers(); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6725 | const int32_t offscreenRootLayerId = INT32_MAX - 2; |
| 6726 | rootProto->set_id(offscreenRootLayerId); |
| 6727 | rootProto->set_name("Offscreen Root"); |
Vishnu Nair | d5aeb61 | 2019-09-20 14:39:39 -0700 | [diff] [blame] | 6728 | rootProto->set_parent(-1); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6729 | |
| 6730 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6731 | // Add layer as child of the fake root |
| 6732 | rootProto->add_children(offscreenLayer->sequence); |
| 6733 | |
| 6734 | // Add layer |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6735 | auto* layerProto = offscreenLayer->writeToProto(layersProto, traceFlags); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6736 | layerProto->set_parent(offscreenRootLayerId); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6737 | } |
| 6738 | } |
| 6739 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 6740 | perfetto::protos::LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6741 | return mScheduler |
| 6742 | ->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 6743 | return dumpDrawingStateProto(traceFlags); |
| 6744 | }) |
| 6745 | .get(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 6746 | } |
| 6747 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6748 | void SurfaceFlinger::dumpOffscreenLayers(std::string& result) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6749 | auto future = mScheduler->schedule([this] { |
| 6750 | std::string result; |
| 6751 | for (Layer* offscreenLayer : mOffscreenLayers) { |
| 6752 | offscreenLayer->traverse(LayerVector::StateSet::Drawing, |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 6753 | [&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); }); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6754 | } |
| 6755 | return result; |
| 6756 | }); |
| 6757 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6758 | result.append("Offscreen Layers:\n"); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 6759 | result.append(future.get()); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 6760 | } |
| 6761 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6762 | void SurfaceFlinger::dumpHwcLayersMinidumpLockedLegacy(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6763 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6764 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6765 | if (!displayId) { |
| 6766 | continue; |
| 6767 | } |
| 6768 | |
| 6769 | 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] | 6770 | displayId == mActiveDisplayId ? "active" : "inactive"); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6771 | Layer::miniDumpHeader(result); |
| 6772 | |
| 6773 | const DisplayDevice& ref = *display; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6774 | mDrawingState.traverseInZOrder([&](Layer* layer) { layer->miniDumpLegacy(result, ref); }); |
| 6775 | result.append("\n"); |
| 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | void SurfaceFlinger::dumpHwcLayersMinidump(std::string& result) const { |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6780 | if (!mLayerLifecycleManagerEnabled) { |
| 6781 | return dumpHwcLayersMinidumpLockedLegacy(result); |
| 6782 | } |
| 6783 | for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6784 | const auto displayId = HalDisplayId::tryCast(display->getId()); |
| 6785 | if (!displayId) { |
| 6786 | continue; |
| 6787 | } |
| 6788 | |
| 6789 | StringAppendF(&result, "Display %s (%s) HWC layers:\n", to_string(*displayId).c_str(), |
| 6790 | displayId == mActiveDisplayId ? "active" : "inactive"); |
| 6791 | Layer::miniDumpHeader(result); |
| 6792 | |
| 6793 | const DisplayDevice& ref = *display; |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 6794 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
| 6795 | [&](const frontend::LayerSnapshot& snapshot) FTL_FAKE_GUARD(kMainThreadContext) { |
| 6796 | if (!snapshot.hasSomethingToDraw() || |
| 6797 | ref.getLayerStack() != snapshot.outputFilter.layerStack) { |
| 6798 | return; |
| 6799 | } |
| 6800 | auto it = mLegacyLayers.find(snapshot.sequence); |
| 6801 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 6802 | "Couldnt find layer object for %s", |
| 6803 | snapshot.getDebugString().c_str()); |
| 6804 | it->second->miniDump(result, snapshot, ref); |
| 6805 | }); |
Ady Abraham | 5ad28d6 | 2022-08-11 11:26:57 -0700 | [diff] [blame] | 6806 | result.append("\n"); |
| 6807 | } |
| 6808 | } |
| 6809 | |
Vishnu Nair | d7ff85f | 2023-12-08 09:51:31 -0800 | [diff] [blame] | 6810 | void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositionLayers, |
| 6811 | std::string& result) const { |
| 6812 | TimedLock lock(mStateLock, s2ns(1), __func__); |
| 6813 | if (!lock.locked()) { |
| 6814 | StringAppendF(&result, "Dumping without lock after timeout: %s (%d)\n", |
| 6815 | strerror(-lock.status), lock.status); |
| 6816 | } |
| 6817 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 6818 | const bool colorize = !args.empty() && args[0] == String16("--color"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6819 | Colorizer colorizer(colorize); |
| 6820 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6821 | // figure out if we're stuck somewhere |
| 6822 | const nsecs_t now = systemTime(); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6823 | const nsecs_t inTransaction(mDebugInTransaction); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6824 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; |
| 6825 | |
| 6826 | /* |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6827 | * Dump library configuration. |
| 6828 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6829 | |
| 6830 | colorizer.bold(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6831 | result.append("Build configuration:"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6832 | colorizer.reset(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6833 | appendSfConfigString(result); |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6834 | result.append("\n"); |
| 6835 | |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 6836 | result.append("\nDisplay identification data:\n"); |
| 6837 | dumpDisplayIdentificationData(result); |
| 6838 | |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 6839 | result.append("\nWide-Color information:\n"); |
| 6840 | dumpWideColorInfo(result); |
| 6841 | |
John Reck | 2a3d29d | 2023-08-17 17:45:01 -0400 | [diff] [blame] | 6842 | dumpHdrInfo(result); |
| 6843 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6844 | colorizer.bold(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6845 | result.append("Sync configuration: "); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6846 | colorizer.reset(result); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6847 | result.append(SyncFeatures::getInstance().toString()); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6848 | result.append("\n\n"); |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 6849 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6850 | colorizer.bold(result); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 6851 | result.append("Scheduler:\n"); |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 6852 | colorizer.reset(result); |
Dominik Laskowski | 03cfce8 | 2022-11-02 12:13:29 -0400 | [diff] [blame] | 6853 | dumpScheduler(result); |
| 6854 | dumpEvents(result); |
| 6855 | dumpVsync(result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 6856 | result.append("\n"); |
Dominik Laskowski | d9e4de6 | 2019-01-21 14:23:01 -0800 | [diff] [blame] | 6857 | |
Andy McFadden | 4803b74 | 2012-09-24 19:07:20 -0700 | [diff] [blame] | 6858 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6859 | * Dump the visible layer list |
| 6860 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6861 | colorizer.bold(result); |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 6862 | StringAppendF(&result, "SurfaceFlinger New Frontend Enabled:%s\n", |
| 6863 | mLayerLifecycleManagerEnabled ? "true" : "false"); |
| 6864 | StringAppendF(&result, "Active Layers - layers with client handles (count = %zu)\n", |
| 6865 | mNumLayers.load()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6866 | colorizer.reset(result); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 6867 | |
Alec Mouri | 6761733 | 2022-09-26 21:37:01 +0000 | [diff] [blame] | 6868 | result.append(compositionLayers); |
Lloyd Pique | 207def9 | 2019-02-28 16:09:52 -0800 | [diff] [blame] | 6869 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6870 | colorizer.bold(result); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6871 | StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6872 | colorizer.reset(result); |
Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 6873 | dumpDisplays(result); |
| 6874 | dumpCompositionDisplays(result); |
| 6875 | result.push_back('\n'); |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 6876 | |
| 6877 | mCompositionEngine->dump(result); |
| 6878 | |
| 6879 | /* |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6880 | * Dump SurfaceFlinger global state |
| 6881 | */ |
| 6882 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6883 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6884 | result.append("SurfaceFlinger global state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6885 | colorizer.reset(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6886 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 6887 | getRenderEngine().dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6888 | |
Robert Carr | beba6f0 | 2021-02-10 21:06:27 -0800 | [diff] [blame] | 6889 | result.append("ClientCache state:\n"); |
| 6890 | ClientCache::getInstance().dump(result); |
Ady Abraham | a3b08ef | 2019-07-15 18:43:10 -0700 | [diff] [blame] | 6891 | DebugEGLImageTracker::getInstance()->dump(result); |
| 6892 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 6893 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 6894 | display->getCompositionDisplay()->getState().undefinedRegion.dump(result, |
| 6895 | "undefinedRegion"); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 6896 | StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", |
| 6897 | toCString(display->getOrientation()), display->isPoweredOn()); |
Lloyd Pique | 2ae2b3b | 2017-12-14 17:18:17 -0800 | [diff] [blame] | 6898 | } |
Carlos Martinez Romero | 779dc1f | 2022-10-27 23:23:30 +0000 | [diff] [blame] | 6899 | StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6900 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 6901 | if (const auto display = getDefaultDisplayDeviceLocked()) { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6902 | std::string peakFps, xDpi, yDpi; |
| 6903 | const auto activeMode = display->refreshRateSelector().getActiveMode(); |
| 6904 | if (const auto activeModePtr = activeMode.modePtr.get()) { |
| 6905 | peakFps = to_string(activeMode.modePtr->getPeakFps()); |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 6906 | const auto dpi = activeModePtr->getDpi(); |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 6907 | xDpi = base::StringPrintf("%.2f", dpi.x); |
| 6908 | yDpi = base::StringPrintf("%.2f", dpi.y); |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6909 | } else { |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6910 | peakFps = "unknown"; |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6911 | xDpi = "unknown"; |
| 6912 | yDpi = "unknown"; |
| 6913 | } |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6914 | StringAppendF(&result, |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6915 | " peak-refresh-rate : %s\n" |
Marin Shalamanov | 9afcbd8 | 2020-08-19 12:34:59 +0200 | [diff] [blame] | 6916 | " x-dpi : %s\n" |
| 6917 | " y-dpi : %s\n", |
Ying Wei | 784a8e7 | 2024-04-20 08:46:42 +0000 | [diff] [blame] | 6918 | peakFps.c_str(), xDpi.c_str(), yDpi.c_str()); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 6919 | } |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6920 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6921 | StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6922 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 6923 | result.append("\nTransaction tracing: "); |
| 6924 | if (mTransactionTracing) { |
| 6925 | result.append("enabled\n"); |
| 6926 | mTransactionTracing->dump(result); |
| 6927 | } else { |
| 6928 | result.append("disabled\n"); |
| 6929 | } |
| 6930 | result.push_back('\n'); |
Yichi Chen | adc6961 | 2018-09-15 14:51:18 +0800 | [diff] [blame] | 6931 | |
Ady Abraham | 2790e9f | 2021-04-28 13:14:20 -0700 | [diff] [blame] | 6932 | { |
| 6933 | DumpArgs plannerArgs; |
| 6934 | plannerArgs.add(); // first argument is ignored |
| 6935 | plannerArgs.add(String16("--layers")); |
| 6936 | dumpPlannerInfo(plannerArgs, result); |
| 6937 | } |
| 6938 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6939 | /* |
| 6940 | * Dump HWComposer state |
| 6941 | */ |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6942 | colorizer.bold(result); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 6943 | result.append("h/w composer state:\n"); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 6944 | colorizer.reset(result); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 6945 | const bool hwcDisabled = mDebugDisableHWC || mDebugFlashDelay; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 6946 | StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); |
Ady Abraham | c4acf51 | 2022-02-18 17:11:59 -0800 | [diff] [blame] | 6947 | dumpHwc(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6948 | |
| 6949 | /* |
| 6950 | * Dump gralloc state |
| 6951 | */ |
| 6952 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 6953 | alloc.dump(result); |
Karthik Ravi Shankar | 171155a | 2017-06-28 15:40:24 -0700 | [diff] [blame] | 6954 | |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6955 | /* |
| 6956 | * Dump flag/property manager state |
| 6957 | */ |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 6958 | FlagManager::getInstance().dump(result); |
rnlee | a2ecd83 | 2021-07-29 13:58:30 -0700 | [diff] [blame] | 6959 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 6960 | result.append(mTimeStats->miniDump()); |
| 6961 | result.append("\n"); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6962 | |
| 6963 | result.append("Window Infos:\n"); |
Patrick Williams | 6681c02 | 2023-05-15 13:38:16 -0500 | [diff] [blame] | 6964 | auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo(); |
| 6965 | StringAppendF(&result, " max send vsync id: %" PRId64 "\n", |
| 6966 | ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId)); |
| 6967 | StringAppendF(&result, " max send delay (ns): %" PRId64 " ns\n", |
| 6968 | windowInfosDebug.maxSendDelayDuration); |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 6969 | StringAppendF(&result, " unsent messages: %zu\n", windowInfosDebug.pendingMessageCount); |
Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 6970 | result.append("\n"); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 6971 | } |
| 6972 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6973 | mat4 SurfaceFlinger::calculateColorMatrix(float saturation) { |
| 6974 | if (saturation == 1) { |
| 6975 | return mat4(); |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 6978 | float3 luminance{0.213f, 0.715f, 0.072f}; |
| 6979 | luminance *= 1.0f - saturation; |
| 6980 | mat4 saturationMatrix = mat4(vec4{luminance.r + saturation, luminance.r, luminance.r, 0.0f}, |
| 6981 | vec4{luminance.g, luminance.g + saturation, luminance.g, 0.0f}, |
| 6982 | vec4{luminance.b, luminance.b, luminance.b + saturation, 0.0f}, |
| 6983 | vec4{0.0f, 0.0f, 0.0f, 1.0f}); |
| 6984 | return saturationMatrix; |
| 6985 | } |
| 6986 | |
| 6987 | void SurfaceFlinger::updateColorMatrixLocked() { |
| 6988 | mat4 colorMatrix = |
| 6989 | mClientColorMatrix * calculateColorMatrix(mGlobalSaturationFactor) * mDaltonizer(); |
| 6990 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 6991 | if (mCurrentState.colorMatrix != colorMatrix) { |
| 6992 | mCurrentState.colorMatrix = colorMatrix; |
| 6993 | mCurrentState.colorMatrixChanged = true; |
| 6994 | setTransactionFlags(eTransactionNeeded); |
| 6995 | } |
| 6996 | } |
| 6997 | |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 6998 | status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 6999 | #pragma clang diagnostic push |
| 7000 | #pragma clang diagnostic error "-Wswitch-enum" |
| 7001 | switch (static_cast<ISurfaceComposerTag>(code)) { |
| 7002 | // These methods should at minimum make sure that the client requested |
| 7003 | // access to SF. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7004 | case GET_HDR_CAPABILITIES: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 7005 | case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: |
Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 7006 | case GET_GAME_CONTENT_TYPE_SUPPORT: |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7007 | case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7008 | // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary |
| 7009 | // permission dynamically. Don't use the permission cache for this check. |
| 7010 | bool usePermissionCache = code != OVERRIDE_HDR_TYPES; |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 7011 | if (!callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 7012 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7013 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", |
| 7014 | ipc->getCallingPid(), ipc->getCallingUid()); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7015 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7016 | } |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 7017 | return OK; |
| 7018 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7019 | // The following calls are currently used by clients that do not |
| 7020 | // request necessary permissions. However, they do not expose any secret |
| 7021 | // information, so it is OK to pass them. |
Peiyong Lin | d1fedb4 | 2019-03-11 17:48:41 -0700 | [diff] [blame] | 7022 | case GET_ACTIVE_COLOR_MODE: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7023 | case GET_ACTIVE_DISPLAY_MODE: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7024 | case GET_DISPLAY_COLOR_MODES: |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 7025 | case GET_DISPLAY_MODES: |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 7026 | case GET_SCHEDULING_POLICY: |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7027 | // Calling setTransactionState is safe, because you need to have been |
| 7028 | // granted a reference to Client* and Handle* to do anything with it. |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7029 | case SET_TRANSACTION_STATE: { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 7030 | // This is not sensitive information, so should not require permission control. |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7031 | return OK; |
| 7032 | } |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 7033 | case BOOT_FINISHED: |
| 7034 | // Used by apps to hook Choreographer to SurfaceFlinger. |
| 7035 | case CREATE_DISPLAY_EVENT_CONNECTION: |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 7036 | case CREATE_CONNECTION: |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 7037 | case CREATE_VIRTUAL_DISPLAY: |
| 7038 | case DESTROY_VIRTUAL_DISPLAY: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7039 | case GET_PRIMARY_PHYSICAL_DISPLAY_ID: |
| 7040 | case GET_PHYSICAL_DISPLAY_IDS: |
| 7041 | case GET_PHYSICAL_DISPLAY_TOKEN: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7042 | case AUTHENTICATE_SURFACE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7043 | case SET_POWER_MODE: |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 7044 | case GET_SUPPORTED_FRAME_TIMESTAMPS: |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7045 | case GET_DISPLAY_STATE: |
| 7046 | case GET_DISPLAY_STATS: |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 7047 | case GET_STATIC_DISPLAY_INFO: |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 7048 | case GET_DYNAMIC_DISPLAY_INFO: |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 7049 | case GET_DISPLAY_NATIVE_PRIMARIES: |
| 7050 | case SET_ACTIVE_COLOR_MODE: |
| 7051 | case SET_BOOT_DISPLAY_MODE: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7052 | case CLEAR_BOOT_DISPLAY_MODE: |
| 7053 | case GET_BOOT_DISPLAY_MODE_SUPPORT: |
| 7054 | case SET_AUTO_LOW_LATENCY_MODE: |
| 7055 | case SET_GAME_CONTENT_TYPE: |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7056 | case CAPTURE_LAYERS: |
| 7057 | case CAPTURE_DISPLAY: |
| 7058 | case CAPTURE_DISPLAY_BY_ID: |
Huihong Luo | 4ed1c91 | 2022-02-22 14:30:01 -0800 | [diff] [blame] | 7059 | case CLEAR_ANIMATION_FRAME_STATS: |
| 7060 | case GET_ANIMATION_FRAME_STATS: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7061 | case OVERRIDE_HDR_TYPES: |
| 7062 | case ON_PULL_ATOM: |
| 7063 | case ENABLE_VSYNC_INJECTIONS: |
| 7064 | case INJECT_VSYNC: |
| 7065 | case GET_LAYER_DEBUG_INFO: |
| 7066 | case GET_COLOR_MANAGEMENT: |
| 7067 | case GET_COMPOSITION_PREFERENCE: |
| 7068 | case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: |
| 7069 | case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7070 | case GET_DISPLAYED_CONTENT_SAMPLE: |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 7071 | case GET_PROTECTED_CONTENT_SUPPORT: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7072 | case IS_WIDE_COLOR_DISPLAY: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7073 | case ADD_REGION_SAMPLING_LISTENER: |
| 7074 | case REMOVE_REGION_SAMPLING_LISTENER: |
| 7075 | case ADD_FPS_LISTENER: |
| 7076 | case REMOVE_FPS_LISTENER: |
| 7077 | case ADD_TUNNEL_MODE_ENABLED_LISTENER: |
| 7078 | case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: |
| 7079 | case ADD_WINDOW_INFOS_LISTENER: |
| 7080 | case REMOVE_WINDOW_INFOS_LISTENER: |
| 7081 | case SET_DESIRED_DISPLAY_MODE_SPECS: |
| 7082 | case GET_DESIRED_DISPLAY_MODE_SPECS: |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 7083 | case GET_DISPLAY_BRIGHTNESS_SUPPORT: |
| 7084 | case SET_DISPLAY_BRIGHTNESS: |
| 7085 | case ADD_HDR_LAYER_INFO_LISTENER: |
| 7086 | case REMOVE_HDR_LAYER_INFO_LISTENER: |
| 7087 | case NOTIFY_POWER_BOOST: |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 7088 | case SET_GLOBAL_SHADOW_SETTINGS: |
| 7089 | case GET_DISPLAY_DECORATION_SUPPORT: |
| 7090 | case SET_FRAME_RATE: |
| 7091 | case SET_OVERRIDE_FRAME_RATE: |
| 7092 | case SET_FRAME_TIMELINE_INFO: |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 7093 | case ADD_TRANSACTION_TRACE_LISTENER: |
| 7094 | case GET_GPU_CONTEXT_PRIORITY: |
| 7095 | case GET_MAX_ACQUIRED_BUFFER_COUNT: |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 7096 | LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 7097 | return PERMISSION_DENIED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | } |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7099 | |
| 7100 | // These codes are used for the IBinder protocol to either interrogate the recipient |
| 7101 | // side of the transaction for its canonical interface descriptor or to dump its state. |
| 7102 | // We let them pass by default. |
| 7103 | if (code == IBinder::INTERFACE_TRANSACTION || code == IBinder::DUMP_TRANSACTION || |
| 7104 | code == IBinder::PING_TRANSACTION || code == IBinder::SHELL_COMMAND_TRANSACTION || |
| 7105 | code == IBinder::SYSPROPS_TRANSACTION) { |
| 7106 | return OK; |
| 7107 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7108 | // Numbers from 1000 to 1045 are currently used for backdoors. The code |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7109 | // in onTransact verifies that the user is root, and has access to use SF. |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7110 | if (code >= 1000 && code <= 1045) { |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7111 | ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code); |
| 7112 | return OK; |
| 7113 | } |
| 7114 | ALOGE("Permission Denial: SurfaceFlinger did not recognize request code: %u", code); |
| 7115 | return PERMISSION_DENIED; |
| 7116 | #pragma clang diagnostic pop |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
Ana Krulec | 13be8ad | 2018-08-21 02:43:56 +0000 | [diff] [blame] | 7119 | status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 7120 | uint32_t flags) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7121 | if (const status_t error = CheckTransactCodeCredentials(code); error != OK) { |
| 7122 | return error; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 7123 | } |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 7124 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); |
| 7126 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 7127 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Romain Guy | 8c6bbd6 | 2017-06-05 13:51:43 -0700 | [diff] [blame] | 7128 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7129 | const int uid = ipc->getCallingUid(); |
| 7130 | if (CC_UNLIKELY(uid != AID_SYSTEM |
| 7131 | && !PermissionCache::checkCallingPermission(sHardwareTest))) { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7132 | const int pid = ipc->getCallingPid(); |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 7133 | ALOGE("Permission Denial: " |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 7134 | "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] | 7135 | return PERMISSION_DENIED; |
| 7136 | } |
| 7137 | int n; |
| 7138 | switch (code) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7139 | case 1000: // Unused. |
| 7140 | case 1001: |
| 7141 | return NAME_NOT_FOUND; |
| 7142 | case 1002: // Toggle flashing on surface damage. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7143 | sfdo_setDebugFlash(data.readInt32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7144 | return NO_ERROR; |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 7145 | case 1004: // Force composite ahead of next VSYNC. |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7146 | case 1006: |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7147 | sfdo_scheduleComposite(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7148 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7149 | case 1005: { // Force commit ahead of next VSYNC. |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7150 | sfdo_scheduleCommit(); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 7151 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7152 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7153 | case 1007: // Unused. |
| 7154 | return NAME_NOT_FOUND; |
| 7155 | case 1008: // Toggle forced GPU composition. |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 7156 | sfdo_forceClientComposition(data.readInt32() != 0); |
Mathias Agopian | 53331da | 2011-08-22 21:44:41 -0700 | [diff] [blame] | 7157 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7158 | case 1009: // Toggle use of transform hint. |
| 7159 | mDebugDisableTransformHint = data.readInt32() != 0; |
| 7160 | scheduleRepaint(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 7161 | return NO_ERROR; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7162 | case 1010: // Interrogate. |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 7163 | reply->writeInt32(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7164 | reply->writeInt32(0); |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7165 | reply->writeInt32(mDebugFlashDelay); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 7166 | reply->writeInt32(0); |
Dianne Hackborn | 12839be | 2012-02-06 21:21:05 -0800 | [diff] [blame] | 7167 | reply->writeInt32(mDebugDisableHWC); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7168 | return NO_ERROR; |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 7169 | case 1013: // Unused. |
| 7170 | return NAME_NOT_FOUND; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7171 | case 1014: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7172 | Mutex::Autolock _l(mStateLock); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7173 | // daltonize |
| 7174 | n = data.readInt32(); |
Isaac Chai | 1ec2d9a | 2024-04-11 20:10:34 +0000 | [diff] [blame] | 7175 | mDaltonizer.setLevel(data.readInt32()); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7176 | switch (n % 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7177 | case 1: |
| 7178 | mDaltonizer.setType(ColorBlindnessType::Protanomaly); |
| 7179 | break; |
| 7180 | case 2: |
| 7181 | mDaltonizer.setType(ColorBlindnessType::Deuteranomaly); |
| 7182 | break; |
| 7183 | case 3: |
| 7184 | mDaltonizer.setType(ColorBlindnessType::Tritanomaly); |
| 7185 | break; |
| 7186 | default: |
| 7187 | mDaltonizer.setType(ColorBlindnessType::None); |
| 7188 | break; |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7189 | } |
| 7190 | if (n >= 10) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7191 | mDaltonizer.setMode(ColorBlindnessMode::Correction); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7192 | } else { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7193 | mDaltonizer.setMode(ColorBlindnessMode::Simulation); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 7194 | } |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7195 | |
| 7196 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7197 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7199 | case 1015: { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7200 | Mutex::Autolock _l(mStateLock); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7201 | // apply a color matrix |
| 7202 | n = data.readInt32(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7203 | if (n) { |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7204 | // color matrix is sent as a column-major mat4 matrix |
Alan Viverette | 794c5ba | 2013-10-03 16:40:52 -0700 | [diff] [blame] | 7205 | for (size_t i = 0 ; i < 4; i++) { |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7206 | for (size_t j = 0; j < 4; j++) { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7207 | mClientColorMatrix[i][j] = data.readFloat(); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 7208 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7209 | } |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7210 | } else { |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7211 | mClientColorMatrix = mat4(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7212 | } |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7213 | |
| 7214 | // Check that supplied matrix's last row is {0,0,0,1} so we can avoid |
| 7215 | // the division by w in the fragment shader |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7216 | float4 lastRow(transpose(mClientColorMatrix)[3]); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 7217 | if (any(greaterThan(abs(lastRow - float4{0, 0, 0, 1}), float4{1e-4f}))) { |
| 7218 | ALOGE("The color transform's last row must be (0, 0, 0, 1)"); |
| 7219 | } |
| 7220 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7221 | updateColorMatrixLocked(); |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 7222 | return NO_ERROR; |
| 7223 | } |
Dominik Laskowski | 8d32ddc | 2019-08-07 11:25:35 -0700 | [diff] [blame] | 7224 | case 1016: { // Unused. |
| 7225 | return NAME_NOT_FOUND; |
Ruchi Kandoi | f52b3c8 | 2014-04-24 16:42:35 -0700 | [diff] [blame] | 7226 | } |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7227 | case 1017: { |
| 7228 | n = data.readInt32(); |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 7229 | mForceFullDamage = n != 0; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 7230 | return NO_ERROR; |
| 7231 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7232 | case 1018: { // Set the render deadline as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7233 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7234 | mScheduler->setDuration(scheduler::Cycle::Render, std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7235 | return NO_ERROR; |
| 7236 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7237 | case 1019: { // Set the deadline of the last composite as a duration until VSYNC. |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7238 | n = data.readInt32(); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7239 | mScheduler->setDuration(scheduler::Cycle::LastComposite, |
| 7240 | std::chrono::nanoseconds(n), 0ns); |
Dan Stoza | db4ac3c | 2015-04-14 11:34:01 -0700 | [diff] [blame] | 7241 | return NO_ERROR; |
| 7242 | } |
Huihong Luo | ab8ffef | 2022-08-18 13:02:26 -0700 | [diff] [blame] | 7243 | case 1020: { // Unused |
| 7244 | return NAME_NOT_FOUND; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 7245 | } |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7246 | case 1021: { // Disable HWC virtual displays |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 7247 | const bool enable = data.readInt32() != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7248 | static_cast<void>( |
| 7249 | mScheduler->schedule([this, enable] { enableHalVirtualDisplays(enable); })); |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 7250 | return NO_ERROR; |
| 7251 | } |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7252 | case 1022: { // Set saturation boost |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7253 | Mutex::Autolock _l(mStateLock); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7254 | mGlobalSaturationFactor = std::max(0.0f, std::min(data.readFloat(), 2.0f)); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7255 | |
Chia-I Wu | 28f320b | 2018-05-03 11:02:56 -0700 | [diff] [blame] | 7256 | updateColorMatrixLocked(); |
Romain Guy | 0147a17 | 2017-06-01 13:53:56 -0700 | [diff] [blame] | 7257 | return NO_ERROR; |
| 7258 | } |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7259 | case 1023: { // Set color mode. |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7260 | mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32()); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 7261 | |
| 7262 | if (int32_t colorMode; data.readInt32(&colorMode) == NO_ERROR) { |
| 7263 | mForceColorMode = static_cast<ui::ColorMode>(colorMode); |
Daniel Solomon | 7c7ede2 | 2019-07-11 16:35:40 -0700 | [diff] [blame] | 7264 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7265 | scheduleRepaint(); |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7266 | return NO_ERROR; |
| 7267 | } |
Peiyong Lin | 4bac91c | 2018-10-25 09:48:33 -0700 | [diff] [blame] | 7268 | // Deprecate, use 1030 to check whether the device is color managed. |
| 7269 | case 1024: { |
| 7270 | return NAME_NOT_FOUND; |
Romain Guy | 54f154a | 2017-10-24 21:40:32 +0100 | [diff] [blame] | 7271 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7272 | // Deprecated, use perfetto to start/stop the layer tracing |
| 7273 | case 1025: { |
| 7274 | return NAME_NOT_FOUND; |
Adrian Roos | 1e1a128 | 2017-11-01 19:05:31 +0100 | [diff] [blame] | 7275 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7276 | // Deprecated, execute "adb shell perfetto --query" to see the ongoing tracing sessions |
| 7277 | case 1026: { |
| 7278 | return NAME_NOT_FOUND; |
Vishnu Nair | 87704c9 | 2018-01-08 15:32:57 -0800 | [diff] [blame] | 7279 | } |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7280 | // Is a DisplayColorSetting supported? |
| 7281 | case 1027: { |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7282 | const auto display = getDefaultDisplayDevice(); |
| 7283 | if (!display) { |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7284 | return NAME_NOT_FOUND; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7285 | } |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7286 | |
| 7287 | DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32()); |
| 7288 | switch (setting) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7289 | case DisplayColorSetting::kManaged: |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7290 | case DisplayColorSetting::kUnmanaged: |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7291 | reply->writeBool(true); |
| 7292 | break; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 7293 | case DisplayColorSetting::kEnhanced: |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7294 | reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE)); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7295 | break; |
| 7296 | default: // vendor display color setting |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 7297 | reply->writeBool( |
| 7298 | display->hasRenderIntent(static_cast<RenderIntent>(setting))); |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 7299 | break; |
| 7300 | } |
| 7301 | return NO_ERROR; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 7302 | } |
Alec Mouri | 9c58bcd | 2020-09-09 18:57:07 -0700 | [diff] [blame] | 7303 | case 1028: { // Unused. |
| 7304 | return NAME_NOT_FOUND; |
Steven Thomas | 97f1f4c | 2018-06-01 12:04:16 -0700 | [diff] [blame] | 7305 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7306 | // Deprecated, use perfetto to set the active layer tracing buffer size |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7307 | case 1029: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7308 | return NAME_NOT_FOUND; |
Nataniel Borges | 2b796da | 2019-02-15 13:32:18 -0800 | [diff] [blame] | 7309 | } |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7310 | // Is device color managed? |
| 7311 | case 1030: { |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 7312 | // ColorDisplayManager stil calls this |
| 7313 | reply->writeBool(true); |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 7314 | return NO_ERROR; |
| 7315 | } |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7316 | // Override default composition data space |
| 7317 | // adb shell service call SurfaceFlinger 1031 i32 1 DATASPACE_NUMBER DATASPACE_NUMBER \ |
| 7318 | // && adb shell stop zygote && adb shell start zygote |
| 7319 | // to restore: adb shell service call SurfaceFlinger 1031 i32 0 && \ |
| 7320 | // adb shell stop zygote && adb shell start zygote |
| 7321 | case 1031: { |
| 7322 | Mutex::Autolock _l(mStateLock); |
| 7323 | n = data.readInt32(); |
| 7324 | if (n) { |
| 7325 | n = data.readInt32(); |
| 7326 | if (n) { |
| 7327 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7328 | if (!validateCompositionDataspace(dataspace)) { |
| 7329 | return BAD_VALUE; |
| 7330 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7331 | mDefaultCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7332 | } |
| 7333 | n = data.readInt32(); |
| 7334 | if (n) { |
| 7335 | Dataspace dataspace = static_cast<Dataspace>(n); |
| 7336 | if (!validateCompositionDataspace(dataspace)) { |
| 7337 | return BAD_VALUE; |
| 7338 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7339 | mWideColorGamutCompositionDataspace = dataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7340 | } |
| 7341 | } else { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7342 | // restore composition data space. |
| 7343 | mDefaultCompositionDataspace = defaultCompositionDataspace; |
| 7344 | mWideColorGamutCompositionDataspace = wideColorGamutCompositionDataspace; |
Peiyong Lin | 9d846a5 | 2018-11-05 13:18:20 -0800 | [diff] [blame] | 7345 | } |
| 7346 | return NO_ERROR; |
| 7347 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7348 | // Deprecated, use perfetto to set layer trace flags |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7349 | case 1033: { |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 7350 | return NAME_NOT_FOUND; |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 7351 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7352 | case 1034: { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 7353 | n = data.readInt32(); |
| 7354 | if (n == 0 || n == 1) { |
| 7355 | sfdo_enableRefreshRateOverlay(static_cast<bool>(n)); |
| 7356 | } else { |
| 7357 | Mutex::Autolock lock(mStateLock); |
| 7358 | reply->writeBool(isRefreshRateOverlayEnabled()); |
| 7359 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 7360 | return NO_ERROR; |
| 7361 | } |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7362 | case 1035: { |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7363 | // Parameters: |
| 7364 | // - (required) i32 mode id. |
| 7365 | // - (optional) i64 display id. Using default display if not provided. |
| 7366 | // - (optional) f min render rate. Using mode's fps is not provided. |
| 7367 | // - (optional) f max render rate. Using mode's fps is not provided. |
| 7368 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7369 | const int modeId = data.readInt32(); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 7370 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7371 | const auto display = [&]() -> sp<IBinder> { |
| 7372 | uint64_t value; |
| 7373 | if (data.readUint64(&value) != NO_ERROR) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 7374 | return getDefaultDisplayDevice()->getDisplayToken().promote(); |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7375 | } |
| 7376 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7377 | if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { |
| 7378 | return getPhysicalDisplayToken(*id); |
| 7379 | } |
| 7380 | |
| 7381 | ALOGE("Invalid physical display ID"); |
| 7382 | return nullptr; |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 7383 | }(); |
| 7384 | |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7385 | const auto getFps = [&] { |
| 7386 | float value; |
| 7387 | if (data.readFloat(&value) == NO_ERROR) { |
| 7388 | return Fps::fromValue(value); |
| 7389 | } |
| 7390 | |
| 7391 | return Fps(); |
| 7392 | }; |
| 7393 | |
| 7394 | const auto minFps = getFps(); |
| 7395 | const auto maxFps = getFps(); |
| 7396 | |
Shiyong Li | 2bcece9 | 2021-08-30 20:38:50 +0000 | [diff] [blame] | 7397 | mDebugDisplayModeSetByBackdoor = false; |
Ady Abraham | 3802726 | 2023-10-17 16:58:25 -0700 | [diff] [blame] | 7398 | const status_t result = |
| 7399 | setActiveModeFromBackdoor(display, DisplayModeId{modeId}, minFps, maxFps); |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7400 | mDebugDisplayModeSetByBackdoor = result == NO_ERROR; |
| 7401 | return result; |
Ady Abraham | 34392f7 | 2019-04-10 11:29:27 -0700 | [diff] [blame] | 7402 | } |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7403 | // Turn on/off frame rate flexibility mode. When turned on it overrides the display |
| 7404 | // manager frame rate policy a new policy which allows switching between all refresh |
| 7405 | // rates. |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7406 | case 1036: { |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7407 | if (data.readInt32() > 0) { // turn on |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7408 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7409 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7410 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7411 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7412 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7413 | // This is a little racy, but not in a way that hurts anything. As |
| 7414 | // we grab the defaultMode from the display manager policy, we could |
| 7415 | // be setting a new display manager policy, leaving us using a stale |
| 7416 | // defaultMode. The defaultMode doesn't matter for the override |
| 7417 | // policy though, since we set allowGroupSwitching to true, so it's |
| 7418 | // not a problem. |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7419 | scheduler::RefreshRateSelector::OverridePolicy overridePolicy; |
| 7420 | overridePolicy.defaultMode = display->refreshRateSelector() |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7421 | .getDisplayManagerPolicy() |
| 7422 | .defaultMode; |
| 7423 | overridePolicy.allowGroupSwitching = true; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7424 | return setDesiredDisplayModeSpecsInternal(display, overridePolicy); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7425 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7426 | .get(); |
| 7427 | } else { // turn off |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7428 | return mScheduler |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7429 | ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7430 | const auto display = |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7431 | FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 7432 | return setDesiredDisplayModeSpecsInternal( |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7433 | display, |
| 7434 | scheduler::RefreshRateSelector::NoOverridePolicy{}); |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7435 | }) |
Marin Shalamanov | fa39ee7 | 2021-11-01 14:04:27 +0100 | [diff] [blame] | 7436 | .get(); |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7437 | } |
Ady Abraham | 07e5470 | 2020-04-16 15:05:37 -0700 | [diff] [blame] | 7438 | } |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7439 | // Inject a hotplug connected event for the primary display. This will deallocate and |
| 7440 | // reallocate the display state including framebuffers. |
| 7441 | case 1037: { |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 7442 | const hal::HWDisplayId hwcId = |
| 7443 | (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); |
| 7444 | |
Huihong Luo | 791bef9 | 2023-09-19 21:18:45 -0700 | [diff] [blame] | 7445 | onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); |
Marin Shalamanov | e6332b0 | 2020-09-03 11:30:37 +0200 | [diff] [blame] | 7446 | return NO_ERROR; |
| 7447 | } |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 7448 | // Modify the max number of display frames stored within FrameTimeline |
| 7449 | case 1038: { |
| 7450 | n = data.readInt32(); |
| 7451 | if (n < 0 || n > MAX_ALLOWED_DISPLAY_FRAMES) { |
| 7452 | ALOGW("Invalid max size. Maximum allowed is %d", MAX_ALLOWED_DISPLAY_FRAMES); |
| 7453 | return BAD_VALUE; |
| 7454 | } |
| 7455 | if (n == 0) { |
| 7456 | // restore to default |
| 7457 | mFrameTimeline->reset(); |
| 7458 | return NO_ERROR; |
| 7459 | } |
| 7460 | mFrameTimeline->setMaxDisplayFrames(n); |
| 7461 | return NO_ERROR; |
| 7462 | } |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7463 | case 1039: { |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 7464 | PhysicalDisplayId displayId = [&]() { |
| 7465 | Mutex::Autolock lock(mStateLock); |
| 7466 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 7467 | }(); |
| 7468 | |
| 7469 | auto inUid = static_cast<uid_t>(data.readInt32()); |
| 7470 | const auto refreshRate = data.readFloat(); |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 7471 | mScheduler->setPreferredRefreshRateForUid(FrameRateOverride{inUid, refreshRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 7472 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 7473 | return NO_ERROR; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 7474 | } |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7475 | // Toggle caching feature |
| 7476 | // First argument is an int32 - nonzero enables caching and zero disables caching |
| 7477 | // Second argument is an optional uint64 - if present, then limits enabling/disabling |
| 7478 | // caching to a particular physical display |
| 7479 | case 1040: { |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7480 | auto future = mScheduler->schedule([&] { |
| 7481 | n = data.readInt32(); |
| 7482 | std::optional<PhysicalDisplayId> inputId = std::nullopt; |
| 7483 | if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { |
| 7484 | inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); |
| 7485 | if (!inputId || getPhysicalDisplayToken(*inputId)) { |
| 7486 | ALOGE("No display with id: %" PRIu64, inputDisplayId); |
| 7487 | return NAME_NOT_FOUND; |
| 7488 | } |
| 7489 | } |
| 7490 | { |
| 7491 | Mutex::Autolock lock(mStateLock); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7492 | mLayerCachingEnabled = n != 0; |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7493 | for (const auto& [_, display] : mDisplays) { |
| 7494 | if (!inputId || *inputId == display->getPhysicalId()) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7495 | display->enableLayerCaching(mLayerCachingEnabled); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7496 | } |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7497 | } |
| 7498 | } |
| 7499 | return OK; |
| 7500 | }); |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7501 | |
Dominik Laskowski | 756b789 | 2021-08-04 12:53:59 -0700 | [diff] [blame] | 7502 | if (const status_t error = future.get(); error != OK) { |
Alec Mouri | cdd722b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 7503 | return error; |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7504 | } |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 7505 | scheduleRepaint(); |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 7506 | return NO_ERROR; |
| 7507 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7508 | case 1041: { // Transaction tracing |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7509 | if (mTransactionTracing) { |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7510 | int arg = data.readInt32(); |
| 7511 | if (arg == -1) { |
Vishnu Nair | 50858e6 | 2023-10-13 23:28:24 +0000 | [diff] [blame] | 7512 | mScheduler->schedule([&]() { mTransactionTracing.reset(); }).get(); |
Vishnu Nair | 640261c | 2023-09-21 21:22:51 -0700 | [diff] [blame] | 7513 | } else if (arg > 0) { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7514 | // Transaction tracing is always running but allow the user to temporarily |
| 7515 | // increase the buffer when actively debugging. |
| 7516 | mTransactionTracing->setBufferSize( |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7517 | TransactionTracing::LEGACY_ACTIVE_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7518 | } else { |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 7519 | TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7520 | mTransactionTracing->setBufferSize( |
| 7521 | TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 7522 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 7523 | } |
| 7524 | reply->writeInt32(NO_ERROR); |
| 7525 | return NO_ERROR; |
| 7526 | } |
Kean Mariotti | 3e68a20 | 2023-04-19 13:41:55 +0000 | [diff] [blame] | 7527 | case 1042: { // Write transaction trace to file |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7528 | if (mTransactionTracing) { |
| 7529 | mTransactionTracing->writeToFile(); |
| 7530 | } |
Nataniel Borges | 533c2f8 | 2022-01-21 12:07:02 +0100 | [diff] [blame] | 7531 | reply->writeInt32(NO_ERROR); |
| 7532 | return NO_ERROR; |
| 7533 | } |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7534 | // hdr sdr ratio overlay |
| 7535 | case 1043: { |
| 7536 | auto future = mScheduler->schedule( |
| 7537 | [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) { |
| 7538 | n = data.readInt32(); |
Sally Qi | 0cd9e86 | 2024-05-15 18:37:02 -0700 | [diff] [blame] | 7539 | if (n == 0 || n == 1) { |
| 7540 | mHdrSdrRatioOverlay = n != 0; |
| 7541 | enableHdrSdrRatioOverlay(mHdrSdrRatioOverlay); |
| 7542 | } else { |
| 7543 | reply->writeBool(isHdrSdrRatioOverlayEnabled()); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 7544 | } |
| 7545 | }); |
| 7546 | future.wait(); |
| 7547 | return NO_ERROR; |
| 7548 | } |
Brian Johnson | 51d8d5d | 2023-07-28 10:18:47 -0700 | [diff] [blame] | 7549 | |
| 7550 | case 1044: { // Enable/Disable mirroring from one display to another |
| 7551 | /* |
| 7552 | * Mirror one display onto another. |
| 7553 | * Ensure the source and destination displays are on. |
| 7554 | * Commands: |
| 7555 | * 0: Mirror one display to another |
| 7556 | * 1: Disable mirroring to a previously mirrored display |
| 7557 | * 2: Disable mirroring on previously mirrored displays |
| 7558 | * |
| 7559 | * Ex: |
| 7560 | * Get the display ids: |
| 7561 | * adb shell dumpsys SurfaceFlinger --display-id |
| 7562 | * Mirror first display to the second: |
| 7563 | * adb shell service call SurfaceFlinger 1044 i64 0 i64 4619827677550801152 i64 |
| 7564 | * 4619827677550801153 |
| 7565 | * Stop mirroring: |
| 7566 | * adb shell service call SurfaceFlinger 1044 i64 1 |
| 7567 | */ |
| 7568 | |
| 7569 | int64_t arg0 = data.readInt64(); |
| 7570 | |
| 7571 | switch (arg0) { |
| 7572 | case 0: { |
| 7573 | // Mirror arg1 to arg2 |
| 7574 | int64_t arg1 = data.readInt64(); |
| 7575 | int64_t arg2 = data.readInt64(); |
| 7576 | // Enable mirroring for one display |
| 7577 | const auto display1id = DisplayId::fromValue(arg1); |
| 7578 | auto mirrorRoot = SurfaceComposerClient::getDefault()->mirrorDisplay( |
| 7579 | display1id.value()); |
| 7580 | auto id2 = DisplayId::fromValue<PhysicalDisplayId>(arg2); |
| 7581 | const auto token2 = getPhysicalDisplayToken(*id2); |
| 7582 | ui::LayerStack layerStack; |
| 7583 | { |
| 7584 | Mutex::Autolock lock(mStateLock); |
| 7585 | sp<DisplayDevice> display = getDisplayDeviceLocked(token2); |
| 7586 | layerStack = display->getLayerStack(); |
| 7587 | } |
| 7588 | SurfaceComposerClient::Transaction t; |
| 7589 | t.setDisplayLayerStack(token2, layerStack); |
| 7590 | t.setLayer(mirrorRoot, INT_MAX); // Top-most layer |
| 7591 | t.setLayerStack(mirrorRoot, layerStack); |
| 7592 | t.apply(); |
| 7593 | |
| 7594 | mMirrorMapForDebug.emplace_or_replace(arg2, mirrorRoot); |
| 7595 | break; |
| 7596 | } |
| 7597 | |
| 7598 | case 1: { |
| 7599 | // Disable mirroring for arg1 |
| 7600 | int64_t arg1 = data.readInt64(); |
| 7601 | mMirrorMapForDebug.erase(arg1); |
| 7602 | break; |
| 7603 | } |
| 7604 | |
| 7605 | case 2: { |
| 7606 | // Disable mirroring for all displays |
| 7607 | mMirrorMapForDebug.clear(); |
| 7608 | break; |
| 7609 | } |
| 7610 | |
| 7611 | default: |
| 7612 | return BAD_VALUE; |
| 7613 | } |
| 7614 | return NO_ERROR; |
| 7615 | } |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7616 | // Inject jank |
| 7617 | // First argument is a float that describes the fraction of frame duration to jank by. |
| 7618 | // Second argument is a delay in ms for triggering the jank. This is useful for working |
| 7619 | // with tools that steal the adb connection. This argument is optional. |
| 7620 | case 1045: { |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 7621 | if (FlagManager::getInstance().vrr_config()) { |
Alec Mouri | 1c7938e | 2023-09-22 04:17:23 +0000 | [diff] [blame] | 7622 | float jankAmount = data.readFloat(); |
| 7623 | int32_t jankDelayMs = 0; |
| 7624 | if (data.readInt32(&jankDelayMs) != NO_ERROR) { |
| 7625 | jankDelayMs = 0; |
| 7626 | } |
| 7627 | |
| 7628 | const auto jankDelayDuration = Duration(std::chrono::milliseconds(jankDelayMs)); |
| 7629 | |
| 7630 | const bool jankAmountValid = jankAmount > 0.0 && jankAmount < 100.0; |
| 7631 | |
| 7632 | if (!jankAmountValid) { |
| 7633 | ALOGD("Ignoring invalid jank amount: %f", jankAmount); |
| 7634 | reply->writeInt32(BAD_VALUE); |
| 7635 | return BAD_VALUE; |
| 7636 | } |
| 7637 | |
| 7638 | (void)mScheduler->scheduleDelayed( |
| 7639 | [&, jankAmount]() FTL_FAKE_GUARD(kMainThreadContext) { |
| 7640 | mScheduler->injectPacesetterDelay(jankAmount); |
| 7641 | scheduleComposite(FrameHint::kActive); |
| 7642 | }, |
| 7643 | jankDelayDuration.ns()); |
| 7644 | reply->writeInt32(NO_ERROR); |
| 7645 | return NO_ERROR; |
| 7646 | } |
| 7647 | return err; |
| 7648 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | } |
| 7650 | } |
| 7651 | return err; |
| 7652 | } |
| 7653 | |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7654 | void SurfaceFlinger::kernelTimerChanged(bool expired) { |
| 7655 | static bool updateOverlay = |
| 7656 | property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 7657 | if (!updateOverlay) return; |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7658 | |
| 7659 | // Update the overlay on the main thread to avoid race conditions with |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 7660 | // RefreshRateSelector::getActiveMode |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 7661 | static_cast<void>(mScheduler->schedule([=, this] { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 7662 | const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7663 | if (!display) { |
| 7664 | ALOGW("%s: default display is null", __func__); |
| 7665 | return; |
| 7666 | } |
Adrian Salido | a942af8 | 2022-02-17 19:22:31 -0800 | [diff] [blame] | 7667 | if (!display->isRefreshRateOverlayEnabled()) return; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7668 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7669 | const auto desiredModeIdOpt = |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 7670 | display->getDesiredMode().transform([](const display::DisplayModeRequest& request) { |
| 7671 | return request.mode.modePtr->getId(); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7672 | }); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 7673 | |
| 7674 | const bool timerExpired = mKernelIdleTimerEnabled && expired; |
| 7675 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 7676 | if (display->onKernelTimerChanged(desiredModeIdOpt, timerExpired)) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 7677 | mScheduler->scheduleFrame(); |
Ady Abraham | a09852a | 2020-02-20 14:23:42 -0800 | [diff] [blame] | 7678 | } |
| 7679 | })); |
| 7680 | } |
| 7681 | |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7682 | std::pair<std::optional<KernelIdleTimerController>, std::chrono::milliseconds> |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 7683 | SurfaceFlinger::getKernelIdleTimerProperties(PhysicalDisplayId displayId) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7684 | const bool isKernelIdleTimerHwcSupported = getHwComposer().getComposer()->isSupported( |
| 7685 | android::Hwc2::Composer::OptionalFeature::KernelIdleTimer); |
| 7686 | const auto timeout = getIdleTimerTimeout(displayId); |
| 7687 | if (isKernelIdleTimerHwcSupported) { |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 7688 | if (getHwComposer().hasDisplayIdleTimerCapability(displayId)) { |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7689 | // In order to decide if we can use the HWC api for idle timer |
| 7690 | // we query DisplayCapability::DISPLAY_IDLE_TIMER directly on the composer |
| 7691 | // without relying on hasDisplayCapability. |
| 7692 | // hasDisplayCapability relies on DisplayCapabilities |
| 7693 | // which are updated after we set the PowerMode::ON. |
| 7694 | // DISPLAY_IDLE_TIMER is a display driver property |
| 7695 | // and is available before the PowerMode::ON |
| 7696 | return {KernelIdleTimerController::HwcApi, timeout}; |
| 7697 | } |
| 7698 | return {std::nullopt, timeout}; |
| 7699 | } |
| 7700 | if (getKernelIdleTimerSyspropConfig(displayId)) { |
| 7701 | return {KernelIdleTimerController::Sysprop, timeout}; |
| 7702 | } |
| 7703 | |
| 7704 | return {std::nullopt, timeout}; |
| 7705 | } |
| 7706 | |
| 7707 | void SurfaceFlinger::updateKernelIdleTimer(std::chrono::milliseconds timeout, |
| 7708 | KernelIdleTimerController controller, |
| 7709 | PhysicalDisplayId displayId) { |
| 7710 | switch (controller) { |
| 7711 | case KernelIdleTimerController::HwcApi: { |
| 7712 | getHwComposer().setIdleTimerEnabled(displayId, timeout); |
| 7713 | break; |
| 7714 | } |
| 7715 | case KernelIdleTimerController::Sysprop: { |
| 7716 | base::SetProperty(KERNEL_IDLE_TIMER_PROP, timeout > 0ms ? "true" : "false"); |
| 7717 | break; |
| 7718 | } |
| 7719 | } |
| 7720 | } |
| 7721 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7722 | void SurfaceFlinger::toggleKernelIdleTimer() { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7723 | using KernelIdleTimerAction = scheduler::RefreshRateSelector::KernelIdleTimerAction; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7724 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 7725 | const auto display = getDefaultDisplayDeviceLocked(); |
| 7726 | if (!display) { |
| 7727 | ALOGW("%s: default display is null", __func__); |
| 7728 | return; |
| 7729 | } |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7730 | |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7731 | // If the support for kernel idle timer is disabled for the active display, |
| 7732 | // don't do anything. |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7733 | const std::optional<KernelIdleTimerController> kernelIdleTimerController = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7734 | display->refreshRateSelector().kernelIdleTimerController(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7735 | if (!kernelIdleTimerController.has_value()) { |
Ady Abraham | e9316b7 | 2021-09-24 17:04:36 -0700 | [diff] [blame] | 7736 | return; |
| 7737 | } |
| 7738 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7739 | const KernelIdleTimerAction action = display->refreshRateSelector().getIdleTimerAction(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7740 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7741 | switch (action) { |
| 7742 | case KernelIdleTimerAction::TurnOff: |
| 7743 | if (mKernelIdleTimerEnabled) { |
| 7744 | ATRACE_INT("KernelIdleTimer", 0); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7745 | std::chrono::milliseconds constexpr kTimerDisabledTimeout = 0ms; |
| 7746 | updateKernelIdleTimer(kTimerDisabledTimeout, kernelIdleTimerController.value(), |
| 7747 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7748 | mKernelIdleTimerEnabled = false; |
| 7749 | } |
| 7750 | break; |
| 7751 | case KernelIdleTimerAction::TurnOn: |
| 7752 | if (!mKernelIdleTimerEnabled) { |
| 7753 | ATRACE_INT("KernelIdleTimer", 1); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7754 | const std::chrono::milliseconds timeout = |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 7755 | display->refreshRateSelector().getIdleTimerTimeout(); |
ramindani | 32cf060 | 2022-03-02 02:30:29 +0000 | [diff] [blame] | 7756 | updateKernelIdleTimer(timeout, kernelIdleTimerController.value(), |
| 7757 | display->getPhysicalId()); |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7758 | mKernelIdleTimerEnabled = true; |
| 7759 | } |
| 7760 | break; |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7764 | // A simple RAII class to disconnect from an ANativeWindow* when it goes out of scope |
| 7765 | class WindowDisconnector { |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7766 | public: |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7767 | WindowDisconnector(ANativeWindow* window, int api) : mWindow(window), mApi(api) {} |
| 7768 | ~WindowDisconnector() { |
| 7769 | native_window_api_disconnect(mWindow, mApi); |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7770 | } |
| 7771 | |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 7772 | private: |
| 7773 | ANativeWindow* mWindow; |
| 7774 | const int mApi; |
Mathias Agopian | 2ed0fe5 | 2013-07-08 17:09:41 -0700 | [diff] [blame] | 7775 | }; |
| 7776 | |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 7777 | static bool hasCaptureBlackoutContentPermission() { |
| 7778 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7779 | const int pid = ipc->getCallingPid(); |
| 7780 | const int uid = ipc->getCallingUid(); |
| 7781 | return uid == AID_GRAPHICS || uid == AID_SYSTEM || |
| 7782 | PermissionCache::checkPermission(sCaptureBlackoutContent, pid, uid); |
| 7783 | } |
| 7784 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7785 | static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { |
| 7786 | IPCThreadState* ipc = IPCThreadState::self(); |
| 7787 | const int pid = ipc->getCallingPid(); |
| 7788 | const int uid = ipc->getCallingUid(); |
| 7789 | if (uid == AID_GRAPHICS || PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 7790 | return OK; |
| 7791 | } |
| 7792 | |
| 7793 | // If the caller doesn't have the correct permissions but is only attempting to screenshot |
| 7794 | // itself, we allow it to continue. |
| 7795 | if (captureArgs.uid == uid) { |
| 7796 | return OK; |
| 7797 | } |
| 7798 | |
| 7799 | ALOGE("Permission Denial: can't take screenshot pid=%d, uid=%d", pid, uid); |
| 7800 | return PERMISSION_DENIED; |
| 7801 | } |
| 7802 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7803 | status_t SurfaceFlinger::setSchedFifo(bool enabled) { |
| 7804 | static constexpr int kFifoPriority = 2; |
| 7805 | static constexpr int kOtherPriority = 0; |
| 7806 | |
| 7807 | struct sched_param param = {0}; |
| 7808 | int sched_policy; |
| 7809 | if (enabled) { |
| 7810 | sched_policy = SCHED_FIFO; |
| 7811 | param.sched_priority = kFifoPriority; |
| 7812 | } else { |
| 7813 | sched_policy = SCHED_OTHER; |
| 7814 | param.sched_priority = kOtherPriority; |
| 7815 | } |
| 7816 | |
| 7817 | if (sched_setscheduler(0, sched_policy, ¶m) != 0) { |
| 7818 | return -errno; |
| 7819 | } |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7820 | |
| 7821 | return NO_ERROR; |
| 7822 | } |
| 7823 | |
| 7824 | status_t SurfaceFlinger::setSchedAttr(bool enabled) { |
| 7825 | static const unsigned int kUclampMin = |
Dominik Laskowski | dd374e1 | 2024-02-21 10:28:15 -0500 | [diff] [blame] | 7826 | base::GetUintProperty<unsigned int>("ro.surface_flinger.uclamp.min"s, 0U); |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7827 | |
| 7828 | if (!kUclampMin) { |
| 7829 | // uclamp.min set to 0 (default), skip setting |
| 7830 | return NO_ERROR; |
| 7831 | } |
| 7832 | |
Wei Wang | 23aa5a6 | 2021-06-04 15:56:57 -0700 | [diff] [blame] | 7833 | sched_attr attr = {}; |
| 7834 | attr.size = sizeof(attr); |
| 7835 | |
| 7836 | attr.sched_flags = (SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP); |
| 7837 | attr.sched_util_min = enabled ? kUclampMin : 0; |
| 7838 | attr.sched_util_max = 1024; |
| 7839 | |
| 7840 | if (syscall(__NR_sched_setattr, 0, &attr, 0)) { |
| 7841 | return -errno; |
| 7842 | } |
| 7843 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 7844 | return NO_ERROR; |
| 7845 | } |
| 7846 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7847 | namespace { |
| 7848 | |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame^] | 7849 | ui::Dataspace pickBestDataspace(ui::Dataspace requestedDataspace, |
| 7850 | const compositionengine::impl::OutputCompositionState& state, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7851 | bool capturingHdrLayers, bool hintForSeamlessTransition) { |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame^] | 7852 | if (requestedDataspace != ui::Dataspace::UNKNOWN) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7853 | return requestedDataspace; |
| 7854 | } |
| 7855 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7856 | const auto dataspaceForColorMode = ui::pickDataspaceFor(state.colorMode); |
| 7857 | |
Alec Mouri | 2964072 | 2023-05-16 23:22:41 +0000 | [diff] [blame] | 7858 | // TODO: Enable once HDR screenshots are ready. |
| 7859 | if constexpr (/* DISABLES CODE */ (false)) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 7860 | // For now since we only support 8-bit screenshots, just use HLG and |
| 7861 | // assume that 1.0 >= display max luminance. This isn't quite as future |
| 7862 | // proof as PQ is, but is good enough. |
| 7863 | // Consider using PQ once we support 16-bit screenshots and we're able |
| 7864 | // to consistently supply metadata to image encoders. |
| 7865 | return ui::Dataspace::BT2020_HLG; |
| 7866 | } |
| 7867 | |
| 7868 | return dataspaceForColorMode; |
| 7869 | } |
| 7870 | |
| 7871 | } // namespace |
| 7872 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7873 | static void invokeScreenCaptureError(const status_t status, |
| 7874 | const sp<IScreenCaptureListener>& captureListener) { |
| 7875 | ScreenCaptureResults captureResults; |
| 7876 | captureResults.fenceResult = base::unexpected(status); |
| 7877 | captureListener->onScreenCaptureCompleted(captureResults); |
| 7878 | } |
| 7879 | |
| 7880 | void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, |
| 7881 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7882 | ATRACE_CALL(); |
| 7883 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7884 | status_t validate = validateScreenshotPermissions(args); |
| 7885 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7886 | ALOGD("Permission denied to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7887 | invokeScreenCaptureError(validate, captureListener); |
| 7888 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 7889 | } |
| 7890 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7891 | if (!args.displayToken) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7892 | ALOGD("Invalid display token to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7893 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7894 | return; |
| 7895 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7896 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7897 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7898 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 7899 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 7900 | return; |
| 7901 | } |
| 7902 | |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7903 | wp<const DisplayDevice> displayWeak; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7904 | ui::LayerStack layerStack; |
| 7905 | ui::Size reqSize(args.width, args.height); |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7906 | std::unordered_set<uint32_t> excludeLayerIds; |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7907 | { |
| 7908 | Mutex::Autolock lock(mStateLock); |
| 7909 | sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7910 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7911 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7912 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7913 | return; |
| 7914 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7915 | displayWeak = display; |
| 7916 | layerStack = display->getLayerStack(); |
| 7917 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7918 | // 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] | 7919 | if (args.width == 0 || args.height == 0) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7920 | reqSize = display->getLayerStackSpaceRect().getSize(); |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7921 | } |
| 7922 | |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7923 | for (const auto& handle : args.excludeHandles) { |
| 7924 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 7925 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 7926 | excludeLayerIds.emplace(excludeLayer); |
| 7927 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7928 | ALOGD("Invalid layer handle passed as excludeLayer to captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7929 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7930 | return; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7931 | } |
| 7932 | } |
chaviw | d243289 | 2020-07-24 17:42:39 -0700 | [diff] [blame] | 7933 | } |
| 7934 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7935 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7936 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7937 | getLayerSnapshots = |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7938 | getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds)); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7939 | } else { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7940 | auto traverseLayers = [this, args, excludeLayerIds, |
| 7941 | layerStack](const LayerVector::Visitor& visitor) { |
| 7942 | traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7943 | }; |
| 7944 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7945 | } |
chaviw | 0390077 | 2020-08-18 12:34:51 -0700 | [diff] [blame] | 7946 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 7947 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
| 7948 | args.sourceCrop, reqSize, args.dataspace, |
| 7949 | args.hintForSeamlessTransition, |
| 7950 | args.captureSecureLayers, displayWeak), |
| 7951 | getLayerSnapshots, reqSize, args.pixelFormat, args.allowProtected, |
| 7952 | args.grayscale, captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7955 | void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7956 | const sp<IScreenCaptureListener>& captureListener) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7957 | ui::LayerStack layerStack; |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7958 | wp<const DisplayDevice> displayWeak; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7959 | ui::Size size; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7960 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 7961 | Mutex::Autolock lock(mStateLock); |
Dominik Laskowski | 7b9bf4c | 2021-03-18 12:21:29 -0700 | [diff] [blame] | 7962 | |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7963 | const auto display = getDisplayDeviceLocked(displayId); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7964 | if (!display) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7965 | ALOGD("Unable to find display device for captureDisplay"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 7966 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 7967 | return; |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7968 | } |
| 7969 | |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7970 | displayWeak = display; |
Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 7971 | layerStack = display->getLayerStack(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 7972 | size = display->getLayerStackSpaceRect().getSize(); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 7973 | } |
| 7974 | |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7975 | size.width *= args.frameScaleX; |
| 7976 | size.height *= args.frameScaleY; |
| 7977 | |
| 7978 | // We could query a real value for this but it'll be a long, long time until we support |
| 7979 | // displays that need upwards of 1GB per buffer so... |
| 7980 | constexpr auto kMaxTextureSize = 16384; |
| 7981 | if (size.width <= 0 || size.height <= 0 || size.width >= kMaxTextureSize || |
| 7982 | size.height >= kMaxTextureSize) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 7983 | ALOGD("captureDisplay resolved to invalid size %d x %d", size.width, size.height); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 7984 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 7985 | return; |
| 7986 | } |
| 7987 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7988 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 7989 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 7990 | getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, |
| 7991 | /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7992 | } else { |
| 7993 | auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 7994 | traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 7995 | }; |
| 7996 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 7997 | } |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 7998 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 7999 | if (captureListener == nullptr) { |
| 8000 | ALOGE("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8001 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8002 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8003 | } |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8004 | |
| 8005 | constexpr bool kAllowProtected = false; |
| 8006 | constexpr bool kGrayscale = false; |
| 8007 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8008 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>, |
| 8009 | Rect(), size, args.dataspace, |
| 8010 | args.hintForSeamlessTransition, |
| 8011 | false /* captureSecureLayers */, displayWeak), |
| 8012 | getLayerSnapshots, size, args.pixelFormat, kAllowProtected, kGrayscale, |
| 8013 | captureListener); |
chaviw | 93df2ea | 2019-04-30 16:45:12 -0700 | [diff] [blame] | 8014 | } |
| 8015 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 8016 | ScreenCaptureResults SurfaceFlinger::captureLayersSync(const LayerCaptureArgs& args) { |
| 8017 | sp<SyncScreenCaptureListener> captureListener = sp<SyncScreenCaptureListener>::make(); |
| 8018 | captureLayers(args, captureListener); |
| 8019 | return captureListener->waitForResults(); |
| 8020 | } |
| 8021 | |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8022 | void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, |
| 8023 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8024 | ATRACE_CALL(); |
| 8025 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8026 | status_t validate = validateScreenshotPermissions(args); |
| 8027 | if (validate != OK) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8028 | ALOGD("Permission denied to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8029 | invokeScreenCaptureError(validate, captureListener); |
| 8030 | return; |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8031 | } |
| 8032 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8033 | ui::Size reqSize; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8034 | sp<Layer> parent; |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8035 | Rect crop(args.sourceCrop); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8036 | std::unordered_set<uint32_t> excludeLayerIds; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8037 | ui::Dataspace dataspace = args.dataspace; |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 8038 | |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8039 | if (args.captureSecureLayers && !hasCaptureBlackoutContentPermission()) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8040 | ALOGD("Attempting to capture secure layers without CAPTURE_BLACKOUT_CONTENT"); |
Chavi Weingarten | f5fb5b0 | 2023-11-30 17:27:52 +0000 | [diff] [blame] | 8041 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
| 8042 | return; |
| 8043 | } |
chaviw | f5bb97b | 2021-04-28 15:35:37 -0500 | [diff] [blame] | 8044 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8045 | { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8046 | Mutex::Autolock lock(mStateLock); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 8047 | |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 8048 | parent = LayerHandle::getLayer(args.layerHandle); |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 8049 | if (parent == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8050 | ALOGD("captureLayers called with an invalid or removed parent"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8051 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8052 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8053 | } |
| 8054 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 8055 | Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getDrawingState()); |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8056 | if (args.sourceCrop.width() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8057 | crop.left = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8058 | crop.right = parentSourceBounds.getWidth(); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8059 | } |
| 8060 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8061 | if (args.sourceCrop.height() <= 0) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8062 | crop.top = 0; |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8063 | crop.bottom = parentSourceBounds.getHeight(); |
| 8064 | } |
| 8065 | |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 8066 | if (crop.isEmpty() || args.frameScaleX <= 0.0f || args.frameScaleY <= 0.0f) { |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 8067 | // Error out if the layer has no source bounds (i.e. they are boundless) and a source |
| 8068 | // crop was not specified, or an invalid frame scale was provided. |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8069 | ALOGD("Boundless layer, unspecified crop, or invalid frame scale to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8070 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8071 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8072 | } |
chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 8073 | reqSize = ui::Size(crop.width() * args.frameScaleX, crop.height() * args.frameScaleY); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8074 | |
chaviw | 3efadb1 | 2020-07-27 10:07:15 -0700 | [diff] [blame] | 8075 | for (const auto& handle : args.excludeHandles) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8076 | uint32_t excludeLayer = LayerHandle::getLayerId(handle); |
| 8077 | if (excludeLayer != UNASSIGNED_LAYER_ID) { |
| 8078 | excludeLayerIds.emplace(excludeLayer); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8079 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8080 | ALOGD("Invalid layer handle passed as excludeLayer to captureLayers"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8081 | invokeScreenCaptureError(NAME_NOT_FOUND, captureListener); |
| 8082 | return; |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 8083 | } |
| 8084 | } |
| 8085 | } // mStateLock |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 8086 | |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 8087 | // really small crop or frameScale |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 8088 | if (reqSize.width <= 0 || reqSize.height <= 0) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8089 | ALOGD("Failed to captureLayers: crop or scale too small"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8090 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8091 | return; |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 8092 | } |
| 8093 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8094 | GetLayerSnapshotsFunction getLayerSnapshots; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8095 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 8096 | std::optional<FloatRect> parentCrop = std::nullopt; |
| 8097 | if (args.childrenOnly) { |
| 8098 | parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height) |
| 8099 | : crop.toFloatRect(); |
| 8100 | } |
| 8101 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8102 | getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid, |
| 8103 | std::move(excludeLayerIds), |
| 8104 | args.childrenOnly, parentCrop); |
| 8105 | } else { |
| 8106 | auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) { |
| 8107 | parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
| 8108 | if (!layer->isVisible()) { |
| 8109 | return; |
| 8110 | } else if (args.childrenOnly && layer == parent.get()) { |
| 8111 | return; |
| 8112 | } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) { |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8113 | return; |
| 8114 | } |
Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 8115 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 8116 | auto p = sp<Layer>::fromExisting(layer); |
| 8117 | while (p != nullptr) { |
| 8118 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8119 | return; |
| 8120 | } |
| 8121 | p = p->getParent(); |
| 8122 | } |
| 8123 | |
| 8124 | visitor(layer); |
| 8125 | }); |
| 8126 | }; |
| 8127 | getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers); |
| 8128 | } |
Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 8129 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8130 | if (captureListener == nullptr) { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 8131 | ALOGD("capture screen must provide a capture listener callback"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8132 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8133 | return; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 8134 | } |
| 8135 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8136 | captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<LayerRenderAreaBuilder>, crop, |
| 8137 | reqSize, dataspace, args.captureSecureLayers, |
| 8138 | args.hintForSeamlessTransition, parent, |
| 8139 | args.childrenOnly), |
| 8140 | getLayerSnapshots, reqSize, args.pixelFormat, args.allowProtected, |
| 8141 | args.grayscale, captureListener); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8142 | } |
| 8143 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8144 | // Creates a Future release fence for a layer and keeps track of it in a list to |
| 8145 | // release the buffer when the Future is complete. Calls from composittion |
| 8146 | // involve needing to refresh the composition start time for stats. |
| 8147 | void SurfaceFlinger::attachReleaseFenceFutureToLayer(Layer* layer, LayerFE* layerFE, |
| 8148 | ui::LayerStack layerStack) { |
| 8149 | ftl::Future<FenceResult> futureFence = layerFE->createReleaseFenceFuture(); |
| 8150 | Layer* clonedFrom = layer->getClonedFrom().get(); |
| 8151 | auto owningLayer = clonedFrom ? clonedFrom : layer; |
| 8152 | owningLayer->prepareReleaseCallbacks(std::move(futureFence), layerStack); |
| 8153 | } |
| 8154 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8155 | bool SurfaceFlinger::layersHasProtectedLayer( |
| 8156 | const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const { |
| 8157 | bool protectedLayerFound = false; |
| 8158 | for (auto& [_, layerFe] : layers) { |
| 8159 | protectedLayerFound |= |
| 8160 | (layerFe->mSnapshot->isVisible && layerFe->mSnapshot->hasProtectedContent); |
| 8161 | if (protectedLayerFound) { |
| 8162 | break; |
| 8163 | } |
| 8164 | } |
| 8165 | return protectedLayerFound; |
| 8166 | } |
| 8167 | |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8168 | void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuilder, |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8169 | GetLayerSnapshotsFunction getLayerSnapshots, |
| 8170 | ui::Size bufferSize, ui::PixelFormat reqPixelFormat, |
| 8171 | bool allowProtected, bool grayscale, |
| 8172 | const sp<IScreenCaptureListener>& captureListener) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8173 | ATRACE_CALL(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8174 | |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8175 | if (exceedsMaxRenderTargetSize(bufferSize.getWidth(), bufferSize.getHeight())) { |
| 8176 | ALOGE("Attempted to capture screen with size (%" PRId32 ", %" PRId32 |
| 8177 | ") that exceeds render target size limit.", |
| 8178 | bufferSize.getWidth(), bufferSize.getHeight()); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8179 | invokeScreenCaptureError(BAD_VALUE, captureListener); |
| 8180 | return; |
Garfield Tan | 9c9c191 | 2021-07-19 12:02:16 -0700 | [diff] [blame] | 8181 | } |
| 8182 | |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8183 | // Loop over all visible layers to see whether there's any protected layer. A protected layer is |
| 8184 | // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. |
| 8185 | // A protected layer has no implication on whether it's secure, which is explicitly set by |
| 8186 | // application to avoid being screenshot or drawn via unsecure display. |
| 8187 | const bool supportsProtected = getRenderEngine().supportsProtectedContent(); |
| 8188 | bool hasProtectedLayer = false; |
| 8189 | if (allowProtected && supportsProtected) { |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8190 | auto layers = mScheduler->schedule([=]() { return getLayerSnapshots(); }).get(); |
| 8191 | hasProtectedLayer = layersHasProtectedLayer(layers); |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 8192 | } |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8193 | const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected; |
Richard Liu | cbcb895 | 2020-04-08 10:51:55 +0000 | [diff] [blame] | 8194 | const uint32_t usage = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER | |
| 8195 | GRALLOC_USAGE_HW_TEXTURE | |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8196 | (isProtected ? GRALLOC_USAGE_PROTECTED |
| 8197 | : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8198 | sp<GraphicBuffer> buffer = |
| 8199 | getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), |
| 8200 | static_cast<android_pixel_format>(reqPixelFormat), |
| 8201 | 1 /* layerCount */, usage, "screenshot"); |
Alec Mouri | 7013b6f | 2021-02-12 11:16:54 -0800 | [diff] [blame] | 8202 | |
| 8203 | const status_t bufferStatus = buffer->initCheck(); |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8204 | if (bufferStatus != OK) { |
| 8205 | // Animations may end up being really janky, but don't crash here. |
| 8206 | // Otherwise an irreponsible process may cause an SF crash by allocating |
| 8207 | // too much. |
| 8208 | ALOGE("%s: Buffer failed to allocate: %d", __func__, bufferStatus); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 8209 | invokeScreenCaptureError(bufferStatus, captureListener); |
| 8210 | return; |
Alec Mouri | d8f17c5 | 2022-07-21 18:43:10 +0000 | [diff] [blame] | 8211 | } |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 8212 | const std::shared_ptr<renderengine::ExternalTexture> texture = std::make_shared< |
| 8213 | renderengine::impl::ExternalTexture>(buffer, getRenderEngine(), |
| 8214 | renderengine::impl::ExternalTexture::Usage:: |
| 8215 | WRITEABLE); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8216 | auto futureFence = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8217 | captureScreenshot(renderAreaBuilder, getLayerSnapshots, texture, |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8218 | false /* regionSampling */, grayscale, isProtected, captureListener); |
| 8219 | futureFence.get(); |
Dan Stoza | ec46008 | 2018-12-17 15:35:09 -0800 | [diff] [blame] | 8220 | } |
| 8221 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8222 | const sp<const DisplayDevice> SurfaceFlinger::getRenderAreaDisplay( |
| 8223 | RenderAreaBuilderVariant& renderAreaBuilder, OutputCompositionState& state) { |
| 8224 | sp<const DisplayDevice> display = nullptr; |
| 8225 | { |
| 8226 | Mutex::Autolock lock(mStateLock); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8227 | if (auto* layerRenderAreaBuilder = |
| 8228 | std::get_if<LayerRenderAreaBuilder>(&renderAreaBuilder)) { |
| 8229 | // LayerSnapshotBuilder should only be accessed from the main thread. |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8230 | const frontend::LayerSnapshot* snapshot = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8231 | mLayerSnapshotBuilder.getSnapshot(layerRenderAreaBuilder->layer->getSequence()); |
| 8232 | if (!snapshot) { |
| 8233 | ALOGW("Couldn't find layer snapshot for %d", |
| 8234 | layerRenderAreaBuilder->layer->getSequence()); |
| 8235 | } else { |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame] | 8236 | layerRenderAreaBuilder->setLayerSnapshot(*snapshot); |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8237 | display = findDisplay( |
| 8238 | [layerStack = snapshot->outputFilter.layerStack](const auto& display) { |
| 8239 | return display.getLayerStack() == layerStack; |
| 8240 | }); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8241 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8242 | } else if (auto* displayRenderAreaBuilder = |
| 8243 | std::get_if<DisplayRenderAreaBuilder>(&renderAreaBuilder)) { |
| 8244 | display = displayRenderAreaBuilder->displayWeak.promote(); |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8245 | } |
| 8246 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8247 | if (display == nullptr) { |
| 8248 | display = getDefaultDisplayDeviceLocked(); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8249 | } |
| 8250 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8251 | if (display != nullptr) { |
| 8252 | state = display->getCompositionDisplay()->getState(); |
| 8253 | } |
| 8254 | } |
| 8255 | return display; |
| 8256 | } |
| 8257 | |
| 8258 | std::vector<std::pair<Layer*, sp<android::LayerFE>>> |
| 8259 | SurfaceFlinger::getLayerSnapshotsFromMainThread(GetLayerSnapshotsFunction getLayerSnapshotsFn) { |
| 8260 | auto layers = getLayerSnapshotsFn(); |
| 8261 | if (FlagManager::getInstance().ce_fence_promise()) { |
| 8262 | for (auto& [layer, layerFE] : layers) { |
| 8263 | attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK); |
| 8264 | } |
| 8265 | } |
| 8266 | return layers; |
| 8267 | } |
| 8268 | |
| 8269 | ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot( |
| 8270 | RenderAreaBuilderVariant renderAreaBuilder, GetLayerSnapshotsFunction getLayerSnapshotsFn, |
| 8271 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 8272 | bool grayscale, bool isProtected, const sp<IScreenCaptureListener>& captureListener) { |
| 8273 | ATRACE_CALL(); |
| 8274 | |
| 8275 | auto takeScreenshotFn = [=, this, renderAreaBuilder = std::move(renderAreaBuilder)]() REQUIRES( |
| 8276 | kMainThreadContext) mutable -> ftl::SharedFuture<FenceResult> { |
| 8277 | auto layers = getLayerSnapshotsFromMainThread(getLayerSnapshotsFn); |
| 8278 | |
| 8279 | OutputCompositionState state; |
| 8280 | const auto display = getRenderAreaDisplay(renderAreaBuilder, state); |
| 8281 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8282 | ScreenCaptureResults captureResults; |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8283 | std::unique_ptr<const RenderArea> renderArea = |
| 8284 | std::visit([](auto&& arg) -> std::unique_ptr<RenderArea> { return arg.build(); }, |
| 8285 | renderAreaBuilder); |
| 8286 | |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8287 | if (!renderArea) { |
| 8288 | ALOGW("Skipping screen capture because of invalid render area."); |
| 8289 | if (captureListener) { |
| 8290 | captureResults.fenceResult = base::unexpected(NO_MEMORY); |
| 8291 | captureListener->onScreenCaptureCompleted(captureResults); |
| 8292 | } |
| 8293 | return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share(); |
| 8294 | } |
| 8295 | |
Melody Hsu | 9db32ff | 2024-04-17 19:52:55 +0000 | [diff] [blame] | 8296 | ftl::SharedFuture<FenceResult> renderFuture = |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8297 | renderScreenImpl(std::move(renderArea), buffer, regionSampling, grayscale, |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8298 | isProtected, captureResults, display, state, layers); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8299 | |
| 8300 | if (captureListener) { |
| 8301 | // Defer blocking on renderFuture back to the Binder thread. |
| 8302 | return ftl::Future(std::move(renderFuture)) |
| 8303 | .then([captureListener, captureResults = std::move(captureResults)]( |
| 8304 | FenceResult fenceResult) mutable -> FenceResult { |
| 8305 | captureResults.fenceResult = std::move(fenceResult); |
Nolan Scobie | 1d2deb2 | 2022-11-18 12:57:47 -0500 | [diff] [blame] | 8306 | captureListener->onScreenCaptureCompleted(captureResults); |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8307 | return base::unexpected(NO_ERROR); |
| 8308 | }) |
| 8309 | .share(); |
| 8310 | } |
| 8311 | return renderFuture; |
| 8312 | }; |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8313 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8314 | // TODO(b/294936197): Run takeScreenshotsFn() in a binder thread to reduce the number |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8315 | // of calls on the main thread. |
Melody Hsu | 82d524e | 2024-02-23 02:37:38 +0000 | [diff] [blame] | 8316 | auto future = |
| 8317 | mScheduler->schedule(FTL_FAKE_GUARD(kMainThreadContext, std::move(takeScreenshotFn))); |
Dan Stoza | 2b6d38e | 2017-06-01 16:40:30 -0700 | [diff] [blame] | 8318 | |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8319 | // Flatten nested futures. |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8320 | auto chain = ftl::Future(std::move(future)).then([](ftl::SharedFuture<FenceResult> future) { |
| 8321 | return future; |
| 8322 | }); |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 8323 | |
| 8324 | return chain.share(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 8325 | } |
| 8326 | |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 8327 | ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl( |
Melody Hsu | 2ffa36b | 2024-05-08 03:51:46 +0000 | [diff] [blame] | 8328 | std::unique_ptr<const RenderArea> renderArea, |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8329 | const std::shared_ptr<renderengine::ExternalTexture>& buffer, bool regionSampling, |
| 8330 | bool grayscale, bool isProtected, ScreenCaptureResults& captureResults, |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8331 | const sp<const DisplayDevice> display, const OutputCompositionState& state, |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8332 | std::vector<std::pair<Layer*, sp<android::LayerFE>>>& layers) { |
| 8333 | ATRACE_CALL(); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8334 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8335 | for (auto& [_, layerFE] : layers) { |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8336 | frontend::LayerSnapshot* snapshot = layerFE->mSnapshot.get(); |
| 8337 | captureResults.capturedSecureLayers |= (snapshot->isVisible && snapshot->isSecure); |
| 8338 | captureResults.capturedHdrLayers |= isHdrLayer(*snapshot); |
| 8339 | layerFE->mSnapshot->geomLayerTransform = |
| 8340 | renderArea->getTransform() * layerFE->mSnapshot->geomLayerTransform; |
Patrick Williams | c6e0cce | 2023-02-28 23:04:45 -0600 | [diff] [blame] | 8341 | layerFE->mSnapshot->geomInverseLayerTransform = |
| 8342 | layerFE->mSnapshot->geomLayerTransform.inverse(); |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 8343 | } |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8344 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8345 | auto capturedBuffer = buffer; |
| 8346 | |
| 8347 | auto requestedDataspace = renderArea->getReqDataSpace(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8348 | auto parent = renderArea->getParentLayer(); |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 8349 | auto renderIntent = RenderIntent::TONE_MAP_COLORIMETRIC; |
Sally Qi | 6c903ca | 2022-04-25 11:24:20 -0700 | [diff] [blame] | 8350 | auto sdrWhitePointNits = DisplayDevice::sDefaultMaxLumiance; |
| 8351 | auto displayBrightnessNits = DisplayDevice::sDefaultMaxLumiance; |
| 8352 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8353 | captureResults.capturedDataspace = requestedDataspace; |
| 8354 | |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8355 | const bool enableLocalTonemapping = FlagManager::getInstance().local_tonemap_screenshots() && |
| 8356 | !renderArea->getHintForSeamlessTransition(); |
| 8357 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8358 | if (display != nullptr) { |
| 8359 | captureResults.capturedDataspace = |
Melody Hsu | 683fe04 | 2024-06-04 17:22:04 +0000 | [diff] [blame^] | 8360 | pickBestDataspace(requestedDataspace, state, captureResults.capturedHdrLayers, |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8361 | renderArea->getHintForSeamlessTransition()); |
| 8362 | sdrWhitePointNits = state.sdrWhitePointNits; |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8363 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8364 | if (!captureResults.capturedHdrLayers) { |
| 8365 | displayBrightnessNits = sdrWhitePointNits; |
| 8366 | } else { |
| 8367 | displayBrightnessNits = state.displayBrightnessNits; |
| 8368 | if (!enableLocalTonemapping) { |
| 8369 | // Only clamp the display brightness if this is not a seamless transition. |
| 8370 | // Otherwise for seamless transitions it's important to match the current |
| 8371 | // display state as the buffer will be shown under these same conditions, and we |
| 8372 | // want to avoid any flickers |
| 8373 | if (sdrWhitePointNits > 1.0f && !renderArea->getHintForSeamlessTransition()) { |
| 8374 | // Restrict the amount of HDR "headroom" in the screenshot to avoid |
| 8375 | // over-dimming the SDR portion. 2.0 chosen by experimentation |
| 8376 | constexpr float kMaxScreenshotHeadroom = 2.0f; |
| 8377 | displayBrightnessNits = std::min(sdrWhitePointNits * kMaxScreenshotHeadroom, |
| 8378 | displayBrightnessNits); |
Alec Mouri | b4814de | 2023-09-11 22:09:03 +0000 | [diff] [blame] | 8379 | } |
Alec Mouri | 5e488f8 | 2023-09-15 01:27:49 +0000 | [diff] [blame] | 8380 | } |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8381 | } |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8382 | |
Melody Hsu | 335ef3e | 2024-05-31 22:58:40 +0000 | [diff] [blame] | 8383 | // Screenshots leaving the device should be colorimetric |
| 8384 | if (requestedDataspace == ui::Dataspace::UNKNOWN && |
| 8385 | renderArea->getHintForSeamlessTransition()) { |
| 8386 | renderIntent = state.renderIntent; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8387 | } |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 8388 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8389 | |
| 8390 | captureResults.buffer = capturedBuffer->getBuffer(); |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame] | 8391 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8392 | ui::LayerStack layerStack{ui::DEFAULT_LAYER_STACK}; |
| 8393 | if (!layers.empty()) { |
| 8394 | const sp<LayerFE>& layerFE = layers.back().second; |
| 8395 | layerStack = layerFE->getCompositionState()->outputFilter.layerStack; |
Yichi Chen | 40773d9 | 2020-04-01 10:10:18 +0800 | [diff] [blame] | 8396 | } |
Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 8397 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8398 | auto copyLayerFEs = [&layers]() { |
| 8399 | std::vector<sp<compositionengine::LayerFE>> layerFEs; |
| 8400 | layerFEs.reserve(layers.size()); |
| 8401 | for (const auto& [_, layerFE] : layers) { |
| 8402 | layerFEs.push_back(layerFE); |
| 8403 | } |
| 8404 | return layerFEs; |
| 8405 | }; |
| 8406 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8407 | auto present = [this, buffer = capturedBuffer, dataspace = captureResults.capturedDataspace, |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8408 | sdrWhitePointNits, displayBrightnessNits, grayscale, isProtected, |
| 8409 | layerFEs = copyLayerFEs(), layerStack, regionSampling, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8410 | renderArea = std::move(renderArea), renderIntent, |
| 8411 | enableLocalTonemapping]() -> FenceResult { |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8412 | std::unique_ptr<compositionengine::CompositionEngine> compositionEngine = |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8413 | mFactory.createCompositionEngine(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8414 | compositionEngine->setRenderEngine(mRenderEngine.get()); |
| 8415 | |
| 8416 | compositionengine::Output::ColorProfile colorProfile{.dataspace = dataspace, |
| 8417 | .renderIntent = renderIntent}; |
| 8418 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8419 | float targetBrightness = 1.0f; |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8420 | if (enableLocalTonemapping) { |
| 8421 | // Boost the whole scene so that SDR white is at 1.0 while still communicating the hdr |
| 8422 | // sdr ratio via display brightness / sdrWhite nits. |
| 8423 | targetBrightness = sdrWhitePointNits / displayBrightnessNits; |
| 8424 | } else if (dataspace == ui::Dataspace::BT2020_HLG) { |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8425 | const float maxBrightnessNits = displayBrightnessNits / sdrWhitePointNits * 203; |
| 8426 | // With a low dimming ratio, don't fit the entire curve. Otherwise mixed content |
| 8427 | // will appear way too bright. |
| 8428 | if (maxBrightnessNits < 1000.f) { |
| 8429 | targetBrightness = 1000.f / maxBrightnessNits; |
| 8430 | } |
| 8431 | } |
| 8432 | |
Alec Mouri | ffb3221 | 2023-09-16 19:29:15 +0000 | [diff] [blame] | 8433 | // Screenshots leaving the device must not dim in gamma space. |
| 8434 | const bool dimInGammaSpaceForEnhancedScreenshots = mDimInGammaSpaceForEnhancedScreenshots && |
| 8435 | renderArea->getHintForSeamlessTransition(); |
| 8436 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8437 | std::shared_ptr<ScreenCaptureOutput> output = createScreenCaptureOutput( |
| 8438 | ScreenCaptureOutputArgs{.compositionEngine = *compositionEngine, |
| 8439 | .colorProfile = colorProfile, |
| 8440 | .renderArea = *renderArea, |
| 8441 | .layerStack = layerStack, |
| 8442 | .buffer = std::move(buffer), |
| 8443 | .sdrWhitePointNits = sdrWhitePointNits, |
| 8444 | .displayBrightnessNits = displayBrightnessNits, |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 8445 | .targetBrightness = targetBrightness, |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 8446 | .regionSampling = regionSampling, |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 8447 | .treat170mAsSrgb = mTreat170mAsSrgb, |
| 8448 | .dimInGammaSpaceForEnhancedScreenshots = |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 8449 | dimInGammaSpaceForEnhancedScreenshots, |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 8450 | .isProtected = isProtected, |
| 8451 | .enableLocalTonemapping = enableLocalTonemapping}); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8452 | |
| 8453 | const float colorSaturation = grayscale ? 0 : 1; |
| 8454 | compositionengine::CompositionRefreshArgs refreshArgs{ |
| 8455 | .outputs = {output}, |
| 8456 | .layers = std::move(layerFEs), |
| 8457 | .updatingOutputGeometryThisFrame = true, |
| 8458 | .updatingGeometryThisFrame = true, |
| 8459 | .colorTransformMatrix = calculateColorMatrix(colorSaturation), |
| 8460 | }; |
| 8461 | compositionEngine->present(refreshArgs); |
| 8462 | |
| 8463 | return output->getRenderSurface()->getClientTargetAcquireFence(); |
| 8464 | }; |
| 8465 | |
| 8466 | // If RenderEngine is threaded, we can safely call CompositionEngine::present off the main |
| 8467 | // thread as the RenderEngine::drawLayers call will run on RenderEngine's thread. Otherwise, |
| 8468 | // we need RenderEngine to run on the main thread so we call CompositionEngine::present |
| 8469 | // immediately. |
| 8470 | // |
| 8471 | // TODO(b/196334700) Once we use RenderEngineThreaded everywhere we can always defer the call |
| 8472 | // to CompositionEngine::present. |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 8473 | auto presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share() |
| 8474 | : ftl::yield(present()).share(); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8475 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 8476 | if (!FlagManager::getInstance().ce_fence_promise()) { |
| 8477 | for (auto& [layer, layerFE] : layers) { |
| 8478 | layer->onLayerDisplayed(presentFuture, ui::INVALID_LAYER_STACK, |
| 8479 | [layerFE = std::move(layerFE)](FenceResult) { |
| 8480 | if (FlagManager::getInstance() |
| 8481 | .screenshot_fence_preservation()) { |
| 8482 | const auto compositionResult = |
| 8483 | layerFE->stealCompositionResult(); |
| 8484 | const auto& fences = compositionResult.releaseFences; |
| 8485 | // CompositionEngine may choose to cull layers that |
| 8486 | // aren't visible, so pass a non-fence. |
| 8487 | return fences.empty() ? Fence::NO_FENCE |
| 8488 | : fences.back().first.get(); |
| 8489 | } else { |
| 8490 | return layerFE->stealCompositionResult() |
| 8491 | .releaseFences.back() |
| 8492 | .first.get(); |
| 8493 | } |
| 8494 | }); |
| 8495 | } |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 8496 | } |
| 8497 | |
| 8498 | return presentFuture; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 8499 | } |
| 8500 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8501 | void SurfaceFlinger::traverseLegacyLayers(const LayerVector::Visitor& visitor) const { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8502 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 8503 | for (auto& layer : mLegacyLayers) { |
| 8504 | visitor(layer.second.get()); |
| 8505 | } |
| 8506 | } else { |
| 8507 | mDrawingState.traverse(visitor); |
| 8508 | } |
| 8509 | } |
| 8510 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 8511 | // --------------------------------------------------------------------------- |
| 8512 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 8513 | void SurfaceFlinger::State::traverse(const LayerVector::Visitor& visitor) const { |
| 8514 | layersSortedByZ.traverse(visitor); |
| 8515 | } |
| 8516 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8517 | void SurfaceFlinger::State::traverseInZOrder(const LayerVector::Visitor& visitor) const { |
| 8518 | layersSortedByZ.traverseInZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8519 | } |
| 8520 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 8521 | void SurfaceFlinger::State::traverseInReverseZOrder(const LayerVector::Visitor& visitor) const { |
| 8522 | layersSortedByZ.traverseInReverseZOrder(stateSet, visitor); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 8523 | } |
| 8524 | |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8525 | void SurfaceFlinger::traverseLayersInLayerStack(ui::LayerStack layerStack, const int32_t uid, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8526 | std::unordered_set<uint32_t> excludeLayerIds, |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 8527 | const LayerVector::Visitor& visitor) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8528 | // We loop through the first level of layers without traversing, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 8529 | // as we need to determine which layers belong to the requested display. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8530 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8531 | if (layer->getLayerStack() != layerStack) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8532 | continue; |
| 8533 | } |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 8534 | // relative layers are traversed in Layer::traverseInZOrder |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8535 | layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 8536 | if (layer->isInternalDisplayOverlay()) { |
Adrian Roos | 8acf5a0 | 2018-01-17 21:28:19 +0100 | [diff] [blame] | 8537 | return; |
| 8538 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8539 | if (!layer->isVisible()) { |
| 8540 | return; |
| 8541 | } |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 8542 | if (uid != CaptureArgs::UNSET_UID && layer->getOwnerUid() != uid) { |
| 8543 | return; |
| 8544 | } |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 8545 | |
| 8546 | if (!excludeLayerIds.empty()) { |
| 8547 | auto p = sp<Layer>::fromExisting(layer); |
| 8548 | while (p != nullptr) { |
| 8549 | if (excludeLayerIds.count(p->sequence) != 0) { |
| 8550 | return; |
| 8551 | } |
| 8552 | p = p->getParent(); |
| 8553 | } |
| 8554 | } |
| 8555 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 8556 | visitor(layer); |
| 8557 | }); |
| 8558 | } |
| 8559 | } |
| 8560 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8561 | ftl::Optional<scheduler::FrameRateMode> SurfaceFlinger::getPreferredDisplayMode( |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8562 | PhysicalDisplayId displayId, DisplayModeId defaultModeId) const { |
| 8563 | if (const auto schedulerMode = mScheduler->getPreferredDisplayMode(); |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8564 | schedulerMode.modePtr->getPhysicalDisplayId() == displayId) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8565 | return schedulerMode; |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8566 | } |
| 8567 | |
| 8568 | return mPhysicalDisplays.get(displayId) |
| 8569 | .transform(&PhysicalDisplay::snapshotRef) |
| 8570 | .and_then([&](const display::DisplaySnapshot& snapshot) { |
| 8571 | return snapshot.displayModes().get(defaultModeId); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 8572 | }) |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8573 | .transform([](const DisplayModePtr& modePtr) { |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 8574 | return scheduler::FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8575 | }); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8576 | } |
| 8577 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8578 | status_t SurfaceFlinger::setDesiredDisplayModeSpecsInternal( |
Steven Thomas | d407190 | 2020-03-24 16:02:53 -0700 | [diff] [blame] | 8579 | const sp<DisplayDevice>& display, |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8580 | const scheduler::RefreshRateSelector::PolicyVariant& policy) { |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8581 | const auto displayId = display->getPhysicalId(); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 8582 | ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8583 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8584 | Mutex::Autolock lock(mStateLock); |
| 8585 | |
Ady Abraham | fb85366 | 2021-04-09 11:46:40 -0700 | [diff] [blame] | 8586 | if (mDebugDisplayModeSetByBackdoor) { |
| 8587 | // ignore this request as mode is overridden by backdoor |
| 8588 | return NO_ERROR; |
| 8589 | } |
| 8590 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8591 | auto& selector = display->refreshRateSelector(); |
| 8592 | using SetPolicyResult = scheduler::RefreshRateSelector::SetPolicyResult; |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8593 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8594 | switch (selector.setPolicy(policy)) { |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8595 | case SetPolicyResult::Invalid: |
| 8596 | return BAD_VALUE; |
| 8597 | case SetPolicyResult::Unchanged: |
| 8598 | return NO_ERROR; |
| 8599 | case SetPolicyResult::Changed: |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8600 | break; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8601 | } |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8602 | |
Dominik Laskowski | fc378b0 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 8603 | return applyRefreshRateSelectorPolicy(displayId, selector); |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8604 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8605 | |
Dominik Laskowski | 3f72640 | 2022-11-21 17:21:22 -0500 | [diff] [blame] | 8606 | status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 8607 | PhysicalDisplayId displayId, const scheduler::RefreshRateSelector& selector) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8608 | const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy(); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8609 | ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str()); |
Adrian Salido | ab6ef6c | 2019-08-28 10:02:49 -0700 | [diff] [blame] | 8610 | |
Ana Krulec | b9afd79 | 2020-06-11 13:16:15 -0700 | [diff] [blame] | 8611 | // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might |
| 8612 | // be depending in this callback. |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8613 | if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8614 | mScheduler->onPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8615 | toggleKernelIdleTimer(); |
| 8616 | } else { |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8617 | mScheduler->onNonPrimaryDisplayModeChanged(scheduler::Cycle::Render, activeMode); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 8618 | } |
Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame] | 8619 | |
Dominik Laskowski | e591b55 | 2022-09-09 10:44:56 -0700 | [diff] [blame] | 8620 | auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8621 | if (!preferredModeOpt) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8622 | ALOGE("%s: Preferred mode is unknown", __func__); |
| 8623 | return NAME_NOT_FOUND; |
| 8624 | } |
| 8625 | |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8626 | auto preferredMode = std::move(*preferredModeOpt); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8627 | const auto preferredModeId = preferredMode.modePtr->getId(); |
Ana Krulec | 3f6a206 | 2020-01-23 15:48:01 -0800 | [diff] [blame] | 8628 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8629 | const Fps preferredFps = preferredMode.fps; |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8630 | ALOGV("Switching to Scheduler preferred mode %d (%s)", ftl::to_underlying(preferredModeId), |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8631 | to_string(preferredFps).c_str()); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8632 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8633 | if (!selector.isModeAllowed(preferredMode)) { |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8634 | ALOGE("%s: Preferred mode %d is disallowed", __func__, ftl::to_underlying(preferredModeId)); |
Dominik Laskowski | f259544 | 2022-08-29 13:51:57 -0700 | [diff] [blame] | 8635 | return INVALID_OPERATION; |
Dominik Laskowski | 4f1dd8c | 2019-04-17 15:54:30 -0700 | [diff] [blame] | 8636 | } |
| 8637 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 8638 | setDesiredMode({std::move(preferredMode), .emitEvent = true}); |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8639 | |
| 8640 | // Update the frameRateOverride list as the display render rate might have changed |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 8641 | if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { |
Ady Abraham | 33a386b | 2023-07-18 15:37:11 -0700 | [diff] [blame] | 8642 | triggerOnFrameRateOverridesChanged(); |
| 8643 | } |
| 8644 | |
Ady Abraham | d9b3ea6 | 2019-02-26 14:08:03 -0800 | [diff] [blame] | 8645 | return NO_ERROR; |
| 8646 | } |
| 8647 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8648 | namespace { |
| 8649 | FpsRange translate(const gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange& aidlRange) { |
| 8650 | return FpsRange{Fps::fromValue(aidlRange.min), Fps::fromValue(aidlRange.max)}; |
| 8651 | } |
| 8652 | |
| 8653 | FpsRanges translate(const gui::DisplayModeSpecs::RefreshRateRanges& aidlRanges) { |
| 8654 | return FpsRanges{translate(aidlRanges.physical), translate(aidlRanges.render)}; |
| 8655 | } |
| 8656 | |
| 8657 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange translate(const FpsRange& range) { |
| 8658 | gui::DisplayModeSpecs::RefreshRateRanges::RefreshRateRange aidlRange; |
| 8659 | aidlRange.min = range.min.getValue(); |
| 8660 | aidlRange.max = range.max.getValue(); |
| 8661 | return aidlRange; |
| 8662 | } |
| 8663 | |
| 8664 | gui::DisplayModeSpecs::RefreshRateRanges translate(const FpsRanges& ranges) { |
| 8665 | gui::DisplayModeSpecs::RefreshRateRanges aidlRanges; |
| 8666 | aidlRanges.physical = translate(ranges.physical); |
| 8667 | aidlRanges.render = translate(ranges.render); |
| 8668 | return aidlRanges; |
| 8669 | } |
| 8670 | |
| 8671 | } // namespace |
| 8672 | |
| 8673 | status_t SurfaceFlinger::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 8674 | const gui::DisplayModeSpecs& specs) { |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8675 | ATRACE_CALL(); |
| 8676 | |
| 8677 | if (!displayToken) { |
| 8678 | return BAD_VALUE; |
| 8679 | } |
| 8680 | |
Nolan Scobie | 0074cd6 | 2023-12-14 16:51:14 -0500 | [diff] [blame] | 8681 | auto future = mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) -> status_t { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8682 | const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayToken)); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8683 | if (!display) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8684 | ALOGE("Attempt to set desired display modes for invalid display token %p", |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8685 | displayToken.get()); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8686 | return NAME_NOT_FOUND; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8687 | } else if (display->isVirtual()) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 8688 | ALOGW("Attempt to set desired display modes for virtual display"); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8689 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8690 | } else { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8691 | using Policy = scheduler::RefreshRateSelector::DisplayManagerPolicy; |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 8692 | const auto idleScreenConfigOpt = |
| 8693 | FlagManager::getInstance().idle_screen_refresh_rate_timeout() |
| 8694 | ? specs.idleScreenRefreshRateConfig |
| 8695 | : std::nullopt; |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8696 | const Policy policy{DisplayModeId(specs.defaultMode), translate(specs.primaryRanges), |
Ady Abraham | 6723172 | 2024-03-21 18:06:21 -0700 | [diff] [blame] | 8697 | translate(specs.appRequestRanges), specs.allowGroupSwitching, |
| 8698 | idleScreenConfigOpt}; |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 8699 | |
Dominik Laskowski | 36dced8 | 2022-09-02 09:24:00 -0700 | [diff] [blame] | 8700 | return setDesiredDisplayModeSpecsInternal(display, policy); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 8701 | } |
| 8702 | }); |
| 8703 | |
| 8704 | return future.get(); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8705 | } |
| 8706 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 8707 | status_t SurfaceFlinger::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8708 | gui::DisplayModeSpecs* outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8709 | ATRACE_CALL(); |
| 8710 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8711 | if (!displayToken || !outSpecs) { |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8712 | return BAD_VALUE; |
| 8713 | } |
| 8714 | |
| 8715 | Mutex::Autolock lock(mStateLock); |
| 8716 | const auto display = getDisplayDeviceLocked(displayToken); |
| 8717 | if (!display) { |
| 8718 | return NAME_NOT_FOUND; |
| 8719 | } |
| 8720 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8721 | if (display->isVirtual()) { |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 8722 | return INVALID_OPERATION; |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 8723 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8724 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8725 | scheduler::RefreshRateSelector::Policy policy = |
| 8726 | display->refreshRateSelector().getDisplayManagerPolicy(); |
Dominik Laskowski | 43baf90 | 2023-11-17 18:13:11 -0500 | [diff] [blame] | 8727 | outSpecs->defaultMode = ftl::to_underlying(policy.defaultMode); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 8728 | outSpecs->allowGroupSwitching = policy.allowGroupSwitching; |
| 8729 | outSpecs->primaryRanges = translate(policy.primaryRanges); |
| 8730 | outSpecs->appRequestRanges = translate(policy.appRequestRanges); |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8731 | return NO_ERROR; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 8732 | } |
| 8733 | |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 8734 | void SurfaceFlinger::onLayerFirstRef(Layer* layer) { |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8735 | mNumLayers++; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8736 | if (!layer->isRemovedFromCurrentState()) { |
| 8737 | mScheduler->registerLayer(layer); |
| 8738 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8739 | } |
| 8740 | |
| 8741 | void SurfaceFlinger::onLayerDestroyed(Layer* layer) { |
| 8742 | mNumLayers--; |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8743 | removeHierarchyFromOffscreenLayers(layer); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 8744 | if (!layer->isRemovedFromCurrentState()) { |
| 8745 | mScheduler->deregisterLayer(layer); |
| 8746 | } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 8747 | if (mTransactionTracing) { |
| 8748 | mTransactionTracing->onLayerRemoved(layer->getSequence()); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 8749 | } |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 8750 | mScheduler->onLayerDestroyed(layer); |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8751 | } |
| 8752 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8753 | void SurfaceFlinger::onLayerUpdate() { |
| 8754 | scheduleCommit(FrameHint::kActive); |
| 8755 | } |
| 8756 | |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8757 | // WARNING: ONLY CALL THIS FROM LAYER DTOR |
| 8758 | // Here we add children in the current state to offscreen layers and remove the |
| 8759 | // layer itself from the offscreen layer list. Since |
| 8760 | // this is the dtor, it is safe to access the current state. This keeps us |
| 8761 | // from dangling children layers such that they are not reachable from the |
| 8762 | // Drawing state nor the offscreen layer list |
| 8763 | // See b/141111965 |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8764 | void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) { |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 8765 | for (auto& child : layer->getCurrentChildren()) { |
| 8766 | mOffscreenLayers.emplace(child.get()); |
| 8767 | } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 8768 | mOffscreenLayers.erase(layer); |
| 8769 | } |
| 8770 | |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 8771 | void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) { |
| 8772 | mOffscreenLayers.erase(layer); |
| 8773 | } |
| 8774 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 8775 | status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, |
| 8776 | float lightPosY, float lightPosZ, |
| 8777 | float lightRadius) { |
| 8778 | Mutex::Autolock _l(mStateLock); |
| 8779 | mCurrentState.globalShadowSettings.ambientColor = vec4(ambientColor); |
| 8780 | mCurrentState.globalShadowSettings.spotColor = vec4(spotColor); |
| 8781 | mCurrentState.globalShadowSettings.lightPos.y = lightPosY; |
| 8782 | mCurrentState.globalShadowSettings.lightPos.z = lightPosZ; |
| 8783 | mCurrentState.globalShadowSettings.lightRadius = lightRadius; |
| 8784 | |
| 8785 | // these values are overridden when calculating the shadow settings for a layer. |
| 8786 | mCurrentState.globalShadowSettings.lightPos.x = 0.f; |
| 8787 | mCurrentState.globalShadowSettings.length = 0.f; |
Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 8788 | return NO_ERROR; |
| 8789 | } |
| 8790 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8791 | const std::unordered_map<std::string, uint32_t>& SurfaceFlinger::getGenericLayerMetadataKeyMap() |
| 8792 | const { |
| 8793 | // TODO(b/149500060): Remove this fixed/static mapping. Please prefer taking |
| 8794 | // on the work to remove the table in that bug rather than adding more to |
| 8795 | // it. |
| 8796 | static const std::unordered_map<std::string, uint32_t> genericLayerMetadataKeyMap{ |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 8797 | {"org.chromium.arc.V1_0.TaskId", gui::METADATA_TASK_ID}, |
| 8798 | {"org.chromium.arc.V1_0.CursorInfo", gui::METADATA_MOUSE_CURSOR}, |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 8799 | }; |
| 8800 | return genericLayerMetadataKeyMap; |
| 8801 | } |
| 8802 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8803 | status_t SurfaceFlinger::setGameModeFrameRateOverride(uid_t uid, float frameRate) { |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8804 | PhysicalDisplayId displayId = [&]() { |
| 8805 | Mutex::Autolock lock(mStateLock); |
| 8806 | return getDefaultDisplayDeviceLocked()->getPhysicalId(); |
| 8807 | }(); |
| 8808 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8809 | mScheduler->setGameModeFrameRateForUid(FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 8810 | mScheduler->onFrameRateOverridesChanged(scheduler::Cycle::Render, displayId); |
Andy Yu | 2ae6b6b | 2021-11-18 14:51:06 -0800 | [diff] [blame] | 8811 | return NO_ERROR; |
| 8812 | } |
| 8813 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 8814 | status_t SurfaceFlinger::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) { |
| 8815 | if (FlagManager::getInstance().game_default_frame_rate()) { |
| 8816 | mScheduler->setGameDefaultFrameRateForUid( |
| 8817 | FrameRateOverride{static_cast<uid_t>(uid), frameRate}); |
| 8818 | } |
| 8819 | return NO_ERROR; |
| 8820 | } |
| 8821 | |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8822 | status_t SurfaceFlinger::updateSmallAreaDetection( |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8823 | std::vector<std::pair<int32_t, float>>& appIdThresholdMappings) { |
| 8824 | mScheduler->updateSmallAreaDetection(appIdThresholdMappings); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8825 | return NO_ERROR; |
| 8826 | } |
| 8827 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 8828 | status_t SurfaceFlinger::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
| 8829 | mScheduler->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 8830 | return NO_ERROR; |
| 8831 | } |
| 8832 | |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8833 | void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 8834 | bool setByHwc = getHwComposer().hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8835 | for (const auto& [id, display] : mPhysicalDisplays) { |
Sally Qi | de329f2 | 2023-09-26 16:21:39 -0700 | [diff] [blame] | 8836 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal || |
| 8837 | FlagManager::getInstance().refresh_rate_overlay_on_external_display()) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8838 | if (const auto device = getDisplayDeviceLocked(id)) { |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8839 | const auto enableOverlay = [&](const bool setByHwc) FTL_FAKE_GUARD( |
| 8840 | kMainThreadContext) { |
| 8841 | device->enableRefreshRateOverlay(enable, setByHwc, mRefreshRateOverlaySpinner, |
| 8842 | mRefreshRateOverlayRenderRate, |
| 8843 | mRefreshRateOverlayShowInMiddle); |
| 8844 | }; |
| 8845 | enableOverlay(setByHwc); |
| 8846 | if (setByHwc) { |
| 8847 | const auto status = |
| 8848 | getHwComposer().setRefreshRateChangedCallbackDebugEnabled(id, enable); |
| 8849 | if (status != NO_ERROR) { |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 8850 | ALOGE("Error %s refresh rate changed callback debug", |
| 8851 | enable ? "enabling" : "disabling"); |
ramindani | 3c722da | 2023-07-12 20:37:59 -0700 | [diff] [blame] | 8852 | enableOverlay(/*setByHwc*/ false); |
| 8853 | } |
| 8854 | } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 8855 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8856 | } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 8857 | } |
Dominik Laskowski | 2013464 | 2020-04-20 22:36:44 -0700 | [diff] [blame] | 8858 | } |
| 8859 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 8860 | void SurfaceFlinger::enableHdrSdrRatioOverlay(bool enable) { |
| 8861 | for (const auto& [id, display] : mPhysicalDisplays) { |
| 8862 | if (display.snapshot().connectionType() == ui::DisplayConnectionType::Internal) { |
| 8863 | if (const auto device = getDisplayDeviceLocked(id)) { |
| 8864 | device->enableHdrSdrRatioOverlay(enable); |
| 8865 | } |
| 8866 | } |
| 8867 | } |
| 8868 | } |
| 8869 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 8870 | int SurfaceFlinger::getGpuContextPriority() { |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 8871 | return getRenderEngine().getContextPriority(); |
Ana Krulec | 31f2b3c | 2020-12-14 14:30:09 -0800 | [diff] [blame] | 8872 | } |
| 8873 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8874 | int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8875 | std::chrono::nanoseconds presentLatency) { |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8876 | auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs(); |
| 8877 | if (presentLatency.count() % refreshRate.getPeriodNsecs()) { |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8878 | pipelineDepth++; |
| 8879 | } |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8880 | return std::max(minAcquiredBuffers, static_cast<int64_t>(pipelineDepth - 1)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8881 | } |
| 8882 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8883 | status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8884 | Fps maxRefreshRate = 60_Hz; |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8885 | |
| 8886 | if (!getHwComposer().isHeadless()) { |
| 8887 | if (const auto display = getDefaultDisplayDevice()) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 8888 | maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8889 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | *buffers = getMaxAcquiredBufferCountForRefreshRate(maxRefreshRate); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 8893 | return NO_ERROR; |
| 8894 | } |
| 8895 | |
rnlee | ed20fa4 | 2021-08-10 18:00:03 -0700 | [diff] [blame] | 8896 | uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 8897 | Fps refreshRate = 60_Hz; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8898 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8899 | if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { |
| 8900 | refreshRate = *frameRateOverride; |
| 8901 | } else if (!getHwComposer().isHeadless()) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 8902 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 8903 | refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8904 | } |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 8905 | } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 8906 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8907 | return getMaxAcquiredBufferCountForRefreshRate(refreshRate); |
| 8908 | } |
| 8909 | |
| 8910 | int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const { |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 8911 | const auto vsyncConfig = |
| 8912 | mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 8913 | const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration; |
| 8914 | return calculateMaxAcquiredBufferCount(refreshRate, presentLatency); |
| 8915 | } |
| 8916 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 8917 | void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state, VsyncId vsyncId) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8918 | sp<Layer> layer = state.layer.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8919 | if (!layer) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8920 | ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); |
| 8921 | return; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8922 | } |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 8923 | MUTEX_ALIAS(mStateLock, layer->mFlinger->mStateLock); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8924 | |
| 8925 | sp<Layer> parent; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8926 | bool addToRoot = state.addToRoot; |
| 8927 | if (state.initialParent != nullptr) { |
| 8928 | parent = state.initialParent.promote(); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8929 | if (parent == nullptr) { |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 8930 | ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8931 | addToRoot = false; |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8932 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8933 | } |
| 8934 | |
Garfield Tan | d712ad3 | 2021-10-27 13:44:22 -0700 | [diff] [blame] | 8935 | if (parent == nullptr && addToRoot) { |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 8936 | layer->setIsAtRoot(true); |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8937 | mCurrentState.layersSortedByZ.add(layer); |
| 8938 | } else if (parent == nullptr) { |
| 8939 | layer->onRemovedFromCurrentState(); |
| 8940 | } else if (parent->isRemovedFromCurrentState()) { |
| 8941 | parent->addChild(layer); |
| 8942 | layer->onRemovedFromCurrentState(); |
| 8943 | } else { |
| 8944 | parent->addChild(layer); |
| 8945 | } |
| 8946 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 8947 | ui::LayerStack layerStack = layer->getLayerStack(LayerVector::StateSet::Current); |
Vishnu Nair | afd527a | 2022-10-18 08:56:10 -0700 | [diff] [blame] | 8948 | sp<const DisplayDevice> hintDisplay; |
| 8949 | // Find the display that includes the layer. |
| 8950 | for (const auto& [token, display] : mDisplays) { |
| 8951 | if (display->getLayerStack() == layerStack) { |
| 8952 | hintDisplay = display; |
| 8953 | break; |
| 8954 | } |
| 8955 | } |
| 8956 | |
| 8957 | if (hintDisplay) { |
| 8958 | layer->updateTransformHint(hintDisplay->getTransformHint()); |
| 8959 | } |
arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 8960 | } |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8961 | |
Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 8962 | void SurfaceFlinger::sample() { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 8963 | if (!mLumaSampling || !mRegionSamplingThread) { |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8964 | return; |
| 8965 | } |
| 8966 | |
ramindani | 32a88b1 | 2024-01-31 18:45:30 -0800 | [diff] [blame] | 8967 | const auto scheduledFrameResultOpt = mScheduler->getScheduledFrameResult(); |
| 8968 | const auto scheduleFrameTimeOpt = scheduledFrameResultOpt |
| 8969 | ? std::optional{scheduledFrameResultOpt->callbackTime} |
| 8970 | : std::nullopt; |
| 8971 | mRegionSamplingThread->onCompositionComplete(scheduleFrameTimeOpt); |
Ady Abraham | 562c271 | 2021-05-07 15:10:42 -0700 | [diff] [blame] | 8972 | } |
| 8973 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8974 | void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) { |
| 8975 | mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight()); |
| 8976 | getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8977 | } |
| 8978 | |
Dominik Laskowski | 3de6727 | 2023-08-09 13:15:31 -0400 | [diff] [blame] | 8979 | sp<DisplayDevice> SurfaceFlinger::getActivatableDisplay() const { |
| 8980 | if (mPhysicalDisplays.size() == 1) return nullptr; |
| 8981 | |
| 8982 | // TODO(b/255635821): Choose the pacesetter display, considering both internal and external |
| 8983 | // displays. For now, pick the other internal display, assuming a dual-display foldable. |
| 8984 | return findDisplay([this](const DisplayDevice& display) REQUIRES(mStateLock) { |
| 8985 | const auto idOpt = PhysicalDisplayId::tryCast(display.getId()); |
| 8986 | return idOpt && *idOpt != mActiveDisplayId && display.isPoweredOn() && |
| 8987 | mPhysicalDisplays.get(*idOpt) |
| 8988 | .transform(&PhysicalDisplay::isInternal) |
| 8989 | .value_or(false); |
| 8990 | }); |
| 8991 | } |
| 8992 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8993 | void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr, |
| 8994 | const DisplayDevice& activeDisplay) { |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 8995 | ATRACE_CALL(); |
| 8996 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 8997 | if (inactiveDisplayPtr) { |
| 8998 | inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false); |
Ady Abraham | db036a8 | 2021-07-16 14:18:34 -0700 | [diff] [blame] | 8999 | } |
| 9000 | |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9001 | mActiveDisplayId = activeDisplay.getPhysicalId(); |
| 9002 | activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 9003 | |
Leon Scroggins III | 823d4ca | 2023-12-12 16:57:34 -0500 | [diff] [blame] | 9004 | mScheduler->resetPhaseConfiguration(activeDisplay.getActiveMode().fps); |
Dominik Laskowski | 14956dc | 2023-02-22 13:43:57 -0500 | [diff] [blame] | 9005 | |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 9006 | // TODO(b/255635711): Check for pending mode changes on other displays. |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 9007 | mScheduler->setModeChangePending(false); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 9008 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 9009 | mScheduler->setPacesetterDisplay(mActiveDisplayId); |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 9010 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9011 | onActiveDisplaySizeChanged(activeDisplay); |
Dominik Laskowski | 39dfc94 | 2023-02-08 16:27:05 -0500 | [diff] [blame] | 9012 | mActiveDisplayTransformHint = activeDisplay.getTransformHint(); |
Leon Scroggins III | 85d4b22 | 2023-05-09 13:58:18 -0400 | [diff] [blame] | 9013 | sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); |
Ady Abraham | 85d692d | 2021-09-28 14:08:54 -0700 | [diff] [blame] | 9014 | |
Dominik Laskowski | 1746afd | 2024-04-10 19:21:37 -0400 | [diff] [blame] | 9015 | // Whether or not the policy of the new active/pacesetter display changed while it was inactive |
| 9016 | // (in which case its preferred mode has already been propagated to HWC via setDesiredMode), the |
| 9017 | // Scheduler's cachedModeChangedParams must be initialized to the newly active mode, and the |
| 9018 | // kernel idle timer of the newly active display must be toggled. |
| 9019 | applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector()); |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 9020 | } |
| 9021 | |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 9022 | status_t SurfaceFlinger::addWindowInfosListener(const sp<IWindowInfosListener>& windowInfosListener, |
| 9023 | gui::WindowInfosListenerInfo* outInfo) { |
| 9024 | mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener, outInfo); |
Patrick Williams | af06b79 | 2023-02-16 17:46:22 -0600 | [diff] [blame] | 9025 | setTransactionFlags(eInputInfoUpdateNeeded); |
chaviw | 60c9d3e | 2021-06-04 12:52:17 -0500 | [diff] [blame] | 9026 | return NO_ERROR; |
| 9027 | } |
| 9028 | |
| 9029 | status_t SurfaceFlinger::removeWindowInfosListener( |
| 9030 | const sp<IWindowInfosListener>& windowInfosListener) const { |
| 9031 | mWindowInfosListenerInvoker->removeWindowInfosListener(windowInfosListener); |
| 9032 | return NO_ERROR; |
| 9033 | } |
| 9034 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9035 | status_t SurfaceFlinger::getStalledTransactionInfo( |
| 9036 | int pid, std::optional<TransactionHandler::StalledTransactionInfo>& result) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9037 | // Used to add a stalled transaction which uses an internal lock. |
| 9038 | ftl::FakeGuard guard(kMainThreadContext); |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 9039 | result = mTransactionHandler.getStalledTransactionInfo(pid); |
| 9040 | return NO_ERROR; |
| 9041 | } |
| 9042 | |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 9043 | void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t connectedLevel, |
| 9044 | int32_t maxLevel) { |
| 9045 | if (!FlagManager::getInstance().connected_display()) { |
| 9046 | return; |
| 9047 | } |
| 9048 | |
| 9049 | Mutex::Autolock lock(mStateLock); |
| 9050 | |
| 9051 | const auto idOpt = getHwComposer().toPhysicalDisplayId(hwcDisplayId); |
| 9052 | if (!idOpt) { |
| 9053 | ALOGE("No display found for HDCP level changed event: connected=%d, max=%d for " |
| 9054 | "display=%" PRIu64, |
| 9055 | connectedLevel, maxLevel, hwcDisplayId); |
| 9056 | return; |
| 9057 | } |
| 9058 | |
| 9059 | const bool isInternalDisplay = |
| 9060 | mPhysicalDisplays.get(*idOpt).transform(&PhysicalDisplay::isInternal).value_or(false); |
| 9061 | if (isInternalDisplay) { |
| 9062 | ALOGW("Unexpected HDCP level changed for internal display: connected=%d, max=%d for " |
| 9063 | "display=%" PRIu64, |
| 9064 | connectedLevel, maxLevel, hwcDisplayId); |
| 9065 | return; |
| 9066 | } |
| 9067 | |
| 9068 | static_cast<void>(mScheduler->schedule([this, displayId = *idOpt, connectedLevel, maxLevel]() { |
| 9069 | if (const auto display = FTL_FAKE_GUARD(mStateLock, getDisplayDeviceLocked(displayId))) { |
| 9070 | Mutex::Autolock lock(mStateLock); |
| 9071 | display->setSecure(connectedLevel >= 2 /* HDCP_V1 */); |
| 9072 | } |
Dominik Laskowski | 4babfc4 | 2024-02-16 12:28:40 -0500 | [diff] [blame] | 9073 | mScheduler->onHdcpLevelsChanged(scheduler::Cycle::Render, displayId, connectedLevel, |
| 9074 | maxLevel); |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 9075 | })); |
| 9076 | } |
| 9077 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9078 | std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData( |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9079 | BufferData& bufferData, const char* layerName, uint64_t transactionId) { |
| 9080 | if (bufferData.buffer && |
| 9081 | exceedsMaxRenderTargetSize(bufferData.buffer->getWidth(), bufferData.buffer->getHeight())) { |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 9082 | std::string errorMessage = |
| 9083 | base::StringPrintf("Attempted to create an ExternalTexture with size (%u, %u) for " |
| 9084 | "layer %s that exceeds render target size limit of %u.", |
| 9085 | bufferData.buffer->getWidth(), bufferData.buffer->getHeight(), |
| 9086 | layerName, static_cast<uint32_t>(mMaxRenderTargetSize)); |
| 9087 | ALOGD("%s", errorMessage.c_str()); |
| 9088 | if (bufferData.releaseBufferListener) { |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 9089 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
| 9090 | String8(errorMessage.c_str())); |
Patrick Williams | ae9ab53 | 2022-11-14 18:41:38 +0000 | [diff] [blame] | 9091 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9092 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9093 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9094 | |
| 9095 | bool cachedBufferChanged = |
| 9096 | bufferData.flags.test(BufferData::BufferDataChange::cachedBufferChanged); |
| 9097 | if (cachedBufferChanged && bufferData.buffer) { |
| 9098 | auto result = ClientCache::getInstance().add(bufferData.cachedBuffer, bufferData.buffer); |
| 9099 | if (result.ok()) { |
| 9100 | return result.value(); |
| 9101 | } |
| 9102 | |
| 9103 | if (result.error() == ClientCache::AddError::CacheFull) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9104 | ALOGE("Attempted to create an ExternalTexture for layer %s but CacheFull", layerName); |
| 9105 | |
| 9106 | if (bufferData.releaseBufferListener) { |
| 9107 | bufferData.releaseBufferListener->onTransactionQueueStalled( |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 9108 | String8("Buffer processing hung due to full buffer cache")); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 9109 | } |
Patrick Williams | f1e5df1 | 2022-10-17 21:37:42 +0000 | [diff] [blame] | 9110 | } |
| 9111 | |
| 9112 | return nullptr; |
| 9113 | } |
| 9114 | |
| 9115 | if (cachedBufferChanged) { |
| 9116 | return ClientCache::getInstance().get(bufferData.cachedBuffer); |
| 9117 | } |
| 9118 | |
| 9119 | if (bufferData.buffer) { |
| 9120 | return std::make_shared< |
| 9121 | renderengine::impl::ExternalTexture>(bufferData.buffer, getRenderEngine(), |
| 9122 | renderengine::impl::ExternalTexture::Usage:: |
| 9123 | READABLE); |
| 9124 | } |
| 9125 | |
| 9126 | return nullptr; |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 9127 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9128 | |
Dominik Laskowski | 08fbd85 | 2022-07-14 08:53:42 -0700 | [diff] [blame] | 9129 | bool SurfaceFlinger::commitMirrorDisplays(VsyncId vsyncId) { |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9130 | std::vector<MirrorDisplayState> mirrorDisplays; |
| 9131 | { |
| 9132 | std::scoped_lock<std::mutex> lock(mMirrorDisplayLock); |
| 9133 | mirrorDisplays = std::move(mMirrorDisplays); |
| 9134 | mMirrorDisplays.clear(); |
| 9135 | if (mirrorDisplays.size() == 0) { |
| 9136 | return false; |
| 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | sp<IBinder> unused; |
| 9141 | for (const auto& mirrorDisplay : mirrorDisplays) { |
| 9142 | // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a display |
| 9143 | // accidentally. |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 9144 | sp<Layer> rootMirrorLayer = LayerHandle::getLayer(mirrorDisplay.rootHandle); |
Qi Jing | b8e4c13 | 2023-08-25 23:01:47 +0000 | [diff] [blame] | 9145 | ssize_t idx = mCurrentState.layersSortedByZ.indexOf(rootMirrorLayer); |
| 9146 | bool ret = rootMirrorLayer->setLayerStack(ui::LayerStack::fromValue(-1)); |
| 9147 | if (idx >= 0 && ret) { |
| 9148 | mCurrentState.layersSortedByZ.removeAt(idx); |
| 9149 | mCurrentState.layersSortedByZ.add(rootMirrorLayer); |
| 9150 | } |
| 9151 | |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9152 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9153 | if (layer->getLayerStack() != mirrorDisplay.layerStack || |
| 9154 | layer->isInternalDisplayOverlay()) { |
| 9155 | continue; |
| 9156 | } |
| 9157 | |
| 9158 | LayerCreationArgs mirrorArgs(this, mirrorDisplay.client, "MirrorLayerParent", |
| 9159 | ISurfaceComposerClient::eNoColorFill, |
| 9160 | gui::LayerMetadata()); |
| 9161 | sp<Layer> childMirror; |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9162 | { |
| 9163 | Mutex::Autolock lock(mStateLock); |
| 9164 | createEffectLayer(mirrorArgs, &unused, &childMirror); |
Josh Gao | 194ff39 | 2022-09-08 16:19:29 -0700 | [diff] [blame] | 9165 | MUTEX_ALIAS(mStateLock, childMirror->mFlinger->mStateLock); |
Melody Hsu | 12ecd08 | 2024-04-17 19:03:13 +0000 | [diff] [blame] | 9166 | childMirror->setClonedChild(layer->createClone()); |
Ying Wei | 2cf827f | 2023-03-22 22:25:28 +0000 | [diff] [blame] | 9167 | childMirror->reparent(mirrorDisplay.rootHandle); |
| 9168 | } |
| 9169 | // lock on mStateLock needs to be released before binder handle gets destroyed |
| 9170 | unused.clear(); |
Chavi Weingarten | 7043a7d | 2022-07-19 23:40:35 +0000 | [diff] [blame] | 9171 | } |
| 9172 | } |
| 9173 | return true; |
| 9174 | } |
| 9175 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9176 | bool SurfaceFlinger::commitCreatedLayers(VsyncId vsyncId, |
| 9177 | std::vector<LayerCreatedState>& createdLayers) { |
| 9178 | if (createdLayers.size() == 0) { |
| 9179 | return false; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9180 | } |
| 9181 | |
| 9182 | Mutex::Autolock _l(mStateLock); |
| 9183 | for (const auto& createdLayer : createdLayers) { |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 9184 | handleLayerCreatedLocked(createdLayer, vsyncId); |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9185 | } |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9186 | mLayersAdded = true; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9187 | return mLayersAdded; |
Vishnu Nair | 0fc7af5 | 2022-01-13 08:11:34 -0800 | [diff] [blame] | 9188 | } |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9189 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 9190 | void SurfaceFlinger::updateLayerMetadataSnapshot() { |
| 9191 | LayerMetadata parentMetadata; |
| 9192 | for (const auto& layer : mDrawingState.layersSortedByZ) { |
| 9193 | layer->updateMetadataSnapshot(parentMetadata); |
| 9194 | } |
| 9195 | |
| 9196 | std::unordered_set<Layer*> visited; |
| 9197 | mDrawingState.traverse([&visited](Layer* layer) { |
| 9198 | if (visited.find(layer) != visited.end()) { |
| 9199 | return; |
| 9200 | } |
| 9201 | |
| 9202 | // If the layer isRelativeOf, then either it's relative metadata will be set |
| 9203 | // recursively when updateRelativeMetadataSnapshot is called on its relative parent or |
| 9204 | // it's relative parent has been deleted. Clear the layer's relativeLayerMetadata to ensure |
| 9205 | // that layers with deleted relative parents don't hold stale relativeLayerMetadata. |
| 9206 | if (layer->getDrawingState().isRelativeOf) { |
| 9207 | layer->editLayerSnapshot()->relativeLayerMetadata = {}; |
| 9208 | return; |
| 9209 | } |
| 9210 | |
| 9211 | layer->updateRelativeMetadataSnapshot({}, visited); |
| 9212 | }); |
| 9213 | } |
| 9214 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9215 | void SurfaceFlinger::moveSnapshotsFromCompositionArgs( |
| 9216 | compositionengine::CompositionRefreshArgs& refreshArgs, |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9217 | const std::vector<std::pair<Layer*, LayerFE*>>& layers) { |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9218 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9219 | std::vector<std::unique_ptr<frontend::LayerSnapshot>>& snapshots = |
| 9220 | mLayerSnapshotBuilder.getSnapshots(); |
| 9221 | for (auto [_, layerFE] : layers) { |
| 9222 | auto i = layerFE->mSnapshot->globalZ; |
| 9223 | snapshots[i] = std::move(layerFE->mSnapshot); |
| 9224 | } |
| 9225 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 9226 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9227 | for (auto [layer, layerFE] : layers) { |
| 9228 | layer->updateLayerSnapshot(std::move(layerFE->mSnapshot)); |
| 9229 | } |
| 9230 | } |
| 9231 | } |
| 9232 | |
| 9233 | std::vector<std::pair<Layer*, LayerFE*>> SurfaceFlinger::moveSnapshotsToCompositionArgs( |
Dominik Laskowski | 16a345b | 2023-04-27 17:07:33 -0400 | [diff] [blame] | 9234 | compositionengine::CompositionRefreshArgs& refreshArgs, bool cursorOnly) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9235 | std::vector<std::pair<Layer*, LayerFE*>> layers; |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9236 | if (mLayerLifecycleManagerEnabled) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9237 | nsecs_t currentTime = systemTime(); |
Garfield Tan | ad34a68 | 2024-05-21 15:25:35 +0000 | [diff] [blame] | 9238 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9239 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 9240 | kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9241 | if (cursorOnly && |
| 9242 | snapshot->compositionType != |
| 9243 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) { |
| 9244 | return; |
| 9245 | } |
| 9246 | |
| 9247 | if (!snapshot->hasSomethingToDraw()) { |
| 9248 | return; |
| 9249 | } |
| 9250 | |
| 9251 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9252 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9253 | "Couldnt find layer object for %s", |
| 9254 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9255 | auto& legacyLayer = it->second; |
| 9256 | sp<LayerFE> layerFE = legacyLayer->getCompositionEngineLayerFE(snapshot->path); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9257 | snapshot->fps = getLayerFramerate(currentTime, snapshot->sequence); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9258 | layerFE->mSnapshot = std::move(snapshot); |
| 9259 | refreshArgs.layers.push_back(layerFE); |
| 9260 | layers.emplace_back(legacyLayer.get(), layerFE.get()); |
| 9261 | }); |
| 9262 | } |
Melody Hsu | ce0fe52 | 2024-05-03 01:54:56 +0000 | [diff] [blame] | 9263 | if (!mLayerLifecycleManagerEnabled) { |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9264 | auto moveSnapshots = [&layers, &refreshArgs, cursorOnly](Layer* layer) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9265 | if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { |
| 9266 | if (cursorOnly && |
| 9267 | layer->getLayerSnapshot()->compositionType != |
| 9268 | aidl::android::hardware::graphics::composer3::Composition::CURSOR) |
| 9269 | return; |
| 9270 | layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); |
| 9271 | layerFE->mSnapshot = layer->stealLayerSnapshot(); |
| 9272 | refreshArgs.layers.push_back(layerFE); |
| 9273 | layers.emplace_back(layer, layerFE.get()); |
| 9274 | } |
Vishnu Nair | 802ac4f | 2023-05-10 13:55:22 -0700 | [diff] [blame] | 9275 | }; |
| 9276 | |
| 9277 | if (cursorOnly || !mVisibleRegionsDirty) { |
| 9278 | // for hot path avoid traversals by walking though the previous composition list |
| 9279 | for (sp<Layer> layer : mPreviouslyComposedLayers) { |
| 9280 | moveSnapshots(layer.get()); |
| 9281 | } |
| 9282 | } else { |
| 9283 | mPreviouslyComposedLayers.clear(); |
| 9284 | mDrawingState.traverseInZOrder( |
| 9285 | [&moveSnapshots](Layer* layer) { moveSnapshots(layer); }); |
| 9286 | mPreviouslyComposedLayers.reserve(layers.size()); |
| 9287 | for (auto [layer, _] : layers) { |
| 9288 | mPreviouslyComposedLayers.push_back(sp<Layer>::fromExisting(layer)); |
| 9289 | } |
| 9290 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9291 | } |
| 9292 | |
| 9293 | return layers; |
| 9294 | } |
| 9295 | |
| 9296 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9297 | SurfaceFlinger::getLayerSnapshotsForScreenshots( |
| 9298 | std::optional<ui::LayerStack> layerStack, uint32_t uid, |
| 9299 | std::function<bool(const frontend::LayerSnapshot&, bool& outStopTraversal)> |
| 9300 | snapshotFilterFn) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9301 | return [&, layerStack, uid]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9302 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9303 | bool stopTraversal = false; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9304 | mLayerSnapshotBuilder.forEachVisibleSnapshot( |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9305 | [&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) FTL_FAKE_GUARD( |
| 9306 | kMainThreadContext) { |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9307 | if (stopTraversal) { |
| 9308 | return; |
| 9309 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9310 | if (layerStack && snapshot->outputFilter.layerStack != *layerStack) { |
| 9311 | return; |
| 9312 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 9313 | if (uid != CaptureArgs::UNSET_UID && snapshot->uid != gui::Uid(uid)) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9314 | return; |
| 9315 | } |
| 9316 | if (!snapshot->hasSomethingToDraw()) { |
| 9317 | return; |
| 9318 | } |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9319 | if (snapshotFilterFn && !snapshotFilterFn(*snapshot, stopTraversal)) { |
| 9320 | return; |
| 9321 | } |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9322 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9323 | auto it = mLegacyLayers.find(snapshot->sequence); |
Vishnu Nair | 5943bf6 | 2023-12-08 22:04:20 +0000 | [diff] [blame] | 9324 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mLegacyLayers.end(), |
| 9325 | "Couldnt find layer object for %s", |
| 9326 | snapshot->getDebugString().c_str()); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9327 | Layer* legacyLayer = (it == mLegacyLayers.end()) ? nullptr : it->second.get(); |
Lloyd Pique | 70ddc67 | 2024-04-30 18:20:40 -0700 | [diff] [blame] | 9328 | sp<LayerFE> layerFE = getFactory().createLayerFE(snapshot->name, legacyLayer); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9329 | layerFE->mSnapshot = std::make_unique<frontend::LayerSnapshot>(*snapshot); |
| 9330 | layers.emplace_back(legacyLayer, std::move(layerFE)); |
| 9331 | }); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9332 | |
| 9333 | return layers; |
| 9334 | }; |
| 9335 | } |
| 9336 | |
| 9337 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9338 | SurfaceFlinger::getLayerSnapshotsForScreenshots(std::optional<ui::LayerStack> layerStack, |
| 9339 | uint32_t uid, |
| 9340 | std::unordered_set<uint32_t> excludeLayerIds) { |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9341 | return [&, layerStack, uid, |
| 9342 | excludeLayerIds = std::move(excludeLayerIds)]() FTL_FAKE_GUARD(kMainThreadContext) { |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9343 | if (excludeLayerIds.empty()) { |
| 9344 | auto getLayerSnapshotsFn = |
| 9345 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9346 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9347 | return layers; |
| 9348 | } |
| 9349 | |
| 9350 | frontend::LayerSnapshotBuilder::Args |
| 9351 | args{.root = mLayerHierarchyBuilder.getHierarchy(), |
| 9352 | .layerLifecycleManager = mLayerLifecycleManager, |
| 9353 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
| 9354 | .displays = mFrontEndDisplayInfos, |
| 9355 | .displayChanges = true, |
| 9356 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9357 | .supportsBlur = mSupportsBlur, |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9358 | .forceFullDamage = mForceFullDamage, |
| 9359 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9360 | .supportedLayerGenericMetadata = |
| 9361 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9362 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9363 | .skipRoundCornersWhenProtected = |
| 9364 | !getRenderEngine().supportsProtectedContent()}; |
Ajinkya Chalke | 0284463 | 2023-03-01 12:10:14 +0000 | [diff] [blame] | 9365 | mLayerSnapshotBuilder.update(args); |
| 9366 | |
| 9367 | auto getLayerSnapshotsFn = |
| 9368 | getLayerSnapshotsForScreenshots(layerStack, uid, /*snapshotFilterFn=*/nullptr); |
| 9369 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9370 | |
| 9371 | args.excludeLayerIds.clear(); |
| 9372 | mLayerSnapshotBuilder.update(args); |
| 9373 | |
| 9374 | return layers; |
| 9375 | }; |
| 9376 | } |
| 9377 | |
| 9378 | std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9379 | SurfaceFlinger::getLayerSnapshotsForScreenshots(uint32_t rootLayerId, uint32_t uid, |
| 9380 | std::unordered_set<uint32_t> excludeLayerIds, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9381 | bool childrenOnly, |
| 9382 | const std::optional<FloatRect>& parentCrop) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9383 | return [&, rootLayerId, uid, excludeLayerIds = std::move(excludeLayerIds), childrenOnly, |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 9384 | parentCrop]() FTL_FAKE_GUARD(kMainThreadContext) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9385 | auto root = mLayerHierarchyBuilder.getPartialHierarchy(rootLayerId, childrenOnly); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9386 | frontend::LayerSnapshotBuilder::Args |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9387 | args{.root = root, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9388 | .layerLifecycleManager = mLayerLifecycleManager, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 9389 | .forceUpdate = frontend::LayerSnapshotBuilder::ForceUpdateFlags::HIERARCHY, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9390 | .displays = mFrontEndDisplayInfos, |
| 9391 | .displayChanges = true, |
| 9392 | .globalShadowSettings = mDrawingState.globalShadowSettings, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 9393 | .supportsBlur = mSupportsBlur, |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9394 | .forceFullDamage = mForceFullDamage, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 9395 | .parentCrop = parentCrop, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 9396 | .excludeLayerIds = std::move(excludeLayerIds), |
| 9397 | .supportedLayerGenericMetadata = |
| 9398 | getHwComposer().getSupportedLayerGenericMetadata(), |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 9399 | .genericLayerMetadataKeyMap = getGenericLayerMetadataKeyMap(), |
| 9400 | .skipRoundCornersWhenProtected = |
| 9401 | !getRenderEngine().supportsProtectedContent()}; |
Vishnu Nair | c54fdb0 | 2023-11-21 17:19:58 -0800 | [diff] [blame] | 9402 | // The layer may not exist if it was just created and a screenshot was requested immediately |
| 9403 | // after. In this case, the hierarchy will be empty so we will not render any layers. |
| 9404 | args.rootSnapshot.isSecure = mLayerLifecycleManager.getLayerFromId(rootLayerId) && |
| 9405 | mLayerLifecycleManager.isLayerSecure(rootLayerId); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9406 | mLayerSnapshotBuilder.update(args); |
| 9407 | |
Vishnu Nair | c5a5b6e | 2023-02-28 00:19:07 +0000 | [diff] [blame] | 9408 | auto getLayerSnapshotsFn = |
| 9409 | getLayerSnapshotsForScreenshots({}, uid, /*snapshotFilterFn=*/nullptr); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9410 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers = getLayerSnapshotsFn(); |
| 9411 | args.root = mLayerHierarchyBuilder.getHierarchy(); |
| 9412 | args.parentCrop.reset(); |
| 9413 | args.excludeLayerIds.clear(); |
| 9414 | mLayerSnapshotBuilder.update(args); |
| 9415 | return layers; |
| 9416 | }; |
| 9417 | } |
| 9418 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9419 | frontend::Update SurfaceFlinger::flushLifecycleUpdates() { |
| 9420 | frontend::Update update; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9421 | ATRACE_NAME("TransactionHandler:flushTransactions"); |
| 9422 | // Locking: |
| 9423 | // 1. to prevent onHandleDestroyed from being called while the state lock is held, |
| 9424 | // we must keep a copy of the transactions (specifically the composer |
| 9425 | // states) around outside the scope of the lock. |
| 9426 | // 2. Transactions and created layers do not share a lock. To prevent applying |
| 9427 | // transactions with layers still in the createdLayer queue, flush the transactions |
| 9428 | // before committing the created layers. |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 9429 | mTransactionHandler.collectTransactions(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9430 | update.transactions = mTransactionHandler.flushTransactions(); |
| 9431 | { |
| 9432 | // TODO(b/238781169) lockless queue this and keep order. |
| 9433 | std::scoped_lock<std::mutex> lock(mCreatedLayersLock); |
| 9434 | update.layerCreatedStates = std::move(mCreatedLayers); |
| 9435 | mCreatedLayers.clear(); |
| 9436 | update.newLayers = std::move(mNewLayers); |
| 9437 | mNewLayers.clear(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9438 | update.layerCreationArgs = std::move(mNewLayerArgs); |
| 9439 | mNewLayerArgs.clear(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 9440 | update.destroyedHandles = std::move(mDestroyedHandles); |
| 9441 | mDestroyedHandles.clear(); |
| 9442 | } |
| 9443 | return update; |
| 9444 | } |
| 9445 | |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9446 | void SurfaceFlinger::doActiveLayersTracingIfNeeded(bool isCompositionComputed, |
| 9447 | bool visibleRegionDirty, TimePoint time, |
| 9448 | VsyncId vsyncId) { |
| 9449 | if (!mLayerTracing.isActiveTracingStarted()) { |
| 9450 | return; |
| 9451 | } |
| 9452 | if (isCompositionComputed != |
| 9453 | mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_COMPOSITION)) { |
| 9454 | return; |
| 9455 | } |
| 9456 | if (!visibleRegionDirty && |
| 9457 | !mLayerTracing.isActiveTracingFlagSet(LayerTracing::Flag::TRACE_BUFFERS)) { |
| 9458 | return; |
| 9459 | } |
| 9460 | auto snapshot = takeLayersSnapshotProto(mLayerTracing.getActiveTracingFlags(), time, vsyncId, |
| 9461 | visibleRegionDirty); |
| 9462 | mLayerTracing.addProtoSnapshotToOstream(std::move(snapshot), LayerTracing::Mode::MODE_ACTIVE); |
| 9463 | } |
| 9464 | |
| 9465 | perfetto::protos::LayersSnapshotProto SurfaceFlinger::takeLayersSnapshotProto( |
| 9466 | uint32_t traceFlags, TimePoint time, VsyncId vsyncId, bool visibleRegionDirty) { |
| 9467 | ATRACE_CALL(); |
| 9468 | perfetto::protos::LayersSnapshotProto snapshot; |
| 9469 | snapshot.set_elapsed_realtime_nanos(time.ns()); |
| 9470 | snapshot.set_vsync_id(ftl::to_underlying(vsyncId)); |
| 9471 | snapshot.set_where(visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched"); |
| 9472 | snapshot.set_excludes_composition_state((traceFlags & LayerTracing::Flag::TRACE_COMPOSITION) == |
| 9473 | 0); |
| 9474 | |
| 9475 | auto layers = dumpDrawingStateProto(traceFlags); |
| 9476 | if (traceFlags & LayerTracing::Flag::TRACE_EXTRA) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9477 | dumpOffscreenLayersProto(layers); |
| 9478 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9479 | *snapshot.mutable_layers() = std::move(layers); |
| 9480 | |
| 9481 | if (traceFlags & LayerTracing::Flag::TRACE_HWC) { |
| 9482 | std::string hwcDump; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9483 | dumpHwc(hwcDump); |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9484 | snapshot.set_hwc_blob(std::move(hwcDump)); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9485 | } |
Kean Mariotti | 639b54f | 2023-04-20 12:06:29 +0000 | [diff] [blame] | 9486 | |
| 9487 | *snapshot.mutable_displays() = dumpDisplayProto(); |
| 9488 | |
| 9489 | return snapshot; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 9490 | } |
| 9491 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 9492 | // sfdo functions |
| 9493 | |
| 9494 | void SurfaceFlinger::sfdo_enableRefreshRateOverlay(bool active) { |
| 9495 | auto future = mScheduler->schedule( |
| 9496 | [&]() FTL_FAKE_GUARD(mStateLock) |
| 9497 | FTL_FAKE_GUARD(kMainThreadContext) { enableRefreshRateOverlay(active); }); |
| 9498 | future.wait(); |
| 9499 | } |
| 9500 | |
| 9501 | void SurfaceFlinger::sfdo_setDebugFlash(int delay) { |
| 9502 | if (delay > 0) { |
| 9503 | mDebugFlashDelay = delay; |
| 9504 | } else { |
| 9505 | mDebugFlashDelay = mDebugFlashDelay ? 0 : 1; |
| 9506 | } |
| 9507 | scheduleRepaint(); |
| 9508 | } |
| 9509 | |
| 9510 | void SurfaceFlinger::sfdo_scheduleComposite() { |
| 9511 | scheduleComposite(SurfaceFlinger::FrameHint::kActive); |
| 9512 | } |
| 9513 | |
| 9514 | void SurfaceFlinger::sfdo_scheduleCommit() { |
| 9515 | Mutex::Autolock lock(mStateLock); |
| 9516 | setTransactionFlags(eTransactionNeeded | eDisplayTransactionNeeded | eTraversalNeeded); |
| 9517 | } |
| 9518 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 9519 | void SurfaceFlinger::sfdo_forceClientComposition(bool enabled) { |
| 9520 | mDebugDisableHWC = enabled; |
| 9521 | scheduleRepaint(); |
| 9522 | } |
| 9523 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9524 | // gui::ISurfaceComposer |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9525 | |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9526 | binder::Status SurfaceComposerAIDL::bootFinished() { |
| 9527 | status_t status = checkAccessPermission(); |
| 9528 | if (status != OK) { |
| 9529 | return binderStatusFromStatusT(status); |
| 9530 | } |
| 9531 | mFlinger->bootFinished(); |
| 9532 | return binder::Status::ok(); |
| 9533 | } |
| 9534 | |
| 9535 | binder::Status SurfaceComposerAIDL::createDisplayEventConnection( |
| 9536 | VsyncSource vsyncSource, EventRegistration eventRegistration, |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9537 | const sp<IBinder>& layerHandle, sp<IDisplayEventConnection>* outConnection) { |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9538 | sp<IDisplayEventConnection> conn = |
Rachel Lee | 2248f52 | 2023-01-27 16:45:23 -0800 | [diff] [blame] | 9539 | mFlinger->createDisplayEventConnection(vsyncSource, eventRegistration, layerHandle); |
Huihong Luo | 1b0c49f | 2022-03-15 19:18:21 -0700 | [diff] [blame] | 9540 | if (conn == nullptr) { |
| 9541 | *outConnection = nullptr; |
| 9542 | return binderStatusFromStatusT(BAD_VALUE); |
| 9543 | } else { |
| 9544 | *outConnection = conn; |
| 9545 | return binder::Status::ok(); |
| 9546 | } |
| 9547 | } |
| 9548 | |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9549 | binder::Status SurfaceComposerAIDL::createConnection(sp<gui::ISurfaceComposerClient>* outClient) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 9550 | const sp<Client> client = sp<Client>::make(mFlinger); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9551 | if (client->initCheck() == NO_ERROR) { |
| 9552 | *outClient = client; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 9553 | if (FlagManager::getInstance().misc1()) { |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 9554 | const int policy = SCHED_FIFO; |
| 9555 | client->setMinSchedulerPolicy(policy, sched_get_priority_min(policy)); |
| 9556 | } |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 9557 | return binder::Status::ok(); |
| 9558 | } else { |
| 9559 | *outClient = nullptr; |
| 9560 | return binderStatusFromStatusT(BAD_VALUE); |
| 9561 | } |
| 9562 | } |
| 9563 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9564 | binder::Status SurfaceComposerAIDL::createVirtualDisplay(const std::string& displayName, |
| 9565 | bool isSecure, const std::string& uniqueId, |
| 9566 | float requestedRefreshRate, |
| 9567 | sp<IBinder>* outDisplay) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9568 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9569 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9570 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9571 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9572 | *outDisplay = |
| 9573 | mFlinger->createVirtualDisplay(displayName, isSecure, uniqueId, requestedRefreshRate); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9574 | return binder::Status::ok(); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9575 | } |
| 9576 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9577 | binder::Status SurfaceComposerAIDL::destroyVirtualDisplay(const sp<IBinder>& displayToken) { |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9578 | status_t status = checkAccessPermission(); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9579 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9580 | return binderStatusFromStatusT(status); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9581 | } |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 9582 | return binder::Status::fromStatusT(mFlinger->destroyVirtualDisplay(displayToken)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9583 | } |
| 9584 | |
| 9585 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { |
| 9586 | std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); |
| 9587 | std::vector<int64_t> displayIds; |
| 9588 | displayIds.reserve(physicalDisplayIds.size()); |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 9589 | for (const auto id : physicalDisplayIds) { |
| 9590 | displayIds.push_back(static_cast<int64_t>(id.value)); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9591 | } |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 9592 | *outDisplayIds = std::move(displayIds); |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9593 | return binder::Status::ok(); |
| 9594 | } |
| 9595 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9596 | binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, |
| 9597 | sp<IBinder>* outDisplay) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9598 | status_t status = checkAccessPermission(); |
| 9599 | if (status != OK) { |
| 9600 | return binderStatusFromStatusT(status); |
| 9601 | } |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 9602 | const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); |
| 9603 | *outDisplay = mFlinger->getPhysicalDisplayToken(*id); |
| 9604 | return binder::Status::ok(); |
| 9605 | } |
| 9606 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9607 | binder::Status SurfaceComposerAIDL::setPowerMode(const sp<IBinder>& display, int mode) { |
| 9608 | status_t status = checkAccessPermission(); |
| 9609 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9610 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9611 | } |
| 9612 | mFlinger->setPowerMode(display, mode); |
| 9613 | return binder::Status::ok(); |
| 9614 | } |
| 9615 | |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9616 | binder::Status SurfaceComposerAIDL::getSupportedFrameTimestamps( |
| 9617 | std::vector<FrameEvent>* outSupported) { |
| 9618 | status_t status; |
| 9619 | if (!outSupported) { |
| 9620 | status = UNEXPECTED_NULL; |
| 9621 | } else { |
| 9622 | outSupported->clear(); |
| 9623 | status = mFlinger->getSupportedFrameTimestamps(outSupported); |
| 9624 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9625 | return binderStatusFromStatusT(status); |
Huihong Luo | 0a81aa3 | 2022-02-22 16:02:36 -0800 | [diff] [blame] | 9626 | } |
| 9627 | |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9628 | binder::Status SurfaceComposerAIDL::getDisplayStats(const sp<IBinder>& display, |
| 9629 | gui::DisplayStatInfo* outStatInfo) { |
| 9630 | DisplayStatInfo statInfo; |
| 9631 | status_t status = mFlinger->getDisplayStats(display, &statInfo); |
| 9632 | if (status == NO_ERROR) { |
| 9633 | outStatInfo->vsyncTime = static_cast<long>(statInfo.vsyncTime); |
| 9634 | outStatInfo->vsyncPeriod = static_cast<long>(statInfo.vsyncPeriod); |
| 9635 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9636 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9637 | } |
| 9638 | |
| 9639 | binder::Status SurfaceComposerAIDL::getDisplayState(const sp<IBinder>& display, |
| 9640 | gui::DisplayState* outState) { |
| 9641 | ui::DisplayState state; |
| 9642 | status_t status = mFlinger->getDisplayState(display, &state); |
| 9643 | if (status == NO_ERROR) { |
| 9644 | outState->layerStack = state.layerStack.id; |
| 9645 | outState->orientation = static_cast<gui::Rotation>(state.orientation); |
| 9646 | outState->layerStackSpaceRect.width = state.layerStackSpaceRect.width; |
| 9647 | outState->layerStackSpaceRect.height = state.layerStackSpaceRect.height; |
| 9648 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9649 | return binderStatusFromStatusT(status); |
Huihong Luo | aa7fc2e | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9650 | } |
| 9651 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9652 | binder::Status SurfaceComposerAIDL::getStaticDisplayInfo(int64_t displayId, |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9653 | gui::StaticDisplayInfo* outInfo) { |
| 9654 | using Tag = gui::DeviceProductInfo::ManufactureOrModelDate::Tag; |
| 9655 | ui::StaticDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9656 | |
| 9657 | status_t status = mFlinger->getStaticDisplayInfo(displayId, &info); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9658 | if (status == NO_ERROR) { |
| 9659 | // convert ui::StaticDisplayInfo to gui::StaticDisplayInfo |
| 9660 | outInfo->connectionType = static_cast<gui::DisplayConnectionType>(info.connectionType); |
| 9661 | outInfo->density = info.density; |
| 9662 | outInfo->secure = info.secure; |
| 9663 | outInfo->installOrientation = static_cast<gui::Rotation>(info.installOrientation); |
| 9664 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9665 | if (const std::optional<DeviceProductInfo> dpi = info.deviceProductInfo) { |
| 9666 | gui::DeviceProductInfo dinfo; |
| 9667 | dinfo.name = std::move(dpi->name); |
| 9668 | dinfo.manufacturerPnpId = std::vector<uint8_t>(dpi->manufacturerPnpId.begin(), |
| 9669 | dpi->manufacturerPnpId.end()); |
| 9670 | dinfo.productId = dpi->productId; |
| 9671 | dinfo.relativeAddress = |
| 9672 | std::vector<uint8_t>(dpi->relativeAddress.begin(), dpi->relativeAddress.end()); |
| 9673 | if (const auto* model = |
| 9674 | std::get_if<DeviceProductInfo::ModelYear>(&dpi->manufactureOrModelDate)) { |
| 9675 | gui::DeviceProductInfo::ModelYear modelYear; |
| 9676 | modelYear.year = model->year; |
| 9677 | dinfo.manufactureOrModelDate.set<Tag::modelYear>(modelYear); |
| 9678 | } else if (const auto* manufacture = std::get_if<DeviceProductInfo::ManufactureYear>( |
| 9679 | &dpi->manufactureOrModelDate)) { |
| 9680 | gui::DeviceProductInfo::ManufactureYear date; |
| 9681 | date.modelYear.year = manufacture->year; |
| 9682 | dinfo.manufactureOrModelDate.set<Tag::manufactureYear>(date); |
| 9683 | } else if (const auto* manufacture = |
| 9684 | std::get_if<DeviceProductInfo::ManufactureWeekAndYear>( |
| 9685 | &dpi->manufactureOrModelDate)) { |
| 9686 | gui::DeviceProductInfo::ManufactureWeekAndYear date; |
| 9687 | date.manufactureYear.modelYear.year = manufacture->year; |
| 9688 | date.week = manufacture->week; |
| 9689 | dinfo.manufactureOrModelDate.set<Tag::manufactureWeekAndYear>(date); |
| 9690 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9691 | |
Snild Dolkow | 8d67564 | 2023-07-14 12:43:35 +0200 | [diff] [blame] | 9692 | outInfo->deviceProductInfo = dinfo; |
| 9693 | } |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9694 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9695 | return binderStatusFromStatusT(status); |
Huihong Luo | a79ddf4 | 2022-02-17 00:01:38 -0800 | [diff] [blame] | 9696 | } |
| 9697 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9698 | void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& info, |
| 9699 | gui::DynamicDisplayInfo*& outInfo) { |
| 9700 | // convert ui::DynamicDisplayInfo to gui::DynamicDisplayInfo |
| 9701 | outInfo->supportedDisplayModes.clear(); |
| 9702 | outInfo->supportedDisplayModes.reserve(info.supportedDisplayModes.size()); |
| 9703 | for (const auto& mode : info.supportedDisplayModes) { |
| 9704 | gui::DisplayMode outMode; |
| 9705 | outMode.id = mode.id; |
| 9706 | outMode.resolution.width = mode.resolution.width; |
| 9707 | outMode.resolution.height = mode.resolution.height; |
| 9708 | outMode.xDpi = mode.xDpi; |
| 9709 | outMode.yDpi = mode.yDpi; |
Alec Mouri | 55e3103 | 2023-10-02 20:34:18 +0000 | [diff] [blame] | 9710 | outMode.peakRefreshRate = mode.peakRefreshRate; |
Alec Mouri | d122a1c | 2023-09-30 01:36:33 +0000 | [diff] [blame] | 9711 | outMode.vsyncRate = mode.vsyncRate; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9712 | outMode.appVsyncOffset = mode.appVsyncOffset; |
| 9713 | outMode.sfVsyncOffset = mode.sfVsyncOffset; |
| 9714 | outMode.presentationDeadline = mode.presentationDeadline; |
| 9715 | outMode.group = mode.group; |
| 9716 | std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(), |
| 9717 | std::back_inserter(outMode.supportedHdrTypes), |
| 9718 | [](const ui::Hdr& value) { return static_cast<int32_t>(value); }); |
| 9719 | outInfo->supportedDisplayModes.push_back(outMode); |
| 9720 | } |
| 9721 | |
| 9722 | outInfo->activeDisplayModeId = info.activeDisplayModeId; |
| 9723 | outInfo->renderFrameRate = info.renderFrameRate; |
| 9724 | |
| 9725 | outInfo->supportedColorModes.clear(); |
| 9726 | outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); |
| 9727 | for (const auto& cmode : info.supportedColorModes) { |
| 9728 | outInfo->supportedColorModes.push_back(static_cast<int32_t>(cmode)); |
| 9729 | } |
| 9730 | |
| 9731 | outInfo->activeColorMode = static_cast<int32_t>(info.activeColorMode); |
| 9732 | |
| 9733 | gui::HdrCapabilities& hdrCapabilities = outInfo->hdrCapabilities; |
| 9734 | hdrCapabilities.supportedHdrTypes.clear(); |
| 9735 | hdrCapabilities.supportedHdrTypes.reserve(info.hdrCapabilities.getSupportedHdrTypes().size()); |
| 9736 | for (const auto& hdr : info.hdrCapabilities.getSupportedHdrTypes()) { |
| 9737 | hdrCapabilities.supportedHdrTypes.push_back(static_cast<int32_t>(hdr)); |
| 9738 | } |
| 9739 | hdrCapabilities.maxLuminance = info.hdrCapabilities.getDesiredMaxLuminance(); |
| 9740 | hdrCapabilities.maxAverageLuminance = info.hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 9741 | hdrCapabilities.minLuminance = info.hdrCapabilities.getDesiredMinLuminance(); |
| 9742 | |
| 9743 | outInfo->autoLowLatencyModeSupported = info.autoLowLatencyModeSupported; |
| 9744 | outInfo->gameContentTypeSupported = info.gameContentTypeSupported; |
| 9745 | outInfo->preferredBootDisplayMode = info.preferredBootDisplayMode; |
| 9746 | } |
| 9747 | |
| 9748 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromToken( |
| 9749 | const sp<IBinder>& display, gui::DynamicDisplayInfo* outInfo) { |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9750 | ui::DynamicDisplayInfo info; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9751 | status_t status = mFlinger->getDynamicDisplayInfoFromToken(display, &info); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9752 | if (status == NO_ERROR) { |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9753 | getDynamicDisplayInfoInternal(info, outInfo); |
| 9754 | } |
| 9755 | return binderStatusFromStatusT(status); |
| 9756 | } |
Marc Kassis | bdf7e4b | 2022-11-04 17:26:48 +0100 | [diff] [blame] | 9757 | |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 9758 | binder::Status SurfaceComposerAIDL::getDynamicDisplayInfoFromId(int64_t displayId, |
| 9759 | gui::DynamicDisplayInfo* outInfo) { |
| 9760 | ui::DynamicDisplayInfo info; |
| 9761 | status_t status = mFlinger->getDynamicDisplayInfoFromId(displayId, &info); |
| 9762 | if (status == NO_ERROR) { |
| 9763 | getDynamicDisplayInfoInternal(info, outInfo); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9764 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9765 | return binderStatusFromStatusT(status); |
Huihong Luo | 38603fd | 2022-02-21 14:32:54 -0800 | [diff] [blame] | 9766 | } |
| 9767 | |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9768 | binder::Status SurfaceComposerAIDL::getDisplayNativePrimaries(const sp<IBinder>& display, |
| 9769 | gui::DisplayPrimaries* outPrimaries) { |
| 9770 | ui::DisplayPrimaries primaries; |
| 9771 | status_t status = mFlinger->getDisplayNativePrimaries(display, primaries); |
| 9772 | if (status == NO_ERROR) { |
| 9773 | outPrimaries->red.X = primaries.red.X; |
| 9774 | outPrimaries->red.Y = primaries.red.Y; |
| 9775 | outPrimaries->red.Z = primaries.red.Z; |
| 9776 | |
| 9777 | outPrimaries->green.X = primaries.green.X; |
| 9778 | outPrimaries->green.Y = primaries.green.Y; |
| 9779 | outPrimaries->green.Z = primaries.green.Z; |
| 9780 | |
| 9781 | outPrimaries->blue.X = primaries.blue.X; |
| 9782 | outPrimaries->blue.Y = primaries.blue.Y; |
| 9783 | outPrimaries->blue.Z = primaries.blue.Z; |
| 9784 | |
| 9785 | outPrimaries->white.X = primaries.white.X; |
| 9786 | outPrimaries->white.Y = primaries.white.Y; |
| 9787 | outPrimaries->white.Z = primaries.white.Z; |
| 9788 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9789 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9790 | } |
| 9791 | |
| 9792 | binder::Status SurfaceComposerAIDL::setActiveColorMode(const sp<IBinder>& display, int colorMode) { |
| 9793 | status_t status = checkAccessPermission(); |
| 9794 | if (status == OK) { |
| 9795 | status = mFlinger->setActiveColorMode(display, static_cast<ui::ColorMode>(colorMode)); |
| 9796 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9797 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9798 | } |
| 9799 | |
| 9800 | binder::Status SurfaceComposerAIDL::setBootDisplayMode(const sp<IBinder>& display, |
| 9801 | int displayModeId) { |
| 9802 | status_t status = checkAccessPermission(); |
| 9803 | if (status == OK) { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 9804 | status = mFlinger->setBootDisplayMode(display, DisplayModeId{displayModeId}); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9805 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9806 | return binderStatusFromStatusT(status); |
Huihong Luo | ca3d9a4 | 2022-02-22 11:07:34 -0800 | [diff] [blame] | 9807 | } |
| 9808 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9809 | binder::Status SurfaceComposerAIDL::clearBootDisplayMode(const sp<IBinder>& display) { |
| 9810 | status_t status = checkAccessPermission(); |
| 9811 | if (status == OK) { |
| 9812 | status = mFlinger->clearBootDisplayMode(display); |
| 9813 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9814 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9815 | } |
| 9816 | |
Sally Qi | 0cbd08b | 2022-08-17 12:12:28 -0700 | [diff] [blame] | 9817 | binder::Status SurfaceComposerAIDL::getOverlaySupport(gui::OverlayProperties* outProperties) { |
| 9818 | status_t status = checkAccessPermission(); |
| 9819 | if (status == OK) { |
| 9820 | status = mFlinger->getOverlaySupport(outProperties); |
| 9821 | } |
| 9822 | return binderStatusFromStatusT(status); |
| 9823 | } |
| 9824 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9825 | binder::Status SurfaceComposerAIDL::getBootDisplayModeSupport(bool* outMode) { |
| 9826 | status_t status = checkAccessPermission(); |
| 9827 | if (status == OK) { |
| 9828 | status = mFlinger->getBootDisplayModeSupport(outMode); |
| 9829 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9830 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9831 | } |
| 9832 | |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9833 | binder::Status SurfaceComposerAIDL::getHdrConversionCapabilities( |
| 9834 | std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) { |
| 9835 | status_t status = checkAccessPermission(); |
| 9836 | if (status == OK) { |
| 9837 | status = mFlinger->getHdrConversionCapabilities(hdrConversionCapabilities); |
| 9838 | } |
| 9839 | return binderStatusFromStatusT(status); |
| 9840 | } |
| 9841 | |
| 9842 | binder::Status SurfaceComposerAIDL::setHdrConversionStrategy( |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9843 | const gui::HdrConversionStrategy& hdrConversionStrategy, |
| 9844 | int32_t* outPreferredHdrOutputType) { |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9845 | status_t status = checkAccessPermission(); |
| 9846 | if (status == OK) { |
Kriti Dang | d432bb5 | 2023-02-09 18:21:04 +0100 | [diff] [blame] | 9847 | status = mFlinger->setHdrConversionStrategy(hdrConversionStrategy, |
| 9848 | outPreferredHdrOutputType); |
Kriti Dang | 674b937 | 2022-11-18 10:58:44 +0100 | [diff] [blame] | 9849 | } |
| 9850 | return binderStatusFromStatusT(status); |
| 9851 | } |
| 9852 | |
| 9853 | binder::Status SurfaceComposerAIDL::getHdrOutputConversionSupport(bool* outMode) { |
| 9854 | status_t status = checkAccessPermission(); |
| 9855 | if (status == OK) { |
| 9856 | status = mFlinger->getHdrOutputConversionSupport(outMode); |
| 9857 | } |
| 9858 | return binderStatusFromStatusT(status); |
| 9859 | } |
| 9860 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9861 | binder::Status SurfaceComposerAIDL::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { |
| 9862 | status_t status = checkAccessPermission(); |
| 9863 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9864 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9865 | } |
| 9866 | mFlinger->setAutoLowLatencyMode(display, on); |
| 9867 | return binder::Status::ok(); |
| 9868 | } |
| 9869 | |
| 9870 | binder::Status SurfaceComposerAIDL::setGameContentType(const sp<IBinder>& display, bool on) { |
| 9871 | status_t status = checkAccessPermission(); |
| 9872 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9873 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 9874 | } |
| 9875 | mFlinger->setGameContentType(display, on); |
| 9876 | return binder::Status::ok(); |
| 9877 | } |
| 9878 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9879 | binder::Status SurfaceComposerAIDL::captureDisplay( |
| 9880 | const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9881 | mFlinger->captureDisplay(args, captureListener); |
| 9882 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9883 | } |
| 9884 | |
| 9885 | binder::Status SurfaceComposerAIDL::captureDisplayById( |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9886 | int64_t displayId, const CaptureArgs& args, |
| 9887 | const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9888 | // status_t status; |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9889 | IPCThreadState* ipc = IPCThreadState::self(); |
| 9890 | const int uid = ipc->getCallingUid(); |
| 9891 | if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 9892 | std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId)); |
John Reck | 7e4c487 | 2023-11-14 18:31:03 -0500 | [diff] [blame] | 9893 | mFlinger->captureDisplay(*id, args, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9894 | } else { |
Melody Hsu | 70c2ee6 | 2024-03-29 21:58:45 +0000 | [diff] [blame] | 9895 | ALOGD("Permission denied to captureDisplayById"); |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9896 | invokeScreenCaptureError(PERMISSION_DENIED, captureListener); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9897 | } |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9898 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9899 | } |
| 9900 | |
Chavi Weingarten | f6fb445 | 2024-01-23 21:10:30 +0000 | [diff] [blame] | 9901 | binder::Status SurfaceComposerAIDL::captureLayersSync(const LayerCaptureArgs& args, |
| 9902 | ScreenCaptureResults* outResults) { |
| 9903 | *outResults = mFlinger->captureLayersSync(args); |
| 9904 | return binderStatusFromStatusT(NO_ERROR); |
| 9905 | } |
| 9906 | |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9907 | binder::Status SurfaceComposerAIDL::captureLayers( |
| 9908 | const LayerCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { |
jeimysantiago | 9be7d0c | 2023-07-12 18:37:06 +0000 | [diff] [blame] | 9909 | mFlinger->captureLayers(args, captureListener); |
| 9910 | return binderStatusFromStatusT(NO_ERROR); |
Huihong Luo | f502922 | 2021-12-16 14:33:46 -0800 | [diff] [blame] | 9911 | } |
| 9912 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9913 | binder::Status SurfaceComposerAIDL::overrideHdrTypes(const sp<IBinder>& display, |
| 9914 | const std::vector<int32_t>& hdrTypes) { |
| 9915 | // overrideHdrTypes is used by CTS tests, which acquire the necessary |
| 9916 | // permission dynamically. Don't use the permission cache for this check. |
| 9917 | status_t status = checkAccessPermission(false); |
| 9918 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9919 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9920 | } |
| 9921 | |
| 9922 | std::vector<ui::Hdr> hdrTypesVector; |
| 9923 | for (int32_t i : hdrTypes) { |
| 9924 | hdrTypesVector.push_back(static_cast<ui::Hdr>(i)); |
| 9925 | } |
| 9926 | status = mFlinger->overrideHdrTypes(display, hdrTypesVector); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9927 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9928 | } |
| 9929 | |
| 9930 | binder::Status SurfaceComposerAIDL::onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) { |
| 9931 | status_t status; |
| 9932 | const int uid = IPCThreadState::self()->getCallingUid(); |
| 9933 | if (uid != AID_SYSTEM) { |
| 9934 | status = PERMISSION_DENIED; |
| 9935 | } else { |
| 9936 | status = mFlinger->onPullAtom(atomId, &outPullData->data, &outPullData->success); |
| 9937 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9938 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9939 | } |
| 9940 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9941 | binder::Status SurfaceComposerAIDL::getCompositionPreference(gui::CompositionPreference* outPref) { |
| 9942 | ui::Dataspace dataspace; |
| 9943 | ui::PixelFormat pixelFormat; |
| 9944 | ui::Dataspace wideColorGamutDataspace; |
| 9945 | ui::PixelFormat wideColorGamutPixelFormat; |
| 9946 | status_t status = |
| 9947 | mFlinger->getCompositionPreference(&dataspace, &pixelFormat, &wideColorGamutDataspace, |
| 9948 | &wideColorGamutPixelFormat); |
| 9949 | if (status == NO_ERROR) { |
| 9950 | outPref->defaultDataspace = static_cast<int32_t>(dataspace); |
| 9951 | outPref->defaultPixelFormat = static_cast<int32_t>(pixelFormat); |
| 9952 | outPref->wideColorGamutDataspace = static_cast<int32_t>(wideColorGamutDataspace); |
| 9953 | outPref->wideColorGamutPixelFormat = static_cast<int32_t>(wideColorGamutPixelFormat); |
| 9954 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9955 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9956 | } |
| 9957 | |
| 9958 | binder::Status SurfaceComposerAIDL::getDisplayedContentSamplingAttributes( |
| 9959 | const sp<IBinder>& display, gui::ContentSamplingAttributes* outAttrs) { |
| 9960 | status_t status = checkAccessPermission(); |
| 9961 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9962 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9963 | } |
| 9964 | |
| 9965 | ui::PixelFormat format; |
| 9966 | ui::Dataspace dataspace; |
| 9967 | uint8_t componentMask; |
| 9968 | status = mFlinger->getDisplayedContentSamplingAttributes(display, &format, &dataspace, |
| 9969 | &componentMask); |
| 9970 | if (status == NO_ERROR) { |
| 9971 | outAttrs->format = static_cast<int32_t>(format); |
| 9972 | outAttrs->dataspace = static_cast<int32_t>(dataspace); |
| 9973 | outAttrs->componentMask = static_cast<int8_t>(componentMask); |
| 9974 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9975 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 9976 | } |
| 9977 | |
| 9978 | binder::Status SurfaceComposerAIDL::setDisplayContentSamplingEnabled(const sp<IBinder>& display, |
| 9979 | bool enable, |
| 9980 | int8_t componentMask, |
| 9981 | int64_t maxFrames) { |
| 9982 | status_t status = checkAccessPermission(); |
| 9983 | if (status == OK) { |
| 9984 | status = mFlinger->setDisplayContentSamplingEnabled(display, enable, |
| 9985 | static_cast<uint8_t>(componentMask), |
| 9986 | static_cast<uint64_t>(maxFrames)); |
| 9987 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 9988 | return binderStatusFromStatusT(status); |
| 9989 | } |
| 9990 | |
| 9991 | binder::Status SurfaceComposerAIDL::getDisplayedContentSample(const sp<IBinder>& display, |
| 9992 | int64_t maxFrames, int64_t timestamp, |
| 9993 | gui::DisplayedFrameStats* outStats) { |
| 9994 | if (!outStats) { |
| 9995 | return binderStatusFromStatusT(BAD_VALUE); |
| 9996 | } |
| 9997 | |
| 9998 | status_t status = checkAccessPermission(); |
| 9999 | if (status != OK) { |
| 10000 | return binderStatusFromStatusT(status); |
| 10001 | } |
| 10002 | |
| 10003 | DisplayedFrameStats stats; |
| 10004 | status = mFlinger->getDisplayedContentSample(display, static_cast<uint64_t>(maxFrames), |
| 10005 | static_cast<uint64_t>(timestamp), &stats); |
| 10006 | if (status == NO_ERROR) { |
| 10007 | // convert from ui::DisplayedFrameStats to gui::DisplayedFrameStats |
| 10008 | outStats->numFrames = static_cast<int64_t>(stats.numFrames); |
| 10009 | outStats->component_0_sample.reserve(stats.component_0_sample.size()); |
| 10010 | for (const auto& s : stats.component_0_sample) { |
| 10011 | outStats->component_0_sample.push_back(static_cast<int64_t>(s)); |
| 10012 | } |
| 10013 | outStats->component_1_sample.reserve(stats.component_1_sample.size()); |
| 10014 | for (const auto& s : stats.component_1_sample) { |
| 10015 | outStats->component_1_sample.push_back(static_cast<int64_t>(s)); |
| 10016 | } |
| 10017 | outStats->component_2_sample.reserve(stats.component_2_sample.size()); |
| 10018 | for (const auto& s : stats.component_2_sample) { |
| 10019 | outStats->component_2_sample.push_back(static_cast<int64_t>(s)); |
| 10020 | } |
| 10021 | outStats->component_3_sample.reserve(stats.component_3_sample.size()); |
| 10022 | for (const auto& s : stats.component_3_sample) { |
| 10023 | outStats->component_3_sample.push_back(static_cast<int64_t>(s)); |
| 10024 | } |
| 10025 | } |
| 10026 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10027 | } |
| 10028 | |
| 10029 | binder::Status SurfaceComposerAIDL::getProtectedContentSupport(bool* outSupported) { |
| 10030 | status_t status = mFlinger->getProtectedContentSupport(outSupported); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10031 | return binderStatusFromStatusT(status); |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 10032 | } |
| 10033 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10034 | binder::Status SurfaceComposerAIDL::isWideColorDisplay(const sp<IBinder>& token, |
| 10035 | bool* outIsWideColorDisplay) { |
| 10036 | status_t status = mFlinger->isWideColorDisplay(token, outIsWideColorDisplay); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10037 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10038 | } |
| 10039 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10040 | binder::Status SurfaceComposerAIDL::addRegionSamplingListener( |
| 10041 | const gui::ARect& samplingArea, const sp<IBinder>& stopLayerHandle, |
| 10042 | const sp<gui::IRegionSamplingListener>& listener) { |
| 10043 | status_t status = checkReadFrameBufferPermission(); |
| 10044 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10045 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10046 | } |
| 10047 | android::Rect rect; |
| 10048 | rect.left = samplingArea.left; |
| 10049 | rect.top = samplingArea.top; |
| 10050 | rect.right = samplingArea.right; |
| 10051 | rect.bottom = samplingArea.bottom; |
| 10052 | status = mFlinger->addRegionSamplingListener(rect, stopLayerHandle, listener); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10053 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10054 | } |
| 10055 | |
| 10056 | binder::Status SurfaceComposerAIDL::removeRegionSamplingListener( |
| 10057 | const sp<gui::IRegionSamplingListener>& listener) { |
| 10058 | status_t status = checkReadFrameBufferPermission(); |
| 10059 | if (status == OK) { |
| 10060 | status = mFlinger->removeRegionSamplingListener(listener); |
| 10061 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10062 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10063 | } |
| 10064 | |
| 10065 | binder::Status SurfaceComposerAIDL::addFpsListener(int32_t taskId, |
| 10066 | const sp<gui::IFpsListener>& listener) { |
| 10067 | status_t status = checkReadFrameBufferPermission(); |
| 10068 | if (status == OK) { |
| 10069 | status = mFlinger->addFpsListener(taskId, listener); |
| 10070 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10071 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10072 | } |
| 10073 | |
| 10074 | binder::Status SurfaceComposerAIDL::removeFpsListener(const sp<gui::IFpsListener>& listener) { |
| 10075 | status_t status = checkReadFrameBufferPermission(); |
| 10076 | if (status == OK) { |
| 10077 | status = mFlinger->removeFpsListener(listener); |
| 10078 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10079 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10080 | } |
| 10081 | |
| 10082 | binder::Status SurfaceComposerAIDL::addTunnelModeEnabledListener( |
| 10083 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 10084 | status_t status = checkAccessPermission(); |
| 10085 | if (status == OK) { |
| 10086 | status = mFlinger->addTunnelModeEnabledListener(listener); |
| 10087 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10088 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10089 | } |
| 10090 | |
| 10091 | binder::Status SurfaceComposerAIDL::removeTunnelModeEnabledListener( |
| 10092 | const sp<gui::ITunnelModeEnabledListener>& listener) { |
| 10093 | status_t status = checkAccessPermission(); |
| 10094 | if (status == OK) { |
| 10095 | status = mFlinger->removeTunnelModeEnabledListener(listener); |
| 10096 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10097 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10098 | } |
| 10099 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10100 | binder::Status SurfaceComposerAIDL::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10101 | const gui::DisplayModeSpecs& specs) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10102 | status_t status = checkAccessPermission(); |
| 10103 | if (status == OK) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10104 | status = mFlinger->setDesiredDisplayModeSpecs(displayToken, specs); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10105 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10106 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10107 | } |
| 10108 | |
| 10109 | binder::Status SurfaceComposerAIDL::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, |
| 10110 | gui::DisplayModeSpecs* outSpecs) { |
| 10111 | if (!outSpecs) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10112 | return binderStatusFromStatusT(BAD_VALUE); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10113 | } |
| 10114 | |
| 10115 | status_t status = checkAccessPermission(); |
| 10116 | if (status != OK) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10117 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10118 | } |
| 10119 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 10120 | status = mFlinger->getDesiredDisplayModeSpecs(displayToken, outSpecs); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10121 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10122 | } |
| 10123 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10124 | binder::Status SurfaceComposerAIDL::getDisplayBrightnessSupport(const sp<IBinder>& displayToken, |
| 10125 | bool* outSupport) { |
| 10126 | status_t status = mFlinger->getDisplayBrightnessSupport(displayToken, outSupport); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10127 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10128 | } |
| 10129 | |
| 10130 | binder::Status SurfaceComposerAIDL::setDisplayBrightness(const sp<IBinder>& displayToken, |
| 10131 | const gui::DisplayBrightness& brightness) { |
| 10132 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10133 | if (status == OK) { |
| 10134 | status = mFlinger->setDisplayBrightness(displayToken, brightness); |
| 10135 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10136 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10137 | } |
| 10138 | |
| 10139 | binder::Status SurfaceComposerAIDL::addHdrLayerInfoListener( |
| 10140 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10141 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10142 | if (status == OK) { |
| 10143 | status = mFlinger->addHdrLayerInfoListener(displayToken, listener); |
| 10144 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10145 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10146 | } |
| 10147 | |
| 10148 | binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener( |
| 10149 | const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) { |
| 10150 | status_t status = checkControlDisplayBrightnessPermission(); |
| 10151 | if (status == OK) { |
| 10152 | status = mFlinger->removeHdrLayerInfoListener(displayToken, listener); |
| 10153 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10154 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10155 | } |
| 10156 | |
| 10157 | binder::Status SurfaceComposerAIDL::notifyPowerBoost(int boostId) { |
| 10158 | status_t status = checkAccessPermission(); |
| 10159 | if (status == OK) { |
| 10160 | status = mFlinger->notifyPowerBoost(boostId); |
| 10161 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10162 | return binderStatusFromStatusT(status); |
| 10163 | } |
| 10164 | |
| 10165 | binder::Status SurfaceComposerAIDL::setGlobalShadowSettings(const gui::Color& ambientColor, |
| 10166 | const gui::Color& spotColor, |
| 10167 | float lightPosY, float lightPosZ, |
| 10168 | float lightRadius) { |
| 10169 | status_t status = checkAccessPermission(); |
| 10170 | if (status != OK) { |
| 10171 | return binderStatusFromStatusT(status); |
| 10172 | } |
| 10173 | |
| 10174 | half4 ambientColorHalf = {ambientColor.r, ambientColor.g, ambientColor.b, ambientColor.a}; |
| 10175 | half4 spotColorHalf = {spotColor.r, spotColor.g, spotColor.b, spotColor.a}; |
| 10176 | status = mFlinger->setGlobalShadowSettings(ambientColorHalf, spotColorHalf, lightPosY, |
| 10177 | lightPosZ, lightRadius); |
| 10178 | return binderStatusFromStatusT(status); |
| 10179 | } |
| 10180 | |
| 10181 | binder::Status SurfaceComposerAIDL::getDisplayDecorationSupport( |
| 10182 | const sp<IBinder>& displayToken, std::optional<gui::DisplayDecorationSupport>* outSupport) { |
| 10183 | std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport> support; |
| 10184 | status_t status = mFlinger->getDisplayDecorationSupport(displayToken, &support); |
| 10185 | if (status != NO_ERROR) { |
| 10186 | ALOGE("getDisplayDecorationSupport failed with error %d", status); |
| 10187 | return binderStatusFromStatusT(status); |
| 10188 | } |
| 10189 | |
| 10190 | if (!support || !support.has_value()) { |
| 10191 | outSupport->reset(); |
| 10192 | } else { |
| 10193 | outSupport->emplace(); |
| 10194 | outSupport->value().format = static_cast<int32_t>(support->format); |
| 10195 | outSupport->value().alphaInterpretation = |
| 10196 | static_cast<int32_t>(support->alphaInterpretation); |
| 10197 | } |
| 10198 | |
| 10199 | return binder::Status::ok(); |
| 10200 | } |
| 10201 | |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10202 | binder::Status SurfaceComposerAIDL::setGameModeFrameRateOverride(int32_t uid, float frameRate) { |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10203 | status_t status; |
| 10204 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10205 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10206 | status = mFlinger->setGameModeFrameRateOverride(uid, frameRate); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10207 | } else { |
Andy Yu | 8c2703d | 2023-11-03 11:22:46 -0700 | [diff] [blame] | 10208 | ALOGE("setGameModeFrameRateOverride() permission denied for uid: %d", c_uid); |
| 10209 | status = PERMISSION_DENIED; |
| 10210 | } |
| 10211 | return binderStatusFromStatusT(status); |
| 10212 | } |
| 10213 | |
| 10214 | binder::Status SurfaceComposerAIDL::setGameDefaultFrameRateOverride(int32_t uid, float frameRate) { |
| 10215 | status_t status; |
| 10216 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10217 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
| 10218 | status = mFlinger->setGameDefaultFrameRateOverride(uid, frameRate); |
| 10219 | } else { |
| 10220 | ALOGE("setGameDefaultFrameRateOverride() permission denied for uid: %d", c_uid); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10221 | status = PERMISSION_DENIED; |
| 10222 | } |
| 10223 | return binderStatusFromStatusT(status); |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10224 | } |
| 10225 | |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 10226 | binder::Status SurfaceComposerAIDL::enableRefreshRateOverlay(bool active) { |
| 10227 | mFlinger->sfdo_enableRefreshRateOverlay(active); |
| 10228 | return binder::Status::ok(); |
| 10229 | } |
| 10230 | |
| 10231 | binder::Status SurfaceComposerAIDL::setDebugFlash(int delay) { |
| 10232 | mFlinger->sfdo_setDebugFlash(delay); |
| 10233 | return binder::Status::ok(); |
| 10234 | } |
| 10235 | |
| 10236 | binder::Status SurfaceComposerAIDL::scheduleComposite() { |
| 10237 | mFlinger->sfdo_scheduleComposite(); |
| 10238 | return binder::Status::ok(); |
| 10239 | } |
| 10240 | |
| 10241 | binder::Status SurfaceComposerAIDL::scheduleCommit() { |
| 10242 | mFlinger->sfdo_scheduleCommit(); |
| 10243 | return binder::Status::ok(); |
| 10244 | } |
| 10245 | |
Carlos Martinez Romero | b4ea9e6 | 2023-10-25 21:48:56 +0000 | [diff] [blame] | 10246 | binder::Status SurfaceComposerAIDL::forceClientComposition(bool enabled) { |
| 10247 | mFlinger->sfdo_forceClientComposition(enabled); |
| 10248 | return binder::Status::ok(); |
| 10249 | } |
| 10250 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10251 | binder::Status SurfaceComposerAIDL::updateSmallAreaDetection(const std::vector<int32_t>& appIds, |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10252 | const std::vector<float>& thresholds) { |
| 10253 | status_t status; |
| 10254 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10255 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10256 | if (appIds.size() != thresholds.size()) return binderStatusFromStatusT(BAD_VALUE); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10257 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10258 | std::vector<std::pair<int32_t, float>> mappings; |
| 10259 | const size_t size = appIds.size(); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10260 | mappings.reserve(size); |
| 10261 | for (int i = 0; i < size; i++) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10262 | auto row = std::make_pair(appIds[i], thresholds[i]); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10263 | mappings.push_back(row); |
| 10264 | } |
| 10265 | status = mFlinger->updateSmallAreaDetection(mappings); |
| 10266 | } else { |
| 10267 | ALOGE("updateSmallAreaDetection() permission denied for uid: %d", c_uid); |
| 10268 | status = PERMISSION_DENIED; |
| 10269 | } |
| 10270 | return binderStatusFromStatusT(status); |
| 10271 | } |
| 10272 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10273 | binder::Status SurfaceComposerAIDL::setSmallAreaDetectionThreshold(int32_t appId, float threshold) { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10274 | status_t status; |
| 10275 | const int c_uid = IPCThreadState::self()->getCallingUid(); |
| 10276 | if (c_uid == AID_ROOT || c_uid == AID_SYSTEM) { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 10277 | status = mFlinger->setSmallAreaDetectionThreshold(appId, threshold); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 10278 | } else { |
| 10279 | ALOGE("setSmallAreaDetectionThreshold() permission denied for uid: %d", c_uid); |
| 10280 | status = PERMISSION_DENIED; |
| 10281 | } |
| 10282 | return binderStatusFromStatusT(status); |
| 10283 | } |
| 10284 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10285 | binder::Status SurfaceComposerAIDL::getGpuContextPriority(int32_t* outPriority) { |
| 10286 | *outPriority = mFlinger->getGpuContextPriority(); |
| 10287 | return binder::Status::ok(); |
| 10288 | } |
| 10289 | |
| 10290 | binder::Status SurfaceComposerAIDL::getMaxAcquiredBufferCount(int32_t* buffers) { |
| 10291 | status_t status = mFlinger->getMaxAcquiredBufferCount(buffers); |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10292 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10293 | } |
| 10294 | |
| 10295 | binder::Status SurfaceComposerAIDL::addWindowInfosListener( |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10296 | const sp<gui::IWindowInfosListener>& windowInfosListener, |
| 10297 | gui::WindowInfosListenerInfo* outInfo) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10298 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10299 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10300 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10301 | // TODO(b/270566761) update permissions check so that only system_server and shell can add |
| 10302 | // WindowInfosListeners |
| 10303 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10304 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Patrick Williams | acd2258 | 2023-07-12 13:47:28 -0500 | [diff] [blame] | 10305 | status = mFlinger->addWindowInfosListener(windowInfosListener, outInfo); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10306 | } else { |
| 10307 | status = PERMISSION_DENIED; |
| 10308 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10309 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10310 | } |
| 10311 | |
| 10312 | binder::Status SurfaceComposerAIDL::removeWindowInfosListener( |
| 10313 | const sp<gui::IWindowInfosListener>& windowInfosListener) { |
| 10314 | status_t status; |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10315 | const int pid = IPCThreadState::self()->getCallingPid(); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10316 | const int uid = IPCThreadState::self()->getCallingUid(); |
Patrick Williams | 0525e9b | 2023-02-13 17:24:18 -0600 | [diff] [blame] | 10317 | if (uid == AID_SYSTEM || uid == AID_GRAPHICS || |
| 10318 | checkPermission(sAccessSurfaceFlinger, pid, uid)) { |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10319 | status = mFlinger->removeWindowInfosListener(windowInfosListener); |
| 10320 | } else { |
| 10321 | status = PERMISSION_DENIED; |
| 10322 | } |
Huihong Luo | 3bdef86 | 2022-03-03 11:57:19 -0800 | [diff] [blame] | 10323 | return binderStatusFromStatusT(status); |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10324 | } |
| 10325 | |
Patrick Williams | 090ad06 | 2023-08-08 12:30:10 -0500 | [diff] [blame] | 10326 | binder::Status SurfaceComposerAIDL::getStalledTransactionInfo( |
| 10327 | int pid, std::optional<gui::StalledTransactionInfo>* outInfo) { |
| 10328 | const int callingPid = IPCThreadState::self()->getCallingPid(); |
| 10329 | const int callingUid = IPCThreadState::self()->getCallingUid(); |
| 10330 | if (!checkPermission(sAccessSurfaceFlinger, callingPid, callingUid)) { |
| 10331 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 10332 | } |
| 10333 | |
| 10334 | std::optional<TransactionHandler::StalledTransactionInfo> stalledTransactionInfo; |
| 10335 | status_t status = mFlinger->getStalledTransactionInfo(pid, stalledTransactionInfo); |
| 10336 | if (stalledTransactionInfo) { |
| 10337 | gui::StalledTransactionInfo result; |
| 10338 | result.layerName = String16{stalledTransactionInfo->layerName.c_str()}, |
| 10339 | result.bufferId = stalledTransactionInfo->bufferId, |
| 10340 | result.frameNumber = stalledTransactionInfo->frameNumber, |
| 10341 | outInfo->emplace(std::move(result)); |
| 10342 | } else { |
| 10343 | outInfo->reset(); |
| 10344 | } |
| 10345 | return binderStatusFromStatusT(status); |
| 10346 | } |
| 10347 | |
Ady Abraham | 07d03c4 | 2023-09-27 19:15:08 -0700 | [diff] [blame] | 10348 | binder::Status SurfaceComposerAIDL::getSchedulingPolicy(gui::SchedulingPolicy* outPolicy) { |
| 10349 | return gui::getSchedulingPolicy(outPolicy); |
| 10350 | } |
| 10351 | |
Wenhui Yang | eafc18a | 2024-05-14 17:15:52 +0000 | [diff] [blame] | 10352 | binder::Status SurfaceComposerAIDL::notifyShutdown() { |
| 10353 | TransactionTraceWriter::getInstance().invoke("systemShutdown_", /* overwrite= */ false); |
| 10354 | return ::android::binder::Status::ok(); |
| 10355 | } |
| 10356 | |
Huihong Luo | 07e7236 | 2022-02-14 14:26:04 -0800 | [diff] [blame] | 10357 | status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { |
| 10358 | if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { |
| 10359 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10360 | ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), |
| 10361 | ipc->getCallingUid()); |
| 10362 | return PERMISSION_DENIED; |
| 10363 | } |
| 10364 | return OK; |
| 10365 | } |
| 10366 | |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10367 | status_t SurfaceComposerAIDL::checkControlDisplayBrightnessPermission() { |
| 10368 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10369 | const int pid = ipc->getCallingPid(); |
| 10370 | const int uid = ipc->getCallingUid(); |
Rheygine Medel | 9e9281e | 2022-09-22 10:13:56 -0700 | [diff] [blame] | 10371 | if ((uid != AID_GRAPHICS) && (uid != AID_SYSTEM) && |
Huihong Luo | 37396db | 2022-02-15 10:43:00 -0800 | [diff] [blame] | 10372 | !PermissionCache::checkPermission(sControlDisplayBrightness, pid, uid)) { |
| 10373 | ALOGE("Permission Denial: can't control brightness pid=%d, uid=%d", pid, uid); |
| 10374 | return PERMISSION_DENIED; |
| 10375 | } |
| 10376 | return OK; |
| 10377 | } |
| 10378 | |
Huihong Luo | 02186fb | 2022-02-23 14:21:54 -0800 | [diff] [blame] | 10379 | status_t SurfaceComposerAIDL::checkReadFrameBufferPermission() { |
| 10380 | IPCThreadState* ipc = IPCThreadState::self(); |
| 10381 | const int pid = ipc->getCallingPid(); |
| 10382 | const int uid = ipc->getCallingUid(); |
| 10383 | if ((uid != AID_GRAPHICS) && !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) { |
| 10384 | ALOGE("Permission Denial: can't read framebuffer pid=%d, uid=%d", pid, uid); |
| 10385 | return PERMISSION_DENIED; |
| 10386 | } |
| 10387 | return OK; |
| 10388 | } |
| 10389 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 10390 | void SurfaceFlinger::forceFutureUpdate(int delayInMs) { |
| 10391 | static_cast<void>(mScheduler->scheduleDelayed([&]() { scheduleRepaint(); }, ms2ns(delayInMs))); |
| 10392 | } |
| 10393 | |
Vishnu Nair | 2f65e97 | 2023-04-04 16:36:28 +0000 | [diff] [blame] | 10394 | const DisplayDevice* SurfaceFlinger::getDisplayFromLayerStack(ui::LayerStack layerStack) { |
| 10395 | for (const auto& [_, display] : mDisplays) { |
| 10396 | if (display->getLayerStack() == layerStack) { |
| 10397 | return display.get(); |
| 10398 | } |
| 10399 | } |
| 10400 | return nullptr; |
| 10401 | } |
| 10402 | |
Dominik Laskowski | 9dab343 | 2019-03-27 13:21:10 -0700 | [diff] [blame] | 10403 | } // namespace android |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 10404 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 10405 | #if defined(__gl_h_) |
| 10406 | #error "don't include gl/gl.h in this file" |
| 10407 | #endif |
| 10408 | |
| 10409 | #if defined(__gl2_h_) |
| 10410 | #error "don't include gl2/gl2.h in this file" |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 10411 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 10412 | |
| 10413 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 10414 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |